Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
changes based on updated interface
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshkshah1992 committed Apr 13, 2020
1 parent 316a855 commit fb9362a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require (
github.com/jbenet/goprocess v0.1.4
github.com/libp2p/go-addr-util v0.0.1
github.com/libp2p/go-conn-security-multistream v0.1.0
github.com/libp2p/go-libp2p-core v0.5.2-0.20200409124714-2f4d34c727d9
github.com/libp2p/go-libp2p-core v0.5.2-0.20200413071328-7f44bb7684b5
github.com/libp2p/go-libp2p-loggables v0.1.0
github.com/libp2p/go-libp2p-peerstore v0.2.2
github.com/libp2p/go-libp2p-secio v0.2.1
Expand All @@ -22,4 +22,4 @@ require (
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7
)

go 1.12
go 1.12
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ github.com/libp2p/go-libp2p-core v0.5.2-0.20200407111719-49c747cbf18c h1:mMOcmG1
github.com/libp2p/go-libp2p-core v0.5.2-0.20200407111719-49c747cbf18c/go.mod h1:uN7L2D4EvPCvzSH5SrhR72UWbnSGpt5/a35Sm4upn4Y=
github.com/libp2p/go-libp2p-core v0.5.2-0.20200409124714-2f4d34c727d9 h1:06F5u6iQNSiJl3FGTnDZfJtSqtIiMYlELemNQ5myESc=
github.com/libp2p/go-libp2p-core v0.5.2-0.20200409124714-2f4d34c727d9/go.mod h1:uN7L2D4EvPCvzSH5SrhR72UWbnSGpt5/a35Sm4upn4Y=
github.com/libp2p/go-libp2p-core v0.5.2-0.20200413070312-0ce93eb25877 h1:cwUIz6V1LXCRFUUnFZ6y4L3HUy9MfaYts0ZJ7CfR1NU=
github.com/libp2p/go-libp2p-core v0.5.2-0.20200413070312-0ce93eb25877/go.mod h1:uN7L2D4EvPCvzSH5SrhR72UWbnSGpt5/a35Sm4upn4Y=
github.com/libp2p/go-libp2p-core v0.5.2-0.20200413071328-7f44bb7684b5 h1:mlXQQ8cEcVb46PFsOFoGByjo1LIL1hw1i0GBeK5b/ZE=
github.com/libp2p/go-libp2p-core v0.5.2-0.20200413071328-7f44bb7684b5/go.mod h1:uN7L2D4EvPCvzSH5SrhR72UWbnSGpt5/a35Sm4upn4Y=
github.com/libp2p/go-libp2p-loggables v0.1.0 h1:h3w8QFfCt2UJl/0/NW4K829HX/0S4KD31PQ7m8UXXO8=
github.com/libp2p/go-libp2p-loggables v0.1.0/go.mod h1:EyumB2Y6PrYjr55Q3/tiJ/o3xoDasoRYM7nOzEpoa90=
github.com/libp2p/go-libp2p-mplex v0.2.0/go.mod h1:Ejl9IyjvXJ0T9iqUTE1jpYATQ9NM3g+OtR+EMMODbKo=
Expand Down
2 changes: 1 addition & 1 deletion swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (s *Swarm) addConn(tc transport.CapableConn, dir network.Direction) (*Conn,
rejectConnection = true
}
case network.DirOutbound:
if !s.ConnGater.InterceptDial(tc.RemoteMultiaddr()) || !s.ConnGater.InterceptPeerDial(p) {
if !s.ConnGater.InterceptPeerAddrDial(p, tc.RemoteMultiaddr()) || !s.ConnGater.InterceptPeerDial(p) {
rejectConnection = true
}
}
Expand Down
6 changes: 3 additions & 3 deletions swarm_dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) {
if len(peerAddrs) == 0 {
return nil, &DialError{Peer: p, Cause: ErrNoAddresses}
}
goodAddrs := s.filterKnownUndialables(peerAddrs)
goodAddrs := s.filterKnownUndialables(p, peerAddrs)
if len(goodAddrs) == 0 {
return nil, &DialError{Peer: p, Cause: ErrNoGoodAddresses}
}
Expand Down Expand Up @@ -402,7 +402,7 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) {
// IPv6 link-local addresses, addresses without a dial-capable transport,
// and addresses that we know to be our own.
// This is an optimization to avoid wasting time on dials that we know are going to fail.
func (s *Swarm) filterKnownUndialables(addrs []ma.Multiaddr) []ma.Multiaddr {
func (s *Swarm) filterKnownUndialables(p peer.ID, addrs []ma.Multiaddr) []ma.Multiaddr {
lisAddrs, _ := s.InterfaceListenAddresses()
var ourAddrs []ma.Multiaddr
for _, addr := range lisAddrs {
Expand All @@ -419,7 +419,7 @@ func (s *Swarm) filterKnownUndialables(addrs []ma.Multiaddr) []ma.Multiaddr {
// TODO: Consider allowing link-local addresses
addrutil.AddrOverNonLocalIP,
func(addr ma.Multiaddr) bool {
return s.ConnGater == nil || s.ConnGater.InterceptDial(addr)
return s.ConnGater == nil || s.ConnGater.InterceptPeerAddrDial(p, addr)
},
)
}
Expand Down
3 changes: 2 additions & 1 deletion swarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ func TestConnectionGating(t *testing.T) {
"no gating": {
p1ConnectednessToP2: network.Connected,
p2ConnectednessToP1: network.Connected,
isP1OutboundErr: false,
},
"p1 gates outbound peer dial": {
p1Gater: func(c *MockConnectionGater) *MockConnectionGater {
Expand All @@ -307,7 +308,7 @@ func TestConnectionGating(t *testing.T) {
},
"p1 gates outbound addr dialing": {
p1Gater: func(c *MockConnectionGater) *MockConnectionGater {
c.Dial = func(addr ma.Multiaddr) bool { return false }
c.Dial = func(p peer.ID, addr ma.Multiaddr) bool { return false }
return c
},
p1ConnectednessToP2: network.NotConnected,
Expand Down
8 changes: 4 additions & 4 deletions testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func DivulgeAddresses(a, b network.Network) {

// MockConnectionGater is a mock connection gater to be used by the tests.
type MockConnectionGater struct {
Dial func(addr ma.Multiaddr) bool
Dial func(p peer.ID, addr ma.Multiaddr) bool
PeerDial func(p peer.ID) bool
Accept func(c network.ConnMultiaddrs) bool
Secured func(network.Direction, peer.ID, network.ConnMultiaddrs) bool
Expand All @@ -125,7 +125,7 @@ type MockConnectionGater struct {

func DefaultMockConnectionGater() *MockConnectionGater {
m := &MockConnectionGater{}
m.Dial = func(addr ma.Multiaddr) bool {
m.Dial = func(p peer.ID, addr ma.Multiaddr) bool {
return true
}

Expand All @@ -148,8 +148,8 @@ func DefaultMockConnectionGater() *MockConnectionGater {
return m
}

func (m *MockConnectionGater) InterceptDial(addr ma.Multiaddr) (allow bool) {
return m.Dial(addr)
func (m *MockConnectionGater) InterceptPeerAddrDial(p peer.ID, addr ma.Multiaddr) (allow bool) {
return m.Dial(p, addr)
}

func (m *MockConnectionGater) InterceptPeerDial(p peer.ID) (allow bool) {
Expand Down

0 comments on commit fb9362a

Please sign in to comment.