@@ -18,12 +18,13 @@ import (
1818)
1919
2020type peerRegistry struct {
21- underlays map [string ]libp2ppeer.ID // map overlay address to underlay peer id
22- overlays map [libp2ppeer.ID ]swarm.Address // map underlay peer id to overlay address
23- full map [libp2ppeer.ID ]bool // map to track whether a node is full or light node (true=full)
24- connections map [libp2ppeer.ID ]map [network.Conn ]struct {} // list of connections for safe removal on Disconnect notification
25- streams map [libp2ppeer.ID ]map [network.Stream ]context.CancelFunc
26- mu sync.RWMutex
21+ underlays map [string ]libp2ppeer.ID // map overlay address to underlay peer id
22+ overlays map [libp2ppeer.ID ]swarm.Address // map underlay peer id to overlay address
23+ full map [libp2ppeer.ID ]bool // map to track whether a node is full or light node (true=full)
24+ bee260Compatibility map [libp2ppeer.ID ]bool // map to track bee260 backward compatibility
25+ connections map [libp2ppeer.ID ]map [network.Conn ]struct {} // list of connections for safe removal on Disconnect notification
26+ streams map [libp2ppeer.ID ]map [network.Stream ]context.CancelFunc
27+ mu sync.RWMutex
2728
2829 //nolint:misspell
2930 disconnecter disconnecter // peerRegistry notifies libp2p on peer disconnection
@@ -36,11 +37,12 @@ type disconnecter interface {
3637
3738func newPeerRegistry () * peerRegistry {
3839 return & peerRegistry {
39- underlays : make (map [string ]libp2ppeer.ID ),
40- overlays : make (map [libp2ppeer.ID ]swarm.Address ),
41- full : make (map [libp2ppeer.ID ]bool ),
42- connections : make (map [libp2ppeer.ID ]map [network.Conn ]struct {}),
43- streams : make (map [libp2ppeer.ID ]map [network.Stream ]context.CancelFunc ),
40+ underlays : make (map [string ]libp2ppeer.ID ),
41+ overlays : make (map [libp2ppeer.ID ]swarm.Address ),
42+ full : make (map [libp2ppeer.ID ]bool ),
43+ bee260Compatibility : make (map [libp2ppeer.ID ]bool ),
44+ connections : make (map [libp2ppeer.ID ]map [network.Conn ]struct {}),
45+ streams : make (map [libp2ppeer.ID ]map [network.Stream ]context.CancelFunc ),
4446
4547 Notifiee : new (network.NoopNotifiee ),
4648 }
@@ -81,6 +83,7 @@ func (r *peerRegistry) Disconnected(_ network.Network, c network.Conn) {
8183 }
8284 delete (r .streams , peerID )
8385 delete (r .full , peerID )
86+ delete (r .bee260Compatibility , peerID )
8487 r .mu .Unlock ()
8588 r .disconnecter .disconnected (overlay )
8689
@@ -176,6 +179,19 @@ func (r *peerRegistry) fullnode(peerID libp2ppeer.ID) (bool, bool) {
176179 return full , found
177180}
178181
182+ func (r * peerRegistry ) bee260 (peerID libp2ppeer.ID ) (compat , found bool ) {
183+ r .mu .RLock ()
184+ defer r .mu .RUnlock ()
185+ compat , found = r .bee260Compatibility [peerID ]
186+ return compat , found
187+ }
188+
189+ func (r * peerRegistry ) setBee260 (peerID libp2ppeer.ID , compat bool ) {
190+ r .mu .Lock ()
191+ defer r .mu .Unlock ()
192+ r .bee260Compatibility [peerID ] = compat
193+ }
194+
179195func (r * peerRegistry ) isConnected (peerID libp2ppeer.ID , remoteAddr ma.Multiaddr ) (swarm.Address , bool ) {
180196 if remoteAddr == nil {
181197 return swarm .ZeroAddress , false
@@ -217,6 +233,7 @@ func (r *peerRegistry) remove(overlay swarm.Address) (found, full bool, peerID l
217233 delete (r .streams , peerID )
218234 full = r .full [peerID ]
219235 delete (r .full , peerID )
236+ delete (r .bee260Compatibility , peerID )
220237 r .mu .Unlock ()
221238
222239 return found , full , peerID
0 commit comments