diff --git a/p2p/net/swarm/limiter.go b/p2p/net/swarm/limiter.go index 5c8d235b8ef1b87fc169803749eb1bf867194ac8..bf4bcf0f5c180344439c7936f4b3e3a0e4c58564 100644 --- a/p2p/net/swarm/limiter.go +++ b/p2p/net/swarm/limiter.go @@ -7,11 +7,11 @@ import ( peer "github.com/ipfs/go-libp2p-peer" ma "github.com/jbenet/go-multiaddr" addrutil "github.com/libp2p/go-addr-util" - conn "github.com/libp2p/go-libp2p-conn" + iconn "github.com/libp2p/go-libp2p-interface-conn" ) type dialResult struct { - Conn conn.Conn + Conn iconn.Conn Err error } @@ -38,14 +38,14 @@ type dialLimiter struct { fdLimit int waitingOnFd []*dialJob - dialFunc func(context.Context, peer.ID, ma.Multiaddr) (conn.Conn, error) + dialFunc func(context.Context, peer.ID, ma.Multiaddr) (iconn.Conn, error) activePerPeer map[peer.ID]int perPeerLimit int waitingOnPeerLimit map[peer.ID][]*dialJob } -type dialfunc func(context.Context, peer.ID, ma.Multiaddr) (conn.Conn, error) +type dialfunc func(context.Context, peer.ID, ma.Multiaddr) (iconn.Conn, error) func newDialLimiter(df dialfunc) *dialLimiter { return newDialLimiterWithParams(df, concurrentFdDials, defaultPerPeerRateLimit) diff --git a/p2p/net/swarm/limiter_test.go b/p2p/net/swarm/limiter_test.go index 7332c0e06a6f8c9aa9dd417777a189aec8d52558..31ac8435df837da0d49ab22ac39b60a8e4d0dcb7 100644 --- a/p2p/net/swarm/limiter_test.go +++ b/p2p/net/swarm/limiter_test.go @@ -10,7 +10,7 @@ import ( peer "github.com/ipfs/go-libp2p-peer" ma "github.com/jbenet/go-multiaddr" - conn "github.com/libp2p/go-libp2p-conn" + iconn "github.com/libp2p/go-libp2p-interface-conn" mafmt "github.com/whyrusleeping/mafmt" ) @@ -55,13 +55,13 @@ func tryDialAddrs(ctx context.Context, l *dialLimiter, p peer.ID, addrs []ma.Mul } func hangDialFunc(hang chan struct{}) dialfunc { - return func(ctx context.Context, p peer.ID, a ma.Multiaddr) (conn.Conn, error) { + return func(ctx context.Context, p peer.ID, a ma.Multiaddr) (iconn.Conn, error) { if mafmt.UTP.Matches(a) { - return conn.Conn(nil), nil + return iconn.Conn(nil), nil } if tcpPortOver(a, 10) { - return conn.Conn(nil), nil + return iconn.Conn(nil), nil } <-hang @@ -171,9 +171,9 @@ func TestFDLimiting(t *testing.T) { func TestTokenRedistribution(t *testing.T) { hangchs := make(map[peer.ID]chan struct{}) - df := func(ctx context.Context, p peer.ID, a ma.Multiaddr) (conn.Conn, error) { + df := func(ctx context.Context, p peer.ID, a ma.Multiaddr) (iconn.Conn, error) { if tcpPortOver(a, 10) { - return (conn.Conn)(nil), nil + return (iconn.Conn)(nil), nil } <-hangchs[p] @@ -260,9 +260,9 @@ func TestTokenRedistribution(t *testing.T) { } func TestStressLimiter(t *testing.T) { - df := func(ctx context.Context, p peer.ID, a ma.Multiaddr) (conn.Conn, error) { + df := func(ctx context.Context, p peer.ID, a ma.Multiaddr) (iconn.Conn, error) { if tcpPortOver(a, 1000) { - return conn.Conn(nil), nil + return iconn.Conn(nil), nil } time.Sleep(time.Millisecond * time.Duration(5+rand.Intn(100))) diff --git a/p2p/net/swarm/swarm_addr.go b/p2p/net/swarm/swarm_addr.go index 87b0829da15df9759c18b3156af54ed7742706fa..0ab2c7ea1c552d473691561c09940e60a31bd06c 100644 --- a/p2p/net/swarm/swarm_addr.go +++ b/p2p/net/swarm/swarm_addr.go @@ -3,7 +3,7 @@ package swarm import ( ma "github.com/jbenet/go-multiaddr" addrutil "github.com/libp2p/go-addr-util" - conn "github.com/libp2p/go-libp2p-conn" + iconn "github.com/libp2p/go-libp2p-interface-conn" ) // ListenAddresses returns a list of addresses at which this swarm listens. @@ -11,7 +11,7 @@ func (s *Swarm) ListenAddresses() []ma.Multiaddr { listeners := s.swarm.Listeners() addrs := make([]ma.Multiaddr, 0, len(listeners)) for _, l := range listeners { - if l2, ok := l.NetListener().(conn.Listener); ok { + if l2, ok := l.NetListener().(iconn.Listener); ok { addrs = append(addrs, l2.Multiaddr()) } } diff --git a/p2p/net/swarm/swarm_conn.go b/p2p/net/swarm/swarm_conn.go index 42fc8905dac4a77c24c23088b8670280a2ac350b..8128a3e6abbf96a2a965bf07c70852f62d4bd120 100644 --- a/p2p/net/swarm/swarm_conn.go +++ b/p2p/net/swarm/swarm_conn.go @@ -4,13 +4,12 @@ import ( "context" "fmt" - inet "github.com/libp2p/go-libp2p-net" - ic "github.com/ipfs/go-libp2p-crypto" peer "github.com/ipfs/go-libp2p-peer" ma "github.com/jbenet/go-multiaddr" ps "github.com/jbenet/go-peerstream" - conn "github.com/libp2p/go-libp2p-conn" + iconn "github.com/libp2p/go-libp2p-interface-conn" + inet "github.com/libp2p/go-libp2p-net" ) // Conn is a simple wrapper around a ps.Conn that also exposes @@ -33,12 +32,12 @@ func (c *Conn) StreamConn() *ps.Conn { return (*ps.Conn)(c) } -func (c *Conn) RawConn() conn.Conn { +func (c *Conn) RawConn() iconn.Conn { // righly panic if these things aren't true. it is an expected // invariant that these Conns are all of the typewe expect: // ps.Conn wrapping a conn.Conn // if we get something else it is programmer error. - return (*ps.Conn)(c).NetConn().(conn.Conn) + return (*ps.Conn)(c).NetConn().(iconn.Conn) } func (c *Conn) String() string { @@ -94,7 +93,7 @@ func (c *Conn) Close() error { func wrapConn(psc *ps.Conn) (*Conn, error) { // grab the underlying connection. - if _, ok := psc.NetConn().(conn.Conn); !ok { + if _, ok := psc.NetConn().(iconn.Conn); !ok { // this should never happen. if we see it ocurring it means that we added // a Listener to the ps.Swarm that is NOT one of our net/conn.Listener. return nil, fmt.Errorf("swarm connHandler: invalid conn (not a conn.Conn): %s", psc) diff --git a/p2p/net/swarm/swarm_dial.go b/p2p/net/swarm/swarm_dial.go index 29694df73b2aa13c241d7665776526587b093b37..bfe9f0382e5b15d7a620d4fb6a18d775797930fa 100644 --- a/p2p/net/swarm/swarm_dial.go +++ b/p2p/net/swarm/swarm_dial.go @@ -11,7 +11,7 @@ import ( peer "github.com/ipfs/go-libp2p-peer" ma "github.com/jbenet/go-multiaddr" addrutil "github.com/libp2p/go-addr-util" - conn "github.com/libp2p/go-libp2p-conn" + iconn "github.com/libp2p/go-libp2p-interface-conn" ) // Diagram of dial sync: @@ -284,7 +284,7 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) { return swarmC, nil } -func (s *Swarm) dialAddrs(ctx context.Context, p peer.ID, remoteAddrs <-chan ma.Multiaddr) (conn.Conn, error) { +func (s *Swarm) dialAddrs(ctx context.Context, p peer.ID, remoteAddrs <-chan ma.Multiaddr) (iconn.Conn, error) { log.Debugf("%s swarm dialing %s %s", s.local, p, remoteAddrs) ctx, cancel := context.WithCancel(ctx) @@ -344,7 +344,7 @@ func (s *Swarm) limitedDial(ctx context.Context, p peer.ID, a ma.Multiaddr, resp }) } -func (s *Swarm) dialAddr(ctx context.Context, p peer.ID, addr ma.Multiaddr) (conn.Conn, error) { +func (s *Swarm) dialAddr(ctx context.Context, p peer.ID, addr ma.Multiaddr) (iconn.Conn, error) { log.Debugf("%s swarm dialing %s %s", s.local, p, addr) connC, err := s.dialer.Dial(ctx, addr, p) @@ -376,7 +376,7 @@ var ConnSetupTimeout = time.Minute * 5 // dialConnSetup is the setup logic for a connection from the dial side. it // needs to add the Conn to the StreamSwarm, then run newConnSetup -func dialConnSetup(ctx context.Context, s *Swarm, connC conn.Conn) (*Conn, error) { +func dialConnSetup(ctx context.Context, s *Swarm, connC iconn.Conn) (*Conn, error) { deadline, ok := ctx.Deadline() if !ok { diff --git a/p2p/net/swarm/swarm_listen.go b/p2p/net/swarm/swarm_listen.go index 0c9d8597356fdfd53acc35362beb15dee52b861d..756084abc7591deb1333e5391f260dee904d4d40 100644 --- a/p2p/net/swarm/swarm_listen.go +++ b/p2p/net/swarm/swarm_listen.go @@ -8,6 +8,7 @@ import ( ma "github.com/jbenet/go-multiaddr" ps "github.com/jbenet/go-peerstream" conn "github.com/libp2p/go-libp2p-conn" + iconn "github.com/libp2p/go-libp2p-interface-conn" mconn "github.com/libp2p/go-libp2p-metrics/conn" inet "github.com/libp2p/go-libp2p-net" transport "github.com/libp2p/go-libp2p-transport" @@ -98,7 +99,7 @@ func (s *Swarm) addListener(tptlist transport.Listener) error { return s.addConnListener(list) } -func (s *Swarm) addConnListener(list conn.Listener) error { +func (s *Swarm) addConnListener(list iconn.Listener) error { // AddListener to the peerstream Listener. this will begin accepting connections // and streams! sl, err := s.swarm.AddListener(list) diff --git a/package.json b/package.json index dd25227604257d25808a3ce3e74d653b639d30dd..ddc11d07397c845bcf7d9ecfad76f285526641eb 100644 --- a/package.json +++ b/package.json @@ -215,21 +215,27 @@ }, { "author": "whyrusleeping", - "hash": "QmTaW4q1AbqMkpfDLUYzW18nW62GsrnFvtVcvR1pnaURm6", + "hash": "Qmd4eGc7VMmVZu225mdCzsagdWJBaAVHmmvNFYSvxSUeX5", "name": "go-libp2p-conn", - "version": "1.0.0" + "version": "1.1.0" }, { "author": "whyrusleeping", - "hash": "QmSctCnUNkE7c7C2LGRGYrdmU9SDH3MtbAeueN7Jq1NN2q", + "hash": "Qmcr6YS5QCPwejhBxZk5iFEvVEHSVzewbLVMyc64zefaUf", "name": "go-libp2p-net", "version": "1.0.0" }, { "author": "whyrusleeping", - "hash": "QmS38TTyj47fP5NVNznxpw4KpFYSU9zHkCEfmuBSkHzb6d", + "hash": "QmbidKjoAxLVE2skY74Rfw1QafReyf4w2FZqA8Sd7MxoVd", "name": "go-libp2p-metrics", - "version": "1.0.0" + "version": "1.1.0" + }, + { + "author": "whyrusleeping", + "hash": "QmRxzoGdQaN6HYyqWnT82NnLLHBAZbTUvxPEfTBTjU7KCn", + "name": "go-libp2p-interface-conn", + "version": "0.1.0" } ], "gxVersion": "0.4.0",