diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 68d7e726..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,10 +0,0 @@ -version: 2 -jobs: - build: - docker: - - image: circleci/golang:1.11 - environment: - GO111MODULE: "on" - steps: - - checkout - - run: go test -v -race -bench . ./... diff --git a/dial_error.go b/dial_error.go index 6d5bb149..d2179617 100644 --- a/dial_error.go +++ b/dial_error.go @@ -4,7 +4,8 @@ import ( "fmt" "strings" - peer "github.com/libp2p/go-libp2p-peer" + "github.com/libp2p/go-libp2p-core/peer" + ma "github.com/multiformats/go-multiaddr" ) diff --git a/dial_sync.go b/dial_sync.go index 82256eca..f746b9a9 100644 --- a/dial_sync.go +++ b/dial_sync.go @@ -4,7 +4,7 @@ import ( "context" "sync" - peer "github.com/libp2p/go-libp2p-peer" + "github.com/libp2p/go-libp2p-core/peer" ) // DialFunc is the type of function expected by DialSync. diff --git a/dial_sync_test.go b/dial_sync_test.go index 53c3fc25..485d1a31 100644 --- a/dial_sync_test.go +++ b/dial_sync_test.go @@ -9,7 +9,7 @@ import ( . "github.com/libp2p/go-libp2p-swarm" - peer "github.com/libp2p/go-libp2p-peer" + "github.com/libp2p/go-libp2p-core/peer" ) func getMockDialFunc() (DialFunc, func(), context.Context, <-chan struct{}) { diff --git a/dial_test.go b/dial_test.go index 99585d2c..73bd02c6 100644 --- a/dial_test.go +++ b/dial_test.go @@ -8,12 +8,15 @@ import ( "time" addrutil "github.com/libp2p/go-addr-util" - peer "github.com/libp2p/go-libp2p-peer" - pstore "github.com/libp2p/go-libp2p-peerstore" + + "github.com/libp2p/go-libp2p-core/peer" + "github.com/libp2p/go-libp2p-core/peerstore" + "github.com/libp2p/go-libp2p-core/transport" + + testutil "github.com/libp2p/go-libp2p-core/test" swarmt "github.com/libp2p/go-libp2p-swarm/testing" - transport "github.com/libp2p/go-libp2p-transport" - testutil "github.com/libp2p/go-testutil" - ci "github.com/libp2p/go-testutil/ci" + "github.com/libp2p/go-libp2p-testing/ci" + ma "github.com/multiformats/go-multiaddr" manet "github.com/multiformats/go-multiaddr-net" @@ -39,7 +42,7 @@ func TestBasicDialPeer(t *testing.T) { s1 := swarms[0] s2 := swarms[1] - s1.Peerstore().AddAddrs(s2.LocalPeer(), s2.ListenAddresses(), pstore.PermanentAddrTTL) + s1.Peerstore().AddAddrs(s2.LocalPeer(), s2.ListenAddresses(), peerstore.PermanentAddrTTL) c, err := s1.DialPeer(ctx, s2.LocalPeer()) if err != nil { @@ -64,7 +67,7 @@ func TestDialWithNoListeners(t *testing.T) { defer closeSwarms(swarms) s2 := swarms[0] - s1.Peerstore().AddAddrs(s2.LocalPeer(), s2.ListenAddresses(), pstore.PermanentAddrTTL) + s1.Peerstore().AddAddrs(s2.LocalPeer(), s2.ListenAddresses(), peerstore.PermanentAddrTTL) c, err := s1.DialPeer(ctx, s2.LocalPeer()) if err != nil { @@ -108,7 +111,7 @@ func TestSimultDials(t *testing.T) { connect := func(s *Swarm, dst peer.ID, addr ma.Multiaddr) { // copy for other peer log.Debugf("TestSimultOpen: connecting: %s --> %s (%s)", s.LocalPeer(), dst, addr) - s.Peerstore().AddAddr(dst, addr, pstore.TempAddrTTL) + s.Peerstore().AddAddr(dst, addr, peerstore.TempAddrTTL) if _, err := s.DialPeer(ctx, dst); err != nil { t.Fatal("error swarm dialing to peer", err) } @@ -179,7 +182,7 @@ func TestDialWait(t *testing.T) { s2p, s2addr, s2l := newSilentPeer(t) go acceptAndHang(s2l) defer s2l.Close() - s1.Peerstore().AddAddr(s2p, s2addr, pstore.PermanentAddrTTL) + s1.Peerstore().AddAddr(s2p, s2addr, peerstore.PermanentAddrTTL) before := time.Now() if c, err := s1.DialPeer(ctx, s2p); err == nil { @@ -221,13 +224,13 @@ func TestDialBackoff(t *testing.T) { if err != nil { t.Fatal(err) } - s1.Peerstore().AddAddrs(s2.LocalPeer(), s2addrs, pstore.PermanentAddrTTL) + s1.Peerstore().AddAddrs(s2.LocalPeer(), s2addrs, peerstore.PermanentAddrTTL) // dial to a non-existent peer. s3p, s3addr, s3l := newSilentPeer(t) go acceptAndHang(s3l) defer s3l.Close() - s1.Peerstore().AddAddr(s3p, s3addr, pstore.PermanentAddrTTL) + s1.Peerstore().AddAddr(s3p, s3addr, peerstore.PermanentAddrTTL) // in this test we will: // 1) dial 10x to each node. @@ -430,7 +433,7 @@ func TestDialBackoffClears(t *testing.T) { defer s2l.Close() // phase 1 -- dial to non-operational addresses - s1.Peerstore().AddAddr(s2.LocalPeer(), s2bad, pstore.PermanentAddrTTL) + s1.Peerstore().AddAddr(s2.LocalPeer(), s2bad, peerstore.PermanentAddrTTL) before := time.Now() if c, err := s1.DialPeer(ctx, s2.LocalPeer()); err == nil { @@ -459,7 +462,7 @@ func TestDialBackoffClears(t *testing.T) { if err != nil { t.Fatal(err) } - s1.Peerstore().AddAddrs(s2.LocalPeer(), ifaceAddrs1, pstore.PermanentAddrTTL) + s1.Peerstore().AddAddrs(s2.LocalPeer(), ifaceAddrs1, peerstore.PermanentAddrTTL) if _, err := s1.DialPeer(ctx, s2.LocalPeer()); err == nil { t.Fatal("should have failed to dial backed off peer") @@ -498,7 +501,7 @@ func TestDialPeerFailed(t *testing.T) { testedSwarm.Peerstore().AddAddr( targetSwarm.LocalPeer(), silentPeerAddress, - pstore.PermanentAddrTTL) + peerstore.PermanentAddrTTL) } _, err := testedSwarm.DialPeer(ctx, targetSwarm.LocalPeer()) diff --git a/go.mod b/go.mod index a922d7da..6d3662d9 100644 --- a/go.mod +++ b/go.mod @@ -1,28 +1,20 @@ module github.com/libp2p/go-libp2p-swarm -go 1.12 - require ( github.com/ipfs/go-log v0.0.1 github.com/jbenet/goprocess v0.1.3 github.com/libp2p/go-addr-util v0.0.1 - github.com/libp2p/go-conn-security-multistream v0.0.2 - github.com/libp2p/go-libp2p-crypto v0.0.2 - github.com/libp2p/go-libp2p-loggables v0.0.1 - github.com/libp2p/go-libp2p-metrics v0.0.1 - github.com/libp2p/go-libp2p-net v0.0.2 - github.com/libp2p/go-libp2p-peer v0.1.1 - github.com/libp2p/go-libp2p-peerstore v0.0.6 - github.com/libp2p/go-libp2p-protocol v0.0.1 - github.com/libp2p/go-libp2p-secio v0.0.3 - github.com/libp2p/go-libp2p-transport v0.0.5 - github.com/libp2p/go-libp2p-transport-upgrader v0.0.4 - github.com/libp2p/go-libp2p-yamux v0.1.2 + github.com/libp2p/go-conn-security-multistream v0.1.0 + github.com/libp2p/go-libp2p-core v0.0.1 + github.com/libp2p/go-libp2p-loggables v0.1.0 + github.com/libp2p/go-libp2p-peerstore v0.1.0 + github.com/libp2p/go-libp2p-secio v0.1.0 + github.com/libp2p/go-libp2p-testing v0.0.3 + github.com/libp2p/go-libp2p-transport-upgrader v0.1.1 + github.com/libp2p/go-libp2p-yamux v0.2.0 github.com/libp2p/go-maddr-filter v0.0.4 - github.com/libp2p/go-stream-muxer v0.0.1 - github.com/libp2p/go-stream-muxer-multistream v0.1.1 - github.com/libp2p/go-tcp-transport v0.0.4 - github.com/libp2p/go-testutil v0.0.1 + github.com/libp2p/go-stream-muxer-multistream v0.2.0 + github.com/libp2p/go-tcp-transport v0.1.0 github.com/multiformats/go-multiaddr v0.0.4 github.com/multiformats/go-multiaddr-net v0.0.1 github.com/whyrusleeping/mafmt v1.2.8 diff --git a/go.sum b/go.sum index e474eb44..256f3314 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,7 @@ github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVa github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -32,9 +33,8 @@ github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmv github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/ipfs/go-cid v0.0.1/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= github.com/ipfs/go-datastore v0.0.1/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE= -github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ6cOk= -github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps= github.com/ipfs/go-ds-badger v0.0.2/go.mod h1:Y3QpeSFWQf6MopLTiZD+VT6IC1yZqaGmjvRcKeSGij8= github.com/ipfs/go-ds-leveldb v0.0.1/go.mod h1:feO8V3kubwsEF22n0YRQCffeb79OOYIykR4L04tMOYc= github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw= @@ -58,68 +58,53 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/libp2p/go-addr-util v0.0.1 h1:TpTQm9cXVRVSKsYbgQ7GKc3KbbHVTnbostgGaDEP+88= github.com/libp2p/go-addr-util v0.0.1/go.mod h1:4ac6O7n9rIAKB1dnd+s8IbbMXkt+oBpzX4/+RACcnlQ= -github.com/libp2p/go-buffer-pool v0.0.1 h1:9Rrn/H46cXjaA2HQ5Y8lyhOS1NhTkZ4yuEs2r3Eechg= github.com/libp2p/go-buffer-pool v0.0.1/go.mod h1:xtyIz9PMobb13WaxR6Zo1Pd1zXJKYg0a8KiIvDp3TzQ= github.com/libp2p/go-buffer-pool v0.0.2 h1:QNK2iAFa8gjAe1SPz6mHSMuCcjs+X1wlHzeOSqcmlfs= github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoRZd1Vi32+RXyFM= -github.com/libp2p/go-conn-security v0.0.1 h1:4kMMrqrt9EUNCNjX1xagSJC+bq16uqjMe9lk1KBMVNs= -github.com/libp2p/go-conn-security v0.0.1/go.mod h1:bGmu51N0KU9IEjX7kl2PQjgZa40JQWnayTvNMgD/vyk= -github.com/libp2p/go-conn-security-multistream v0.0.2 h1:Ykz0lnNjxk+0SdslUmlLNyrleqdpS1S/VW+dxFdt74Y= -github.com/libp2p/go-conn-security-multistream v0.0.2/go.mod h1:nc9vud7inQ+d6SO0I/6dSWrdMnHnzZNHeyUQqrAJulE= +github.com/libp2p/go-conn-security-multistream v0.1.0 h1:aqGmto+ttL/uJgX0JtQI0tD21CIEy5eYd1Hlp0juHY0= +github.com/libp2p/go-conn-security-multistream v0.1.0/go.mod h1:aw6eD7LOsHEX7+2hJkDxw1MteijaVcI+/eP2/x3J1xc= github.com/libp2p/go-flow-metrics v0.0.1 h1:0gxuFd2GuK7IIP5pKljLwps6TvcuYgvG7Atqi3INF5s= github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZxBdp967ls1g+k8= -github.com/libp2p/go-libp2p-crypto v0.0.1/go.mod h1:yJkNyDmO341d5wwXxDUGO0LykUVT72ImHNUqh5D/dBE= -github.com/libp2p/go-libp2p-crypto v0.0.2 h1:TTdJ4y6Uoa6NxQcuEaVkQfFRcQeCE2ReDk8Ok4I0Fyw= -github.com/libp2p/go-libp2p-crypto v0.0.2/go.mod h1:eETI5OUfBnvARGOHrJz2eWNyTUxEGZnBxMcbUjfIj4I= -github.com/libp2p/go-libp2p-interface-pnet v0.0.1 h1:7GnzRrBTJHEsofi1ahFdPN9Si6skwXQE9UqR2S+Pkh8= -github.com/libp2p/go-libp2p-interface-pnet v0.0.1/go.mod h1:el9jHpQAXK5dnTpKA4yfCNBZXvrzdOU75zz+C6ryp3k= -github.com/libp2p/go-libp2p-loggables v0.0.1 h1:HVww9oAnINIxbt69LJNkxD8lnbfgteXR97Xm4p3l9ps= -github.com/libp2p/go-libp2p-loggables v0.0.1/go.mod h1:lDipDlBNYbpyqyPX/KcoO+eq0sJYEVR2JgOexcivchg= -github.com/libp2p/go-libp2p-metrics v0.0.1 h1:yumdPC/P2VzINdmcKZd0pciSUCpou+s0lwYCjBbzQZU= -github.com/libp2p/go-libp2p-metrics v0.0.1/go.mod h1:jQJ95SXXA/K1VZi13h52WZMa9ja78zjyy5rspMsC/08= -github.com/libp2p/go-libp2p-mplex v0.1.1 h1:lSPS1VJ36P01gGO//KgcsmSah5uoC3X9r7WY5j+iP4c= -github.com/libp2p/go-libp2p-mplex v0.1.1/go.mod h1:KUQWpGkCzfV7UIpi8SKsAVxyBgz1c9R5EvxgnwLsb/I= -github.com/libp2p/go-libp2p-net v0.0.1/go.mod h1:Yt3zgmlsHOgUWSXmt5V/Jpz9upuJBE8EgNU9DrCcR8c= -github.com/libp2p/go-libp2p-net v0.0.2 h1:qP06u4TYXfl7uW/hzqPhlVVTSA2nw1B/bHBJaUnbh6M= -github.com/libp2p/go-libp2p-net v0.0.2/go.mod h1:Yt3zgmlsHOgUWSXmt5V/Jpz9upuJBE8EgNU9DrCcR8c= -github.com/libp2p/go-libp2p-peer v0.0.1/go.mod h1:nXQvOBbwVqoP+T5Y5nCjeH4sP9IX/J0AMzcDUVruVoo= -github.com/libp2p/go-libp2p-peer v0.1.1 h1:qGCWD1a+PyZcna6htMPo26jAtqirVnJ5NvBQIKV7rRY= -github.com/libp2p/go-libp2p-peer v0.1.1/go.mod h1:jkF12jGB4Gk/IOo+yomm+7oLWxF278F7UnrYUQ1Q8es= -github.com/libp2p/go-libp2p-peerstore v0.0.1/go.mod h1:RabLyPVJLuNQ+GFyoEkfi8H4Ti6k/HtZJ7YKgtSq+20= -github.com/libp2p/go-libp2p-peerstore v0.0.6 h1:RgX/djPFXqZGktW0j2eF4NAX0pzDsCot45jO2GewC+g= -github.com/libp2p/go-libp2p-peerstore v0.0.6/go.mod h1:RabLyPVJLuNQ+GFyoEkfi8H4Ti6k/HtZJ7YKgtSq+20= -github.com/libp2p/go-libp2p-protocol v0.0.1 h1:+zkEmZ2yFDi5adpVE3t9dqh/N9TbpFWywowzeEzBbLM= -github.com/libp2p/go-libp2p-protocol v0.0.1/go.mod h1:Af9n4PiruirSDjHycM1QuiMi/1VZNHYcK8cLgFJLZ4s= -github.com/libp2p/go-libp2p-secio v0.0.3 h1:h3fPeDrej7bvvARnC2oSjAfcLZOaS4REZKgWCRQNpE4= -github.com/libp2p/go-libp2p-secio v0.0.3/go.mod h1:hS7HQ00MgLhRO/Wyu1bTX6ctJKhVpm+j2/S2A5UqYb0= -github.com/libp2p/go-libp2p-transport v0.0.1/go.mod h1:UzbUs9X+PHOSw7S3ZmeOxfnwaQY5vGDzZmKPod3N3tk= -github.com/libp2p/go-libp2p-transport v0.0.5 h1:pV6+UlRxyDpASSGD+60vMvdifSCby6JkJDfi+yUMHac= -github.com/libp2p/go-libp2p-transport v0.0.5/go.mod h1:StoY3sx6IqsP6XKoabsPnHCwqKXWUMWU7Rfcsubee/A= -github.com/libp2p/go-libp2p-transport-upgrader v0.0.4 h1:uGMOd14BL1oFlfb/cGfOxPjiTKBhzWV4aMjjoCF1Z1o= -github.com/libp2p/go-libp2p-transport-upgrader v0.0.4/go.mod h1:RGq+tupk+oj7PzL2kn/m1w6YXxcIAYJYeI90h6BGgUc= -github.com/libp2p/go-libp2p-yamux v0.1.2 h1:DgGItlrWi0j9y1OhRMC8qqL4zj2MEPWeKJTHb55R16Q= -github.com/libp2p/go-libp2p-yamux v0.1.2/go.mod h1:xUoV/RmYkg6BW/qGxA9XJyg+HzXFYkeXbnhjmnYzKp8= -github.com/libp2p/go-maddr-filter v0.0.1/go.mod h1:6eT12kSQMA9x2pvFQa+xesMKUBlj9VImZbj3B9FBH/Q= +github.com/libp2p/go-libp2p-core v0.0.1 h1:HSTZtFIq/W5Ue43Zw+uWZyy2Vl5WtF0zDjKN8/DT/1I= +github.com/libp2p/go-libp2p-core v0.0.1/go.mod h1:g/VxnTZ/1ygHxH3dKok7Vno1VfpvGcGip57wjTU4fco= +github.com/libp2p/go-libp2p-crypto v0.1.0 h1:k9MFy+o2zGDNGsaoZl0MA3iZ75qXxr9OOoAZF+sD5OQ= +github.com/libp2p/go-libp2p-crypto v0.1.0/go.mod h1:sPUokVISZiy+nNuTTH/TY+leRSxnFj/2GLjtOTW90hI= +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= +github.com/libp2p/go-libp2p-mplex v0.2.1 h1:E1xaJBQnbSiTHGI1gaBKmKhu1TUKkErKJnE8iGvirYI= +github.com/libp2p/go-libp2p-mplex v0.2.1/go.mod h1:SC99Rxs8Vuzrf/6WhmH41kNn13TiYdAWNYHrwImKLnE= +github.com/libp2p/go-libp2p-peer v0.2.0 h1:EQ8kMjaCUwt/Y5uLgjT8iY2qg0mGUT0N1zUjer50DsY= +github.com/libp2p/go-libp2p-peer v0.2.0/go.mod h1:RCffaCvUyW2CJmG2gAWVqwePwW7JMgxjsHm7+J5kjWY= +github.com/libp2p/go-libp2p-peerstore v0.1.0 h1:MKh7pRNPHSh1fLPj8u/M/s/napdmeNpoi9BRy9lPN0E= +github.com/libp2p/go-libp2p-peerstore v0.1.0/go.mod h1:2CeHkQsr8svp4fZ+Oi9ykN1HBb6u0MOvdJ7YIsmcwtY= +github.com/libp2p/go-libp2p-secio v0.1.0 h1:NNP5KLxuP97sE5Bu3iuwOWyT/dKEGMN5zSLMWdB7GTQ= +github.com/libp2p/go-libp2p-secio v0.1.0/go.mod h1:tMJo2w7h3+wN4pgU2LSYeiKPrfqBgkOsdiKK77hE7c8= +github.com/libp2p/go-libp2p-testing v0.0.2/go.mod h1:gvchhf3FQOtBdr+eFUABet5a4MBLK8jM3V4Zghvmi+E= +github.com/libp2p/go-libp2p-testing v0.0.3 h1:bdij4bKaaND7tCsaXVjRfYkMpvoOeKj9AVQGJllA6jM= +github.com/libp2p/go-libp2p-testing v0.0.3/go.mod h1:gvchhf3FQOtBdr+eFUABet5a4MBLK8jM3V4Zghvmi+E= +github.com/libp2p/go-libp2p-transport-upgrader v0.1.1 h1:PZMS9lhjK9VytzMCW3tWHAXtKXmlURSc3ZdvwEcKCzw= +github.com/libp2p/go-libp2p-transport-upgrader v0.1.1/go.mod h1:IEtA6or8JUbsV07qPW4r01GnTenLW4oi3lOPbUMGJJA= +github.com/libp2p/go-libp2p-yamux v0.2.0 h1:TSPZ5cMMz/wdoYsye/wU1TE4G3LDGMoeEN0xgnCKU/I= +github.com/libp2p/go-libp2p-yamux v0.2.0/go.mod h1:Db2gU+XfLpm6E4rG5uGCFX6uXA8MEXOxFcRoXUODaK8= github.com/libp2p/go-maddr-filter v0.0.4 h1:hx8HIuuwk34KePddrp2mM5ivgPkZ09JH4AvsALRbFUs= github.com/libp2p/go-maddr-filter v0.0.4/go.mod h1:6eT12kSQMA9x2pvFQa+xesMKUBlj9VImZbj3B9FBH/Q= -github.com/libp2p/go-mplex v0.0.3 h1:YiMaevQcZtFU6DmKIF8xEO0vaui5kM5HJ1V1xkWQv14= github.com/libp2p/go-mplex v0.0.3/go.mod h1:pK5yMLmOoBR1pNCqDlA2GQrdAVTMkqFalaTWe7l4Yd0= +github.com/libp2p/go-mplex v0.1.0 h1:/nBTy5+1yRyY82YaO6HXQRnO5IAGsXTjEJaR3LdTPc0= +github.com/libp2p/go-mplex v0.1.0/go.mod h1:SXgmdki2kwCUlCCbfGLEgHjC4pFqhTp0ZoV6aiKgxDU= github.com/libp2p/go-msgio v0.0.2 h1:ivPvEKHxmVkTClHzg6RXTYHqaJQ0V9cDbq+6lKb3UV0= github.com/libp2p/go-msgio v0.0.2/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ= github.com/libp2p/go-reuseport v0.0.1 h1:7PhkfH73VXfPJYKQ6JwS5I/eVcoyYi9IMNGc6FWpFLw= github.com/libp2p/go-reuseport v0.0.1/go.mod h1:jn6RmB1ufnQwl0Q1f+YxAj8isJgDCQzaaxIFYDhcYEA= github.com/libp2p/go-reuseport-transport v0.0.2 h1:WglMwyXyBu61CMkjCCtnmqNqnjib0GIEjMiHTwR/KN4= github.com/libp2p/go-reuseport-transport v0.0.2/go.mod h1:YkbSDrvjUVDL6b8XqriyA20obEtsW9BLkuOUyQAOCbs= -github.com/libp2p/go-stream-muxer v0.0.1 h1:Ce6e2Pyu+b5MC1k3eeFtAax0pW4gc6MosYSLV05UeLw= github.com/libp2p/go-stream-muxer v0.0.1/go.mod h1:bAo8x7YkSpadMTbtTaxGVHWUQsR/l5MEaHbKaliuT14= -github.com/libp2p/go-stream-muxer-multistream v0.1.1 h1:DhHqb4nu1fQv/vQKeLAaZGmhLsUA4SF77IdYJiWE1d4= -github.com/libp2p/go-stream-muxer-multistream v0.1.1/go.mod h1:zmGdfkQ1AzOECIAcccoL8L//laqawOsO03zX8Sa+eGw= -github.com/libp2p/go-tcp-transport v0.0.4 h1:2iRu994wCT/iEz62F+c60FUoSkijNEQ0q2Itc+79XlQ= -github.com/libp2p/go-tcp-transport v0.0.4/go.mod h1:+E8HvC8ezEVOxIo3V5vCK9l1y/19K427vCzQ+xHKH/o= -github.com/libp2p/go-testutil v0.0.1 h1:Xg+O0G2HIMfHqBOBDcMS1iSZJ3GEcId4qOxCQvsGZHk= -github.com/libp2p/go-testutil v0.0.1/go.mod h1:iAcJc/DKJQanJ5ws2V+u5ywdL2n12X1WbbEG+Jjy69I= -github.com/libp2p/go-yamux v1.2.1 h1:VumHkMhJ2iFk1lzAeoDRgekiZSylGc6NnAEihVdBCiw= -github.com/libp2p/go-yamux v1.2.1/go.mod h1:FGTiPvoV/3DVdgWpX+tM0OW3tsM+W5bSE3gZwqQTcow= +github.com/libp2p/go-stream-muxer-multistream v0.2.0 h1:714bRJ4Zy9mdhyTLJ+ZKiROmAFwUHpeRidG+q7LTQOg= +github.com/libp2p/go-stream-muxer-multistream v0.2.0/go.mod h1:j9eyPol/LLRqT+GPLSxvimPhNph4sfYfMoDPd7HkzIc= +github.com/libp2p/go-tcp-transport v0.1.0 h1:IGhowvEqyMFknOar4FWCKSWE0zL36UFKQtiRQD60/8o= +github.com/libp2p/go-tcp-transport v0.1.0/go.mod h1:oJ8I5VXryj493DEJ7OsBieu8fcg2nHGctwtInJVpipc= +github.com/libp2p/go-yamux v1.2.2 h1:s6J6o7+ajoQMjHe7BEnq+EynOj5D2EoG8CuQgL3F2vg= +github.com/libp2p/go-yamux v1.2.2/go.mod h1:FGTiPvoV/3DVdgWpX+tM0OW3tsM+W5bSE3gZwqQTcow= github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-isatty v0.0.5 h1:tHXDdz1cpzGaovsTB+TVB8q90WEokoVmfMqoVcrLUgw= @@ -127,31 +112,38 @@ github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= -github.com/minio/sha256-simd v0.0.0-20190328051042-05b4dd3047e5 h1:l16XLUUJ34wIz+RIvLhSwGvLvKyy+W598b135bJN6mg= github.com/minio/sha256-simd v0.0.0-20190328051042-05b4dd3047e5/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= +github.com/minio/sha256-simd v0.1.0 h1:U41/2erhAKcmSI14xh/ZTUdBPOzDOIfS93ibzUSl8KM= +github.com/minio/sha256-simd v0.1.0/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= +github.com/mr-tron/base58 v1.1.1/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= github.com/mr-tron/base58 v1.1.2 h1:ZEw4I2EgPKDJ2iEw0cNmLB3ROrEmkOtXIkaG7wZg+78= github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= github.com/multiformats/go-multiaddr v0.0.1/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= +github.com/multiformats/go-multiaddr v0.0.2/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= github.com/multiformats/go-multiaddr v0.0.4 h1:WgMSI84/eRLdbptXMkMWDXPjPq7SPLIgGUVm2eroyU4= github.com/multiformats/go-multiaddr v0.0.4/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= -github.com/multiformats/go-multiaddr-dns v0.0.1 h1:jQt9c6tDSdQLIlBo4tXYx7QUHCPjxsB1zXcag/2S7zc= github.com/multiformats/go-multiaddr-dns v0.0.1/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q= +github.com/multiformats/go-multiaddr-dns v0.0.2 h1:/Bbsgsy3R6e3jf2qBahzNHzww6usYaZ0NhNH3sqdFS8= +github.com/multiformats/go-multiaddr-dns v0.0.2/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q= +github.com/multiformats/go-multiaddr-fmt v0.0.1 h1:5YjeOIzbX8OTKVaN72aOzGIYW7PnrZrnkDyOfAWRSMA= +github.com/multiformats/go-multiaddr-fmt v0.0.1/go.mod h1:aBYjqL4T/7j4Qx+R73XSv/8JsgnRFlf0w2KGLCmXl3Q= github.com/multiformats/go-multiaddr-net v0.0.1 h1:76O59E3FavvHqNg7jvzWzsPSW5JSi/ek0E4eiDVbg9g= github.com/multiformats/go-multiaddr-net v0.0.1/go.mod h1:nw6HSxNmCIQH27XPGBuX+d1tnvM7ihcFwHMSstNAVUU= +github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U= github.com/multiformats/go-multihash v0.0.5 h1:1wxmCvTXAifAepIMyF39vZinRw5sbqjPs/UIi93+uik= github.com/multiformats/go-multihash v0.0.5/go.mod h1:lt/HCbqlQwlPBz7lv0sQCdtfcMtlJvakRUn/0Ual8po= -github.com/multiformats/go-multistream v0.0.1 h1:JV4VfSdY9n7ECTtY59/TlSyFCzRILvYx4T4Ws8ZgihU= -github.com/multiformats/go-multistream v0.0.1/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg= -github.com/multiformats/go-multistream v0.0.4 h1:rNgWgFyzRSTI9L+xISrz7kN5MdNXoEcoIeeCH05wLKA= -github.com/multiformats/go-multistream v0.0.4/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg= +github.com/multiformats/go-multistream v0.1.0 h1:UpO6jrsjqs46mqAK3n6wKRYFhugss9ArzbyUzU+4wkQ= +github.com/multiformats/go-multistream v0.1.0/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= +github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w= +github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo= +github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg4X946/Y5Zwg= github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= @@ -178,10 +170,10 @@ github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7/go. golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190225124518-7f87c0fbb88b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734 h1:p/H982KKEjUnLJkM3tt/LemDnOc1GiZL5FCVlORJ5zo= golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f h1:R423Cnkcp5JABoeemiGEPlt9tHXFfw5kvc0yqlxRPWo= +golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190227160552-c95aed5357e7/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= diff --git a/limiter.go b/limiter.go index bd4ab572..6808dd71 100644 --- a/limiter.go +++ b/limiter.go @@ -7,14 +7,15 @@ import ( "sync" "time" + "github.com/libp2p/go-libp2p-core/peer" + "github.com/libp2p/go-libp2p-core/transport" + addrutil "github.com/libp2p/go-addr-util" - peer "github.com/libp2p/go-libp2p-peer" - transport "github.com/libp2p/go-libp2p-transport" ma "github.com/multiformats/go-multiaddr" ) type dialResult struct { - Conn transport.Conn + Conn transport.CapableConn Addr ma.Multiaddr Err error } @@ -53,7 +54,7 @@ type dialLimiter struct { waitingOnPeerLimit map[peer.ID][]*dialJob } -type dialfunc func(context.Context, peer.ID, ma.Multiaddr) (transport.Conn, error) +type dialfunc func(context.Context, peer.ID, ma.Multiaddr) (transport.CapableConn, error) func newDialLimiter(df dialfunc) *dialLimiter { fd := ConcurrentFdDials diff --git a/limiter_test.go b/limiter_test.go index 4338cad5..32d87fa1 100644 --- a/limiter_test.go +++ b/limiter_test.go @@ -9,8 +9,8 @@ import ( "testing" "time" - peer "github.com/libp2p/go-libp2p-peer" - transport "github.com/libp2p/go-libp2p-transport" + "github.com/libp2p/go-libp2p-core/peer" + "github.com/libp2p/go-libp2p-core/transport" ma "github.com/multiformats/go-multiaddr" mafmt "github.com/whyrusleeping/mafmt" ) @@ -56,13 +56,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) (transport.Conn, error) { + return func(ctx context.Context, p peer.ID, a ma.Multiaddr) (transport.CapableConn, error) { if mafmt.UTP.Matches(a) { - return transport.Conn(nil), nil + return transport.CapableConn(nil), nil } if tcpPortOver(a, 10) { - return transport.Conn(nil), nil + return transport.CapableConn(nil), nil } <-hang @@ -173,9 +173,9 @@ func TestFDLimiting(t *testing.T) { func TestTokenRedistribution(t *testing.T) { var lk sync.Mutex hangchs := make(map[peer.ID]chan struct{}) - df := func(ctx context.Context, p peer.ID, a ma.Multiaddr) (transport.Conn, error) { + df := func(ctx context.Context, p peer.ID, a ma.Multiaddr) (transport.CapableConn, error) { if tcpPortOver(a, 10) { - return (transport.Conn)(nil), nil + return (transport.CapableConn)(nil), nil } lk.Lock() @@ -268,9 +268,9 @@ func TestTokenRedistribution(t *testing.T) { } func TestStressLimiter(t *testing.T) { - df := func(ctx context.Context, p peer.ID, a ma.Multiaddr) (transport.Conn, error) { + df := func(ctx context.Context, p peer.ID, a ma.Multiaddr) (transport.CapableConn, error) { if tcpPortOver(a, 1000) { - return transport.Conn(nil), nil + return transport.CapableConn(nil), nil } time.Sleep(time.Millisecond * time.Duration(5+rand.Intn(100))) @@ -322,7 +322,7 @@ func TestStressLimiter(t *testing.T) { } func TestFDLimitUnderflow(t *testing.T) { - df := func(ctx context.Context, p peer.ID, a ma.Multiaddr) (transport.Conn, error) { + df := func(ctx context.Context, p peer.ID, a ma.Multiaddr) (transport.CapableConn, error) { timeout := make(chan bool, 1) go func() { time.Sleep(time.Second * 5) diff --git a/peers_test.go b/peers_test.go index 76cc00b0..fd1984d0 100644 --- a/peers_test.go +++ b/peers_test.go @@ -1,19 +1,19 @@ package swarm_test import ( + "context" "testing" - "context" - inet "github.com/libp2p/go-libp2p-net" - peer "github.com/libp2p/go-libp2p-peer" - pstore "github.com/libp2p/go-libp2p-peerstore" + "github.com/libp2p/go-libp2p-core/network" + "github.com/libp2p/go-libp2p-core/peer" + "github.com/libp2p/go-libp2p-core/peerstore" + ma "github.com/multiformats/go-multiaddr" . "github.com/libp2p/go-libp2p-swarm" ) func TestPeers(t *testing.T) { - ctx := context.Background() swarms := makeSwarms(ctx, t, 2) s1 := swarms[0] @@ -21,7 +21,7 @@ func TestPeers(t *testing.T) { connect := func(s *Swarm, dst peer.ID, addr ma.Multiaddr) { // TODO: make a DialAddr func. - s.Peerstore().AddAddr(dst, addr, pstore.PermanentAddrTTL) + s.Peerstore().AddAddr(dst, addr, peerstore.PermanentAddrTTL) // t.Logf("connections from %s", s.LocalPeer()) // for _, c := range s.ConnsToPeer(dst) { // t.Logf("connection from %s to %s: %v", s.LocalPeer(), dst, c) @@ -35,10 +35,10 @@ func TestPeers(t *testing.T) { s1GotConn := make(chan struct{}, 0) s2GotConn := make(chan struct{}, 0) - s1.SetConnHandler(func(c inet.Conn) { + s1.SetConnHandler(func(c network.Conn) { s1GotConn <- struct{}{} }) - s2.SetConnHandler(func(c inet.Conn) { + s2.SetConnHandler(func(c network.Conn) { s2GotConn <- struct{}{} }) diff --git a/simul_test.go b/simul_test.go index b162ab38..0373e37d 100644 --- a/simul_test.go +++ b/simul_test.go @@ -7,13 +7,14 @@ import ( "testing" "time" - peer "github.com/libp2p/go-libp2p-peer" - pstore "github.com/libp2p/go-libp2p-peerstore" - ci "github.com/libp2p/go-testutil/ci" + "github.com/libp2p/go-libp2p-core/peer" + "github.com/libp2p/go-libp2p-core/peerstore" + ma "github.com/multiformats/go-multiaddr" . "github.com/libp2p/go-libp2p-swarm" swarmt "github.com/libp2p/go-libp2p-swarm/testing" + "github.com/libp2p/go-libp2p-testing/ci" ) func TestSimultOpen(t *testing.T) { @@ -30,7 +31,7 @@ func TestSimultOpen(t *testing.T) { defer wg.Done() // copy for other peer log.Debugf("TestSimultOpen: connecting: %s --> %s (%s)", s.LocalPeer(), dst, addr) - s.Peerstore().AddAddr(dst, addr, pstore.PermanentAddrTTL) + s.Peerstore().AddAddr(dst, addr, peerstore.PermanentAddrTTL) if _, err := s.DialPeer(ctx, dst); err != nil { t.Error("error swarm dialing to peer", err) } diff --git a/swarm.go b/swarm.go index 1094e72e..b14e9cf0 100644 --- a/swarm.go +++ b/swarm.go @@ -9,14 +9,16 @@ import ( "sync/atomic" "time" + "github.com/libp2p/go-libp2p-core/metrics" + "github.com/libp2p/go-libp2p-core/network" + "github.com/libp2p/go-libp2p-core/peer" + "github.com/libp2p/go-libp2p-core/peerstore" + "github.com/libp2p/go-libp2p-core/transport" + logging "github.com/ipfs/go-log" "github.com/jbenet/goprocess" goprocessctx "github.com/jbenet/goprocess/context" - metrics "github.com/libp2p/go-libp2p-metrics" - inet "github.com/libp2p/go-libp2p-net" - peer "github.com/libp2p/go-libp2p-peer" - pstore "github.com/libp2p/go-libp2p-peerstore" - transport "github.com/libp2p/go-libp2p-transport" + filter "github.com/libp2p/go-maddr-filter" mafilter "github.com/whyrusleeping/multiaddr-filter" ) @@ -47,7 +49,7 @@ type Swarm struct { refs sync.WaitGroup local peer.ID - peers pstore.Peerstore + peers peerstore.Peerstore conns struct { sync.RWMutex @@ -61,7 +63,7 @@ type Swarm struct { notifs struct { sync.RWMutex - m map[inet.Notifiee]struct{} + m map[network.Notifiee]struct{} } transports struct { @@ -87,7 +89,7 @@ type Swarm struct { } // NewSwarm constructs a Swarm -func NewSwarm(ctx context.Context, local peer.ID, peers pstore.Peerstore, bwc metrics.Reporter) *Swarm { +func NewSwarm(ctx context.Context, local peer.ID, peers peerstore.Peerstore, bwc metrics.Reporter) *Swarm { s := &Swarm{ local: local, peers: peers, @@ -98,7 +100,7 @@ func NewSwarm(ctx context.Context, local peer.ID, peers pstore.Peerstore, bwc me s.conns.m = make(map[peer.ID][]*Conn) s.listeners.m = make(map[transport.Listener]struct{}) s.transports.m = make(map[int]transport.Transport) - s.notifs.m = make(map[inet.Notifiee]struct{}) + s.notifs.m = make(map[network.Notifiee]struct{}) s.dsync = NewDialSync(s.doDial) s.limiter = newDialLimiter(s.dialAddr) @@ -165,7 +167,7 @@ func (s *Swarm) Process() goprocess.Process { return s.proc } -func (s *Swarm) addConn(tc transport.Conn, dir inet.Direction) (*Conn, error) { +func (s *Swarm) addConn(tc transport.CapableConn, dir network.Direction) (*Conn, error) { // The underlying transport (or the dialer) *should* filter it's own // connections but we should double check anyways. raddr := tc.RemoteMultiaddr() @@ -194,7 +196,7 @@ func (s *Swarm) addConn(tc transport.Conn, dir inet.Direction) (*Conn, error) { } // Wrap and register the connection. - stat := inet.Stat{Direction: dir} + stat := network.Stat{Direction: dir} c := &Conn{ conn: tc, swarm: s, @@ -217,7 +219,7 @@ func (s *Swarm) addConn(tc transport.Conn, dir inet.Direction) (*Conn, error) { // This should be fast, no reason to wait till later. s.dsync.CancelDial(p) - s.notifyAll(func(f inet.Notifiee) { + s.notifyAll(func(f network.Notifiee) { f.Connected(s, c) }) c.notifyLk.Unlock() @@ -235,7 +237,7 @@ func (s *Swarm) addConn(tc transport.Conn, dir inet.Direction) (*Conn, error) { } // Peerstore returns this swarms internal Peerstore. -func (s *Swarm) Peerstore() pstore.Peerstore { +func (s *Swarm) Peerstore() peerstore.Peerstore { return s.peers } @@ -253,30 +255,30 @@ func (s *Swarm) Close() error { // SetConnHandler assigns the handler for new connections. // You will rarely use this. See SetStreamHandler -func (s *Swarm) SetConnHandler(handler inet.ConnHandler) { +func (s *Swarm) SetConnHandler(handler network.ConnHandler) { s.connh.Store(handler) } // ConnHandler gets the handler for new connections. -func (s *Swarm) ConnHandler() inet.ConnHandler { - handler, _ := s.connh.Load().(inet.ConnHandler) +func (s *Swarm) ConnHandler() network.ConnHandler { + handler, _ := s.connh.Load().(network.ConnHandler) return handler } // SetStreamHandler assigns the handler for new streams. -func (s *Swarm) SetStreamHandler(handler inet.StreamHandler) { +func (s *Swarm) SetStreamHandler(handler network.StreamHandler) { s.streamh.Store(handler) } // StreamHandler gets the handler for new streams. -func (s *Swarm) StreamHandler() inet.StreamHandler { - handler, _ := s.streamh.Load().(inet.StreamHandler) +func (s *Swarm) StreamHandler() network.StreamHandler { + handler, _ := s.streamh.Load().(network.StreamHandler) return handler } // NewStream creates a new stream on any available connection to peer, dialing // if necessary. -func (s *Swarm) NewStream(ctx context.Context, p peer.ID) (inet.Stream, error) { +func (s *Swarm) NewStream(ctx context.Context, p peer.ID) (network.Stream, error) { log.Debugf("[%s] opening stream to peer [%s]", s.local, p) // Algorithm: @@ -295,8 +297,8 @@ func (s *Swarm) NewStream(ctx context.Context, p peer.ID) (inet.Stream, error) { for { c := s.bestConnToPeer(p) if c == nil { - if nodial, _ := inet.GetNoDial(ctx); nodial { - return nil, inet.ErrNoConn + if nodial, _ := network.GetNoDial(ctx); nodial { + return nil, network.ErrNoConn } if dials >= DialAttempts { @@ -322,13 +324,13 @@ func (s *Swarm) NewStream(ctx context.Context, p peer.ID) (inet.Stream, error) { } // ConnsToPeer returns all the live connections to peer. -func (s *Swarm) ConnsToPeer(p peer.ID) []inet.Conn { +func (s *Swarm) ConnsToPeer(p peer.ID) []network.Conn { // TODO: Consider sorting the connection list best to worst. Currently, // it's sorted oldest to newest. s.conns.RLock() defer s.conns.RUnlock() conns := s.conns.m[p] - output := make([]inet.Conn, len(conns)) + output := make([]network.Conn, len(conns)) for i, c := range conns { output[i] = c } @@ -366,20 +368,20 @@ func (s *Swarm) bestConnToPeer(p peer.ID) *Conn { // Connectedness returns our "connectedness" state with the given peer. // // To check if we have an open connection, use `s.Connectedness(p) == -// inet.Connected`. -func (s *Swarm) Connectedness(p peer.ID) inet.Connectedness { +// network.Connected`. +func (s *Swarm) Connectedness(p peer.ID) network.Connectedness { if s.bestConnToPeer(p) != nil { - return inet.Connected + return network.Connected } - return inet.NotConnected + return network.NotConnected } // Conns returns a slice of all connections. -func (s *Swarm) Conns() []inet.Conn { +func (s *Swarm) Conns() []network.Conn { s.conns.RLock() defer s.conns.RUnlock() - conns := make([]inet.Conn, 0, len(s.conns.m)) + conns := make([]network.Conn, 0, len(s.conns.m)) for _, cs := range s.conns.m { for _, c := range cs { conns = append(conns, c) @@ -399,7 +401,7 @@ func (s *Swarm) ClosePeer(p peer.ID) error { default: errCh := make(chan error) for _, c := range conns { - go func(c inet.Conn) { + go func(c network.Conn) { errCh <- c.Close() }(c) } @@ -441,13 +443,13 @@ func (s *Swarm) Backoff() *DialBackoff { } // notifyAll sends a signal to all Notifiees -func (s *Swarm) notifyAll(notify func(inet.Notifiee)) { +func (s *Swarm) notifyAll(notify func(network.Notifiee)) { var wg sync.WaitGroup s.notifs.RLock() wg.Add(len(s.notifs.m)) for f := range s.notifs.m { - go func(f inet.Notifiee) { + go func(f network.Notifiee) { defer wg.Done() notify(f) }(f) @@ -458,14 +460,14 @@ func (s *Swarm) notifyAll(notify func(inet.Notifiee)) { } // Notify signs up Notifiee to receive signals when events happen -func (s *Swarm) Notify(f inet.Notifiee) { +func (s *Swarm) Notify(f network.Notifiee) { s.notifs.Lock() s.notifs.m[f] = struct{}{} s.notifs.Unlock() } // StopNotify unregisters Notifiee fromr receiving signals -func (s *Swarm) StopNotify(f inet.Notifiee) { +func (s *Swarm) StopNotify(f network.Notifiee) { s.notifs.Lock() delete(s.notifs.m, f) s.notifs.Unlock() @@ -500,5 +502,5 @@ func (s *Swarm) String() string { } // Swarm is a Network. -var _ inet.Network = (*Swarm)(nil) -var _ transport.Network = (*Swarm)(nil) +var _ network.Network = (*Swarm)(nil) +var _ transport.TransportNetwork = (*Swarm)(nil) diff --git a/swarm_addr_test.go b/swarm_addr_test.go index bafcfb66..e75d6606 100644 --- a/swarm_addr_test.go +++ b/swarm_addr_test.go @@ -4,8 +4,9 @@ import ( "context" "testing" - pstore "github.com/libp2p/go-libp2p-peerstore" - testutil "github.com/libp2p/go-testutil" + "github.com/libp2p/go-libp2p-core/peerstore" + "github.com/libp2p/go-libp2p-core/test" + ma "github.com/multiformats/go-multiaddr" ) @@ -23,8 +24,8 @@ func TestDialBadAddrs(t *testing.T) { s := makeSwarms(ctx, t, 1)[0] test := func(a ma.Multiaddr) { - p := testutil.RandPeerIDFatal(t) - s.Peerstore().AddAddr(p, a, pstore.PermanentAddrTTL) + p := test.RandPeerIDFatal(t) + s.Peerstore().AddAddr(p, a, peerstore.PermanentAddrTTL) if _, err := s.DialPeer(ctx, p); err == nil { t.Errorf("swarm should not dial: %s", p) } diff --git a/swarm_conn.go b/swarm_conn.go index 26a7794d..cdb9866a 100644 --- a/swarm_conn.go +++ b/swarm_conn.go @@ -5,11 +5,12 @@ import ( "fmt" "sync" - ic "github.com/libp2p/go-libp2p-crypto" - inet "github.com/libp2p/go-libp2p-net" - peer "github.com/libp2p/go-libp2p-peer" - transport "github.com/libp2p/go-libp2p-transport" - smux "github.com/libp2p/go-stream-muxer" + ic "github.com/libp2p/go-libp2p-core/crypto" + "github.com/libp2p/go-libp2p-core/mux" + "github.com/libp2p/go-libp2p-core/network" + "github.com/libp2p/go-libp2p-core/peer" + "github.com/libp2p/go-libp2p-core/transport" + ma "github.com/multiformats/go-multiaddr" ) @@ -21,7 +22,7 @@ var ErrConnClosed = errors.New("connection closed") // Conn is the connection type used by swarm. In general, you won't use this // type directly. type Conn struct { - conn transport.Conn + conn transport.CapableConn swarm *Swarm closeOnce sync.Once @@ -34,7 +35,7 @@ type Conn struct { m map[*Stream]struct{} } - stat inet.Stat + stat network.Stat } // Close closes this connection. @@ -71,7 +72,7 @@ func (c *Conn) doClose() { c.notifyLk.Lock() defer c.notifyLk.Unlock() - c.swarm.notifyAll(func(f inet.Notifiee) { + c.swarm.notifyAll(func(f network.Notifiee) { f.Disconnected(c.swarm, c) }) c.swarm.refs.Done() // taken in Swarm.addConn @@ -100,7 +101,7 @@ func (c *Conn) start() { } c.swarm.refs.Add(1) go func() { - s, err := c.addStream(ts, inet.DirInbound) + s, err := c.addStream(ts, network.DirInbound) // Don't defer this. We don't want to block // swarm shutdown on the connection handler. @@ -161,20 +162,20 @@ func (c *Conn) RemotePublicKey() ic.PubKey { } // Stat returns metadata pertaining to this connection -func (c *Conn) Stat() inet.Stat { +func (c *Conn) Stat() network.Stat { return c.stat } // NewStream returns a new Stream from this connection -func (c *Conn) NewStream() (inet.Stream, error) { +func (c *Conn) NewStream() (network.Stream, error) { ts, err := c.conn.OpenStream() if err != nil { return nil, err } - return c.addStream(ts, inet.DirOutbound) + return c.addStream(ts, network.DirOutbound) } -func (c *Conn) addStream(ts smux.Stream, dir inet.Direction) (*Stream, error) { +func (c *Conn) addStream(ts mux.MuxedStream, dir network.Direction) (*Stream, error) { c.streams.Lock() // Are we still online? if c.streams.m == nil { @@ -184,7 +185,7 @@ func (c *Conn) addStream(ts smux.Stream, dir inet.Direction) (*Stream, error) { } // Wrap and register the stream. - stat := inet.Stat{Direction: dir} + stat := network.Stat{Direction: dir} s := &Stream{ stream: ts, conn: c, @@ -202,7 +203,7 @@ func (c *Conn) addStream(ts smux.Stream, dir inet.Direction) (*Stream, error) { s.notifyLk.Lock() c.streams.Unlock() - c.swarm.notifyAll(func(f inet.Notifiee) { + c.swarm.notifyAll(func(f network.Notifiee) { f.OpenedStream(c.swarm, s) }) s.notifyLk.Unlock() @@ -211,10 +212,10 @@ func (c *Conn) addStream(ts smux.Stream, dir inet.Direction) (*Stream, error) { } // GetStreams returns the streams associated with this connection. -func (c *Conn) GetStreams() []inet.Stream { +func (c *Conn) GetStreams() []network.Stream { c.streams.Lock() defer c.streams.Unlock() - streams := make([]inet.Stream, 0, len(c.streams.m)) + streams := make([]network.Stream, 0, len(c.streams.m)) for s := range c.streams.m { streams = append(streams, s) } diff --git a/swarm_dial.go b/swarm_dial.go index 3feeffe3..40faad78 100644 --- a/swarm_dial.go +++ b/swarm_dial.go @@ -7,12 +7,13 @@ import ( "sync" "time" + "github.com/libp2p/go-libp2p-core/network" + "github.com/libp2p/go-libp2p-core/peer" + "github.com/libp2p/go-libp2p-core/transport" + lgbl "github.com/libp2p/go-libp2p-loggables" + logging "github.com/ipfs/go-log" addrutil "github.com/libp2p/go-addr-util" - lgbl "github.com/libp2p/go-libp2p-loggables" - inet "github.com/libp2p/go-libp2p-net" - peer "github.com/libp2p/go-libp2p-peer" - transport "github.com/libp2p/go-libp2p-transport" ma "github.com/multiformats/go-multiaddr" ) @@ -180,7 +181,7 @@ func (db *DialBackoff) Clear(p peer.ID) { // the connection will happen over. Swarm can use whichever it choses. // 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) (inet.Conn, error) { +func (s *Swarm) DialPeer(ctx context.Context, p peer.ID) (network.Conn, error) { return s.dialPeer(ctx, p) } @@ -216,7 +217,7 @@ func (s *Swarm) dialPeer(ctx context.Context, p peer.ID) (*Conn, error) { } // apply the DialPeer timeout - ctx, cancel := context.WithTimeout(ctx, inet.GetDialPeerTimeout(ctx)) + ctx, cancel := context.WithTimeout(ctx, network.GetDialPeerTimeout(ctx)) defer cancel() conn, err = s.dsync.DialLock(ctx, p) @@ -330,7 +331,7 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) { "localAddr": connC.LocalMultiaddr(), "remoteAddr": connC.RemoteMultiaddr(), } - swarmC, err := s.addConn(connC, inet.DirOutbound) + swarmC, err := s.addConn(connC, network.DirOutbound) if err != nil { logdial["error"] = err.Error() connC.Close() // close the connection. didn't work out :( @@ -366,7 +367,7 @@ func (s *Swarm) filterKnownUndialables(addrs []ma.Multiaddr) []ma.Multiaddr { ) } -func (s *Swarm) dialAddrs(ctx context.Context, p peer.ID, remoteAddrs <-chan ma.Multiaddr) (transport.Conn, *DialError) { +func (s *Swarm) dialAddrs(ctx context.Context, p peer.ID, remoteAddrs <-chan ma.Multiaddr) (transport.CapableConn, *DialError) { log.Debugf("%s swarm dialing %s", s.local, p) ctx, cancel := context.WithCancel(ctx) @@ -427,7 +428,7 @@ dialLoop: if ctxErr := ctx.Err(); ctxErr != nil { err.Cause = ctxErr } else if len(err.DialErrors) == 0 { - err.Cause = inet.ErrNoRemoteAddrs + err.Cause = network.ErrNoRemoteAddrs } else { err.Cause = ErrAllDialsFailed } @@ -446,7 +447,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) (transport.Conn, error) { +func (s *Swarm) dialAddr(ctx context.Context, p peer.ID, addr ma.Multiaddr) (transport.CapableConn, error) { // Just to double check. Costs nothing. if s.local == p { return nil, ErrDialToSelf diff --git a/swarm_listen.go b/swarm_listen.go index 7b37d534..85060c4e 100644 --- a/swarm_listen.go +++ b/swarm_listen.go @@ -3,7 +3,8 @@ package swarm import ( "fmt" - inet "github.com/libp2p/go-libp2p-net" + "github.com/libp2p/go-libp2p-core/network" + ma "github.com/multiformats/go-multiaddr" ) @@ -59,7 +60,7 @@ func (s *Swarm) AddListenAddr(a ma.Multiaddr) error { maddr := list.Multiaddr() // signal to our notifiees on successful conn. - s.notifyAll(func(n inet.Notifiee) { + s.notifyAll(func(n network.Notifiee) { n.Listen(s, maddr) }) @@ -83,7 +84,7 @@ func (s *Swarm) AddListenAddr(a ma.Multiaddr) error { s.refs.Add(1) go func() { defer s.refs.Done() - _, err := s.addConn(c, inet.DirInbound) + _, err := s.addConn(c, network.DirInbound) if err != nil { // Probably just means that the swarm has been closed. log.Warningf("add conn failed: ", err) diff --git a/swarm_net_test.go b/swarm_net_test.go index 425a1707..2ba64edb 100644 --- a/swarm_net_test.go +++ b/swarm_net_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - inet "github.com/libp2p/go-libp2p-net" + "github.com/libp2p/go-libp2p-core/network" . "github.com/libp2p/go-libp2p-swarm/testing" ) @@ -17,14 +17,14 @@ func TestConnectednessCorrect(t *testing.T) { ctx := context.Background() - nets := make([]inet.Network, 4) + nets := make([]network.Network, 4) for i := 0; i < 4; i++ { nets[i] = GenSwarm(t, ctx) } // connect 0-1, 0-2, 0-3, 1-2, 2-3 - dial := func(a, b inet.Network) { + dial := func(a, b network.Network) { DivulgeAddresses(b, a) if _, err := a.DialPeer(ctx, b.LocalPeer()); err != nil { t.Fatalf("Failed to dial: %s", err) @@ -44,14 +44,14 @@ func TestConnectednessCorrect(t *testing.T) { // test those connected show up correctly // test connected - expectConnectedness(t, nets[0], nets[1], inet.Connected) - expectConnectedness(t, nets[0], nets[3], inet.Connected) - expectConnectedness(t, nets[1], nets[2], inet.Connected) - expectConnectedness(t, nets[3], nets[2], inet.Connected) + expectConnectedness(t, nets[0], nets[1], network.Connected) + expectConnectedness(t, nets[0], nets[3], network.Connected) + expectConnectedness(t, nets[1], nets[2], network.Connected) + expectConnectedness(t, nets[3], nets[2], network.Connected) // test not connected - expectConnectedness(t, nets[0], nets[2], inet.NotConnected) - expectConnectedness(t, nets[1], nets[3], inet.NotConnected) + expectConnectedness(t, nets[0], nets[2], network.NotConnected) + expectConnectedness(t, nets[1], nets[3], network.NotConnected) if len(nets[0].Peers()) != 2 { t.Fatal("expected net 0 to have two peers") @@ -71,7 +71,7 @@ func TestConnectednessCorrect(t *testing.T) { time.Sleep(time.Millisecond * 50) - expectConnectedness(t, nets[2], nets[1], inet.NotConnected) + expectConnectedness(t, nets[2], nets[1], network.NotConnected) for _, n := range nets { n.Close() @@ -82,7 +82,7 @@ func TestConnectednessCorrect(t *testing.T) { } } -func expectConnectedness(t *testing.T, a, b inet.Network, expected inet.Connectedness) { +func expectConnectedness(t *testing.T, a, b network.Network, expected network.Connectedness) { es := "%s is connected to %s, but Connectedness incorrect. %s %s %s" atob := a.Connectedness(b.LocalPeer()) btoa := b.Connectedness(a.LocalPeer()) @@ -96,7 +96,7 @@ func expectConnectedness(t *testing.T, a, b inet.Network, expected inet.Connecte } } -func printConns(n inet.Network) string { +func printConns(n network.Network) string { s := fmt.Sprintf("Connections in %s:\n", n) for _, c := range n.Conns() { s = s + fmt.Sprintf("- %s\n", c) @@ -108,12 +108,12 @@ func TestNetworkOpenStream(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - nets := make([]inet.Network, 4) + nets := make([]network.Network, 4) for i := 0; i < 4; i++ { nets[i] = GenSwarm(t, ctx) } - dial := func(a, b inet.Network) { + dial := func(a, b network.Network) { DivulgeAddresses(b, a) if _, err := a.DialPeer(ctx, b.LocalPeer()); err != nil { t.Fatalf("Failed to dial: %s", err) @@ -125,7 +125,7 @@ func TestNetworkOpenStream(t *testing.T) { dial(nets[1], nets[2]) done := make(chan bool) - nets[1].SetStreamHandler(func(s inet.Stream) { + nets[1].SetStreamHandler(func(s network.Stream) { defer close(done) defer s.Close() diff --git a/swarm_notif_test.go b/swarm_notif_test.go index d05766d6..f2c91ebb 100644 --- a/swarm_notif_test.go +++ b/swarm_notif_test.go @@ -1,12 +1,13 @@ package swarm_test import ( + "context" "testing" "time" - "context" - inet "github.com/libp2p/go-libp2p-net" - peer "github.com/libp2p/go-libp2p-peer" + "github.com/libp2p/go-libp2p-core/network" + "github.com/libp2p/go-libp2p-core/peer" + ma "github.com/multiformats/go-multiaddr" . "github.com/libp2p/go-libp2p-swarm" @@ -41,7 +42,7 @@ func TestNotifications(t *testing.T) { // test everyone got the correct connection opened calls for i, s := range swarms { n := notifiees[i] - notifs := make(map[peer.ID][]inet.Conn) + notifs := make(map[peer.ID][]network.Conn) for j, s2 := range swarms { if i == j { continue @@ -81,7 +82,7 @@ func TestNotifications(t *testing.T) { } } - complement := func(c inet.Conn) (*Swarm, *netNotifiee, *Conn) { + complement := func(c network.Conn) (*Swarm, *netNotifiee, *Conn) { for i, s := range swarms { for _, c2 := range s.Conns() { if c.LocalMultiaddr().Equal(c2.RemoteMultiaddr()) && @@ -94,8 +95,8 @@ func TestNotifications(t *testing.T) { return nil, nil, nil } - testOCStream := func(n *netNotifiee, s inet.Stream) { - var s2 inet.Stream + testOCStream := func(n *netNotifiee, s network.Stream) { + var s2 network.Stream select { case s2 = <-n.openedStream: t.Log("got notif for opened stream") @@ -117,9 +118,9 @@ func TestNotifications(t *testing.T) { } } - streams := make(chan inet.Stream) + streams := make(chan network.Stream) for _, s := range swarms { - s.SetStreamHandler(func(s inet.Stream) { + s.SetStreamHandler(func(s network.Stream) { streams <- s s.Reset() }) @@ -151,7 +152,7 @@ func TestNotifications(t *testing.T) { c.Close() c2.Close() - var c3, c4 inet.Conn + var c3, c4 network.Conn select { case c3 = <-n.disconnected: case <-time.After(timeout): @@ -176,38 +177,38 @@ func TestNotifications(t *testing.T) { type netNotifiee struct { listen chan ma.Multiaddr listenClose chan ma.Multiaddr - connected chan inet.Conn - disconnected chan inet.Conn - openedStream chan inet.Stream - closedStream chan inet.Stream + connected chan network.Conn + disconnected chan network.Conn + openedStream chan network.Stream + closedStream chan network.Stream } func newNetNotifiee(buffer int) *netNotifiee { return &netNotifiee{ listen: make(chan ma.Multiaddr, buffer), listenClose: make(chan ma.Multiaddr, buffer), - connected: make(chan inet.Conn, buffer), - disconnected: make(chan inet.Conn, buffer), - openedStream: make(chan inet.Stream, buffer), - closedStream: make(chan inet.Stream, buffer), + connected: make(chan network.Conn, buffer), + disconnected: make(chan network.Conn, buffer), + openedStream: make(chan network.Stream, buffer), + closedStream: make(chan network.Stream, buffer), } } -func (nn *netNotifiee) Listen(n inet.Network, a ma.Multiaddr) { +func (nn *netNotifiee) Listen(n network.Network, a ma.Multiaddr) { nn.listen <- a } -func (nn *netNotifiee) ListenClose(n inet.Network, a ma.Multiaddr) { +func (nn *netNotifiee) ListenClose(n network.Network, a ma.Multiaddr) { nn.listenClose <- a } -func (nn *netNotifiee) Connected(n inet.Network, v inet.Conn) { +func (nn *netNotifiee) Connected(n network.Network, v network.Conn) { nn.connected <- v } -func (nn *netNotifiee) Disconnected(n inet.Network, v inet.Conn) { +func (nn *netNotifiee) Disconnected(n network.Network, v network.Conn) { nn.disconnected <- v } -func (nn *netNotifiee) OpenedStream(n inet.Network, v inet.Stream) { +func (nn *netNotifiee) OpenedStream(n network.Network, v network.Stream) { nn.openedStream <- v } -func (nn *netNotifiee) ClosedStream(n inet.Network, v inet.Stream) { +func (nn *netNotifiee) ClosedStream(n network.Network, v network.Stream) { nn.closedStream <- v } diff --git a/swarm_stream.go b/swarm_stream.go index 754dbd50..9dded2a9 100644 --- a/swarm_stream.go +++ b/swarm_stream.go @@ -7,9 +7,9 @@ import ( "sync/atomic" "time" - inet "github.com/libp2p/go-libp2p-net" - protocol "github.com/libp2p/go-libp2p-protocol" - smux "github.com/libp2p/go-stream-muxer" + "github.com/libp2p/go-libp2p-core/mux" + "github.com/libp2p/go-libp2p-core/network" + "github.com/libp2p/go-libp2p-core/protocol" ) type streamState int @@ -23,12 +23,12 @@ const ( ) // Validate Stream conforms to the go-libp2p-net Stream interface -var _ inet.Stream = &Stream{} +var _ network.Stream = &Stream{} // Stream is the stream type used by swarm. In general, you won't use this type // directly. type Stream struct { - stream smux.Stream + stream mux.MuxedStream conn *Conn state struct { @@ -40,7 +40,7 @@ type Stream struct { protocol atomic.Value - stat inet.Stat + stat network.Stat } func (s *Stream) String() string { @@ -54,8 +54,8 @@ func (s *Stream) String() string { ) } -// Conn returns the Conn associated with this stream, as an inet.Conn -func (s *Stream) Conn() inet.Conn { +// Conn returns the Conn associated with this stream, as an network.Conn +func (s *Stream) Conn() network.Conn { return s.conn } @@ -133,7 +133,7 @@ func (s *Stream) remove() { s.notifyLk.Lock() defer s.notifyLk.Unlock() - s.conn.swarm.notifyAll(func(f inet.Notifiee) { + s.conn.swarm.notifyAll(func(f network.Notifiee) { f.ClosedStream(s.conn.swarm, s) }) s.conn.swarm.refs.Done() @@ -172,6 +172,6 @@ func (s *Stream) SetWriteDeadline(t time.Time) error { } // Stat returns metadata information for this stream. -func (s *Stream) Stat() inet.Stat { +func (s *Stream) Stat() network.Stat { return s.stat } diff --git a/swarm_test.go b/swarm_test.go index 69eceb94..b155373f 100644 --- a/swarm_test.go +++ b/swarm_test.go @@ -11,9 +11,10 @@ import ( "time" logging "github.com/ipfs/go-log" - inet "github.com/libp2p/go-libp2p-net" - peer "github.com/libp2p/go-libp2p-peer" - pstore "github.com/libp2p/go-libp2p-peerstore" + "github.com/libp2p/go-libp2p-core/network" + "github.com/libp2p/go-libp2p-core/peer" + "github.com/libp2p/go-libp2p-core/peerstore" + ma "github.com/multiformats/go-multiaddr" . "github.com/libp2p/go-libp2p-swarm" @@ -22,7 +23,7 @@ import ( var log = logging.Logger("swarm_test") -func EchoStreamHandler(stream inet.Stream) { +func EchoStreamHandler(stream network.Stream) { go func() { defer stream.Close() @@ -77,7 +78,7 @@ func connectSwarms(t *testing.T, ctx context.Context, swarms []*Swarm) { var wg sync.WaitGroup connect := func(s *Swarm, dst peer.ID, addr ma.Multiaddr) { // TODO: make a DialAddr func. - s.Peerstore().AddAddr(dst, addr, pstore.PermanentAddrTTL) + s.Peerstore().AddAddr(dst, addr, peerstore.PermanentAddrTTL) if _, err := s.DialPeer(ctx, dst); err != nil { t.Fatal("error swarm dialing to peer", err) } @@ -116,7 +117,7 @@ func SubtestSwarm(t *testing.T, SwarmNum int, MsgNum int) { _, cancel := context.WithCancel(ctx) got := map[peer.ID]int{} errChan := make(chan error, MsgNum*len(swarms)) - streamChan := make(chan inet.Stream, MsgNum) + streamChan := make(chan network.Stream, MsgNum) // send out "ping" x MsgNum to every peer go func() { @@ -252,7 +253,7 @@ func TestConnHandler(t *testing.T) { swarms := makeSwarms(ctx, t, 5) gotconn := make(chan struct{}, 10) - swarms[0].SetConnHandler(func(conn inet.Conn) { + swarms[0].SetConnHandler(func(conn network.Conn) { gotconn <- struct{}{} }) @@ -283,7 +284,7 @@ func TestAddrBlocking(t *testing.T) { ctx := context.Background() swarms := makeSwarms(ctx, t, 2) - swarms[0].SetConnHandler(func(conn inet.Conn) { + swarms[0].SetConnHandler(func(conn network.Conn) { t.Errorf("no connections should happen! -- %s", conn) }) @@ -294,13 +295,13 @@ func TestAddrBlocking(t *testing.T) { swarms[1].Filters.AddDialFilter(block) - swarms[1].Peerstore().AddAddr(swarms[0].LocalPeer(), swarms[0].ListenAddresses()[0], pstore.PermanentAddrTTL) + swarms[1].Peerstore().AddAddr(swarms[0].LocalPeer(), swarms[0].ListenAddresses()[0], peerstore.PermanentAddrTTL) _, err = swarms[1].DialPeer(ctx, swarms[0].LocalPeer()) if err == nil { t.Fatal("dial should have failed") } - swarms[0].Peerstore().AddAddr(swarms[1].LocalPeer(), swarms[1].ListenAddresses()[0], pstore.PermanentAddrTTL) + swarms[0].Peerstore().AddAddr(swarms[1].LocalPeer(), swarms[1].ListenAddresses()[0], peerstore.PermanentAddrTTL) _, err = swarms[0].DialPeer(ctx, swarms[1].LocalPeer()) if err == nil { t.Fatal("dial should have failed") @@ -312,7 +313,7 @@ func TestFilterBounds(t *testing.T) { swarms := makeSwarms(ctx, t, 2) conns := make(chan struct{}, 8) - swarms[0].SetConnHandler(func(conn inet.Conn) { + swarms[0].SetConnHandler(func(conn network.Conn) { conns <- struct{}{} }) @@ -340,8 +341,8 @@ func TestNoDial(t *testing.T) { ctx := context.Background() swarms := makeSwarms(ctx, t, 2) - _, err := swarms[0].NewStream(inet.WithNoDial(ctx, "swarm test"), swarms[1].LocalPeer()) - if err != inet.ErrNoConn { + _, err := swarms[0].NewStream(network.WithNoDial(ctx, "swarm test"), swarms[1].LocalPeer()) + if err != network.ErrNoConn { t.Fatal("should have failed with ErrNoConn") } } diff --git a/swarm_transport.go b/swarm_transport.go index 04314887..307bfe64 100644 --- a/swarm_transport.go +++ b/swarm_transport.go @@ -4,7 +4,8 @@ import ( "fmt" "strings" - transport "github.com/libp2p/go-libp2p-transport" + "github.com/libp2p/go-libp2p-core/transport" + ma "github.com/multiformats/go-multiaddr" ) diff --git a/testing/testing.go b/testing/testing.go index edaaf5b2..6ffe7d2a 100644 --- a/testing/testing.go +++ b/testing/testing.go @@ -4,17 +4,18 @@ import ( "context" "testing" + "github.com/libp2p/go-libp2p-core/metrics" + "github.com/libp2p/go-libp2p-core/network" + "github.com/libp2p/go-libp2p-core/peerstore" + "github.com/libp2p/go-libp2p-testing/net" + "github.com/libp2p/go-tcp-transport" + csms "github.com/libp2p/go-conn-security-multistream" - metrics "github.com/libp2p/go-libp2p-metrics" - inet "github.com/libp2p/go-libp2p-net" - pstore "github.com/libp2p/go-libp2p-peerstore" pstoremem "github.com/libp2p/go-libp2p-peerstore/pstoremem" secio "github.com/libp2p/go-libp2p-secio" tptu "github.com/libp2p/go-libp2p-transport-upgrader" yamux "github.com/libp2p/go-libp2p-yamux" msmux "github.com/libp2p/go-stream-muxer-multistream" - tcp "github.com/libp2p/go-tcp-transport" - tu "github.com/libp2p/go-testutil" swarm "github.com/libp2p/go-libp2p-swarm" ) @@ -65,7 +66,7 @@ func GenSwarm(t *testing.T, ctx context.Context, opts ...Option) *swarm.Swarm { o(t, &cfg) } - p := tu.RandPeerNetParamsOrFatal(t) + p := tnet.RandPeerNetParamsOrFatal(t) ps := pstoremem.NewPeerstore() ps.AddPubKey(p.ID, p.PubKey) @@ -84,15 +85,15 @@ func GenSwarm(t *testing.T, ctx context.Context, opts ...Option) *swarm.Swarm { t.Fatal(err) } - s.Peerstore().AddAddrs(p.ID, s.ListenAddresses(), pstore.PermanentAddrTTL) + s.Peerstore().AddAddrs(p.ID, s.ListenAddresses(), peerstore.PermanentAddrTTL) } return s } // DivulgeAddresses adds swarm a's addresses to swarm b's peerstore. -func DivulgeAddresses(a, b inet.Network) { +func DivulgeAddresses(a, b network.Network) { id := a.LocalPeer() addrs := a.Peerstore().Addrs(id) - b.Peerstore().AddAddrs(id, addrs, pstore.PermanentAddrTTL) + b.Peerstore().AddAddrs(id, addrs, peerstore.PermanentAddrTTL) } diff --git a/transport_test.go b/transport_test.go index 018775b2..f6090a6e 100644 --- a/transport_test.go +++ b/transport_test.go @@ -6,8 +6,8 @@ import ( swarmt "github.com/libp2p/go-libp2p-swarm/testing" - peer "github.com/libp2p/go-libp2p-peer" - transport "github.com/libp2p/go-libp2p-transport" + "github.com/libp2p/go-libp2p-core/peer" + "github.com/libp2p/go-libp2p-core/transport" ma "github.com/multiformats/go-multiaddr" ) @@ -16,7 +16,7 @@ type dummyTransport struct { proxy bool } -func (dt *dummyTransport) Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (transport.Conn, error) { +func (dt *dummyTransport) Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (transport.CapableConn, error) { panic("unimplemented") }