X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fnode.go;h=10577b17289cbee491496b2c7653459fc5c8e9d7;hb=0ed43747344437800094782e78313b1c41c2cc1c;hp=dd2442b06d52516627d325056b01747ede14de41;hpb=d529dd1ff29a8dc0a2d22a75e044e9162a0afb78;p=nncp.git diff --git a/src/node.go b/src/node.go index dd2442b..10577b1 100644 --- a/src/node.go +++ b/src/node.go @@ -1,6 +1,6 @@ /* NNCP -- Node to Node copy, utilities for store-and-forward data exchange -Copyright (C) 2016-2019 Sergey Matveev +Copyright (C) 2016-2022 Sergey Matveev 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 @@ -20,7 +20,9 @@ package nncp import ( "crypto/rand" "errors" + "fmt" "sync" + "time" "github.com/flynn/noise" "golang.org/x/crypto/blake2b" @@ -28,10 +30,12 @@ import ( "golang.org/x/crypto/nacl/box" ) +const DummyB32Id = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + type NodeId [blake2b.Size256]byte func (id NodeId) String() string { - return ToBase32(id[:]) + return Base32Codec.EncodeToString(id[:]) } type Node struct { @@ -45,12 +49,13 @@ type Node struct { FreqPath *string FreqChunked int64 FreqMinSize int64 + FreqMaxSize int64 Via []*NodeId Addrs map[string]string RxRate int TxRate int - OnlineDeadline uint - MaxOnlineTime uint + OnlineDeadline time.Duration + MaxOnlineTime time.Duration Calls []*Call Busy bool @@ -105,19 +110,28 @@ func (nodeOur *NodeOur) Their() *Node { ExchPub: nodeOur.ExchPub, SignPub: nodeOur.SignPub, FreqChunked: MaxFileSize, + FreqMaxSize: MaxFileSize, } } func NodeIdFromString(raw string) (*NodeId, error) { - decoded, err := FromBase32(raw) + decoded, err := Base32Codec.DecodeString(raw) if err != nil { - return nil, err + return nil, fmt.Errorf("Can not parse node: %s: %s", raw, err) } if len(decoded) != blake2b.Size256 { return nil, errors.New("Invalid node id size") } - buf := new([blake2b.Size256]byte) - copy(buf[:], decoded) - nodeId := NodeId(*buf) - return &nodeId, nil + nodeId := new(NodeId) + copy(nodeId[:], decoded) + return nodeId, nil +} + +func (ctx *Ctx) NodeName(id *NodeId) string { + idS := id.String() + node, err := ctx.FindNode(idS) + if err == nil { + return node.Name + } + return idS }