/*
NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2020 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2023 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
import (
"crypto/rand"
"errors"
+ "fmt"
"sync"
"time"
"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 {
}
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
}