]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/node.go
Mode NodeName to appropriate place
[nncp.git] / src / node.go
index 999af3d9b3bc88e5624669e004809c62bba5b2be..f5bea183cce561b972dc009f4d440a0479082d0e 100644 (file)
@@ -1,6 +1,6 @@
 /*
 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2020 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2021 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
@@ -119,8 +119,16 @@ func NodeIdFromString(raw string) (*NodeId, error) {
        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
 }