-
Notifications
You must be signed in to change notification settings - Fork 37
implement connection gating support: intercept peer, address dials, upgraded conns #201
Conversation
swarm.go
Outdated
if s.Filters.AddrBlocked(raddr) { | ||
tc.Close() | ||
return nil, ErrAddrFiltered | ||
func (s *Swarm) denyConn(tc transport.CapableConn, dir network.Direction) (deny bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given that there's only one caller of this function, and the way that the ConnGater is getting invoked is slighty different based on if we know the specific address or just the peer, i wonder if this function is useful, or if we should just directly check the ConnGater in swarm_listen, like we do when dialing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good; my main gripe is that we're duplicating concerns across layers.
swarm.go
Outdated
rejectConnection = true | ||
} | ||
case network.DirOutbound: | ||
if !s.ConnGater.InterceptPeerAddrDial(p, tc.RemoteMultiaddr()) || !s.ConnGater.InterceptPeerDial(p) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we intercept this after the connection has been established? Can't we intercept it before we make the connection attempt (since we already know the target peer ID and the multiaddr we're about to dial)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been removed.
swarm_dial.go
Outdated
@@ -409,7 +418,9 @@ func (s *Swarm) filterKnownUndialables(addrs []ma.Multiaddr) []ma.Multiaddr { | |||
s.canDial, | |||
// TODO: Consider allowing link-local addresses | |||
addrutil.AddrOverNonLocalIP, | |||
addrutil.FilterNeg(s.Filters.AddrBlocked), | |||
func(addr ma.Multiaddr) bool { | |||
return s.ConnGater == nil || s.ConnGater.InterceptPeerAddrDial(p, addr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do this here and on addConn
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been removed from addConn
.
fb9362a
to
8d88eff
Compare
@raulk Have changed the imports for libp2p-core & libp2p-upgrader & have addressed your changes. Let me know what you think. |
For libp2p/go-libp2p#872.
Core PR at libp2p/go-libp2p-core#139.
Upgrader PR at libp2p/go-libp2p-transport-upgrader#55.
This PR uses the connection lifecycle state based Connection Gating interface to gate connections.