mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-16 18:37:51 +01:00
Refactoring code. Use protocol.HashData and HashSize. Move PublicKey2NodeID into protocol.
This commit is contained in:
13
Peer ID.go
13
Peer ID.go
@@ -32,7 +32,7 @@ func initPeerID() {
|
||||
configPK, err := hex.DecodeString(config.PrivateKey)
|
||||
if err == nil {
|
||||
peerPrivateKey, peerPublicKey = btcec.PrivKeyFromBytes(btcec.S256(), configPK)
|
||||
nodeID = PublicKey2NodeID(peerPublicKey)
|
||||
nodeID = protocol.PublicKey2NodeID(peerPublicKey)
|
||||
|
||||
if config.AutoUpdateSeedList {
|
||||
configUpdateSeedList()
|
||||
@@ -51,7 +51,7 @@ func initPeerID() {
|
||||
Filters.LogError("initPeerID", "generating public-private key pairs: %s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
nodeID = PublicKey2NodeID(peerPublicKey)
|
||||
nodeID = protocol.PublicKey2NodeID(peerPublicKey)
|
||||
|
||||
// save the newly generated private key into the config
|
||||
config.PrivateKey = hex.EncodeToString(peerPrivateKey.Serialize())
|
||||
@@ -127,7 +127,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: protocol.PublicKey2NodeID(PublicKey), messageSequence: rand.Uint32()}
|
||||
_, peer.IsRootPeer = rootPeers[publicKeyCompressed]
|
||||
|
||||
peerList[publicKeyCompressed] = peer
|
||||
@@ -197,11 +197,6 @@ func publicKey2Compressed(publicKey *btcec.PublicKey) [btcec.PubKeyBytesLenCompr
|
||||
return key
|
||||
}
|
||||
|
||||
// PublicKey2NodeID translates the Public Key into the node ID used in the Kademlia network.
|
||||
func PublicKey2NodeID(publicKey *btcec.PublicKey) (nodeID []byte) {
|
||||
return protocol.HashData(publicKey.SerializeCompressed())
|
||||
}
|
||||
|
||||
// records2Nodes translates infoPeer structures to nodes. If the reported nodes are not in the peer table, it will create temporary PeerInfo structures.
|
||||
// LastContact is passed on in the Node.LastSeen field.
|
||||
func records2Nodes(records []PeerRecord, peerSource *PeerInfo) (nodes []*dht.Node) {
|
||||
@@ -222,7 +217,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: protocol.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})
|
||||
|
||||
Reference in New Issue
Block a user