@@ -109,34 +109,32 @@ func (n *streamManager) dispatch(ctx context.Context, remotePeer peer.ID, stream
109
109
}
110
110
}
111
111
112
- // Connected is called when a connection is opened
113
- // for both incoming (listener -> addConn) and outgoing (dialer -> addConn) connections.
114
- func (n * streamManager ) Connected (net network.Network , conn network.Conn ) {
115
- }
116
-
117
112
func (n * streamManager ) peerWatcher (ctx context.Context , sub event.Subscription ) {
118
113
defer sub .Close ()
119
114
for e := range sub .Out () {
120
115
evt := e .(event.EvtPeerIdentificationCompleted )
121
116
conn := evt .Conn
122
- if conn .Stat ().Direction == network .DirInbound && ! n .allowIncomingGossip {
123
- n .log .Debugf ("ignoring incoming connection from %s" , conn .RemotePeer ().String ())
124
- continue
125
- }
126
117
127
118
remotePeer := conn .RemotePeer ()
128
119
localPeer := n .host .ID ()
129
120
121
+ if conn .Stat ().Direction == network .DirInbound && ! n .allowIncomingGossip {
122
+ n .log .Debugf ("%s: ignoring incoming connection from %s" , localPeer .String (), remotePeer .String ())
123
+ continue
124
+ }
125
+
130
126
// ensure that only one of the peers initiates the stream
131
127
if localPeer > remotePeer {
132
- return
128
+ n .log .Debugf ("%s: ignoring a lesser peer ID %s" , localPeer .String (), remotePeer .String ())
129
+ continue
133
130
}
134
131
135
132
n .streamsLock .Lock ()
136
133
_ , ok := n .streams [remotePeer ]
137
134
if ok {
138
135
n .streamsLock .Unlock ()
139
- return // there's already an active stream with this peer for our protocol
136
+ n .log .Debugf ("%s: already have a stream to/from %s" , localPeer .String (), remotePeer .String ())
137
+ continue // there's already an active stream with this peer for our protocol
140
138
}
141
139
142
140
protos := evt .Protocols
@@ -147,9 +145,9 @@ func (n *streamManager) peerWatcher(ctx context.Context, sub event.Subscription)
147
145
148
146
stream , err := n .host .NewStream (n .ctx , remotePeer , targetProto )
149
147
if err != nil {
150
- n .log .Infof ("Failed to open stream to %s (%s): %v" , remotePeer , conn .RemoteMultiaddr ().String (), err )
148
+ n .log .Infof ("%s: failed to open stream to %s (%s): %v" , localPeer . String () , remotePeer , conn .RemoteMultiaddr ().String (), err )
151
149
n .streamsLock .Unlock ()
152
- return
150
+ continue
153
151
}
154
152
n .streams [remotePeer ] = stream
155
153
n .streamsLock .Unlock ()
@@ -158,7 +156,7 @@ func (n *streamManager) peerWatcher(ctx context.Context, sub event.Subscription)
158
156
if handler , ok := n .handlers [targetProto ]; ok {
159
157
handler (n .ctx , remotePeer , stream , incoming )
160
158
} else {
161
- n .log .Errorf ("No handler for protocol %s, peer %s" , targetProto , remotePeer )
159
+ n .log .Errorf ("%s: no handler for protocol %s, peer %s" , localPeer . String () , targetProto , remotePeer )
162
160
_ = stream .Reset ()
163
161
}
164
162
@@ -170,6 +168,11 @@ func (n *streamManager) peerWatcher(ctx context.Context, sub event.Subscription)
170
168
}
171
169
}
172
170
171
+ // Connected is called when a connection is opened
172
+ // for both incoming (listener -> addConn) and outgoing (dialer -> addConn) connections.
173
+ func (n * streamManager ) Connected (net network.Network , conn network.Conn ) {
174
+ }
175
+
173
176
// Disconnected is called when a connection is closed
174
177
func (n * streamManager ) Disconnected (net network.Network , conn network.Conn ) {
175
178
n .streamsLock .Lock ()
0 commit comments