New flag: IsRootPeer. Rearranged initialization priority (initNetwork should always be last).

This commit is contained in:
Kleissner
2021-04-25 05:34:00 +02:00
parent 35f50230cd
commit 250f60a4b6
3 changed files with 9 additions and 4 deletions

View File

@@ -33,6 +33,7 @@ type rootPeer struct {
var rootPeers map[[btcec.PubKeyBytesLenCompressed]byte]*rootPeer
// initSeedList loads the seed list from the config
// Note: This should be called before any network listening function so that incoming root peers are properly recognized.
func initSeedList() {
rootPeers = make(map[[btcec.PubKeyBytesLenCompressed]byte]*rootPeer)

View File

@@ -88,6 +88,7 @@ type PeerInfo struct {
connectionLatest *Connection // Latest valid connection.
sync.RWMutex // Mutex for access to list of connections.
messageSequence uint32 // Sequence number. Increased with every message.
IsRootPeer bool // Whether the peer is a trusted root peer.
// statistics
StatsPacketSent uint64 // Count of packets sent
@@ -102,17 +103,20 @@ func PeerlistAdd(PublicKey *btcec.PublicKey, connections ...*Connection) (peer *
if len(connections) == 0 {
return nil, false
}
publicKeyCompressed := publicKey2Compressed(PublicKey)
peerlistMutex.Lock()
defer peerlistMutex.Unlock()
peer, ok := peerList[publicKey2Compressed(PublicKey)]
peer, ok := peerList[publicKeyCompressed]
if ok {
return peer, false
}
peer = &PeerInfo{PublicKey: PublicKey, connectionActive: connections, connectionLatest: connections[0], NodeID: publicKey2NodeID(PublicKey), messageSequence: rand.Uint32()}
peerList[publicKey2Compressed(peer.PublicKey)] = peer
_, peer.IsRootPeer = rootPeers[publicKeyCompressed]
peerList[publicKeyCompressed] = peer
// add to Kademlia
nodesDHT.AddNode(&dht.Node{ID: peer.NodeID, Info: peer})

View File

@@ -11,11 +11,11 @@ func Init() {
initPeerID()
initKademlia()
initMessageSequence()
initSeedList()
initMulticastIPv6()
initBroadcastIPv4()
initNetwork()
initSeedList()
initStore()
initNetwork()
}
// Connect starts bootstrapping and local peer discovery.