]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cypherpunks.ru/nncp/node.go
Merge branch 'develop'
[nncp.git] / src / cypherpunks.ru / nncp / node.go
index 8b3a012732cdea009e647511faa0921eaa2caf2d..f1fb79ff5bdf8df4b7bca8f44bdc1eb08e3b4802 100644 (file)
@@ -1,6 +1,6 @@
 /*
 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2017 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2018 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -21,8 +21,10 @@ package nncp
 import (
        "crypto/rand"
        "errors"
+       "sync"
 
        "github.com/flynn/noise"
+       "github.com/gorhill/cronexpr"
        "golang.org/x/crypto/blake2b"
        "golang.org/x/crypto/ed25519"
        "golang.org/x/crypto/nacl/box"
@@ -35,16 +37,24 @@ func (id NodeId) String() string {
 }
 
 type Node struct {
-       Name     string
-       Id       *NodeId
-       ExchPub  *[32]byte
-       SignPub  ed25519.PublicKey
-       NoisePub *[32]byte
-       Sendmail []string
-       Incoming *string
-       Freq     *string
-       Via      []*NodeId
-       Addrs    map[string]string
+       Name           string
+       Id             *NodeId
+       ExchPub        *[32]byte
+       SignPub        ed25519.PublicKey
+       NoisePub       *[32]byte
+       Exec           map[string][]string
+       Incoming       *string
+       Freq           *string
+       FreqChunked    int64
+       FreqMinSize    int64
+       Via            []*NodeId
+       Addrs          map[string]string
+       OnlineDeadline uint
+       MaxOnlineTime  uint
+       Calls          []*Call
+
+       Busy bool
+       sync.Mutex
 }
 
 type NodeOur struct {
@@ -57,6 +67,15 @@ type NodeOur struct {
        NoisePrv *[32]byte
 }
 
+type Call struct {
+       Cron           *cronexpr.Expression
+       Nice           uint8
+       Xx             TRxTx
+       Addr           *string
+       OnlineDeadline uint
+       MaxOnlineTime  uint
+}
+
 func NewNodeGenerate() (*NodeOur, error) {
        exchPub, exchPrv, err := box.GenerateKey(rand.Reader)
        if err != nil {
@@ -66,7 +85,10 @@ func NewNodeGenerate() (*NodeOur, error) {
        if err != nil {
                return nil, err
        }
-       noiseKey := noise.DH25519.GenerateKeypair(rand.Reader)
+       noiseKey, err := noise.DH25519.GenerateKeypair(rand.Reader)
+       if err != nil {
+               return nil, err
+       }
        noisePub := new([32]byte)
        noisePrv := new([32]byte)
        copy(noisePrv[:], noiseKey.Private)