mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-08 14:21:14 +00:00
p2p: rename PubKeyToID to NodeIDFromPubKey
This commit is contained in:
committed by
Erik Grinaker
parent
b4ce1de44a
commit
91bef75f62
16
p2p/key.go
16
p2p/key.go
@@ -21,6 +21,12 @@ type NodeID string
|
||||
// FIXME: support other length addresses?
|
||||
const NodeIDByteLength = crypto.AddressSize
|
||||
|
||||
// NodeIDFromPubKey returns the noe ID corresponding to the given PubKey. It's
|
||||
// the hex-encoding of the pubKey.Address().
|
||||
func NodeIDFromPubKey(pubKey crypto.PubKey) NodeID {
|
||||
return NodeID(hex.EncodeToString(pubKey.Address()))
|
||||
}
|
||||
|
||||
// Bytes converts the node ID to it's binary byte representation.
|
||||
func (id NodeID) Bytes() ([]byte, error) {
|
||||
bz, err := hex.DecodeString(string(id))
|
||||
@@ -76,12 +82,6 @@ func (nodeKey NodeKey) SaveAs(filePath string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// PubKeyToID returns the ID corresponding to the given PubKey.
|
||||
// It's the hex-encoding of the pubKey.Address().
|
||||
func PubKeyToID(pubKey crypto.PubKey) NodeID {
|
||||
return NodeID(hex.EncodeToString(pubKey.Address()))
|
||||
}
|
||||
|
||||
// LoadOrGenNodeKey attempts to load the NodeKey from the given filePath. If
|
||||
// the file does not exist, it generates and saves a new NodeKey.
|
||||
func LoadOrGenNodeKey(filePath string) (NodeKey, error) {
|
||||
@@ -106,7 +106,7 @@ func LoadOrGenNodeKey(filePath string) (NodeKey, error) {
|
||||
func GenNodeKey() NodeKey {
|
||||
privKey := ed25519.GenPrivKey()
|
||||
return NodeKey{
|
||||
ID: PubKeyToID(privKey.PubKey()),
|
||||
ID: NodeIDFromPubKey(privKey.PubKey()),
|
||||
PrivKey: privKey,
|
||||
}
|
||||
}
|
||||
@@ -122,6 +122,6 @@ func LoadNodeKey(filePath string) (NodeKey, error) {
|
||||
if err != nil {
|
||||
return NodeKey{}, err
|
||||
}
|
||||
nodeKey.ID = PubKeyToID(nodeKey.PubKey())
|
||||
nodeKey.ID = NodeIDFromPubKey(nodeKey.PubKey())
|
||||
return nodeKey, nil
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ func newPeerConn(outbound, persistent bool, conn Connection) peerConn {
|
||||
|
||||
// ID only exists for SecretConnection.
|
||||
func (pc peerConn) ID() NodeID {
|
||||
return PubKeyToID(pc.conn.PubKey())
|
||||
return NodeIDFromPubKey(pc.conn.PubKey())
|
||||
}
|
||||
|
||||
// Return the IP from the connection RemoteAddr
|
||||
|
||||
@@ -81,7 +81,7 @@ func createOutboundPeerAndPerformHandshake(
|
||||
{ID: testCh, Priority: 1},
|
||||
}
|
||||
pk := ed25519.GenPrivKey()
|
||||
ourNodeInfo := testNodeInfo(PubKeyToID(pk.PubKey()), "host_peer")
|
||||
ourNodeInfo := testNodeInfo(NodeIDFromPubKey(pk.PubKey()), "host_peer")
|
||||
transport := NewMConnTransport(log.TestingLogger(), ourNodeInfo, pk, mConfig)
|
||||
transport.SetChannelDescriptors(chDescs)
|
||||
reactorsByCh := map[byte]Reactor{testCh: NewTestReactor(chDescs, true)}
|
||||
@@ -154,7 +154,7 @@ func (rp *remotePeer) Addr() *NetAddress {
|
||||
}
|
||||
|
||||
func (rp *remotePeer) ID() NodeID {
|
||||
return PubKeyToID(rp.PrivKey.PubKey())
|
||||
return NodeIDFromPubKey(rp.PrivKey.PubKey())
|
||||
}
|
||||
|
||||
func (rp *remotePeer) Start() {
|
||||
@@ -167,7 +167,7 @@ func (rp *remotePeer) Start() {
|
||||
golog.Fatalf("net.Listen tcp :0: %+v", e)
|
||||
}
|
||||
rp.listener = l
|
||||
rp.addr = NewNetAddress(PubKeyToID(rp.PrivKey.PubKey()), l.Addr())
|
||||
rp.addr = NewNetAddress(NodeIDFromPubKey(rp.PrivKey.PubKey()), l.Addr())
|
||||
if rp.channels == nil {
|
||||
rp.channels = []byte{testCh}
|
||||
}
|
||||
|
||||
@@ -466,7 +466,7 @@ func newMConnConnection(
|
||||
|
||||
// For outgoing conns, ensure connection key matches dialed key.
|
||||
if expectPeerID != "" {
|
||||
peerID := PubKeyToID(c.PubKey())
|
||||
peerID := NodeIDFromPubKey(c.PubKey())
|
||||
if expectPeerID != peerID {
|
||||
err = ErrRejected{
|
||||
conn: tcpConn,
|
||||
|
||||
@@ -65,7 +65,7 @@ func (n *MemoryNetwork) CreateTransport(
|
||||
// Transport.Endpoints().
|
||||
func (n *MemoryNetwork) GenerateTransport() *MemoryTransport {
|
||||
privKey := ed25519.GenPrivKey()
|
||||
nodeID := PubKeyToID(privKey.PubKey())
|
||||
nodeID := NodeIDFromPubKey(privKey.PubKey())
|
||||
nodeInfo := NodeInfo{
|
||||
NodeID: nodeID,
|
||||
ListenAddr: fmt.Sprintf("%v:%v", MemoryProtocol, nodeID),
|
||||
|
||||
Reference in New Issue
Block a user