@@ -16,11 +16,12 @@ import (
16
16
)
17
17
18
18
type peerTracker struct {
19
- host host.Host
20
- connGater * conngater.BasicConnectionGater
21
- metrics * exchangeMetrics
22
19
protocolID protocol.ID
23
- peerLk sync.RWMutex
20
+
21
+ host host.Host
22
+ connGater * conngater.BasicConnectionGater
23
+
24
+ peerLk sync.RWMutex
24
25
// trackedPeers contains active peers that we can request to.
25
26
// we cache the peer once they disconnect,
26
27
// so we can guarantee that peerQueue will only contain active peers
@@ -30,6 +31,8 @@ type peerTracker struct {
30
31
// good peers during garbage collection
31
32
pidstore PeerIDStore
32
33
34
+ metrics * exchangeMetrics
35
+
33
36
ctx context.Context
34
37
cancel context.CancelFunc
35
38
// done is used to gracefully stop the peerTracker.
@@ -135,11 +138,13 @@ func (p *peerTracker) track() {
135
138
if network .NotConnected == ev .Connectedness {
136
139
p .disconnected (ev .Peer )
137
140
}
138
- case subscription := <- identifySub .Out ():
139
- ev := subscription .(event.EvtPeerIdentificationCompleted )
140
- p .connected (ev .Peer )
141
- case subscription := <- protocolSub .Out ():
142
- ev := subscription .(event.EvtPeerProtocolsUpdated )
141
+ case identSubscription := <- identifySub .Out ():
142
+ ev := identSubscription .(event.EvtPeerIdentificationCompleted )
143
+ if slices .Contains (ev .Protocols , p .protocolID ) {
144
+ p .connected (ev .Peer )
145
+ }
146
+ case protocolSubscription := <- protocolSub .Out ():
147
+ ev := protocolSubscription .(event.EvtPeerProtocolsUpdated )
143
148
if slices .Contains (ev .Removed , p .protocolID ) {
144
149
p .disconnected (ev .Peer )
145
150
break
@@ -173,15 +178,6 @@ func (p *peerTracker) connected(pID libpeer.ID) {
173
178
return
174
179
}
175
180
176
- // check that peer supports our protocol id.
177
- protocol , err := p .host .Peerstore ().SupportsProtocols (pID , p .protocolID )
178
- if err != nil {
179
- return
180
- }
181
- if ! slices .Contains (protocol , p .protocolID ) {
182
- return
183
- }
184
-
185
181
for _ , c := range p .host .Network ().ConnsToPeer (pID ) {
186
182
// check if connection is short-termed and skip this peer
187
183
if c .Stat ().Limited {
0 commit comments