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.
This commit is contained in:
Steven Allen 2022-07-01 11:05:53 -07:00 committed by GitHub
parent 95e9ff7568
commit a39f547b66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -220,11 +220,6 @@ func (db *DialBackoff) cleanup() {
// This allows us to use various transport protocols, do NAT traversal/relay,
// etc. to achieve connection.
func (s *Swarm) DialPeer(ctx context.Context, p peer.ID) (network.Conn, error) {
if s.gater != nil && !s.gater.InterceptPeerDial(p) {
log.Debugf("gater disallowed outbound connection to peer %s", p.Pretty())
return nil, &DialError{Peer: p, Cause: ErrGaterDisallowedConnection}
}
// Avoid typed nil issues.
c, err := s.dialPeer(ctx, p)
if err != nil {
@ -254,6 +249,11 @@ func (s *Swarm) dialPeer(ctx context.Context, p peer.ID) (*Conn, error) {
return conn, nil
}
if s.gater != nil && !s.gater.InterceptPeerDial(p) {
log.Debugf("gater disallowed outbound connection to peer %s", p.Pretty())
return nil, &DialError{Peer: p, Cause: ErrGaterDisallowedConnection}
}
// apply the DialPeer timeout
ctx, cancel := context.WithTimeout(ctx, network.GetDialPeerTimeout(ctx))
defer cancel()