2018-06-22 14:33:57 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package kademlia
|
|
|
|
|
|
|
|
import base58 "github.com/jbenet/go-base58"
|
|
|
|
|
|
|
|
// NodeID is the unique identifer of a Node in the overlay network
|
|
|
|
type NodeID string
|
|
|
|
|
|
|
|
// String transforms the nodeID to a string type
|
|
|
|
func (n *NodeID) String() string {
|
|
|
|
return string(*n)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bytes transforms the nodeID to type []byte
|
|
|
|
func (n *NodeID) Bytes() []byte {
|
|
|
|
return []byte(*n)
|
|
|
|
}
|
|
|
|
|
|
|
|
// StringToNodeID trsansforms a string to a NodeID
|
|
|
|
func StringToNodeID(s string) *NodeID {
|
|
|
|
n := NodeID(s)
|
|
|
|
return &n
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewID returns a pointer to a newly intialized NodeID
|
2018-08-17 20:11:46 +01:00
|
|
|
// TODO@ASK: this should be removed; superseded by `CASetupConfig.Create` / `IdentitySetupConfig.Create`
|
2018-06-22 14:33:57 +01:00
|
|
|
func NewID() (*NodeID, error) {
|
|
|
|
b, err := newID()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
bb := NodeID(base58.Encode(b))
|
|
|
|
return &bb, nil
|
|
|
|
}
|