diff --git a/p2p/host/basic/basic_host.go b/p2p/host/basic/basic_host.go index 58b4d5e67..170677c83 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 549931aeb..00a9d20f1 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 20af1e914..4fee58049 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 571d652c2..84b5def8f 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 2ae808c5f..7737a592a 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 3b5fedd59..e34ec1c51 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 1ceb1e95c..814e94fcf 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 14de24c57..3eddfd4db 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 22b3f9370..9c1d12147 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 61cf623ed..cc49606bb 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 8bacd0e87..6098ff79c 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 c31ad0b75..000000000 --- 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 8cd0bcc33..000000000 --- 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 56237b7f6..fffe0cda5 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 dac95688f..4aa623a6f 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 5fe27425b..e00cb10ac 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 4eebf626b..19ccf13ee 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 dc365e8c0..51c846001 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 f7e4a32ba..000000000 --- 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 0b90f9918..c485d700f 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 598bdc7f8..d541876c3 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 c4873ce10..6b6af8238 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 d60d6c437..017c80d04 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 e68f2a77d..f289bbe0f 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",