Skip to content

Commit a39f547

Browse files
authored
fix: deny connections to peers in the right place (#1627)
The previous location would prevent explicit calls to `Connect`, but not implicit connections on `NewStream`. Given that the host calls `Connect` before calling `NewStream`, it's unclear whether or not this would likely be triggered by user code, but we still need to fix it.
1 parent 95e9ff7 commit a39f547

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

p2p/net/swarm/swarm_dial.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,6 @@ func (db *DialBackoff) cleanup() {
220220
// This allows us to use various transport protocols, do NAT traversal/relay,
221221
// etc. to achieve connection.
222222
func (s *Swarm) DialPeer(ctx context.Context, p peer.ID) (network.Conn, error) {
223-
if s.gater != nil && !s.gater.InterceptPeerDial(p) {
224-
log.Debugf("gater disallowed outbound connection to peer %s", p.Pretty())
225-
return nil, &DialError{Peer: p, Cause: ErrGaterDisallowedConnection}
226-
}
227-
228223
// Avoid typed nil issues.
229224
c, err := s.dialPeer(ctx, p)
230225
if err != nil {
@@ -254,6 +249,11 @@ func (s *Swarm) dialPeer(ctx context.Context, p peer.ID) (*Conn, error) {
254249
return conn, nil
255250
}
256251

252+
if s.gater != nil && !s.gater.InterceptPeerDial(p) {
253+
log.Debugf("gater disallowed outbound connection to peer %s", p.Pretty())
254+
return nil, &DialError{Peer: p, Cause: ErrGaterDisallowedConnection}
255+
}
256+
257257
// apply the DialPeer timeout
258258
ctx, cancel := context.WithTimeout(ctx, network.GetDialPeerTimeout(ctx))
259259
defer cancel()

0 commit comments

Comments
 (0)