X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fnode.go;h=0587fbc2b90c2234d2911c80e2adc8ebab9e2e3c;hb=2e22bda93fdf8f2f84e4d19b3f1d46318b497139;hp=999af3d9b3bc88e5624669e004809c62bba5b2be;hpb=9cf466a3b95f9b95a7bce1c1cc2b5c970f9fa6a6;p=nncp.git diff --git a/src/node.go b/src/node.go index 999af3d..0587fbc 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-2020 Sergey Matveev +Copyright (C) 2016-2023 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,6 +20,7 @@ package nncp import ( "crypto/rand" "errors" + "fmt" "sync" "time" @@ -29,6 +30,8 @@ import ( "golang.org/x/crypto/nacl/box" ) +const DummyB32Id = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + type NodeId [blake2b.Size256]byte func (id NodeId) String() string { @@ -47,6 +50,8 @@ type Node struct { FreqChunked int64 FreqMinSize int64 FreqMaxSize int64 + ACKNice uint8 + ACKMinSize int64 Via []*NodeId Addrs map[string]string RxRate int @@ -114,13 +119,21 @@ func (nodeOur *NodeOur) Their() *Node { func NodeIdFromString(raw string) (*NodeId, error) { 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 }