From c1ccc3c344ff5d85ecbbc7e2e3408c4545ba400b Mon Sep 17 00:00:00 2001 From: Kleissner Date: Wed, 7 Jul 2021 02:40:07 +0200 Subject: [PATCH] Export PublicKey2NodeID --- Command Traverse.go | 2 +- Message Encoding.go | 2 +- Peer ID.go | 13 ++++++------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Command Traverse.go b/Command Traverse.go index 2e6b26e..727b638 100644 --- a/Command Traverse.go +++ b/Command Traverse.go @@ -98,7 +98,7 @@ func (peer *PeerInfo) cmdTraverseReceive(msg *MessageTraverse) { // process the packet and create a virtual peer raw := &MessageRaw{SenderPublicKey: senderPublicKey, PacketRaw: *decoded, connection: nil} - peerV := &PeerInfo{PublicKey: senderPublicKey, connectionActive: nil, connectionLatest: nil, NodeID: publicKey2NodeID(senderPublicKey), messageSequence: rand.Uint32(), isVirtual: true, targetAddresses: addresses} + peerV := &PeerInfo{PublicKey: senderPublicKey, connectionActive: nil, connectionLatest: nil, NodeID: PublicKey2NodeID(senderPublicKey), messageSequence: rand.Uint32(), isVirtual: true, targetAddresses: addresses} // process it! switch decoded.Command { diff --git a/Message Encoding.go b/Message Encoding.go index 89a46e7..2d49338 100644 --- a/Message Encoding.go +++ b/Message Encoding.go @@ -437,7 +437,7 @@ func decodePeerRecord(data []byte, count int) (hash2Peers []Hash2Peer, read int, return nil, 0, false } - peer.NodeID = publicKey2NodeID(peer.PublicKey) + peer.NodeID = PublicKey2NodeID(peer.PublicKey) if reason == 0 { // Peer was returned because it is close to the requested hash hash2Peer.Closest = append(hash2Peer.Closest, peer) diff --git a/Peer ID.go b/Peer ID.go index 5116944..6a0eabb 100644 --- a/Peer ID.go +++ b/Peer ID.go @@ -31,7 +31,7 @@ func initPeerID() { configPK, err := hex.DecodeString(config.PrivateKey) if err == nil { peerPrivateKey, peerPublicKey = btcec.PrivKeyFromBytes(btcec.S256(), configPK) - nodeID = publicKey2NodeID(peerPublicKey) + nodeID = PublicKey2NodeID(peerPublicKey) if config.AutoUpdateSeedList { configUpdateSeedList() @@ -50,7 +50,7 @@ func initPeerID() { Filters.LogError("initPeerID", "generating public-private key pairs: %s\n", err.Error()) os.Exit(1) } - nodeID = publicKey2NodeID(peerPublicKey) + nodeID = PublicKey2NodeID(peerPublicKey) // save the newly generated private key into the config config.PrivateKey = hex.EncodeToString(peerPrivateKey.Serialize()) @@ -126,7 +126,7 @@ func PeerlistAdd(PublicKey *btcec.PublicKey, connections ...*Connection) (peer * return peer, false } - peer = &PeerInfo{PublicKey: PublicKey, connectionActive: connections, connectionLatest: connections[0], NodeID: publicKey2NodeID(PublicKey), messageSequence: rand.Uint32()} + peer = &PeerInfo{PublicKey: PublicKey, connectionActive: connections, connectionLatest: connections[0], NodeID: PublicKey2NodeID(PublicKey), messageSequence: rand.Uint32()} _, peer.IsRootPeer = rootPeers[publicKeyCompressed] peerList[publicKeyCompressed] = peer @@ -196,9 +196,8 @@ func publicKey2Compressed(publicKey *btcec.PublicKey) [btcec.PubKeyBytesLenCompr return key } -// publicKey2NodeID translates the Public Key into the node ID used in the Kademlia network. -// This is very important for lookup of data in the DHT. -func publicKey2NodeID(publicKey *btcec.PublicKey) (nodeID []byte) { +// PublicKey2NodeID translates the Public Key into the node ID used in the Kademlia network. +func PublicKey2NodeID(publicKey *btcec.PublicKey) (nodeID []byte) { return hashData(publicKey.SerializeCompressed()) } @@ -222,7 +221,7 @@ func records2Nodes(records []PeerRecord, peerSource *PeerInfo) (nodes []*dht.Nod continue } - peer = &PeerInfo{PublicKey: record.PublicKey, connectionActive: nil, connectionLatest: nil, NodeID: publicKey2NodeID(record.PublicKey), messageSequence: rand.Uint32(), isVirtual: true, targetAddresses: addresses, traversePeer: peerSource} + peer = &PeerInfo{PublicKey: record.PublicKey, connectionActive: nil, connectionLatest: nil, NodeID: PublicKey2NodeID(record.PublicKey), messageSequence: rand.Uint32(), isVirtual: true, targetAddresses: addresses, traversePeer: peerSource} } nodes = append(nodes, &dht.Node{ID: peer.NodeID, LastSeen: record.LastContactT, Info: peer})