X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fnode.go;h=aabf8477535f831cd7da681f2f7ea3dd01f65820;hb=ab7c7eca0e53661f0ba904c2a6ba752990bea367;hp=c965796ead59c38de3c774ef6968d41fe66a3c12;hpb=1c773d7a2acd7fef4b7b1567b59e1601a79d55fe;p=nncp.git diff --git a/src/node.go b/src/node.go index c965796..aabf847 100644 --- a/src/node.go +++ b/src/node.go @@ -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 { @@ -114,13 +117,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 }