diff --git a/p2p/host/basic/basic_host.go b/p2p/host/basic/basic_host.go index 58b4d5e67d8e0a1c03a4793e11c5c6b2b61356e3..170677c83256759d7b91bdcc509b20834cf71a6f 100644 --- a/p2p/host/basic/basic_host.go +++ b/p2p/host/basic/basic_host.go @@ -10,10 +10,10 @@ import ( logging "github.com/ipfs/go-log" ma "github.com/jbenet/go-multiaddr" goprocess "github.com/jbenet/goprocess" + protocol "github.com/libp2p/go-libp2p-protocol" metrics "github.com/libp2p/go-libp2p/p2p/metrics" mstream "github.com/libp2p/go-libp2p/p2p/metrics/stream" inet "github.com/libp2p/go-libp2p/p2p/net" - protocol "github.com/libp2p/go-libp2p/p2p/protocol" identify "github.com/libp2p/go-libp2p/p2p/protocol/identify" relay "github.com/libp2p/go-libp2p/p2p/protocol/relay" diff --git a/p2p/host/basic/basic_host_test.go b/p2p/host/basic/basic_host_test.go index 549931aeb3173c844064e0f744afae57ef285b68..00a9d20f1928a1a15cd4b06bea0b40aba67d90c6 100644 --- a/p2p/host/basic/basic_host_test.go +++ b/p2p/host/basic/basic_host_test.go @@ -7,9 +7,9 @@ import ( "testing" "time" + protocol "github.com/libp2p/go-libp2p-protocol" host "github.com/libp2p/go-libp2p/p2p/host" inet "github.com/libp2p/go-libp2p/p2p/net" - protocol "github.com/libp2p/go-libp2p/p2p/protocol" testutil "github.com/libp2p/go-libp2p/p2p/test/util" ) diff --git a/p2p/host/host.go b/p2p/host/host.go index 20af1e9147656969fd29252b4878c3fbd3f32815..4fee58049bfdfccd00b60cf1c164df527d8a9f33 100644 --- a/p2p/host/host.go +++ b/p2p/host/host.go @@ -7,9 +7,9 @@ import ( pstore "github.com/ipfs/go-libp2p-peerstore" logging "github.com/ipfs/go-log" ma "github.com/jbenet/go-multiaddr" + protocol "github.com/libp2p/go-libp2p-protocol" metrics "github.com/libp2p/go-libp2p/p2p/metrics" inet "github.com/libp2p/go-libp2p/p2p/net" - protocol "github.com/libp2p/go-libp2p/p2p/protocol" msmux "github.com/whyrusleeping/go-multistream" ) diff --git a/p2p/host/match.go b/p2p/host/match.go index 571d652c23a6065072b1f496c816d98056b97285..84b5def8f8be33c635263e832a4d252f7e480406 100644 --- a/p2p/host/match.go +++ b/p2p/host/match.go @@ -1,7 +1,7 @@ package host import ( - "github.com/libp2p/go-libp2p/p2p/protocol" + "github.com/libp2p/go-libp2p-protocol" "strings" semver "github.com/coreos/go-semver/semver" diff --git a/p2p/host/routed/routed.go b/p2p/host/routed/routed.go index 2ae808c5f1e8d1ced8ccc48debd7f8bce4c7599a..7737a592a20b17a5d454dd7ec082c3baa4a10a0d 100644 --- a/p2p/host/routed/routed.go +++ b/p2p/host/routed/routed.go @@ -10,10 +10,10 @@ import ( pstore "github.com/ipfs/go-libp2p-peerstore" logging "github.com/ipfs/go-log" ma "github.com/jbenet/go-multiaddr" + protocol "github.com/libp2p/go-libp2p-protocol" host "github.com/libp2p/go-libp2p/p2p/host" metrics "github.com/libp2p/go-libp2p/p2p/metrics" inet "github.com/libp2p/go-libp2p/p2p/net" - protocol "github.com/libp2p/go-libp2p/p2p/protocol" msmux "github.com/whyrusleeping/go-multistream" ) diff --git a/p2p/metrics/bw_stats.go b/p2p/metrics/bw_stats.go index 3b5fedd59960ff307581cee79654245dab4ffefd..e34ec1c51fed56a1b6848cab15135f62801d7565 100644 --- a/p2p/metrics/bw_stats.go +++ b/p2p/metrics/bw_stats.go @@ -5,7 +5,7 @@ import ( "sync" peer "github.com/ipfs/go-libp2p-peer" - protocol "github.com/libp2p/go-libp2p/p2p/protocol" + protocol "github.com/libp2p/go-libp2p-protocol" ) type Stats struct { diff --git a/p2p/metrics/interface.go b/p2p/metrics/interface.go index 1ceb1e95c51694ebd61a66980d529297ff668eb4..814e94fcf9c415532dad554db1bc10735e90c4d6 100644 --- a/p2p/metrics/interface.go +++ b/p2p/metrics/interface.go @@ -2,7 +2,7 @@ package metrics import ( peer "github.com/ipfs/go-libp2p-peer" - protocol "github.com/libp2p/go-libp2p/p2p/protocol" + protocol "github.com/libp2p/go-libp2p-protocol" ) type StreamMeterCallback func(int64, protocol.ID, peer.ID) diff --git a/p2p/metrics/stream/metered.go b/p2p/metrics/stream/metered.go index 14de24c575de682e62686a11b6ea9b46b123241c..3eddfd4dbee1376d17e1c7bc7a46ee3dfd350390 100644 --- a/p2p/metrics/stream/metered.go +++ b/p2p/metrics/stream/metered.go @@ -2,9 +2,9 @@ package meterstream import ( peer "github.com/ipfs/go-libp2p-peer" + protocol "github.com/libp2p/go-libp2p-protocol" metrics "github.com/libp2p/go-libp2p/p2p/metrics" inet "github.com/libp2p/go-libp2p/p2p/net" - protocol "github.com/libp2p/go-libp2p/p2p/protocol" ) type meteredStream struct { diff --git a/p2p/metrics/stream/metered_test.go b/p2p/metrics/stream/metered_test.go index 22b3f9370149d0eba22d7211f793b2c9ada71299..9c1d1214700dbd932309221d14a257f7c22a45d5 100644 --- a/p2p/metrics/stream/metered_test.go +++ b/p2p/metrics/stream/metered_test.go @@ -7,8 +7,8 @@ import ( randbo "github.com/dustin/randbo" peer "github.com/ipfs/go-libp2p-peer" + protocol "github.com/libp2p/go-libp2p-protocol" inet "github.com/libp2p/go-libp2p/p2p/net" - protocol "github.com/libp2p/go-libp2p/p2p/protocol" ) type FakeStream struct { diff --git a/p2p/net/conn/interface.go b/p2p/net/conn/interface.go index 61cf623ed7c8ecfda078791fc84c7e71cf523c85..cc49606bb6a962ee145089b31d037ffe6ea60ec4 100644 --- a/p2p/net/conn/interface.go +++ b/p2p/net/conn/interface.go @@ -9,7 +9,7 @@ import ( peer "github.com/ipfs/go-libp2p-peer" ma "github.com/jbenet/go-multiaddr" transport "github.com/libp2p/go-libp2p-transport" - filter "github.com/libp2p/go-libp2p/p2p/net/filter" + filter "github.com/libp2p/go-maddr-filter" ) type PeerConn interface { diff --git a/p2p/net/conn/listen.go b/p2p/net/conn/listen.go index 8bacd0e87b37e75e6bb387defe2c3aeb677a1d36..6098ff79c755d16ed6aae17d735d65b6ce523bf6 100644 --- a/p2p/net/conn/listen.go +++ b/p2p/net/conn/listen.go @@ -15,7 +15,7 @@ import ( "github.com/jbenet/goprocess" goprocessctx "github.com/jbenet/goprocess/context" transport "github.com/libp2p/go-libp2p-transport" - filter "github.com/libp2p/go-libp2p/p2p/net/filter" + filter "github.com/libp2p/go-maddr-filter" msmux "github.com/whyrusleeping/go-multistream" ) diff --git a/p2p/net/filter/filter.go b/p2p/net/filter/filter.go deleted file mode 100644 index c31ad0b752e59a1c16bc7efbb00b63bb3457223c..0000000000000000000000000000000000000000 --- a/p2p/net/filter/filter.go +++ /dev/null @@ -1,67 +0,0 @@ -package filter - -import ( - "net" - "sync" - - ma "github.com/jbenet/go-multiaddr" - manet "github.com/jbenet/go-multiaddr-net" -) - -type Filters struct { - mu sync.RWMutex - filters map[string]*net.IPNet -} - -func NewFilters() *Filters { - return &Filters{ - filters: make(map[string]*net.IPNet), - } -} - -func (fs *Filters) AddDialFilter(f *net.IPNet) { - fs.mu.Lock() - defer fs.mu.Unlock() - fs.filters[f.String()] = f -} - -func (f *Filters) AddrBlocked(a ma.Multiaddr) bool { - maddr := ma.Split(a) - if len(maddr) == 0 { - return false - } - netaddr, err := manet.ToNetAddr(maddr[0]) - if err != nil { - // if we cant parse it, its probably not blocked - return false - } - netip := net.ParseIP(netaddr.String()) - if netip == nil { - return false - } - - f.mu.RLock() - defer f.mu.RUnlock() - for _, ft := range f.filters { - if ft.Contains(netip) { - return true - } - } - return false -} - -func (f *Filters) Filters() []*net.IPNet { - var out []*net.IPNet - f.mu.RLock() - defer f.mu.RUnlock() - for _, ff := range f.filters { - out = append(out, ff) - } - return out -} - -func (f *Filters) Remove(ff *net.IPNet) { - f.mu.Lock() - defer f.mu.Unlock() - delete(f.filters, ff.String()) -} diff --git a/p2p/net/filter/filter_test.go b/p2p/net/filter/filter_test.go deleted file mode 100644 index 8cd0bcc339d615f31932bbde085270d2b389f58c..0000000000000000000000000000000000000000 --- a/p2p/net/filter/filter_test.go +++ /dev/null @@ -1,51 +0,0 @@ -package filter - -import ( - "net" - "testing" - - ma "github.com/jbenet/go-multiaddr" -) - -func TestFilter(t *testing.T) { - f := NewFilters() - for _, cidr := range []string{ - "1.2.3.0/24", - "4.3.2.1/32", - "fd00::/8", - "fc00::1/128", - } { - _, ipnet, _ := net.ParseCIDR(cidr) - f.AddDialFilter(ipnet) - } - - for _, blocked := range []string{ - "/ip4/1.2.3.4/tcp/123", - "/ip4/4.3.2.1/udp/123", - "/ip6/fd00::2/tcp/321", - "/ip6/fc00::1/udp/321", - } { - maddr, err := ma.NewMultiaddr(blocked) - if err != nil { - t.Error(err) - } - if !f.AddrBlocked(maddr) { - t.Fatalf("expected %s to be blocked", blocked) - } - } - - for _, notBlocked := range []string{ - "/ip4/1.2.4.1/tcp/123", - "/ip4/4.3.2.2/udp/123", - "/ip6/fe00::1/tcp/321", - "/ip6/fc00::2/udp/321", - } { - maddr, err := ma.NewMultiaddr(notBlocked) - if err != nil { - t.Error(err) - } - if f.AddrBlocked(maddr) { - t.Fatalf("expected %s to not be blocked", notBlocked) - } - } -} diff --git a/p2p/net/interface.go b/p2p/net/interface.go index 56237b7f6f0c4e0666b71f1a31989c25254f6e99..fffe0cda5454b3f96af7049c639b353184c08d5c 100644 --- a/p2p/net/interface.go +++ b/p2p/net/interface.go @@ -8,8 +8,8 @@ import ( pstore "github.com/ipfs/go-libp2p-peerstore" ma "github.com/jbenet/go-multiaddr" "github.com/jbenet/goprocess" + protocol "github.com/libp2p/go-libp2p-protocol" conn "github.com/libp2p/go-libp2p/p2p/net/conn" - protocol "github.com/libp2p/go-libp2p/p2p/protocol" ) // MessageSizeMax is a soft (recommended) maximum for network messages. diff --git a/p2p/net/mock/mock_stream.go b/p2p/net/mock/mock_stream.go index dac95688f4a2c3044df93eeba16323513a0da1b4..4aa623a6fadb7407f077c3d2d1aa69d8dd46570d 100644 --- a/p2p/net/mock/mock_stream.go +++ b/p2p/net/mock/mock_stream.go @@ -6,8 +6,8 @@ import ( "time" process "github.com/jbenet/goprocess" + protocol "github.com/libp2p/go-libp2p-protocol" inet "github.com/libp2p/go-libp2p/p2p/net" - protocol "github.com/libp2p/go-libp2p/p2p/protocol" ) // stream implements inet.Stream diff --git a/p2p/net/mock/mock_test.go b/p2p/net/mock/mock_test.go index 5fe27425ba5f38e24fbb8c776dfd0d947bac2f8d..e00cb10acc866400f94505f1aef08012f7c15fe2 100644 --- a/p2p/net/mock/mock_test.go +++ b/p2p/net/mock/mock_test.go @@ -10,8 +10,8 @@ import ( "time" peer "github.com/ipfs/go-libp2p-peer" + protocol "github.com/libp2p/go-libp2p-protocol" inet "github.com/libp2p/go-libp2p/p2p/net" - protocol "github.com/libp2p/go-libp2p/p2p/protocol" testutil "github.com/libp2p/go-libp2p/testutil" "context" diff --git a/p2p/net/swarm/swarm.go b/p2p/net/swarm/swarm.go index 4eebf626bea5f62145938900b1cca00036568fba..19ccf13eef72908fc4407e4dc01059ae829f5a61 100644 --- a/p2p/net/swarm/swarm.go +++ b/p2p/net/swarm/swarm.go @@ -15,7 +15,6 @@ import ( mconn "github.com/libp2p/go-libp2p/p2p/metrics/conn" inet "github.com/libp2p/go-libp2p/p2p/net" conn "github.com/libp2p/go-libp2p/p2p/net/conn" - filter "github.com/libp2p/go-libp2p/p2p/net/filter" addrutil "github.com/libp2p/go-libp2p/p2p/net/swarm/addr" ci "github.com/ipfs/go-libp2p-crypto" @@ -28,6 +27,7 @@ import ( "github.com/jbenet/goprocess" goprocessctx "github.com/jbenet/goprocess/context" transport "github.com/libp2p/go-libp2p-transport" + filter "github.com/libp2p/go-maddr-filter" tcpt "github.com/libp2p/go-tcp-transport" psmss "github.com/whyrusleeping/go-smux-multistream" spdy "github.com/whyrusleeping/go-smux-spdystream" diff --git a/p2p/net/swarm/swarm_stream.go b/p2p/net/swarm/swarm_stream.go index dc365e8c092c79d439daf532980412d88e07008d..51c846001a5df43c85e7ff7e445459ead056d85b 100644 --- a/p2p/net/swarm/swarm_stream.go +++ b/p2p/net/swarm/swarm_stream.go @@ -1,8 +1,8 @@ package swarm import ( + protocol "github.com/libp2p/go-libp2p-protocol" inet "github.com/libp2p/go-libp2p/p2p/net" - protocol "github.com/libp2p/go-libp2p/p2p/protocol" ps "github.com/jbenet/go-peerstream" ) diff --git a/p2p/protocol/protocol.go b/p2p/protocol/protocol.go deleted file mode 100644 index f7e4a32baf00a9f1cb2e91a053939ca40f7ec8a3..0000000000000000000000000000000000000000 --- a/p2p/protocol/protocol.go +++ /dev/null @@ -1,9 +0,0 @@ -package protocol - -// ID is an identifier used to write protocol headers in streams. -type ID string - -// These are reserved protocol.IDs. -const ( - TestingID ID = "/p2p/_testing" -) diff --git a/p2p/protocol/relay/relay.go b/p2p/protocol/relay/relay.go index 0b90f9918693b2048cf37f8e9159895eaed6398c..c485d700f01e446a79ec66f565cb40112af02cbc 100644 --- a/p2p/protocol/relay/relay.go +++ b/p2p/protocol/relay/relay.go @@ -9,9 +9,9 @@ import ( peer "github.com/ipfs/go-libp2p-peer" logging "github.com/ipfs/go-log" mh "github.com/jbenet/go-multihash" + protocol "github.com/libp2p/go-libp2p-protocol" host "github.com/libp2p/go-libp2p/p2p/host" inet "github.com/libp2p/go-libp2p/p2p/net" - protocol "github.com/libp2p/go-libp2p/p2p/protocol" ) var log = logging.Logger("github.com/libp2p/go-libp2p/p2p/protocol/relay") diff --git a/p2p/protocol/relay/relay_test.go b/p2p/protocol/relay/relay_test.go index 598bdc7f8d08d550bd68d4ca20ae4283fbedddb6..d541876c3e1c3810ed4a1c45497067cb6de228ac 100644 --- a/p2p/protocol/relay/relay_test.go +++ b/p2p/protocol/relay/relay_test.go @@ -6,8 +6,8 @@ import ( "context" logging "github.com/ipfs/go-log" + protocol "github.com/libp2p/go-libp2p-protocol" inet "github.com/libp2p/go-libp2p/p2p/net" - protocol "github.com/libp2p/go-libp2p/p2p/protocol" relay "github.com/libp2p/go-libp2p/p2p/protocol/relay" testutil "github.com/libp2p/go-libp2p/p2p/test/util" msmux "github.com/whyrusleeping/go-multistream" diff --git a/p2p/test/backpressure/backpressure_test.go b/p2p/test/backpressure/backpressure_test.go index c4873ce100fc3ce8317bfe26848be1043fa0799a..6b6af8238ead832991af6b24bdd6505a076f8732 100644 --- a/p2p/test/backpressure/backpressure_test.go +++ b/p2p/test/backpressure/backpressure_test.go @@ -10,9 +10,9 @@ import ( u "github.com/ipfs/go-ipfs-util" peer "github.com/ipfs/go-libp2p-peer" logging "github.com/ipfs/go-log" + protocol "github.com/libp2p/go-libp2p-protocol" host "github.com/libp2p/go-libp2p/p2p/host" inet "github.com/libp2p/go-libp2p/p2p/net" - protocol "github.com/libp2p/go-libp2p/p2p/protocol" testutil "github.com/libp2p/go-libp2p/p2p/test/util" ) diff --git a/p2p/test/reconnects/reconnect_test.go b/p2p/test/reconnects/reconnect_test.go index d60d6c437f30008ce19e5307d173e58f69e0f74d..017c80d04951eb18861a047f81cc1bc198e7c0c0 100644 --- a/p2p/test/reconnects/reconnect_test.go +++ b/p2p/test/reconnects/reconnect_test.go @@ -11,10 +11,10 @@ import ( u "github.com/ipfs/go-ipfs-util" logging "github.com/ipfs/go-log" ps "github.com/jbenet/go-peerstream" + protocol "github.com/libp2p/go-libp2p-protocol" host "github.com/libp2p/go-libp2p/p2p/host" inet "github.com/libp2p/go-libp2p/p2p/net" swarm "github.com/libp2p/go-libp2p/p2p/net/swarm" - protocol "github.com/libp2p/go-libp2p/p2p/protocol" testutil "github.com/libp2p/go-libp2p/p2p/test/util" ) diff --git a/package.json b/package.json index e68f2a77d6ab637cb723ef88f6e3d3b379a965ce..f289bbe0f9b0504b56b20bee8a0241ea9e6fb43d 100644 --- a/package.json +++ b/package.json @@ -188,6 +188,18 @@ "hash": "QmXFU6HbpMaxJ3wtw96aSSqBcdJJqtuE2ipMopmh1T3be8", "name": "go-tcp-transport", "version": "1.0.2" + }, + { + "author": "whyrusleeping", + "hash": "QmaRNdghe7SY53L9WfyVesio7yvVnyXtgSpbBd9CJYfvJg", + "name": "go-maddr-filter", + "version": "1.0.0" + }, + { + "author": "whyrusleeping", + "hash": "QmZNkThpqfVXs9GNbexPrfBbXSLNYeKrE7jwFM2oqHbyqN", + "name": "go-libp2p-protocol", + "version": "1.0.0" } ], "gxVersion": "0.4.0",