From 650c35a8b607e801cc235fac0bd0dc1b111a3005 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 24 Jun 2022 09:47:03 +0200 Subject: [PATCH] use multiaddr ipcidr to parse multiaddr filters (#1606) --- go.mod | 3 +-- go.sum | 3 ++- p2p/net/swarm/addrs.go | 10 +++++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 9097a4e097..a676545d9f 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,7 @@ require ( github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b github.com/minio/sha256-simd v1.0.0 - github.com/multiformats/go-multiaddr v0.5.0 + github.com/multiformats/go-multiaddr v0.6.0 github.com/multiformats/go-multiaddr-dns v0.3.1 github.com/multiformats/go-multiaddr-fmt v0.1.0 github.com/multiformats/go-multihash v0.1.0 @@ -45,7 +45,6 @@ require ( github.com/prometheus/client_golang v1.12.1 github.com/raulk/go-watchdog v1.2.0 github.com/stretchr/testify v1.7.0 - github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 diff --git a/go.sum b/go.sum index 99a0dccf7d..eba987e9d8 100644 --- a/go.sum +++ b/go.sum @@ -557,8 +557,9 @@ github.com/multiformats/go-multiaddr v0.3.1/go.mod h1:uPbspcUPd5AfaP6ql3ujFY+QWz github.com/multiformats/go-multiaddr v0.3.3/go.mod h1:lCKNGP1EQ1eZ35Za2wlqnabm9xQkib3fyB+nZXHLag0= github.com/multiformats/go-multiaddr v0.4.0/go.mod h1:YcpyLH8ZPudLxQlemYBPhSm0/oCXAT8Z4mzFpyoPyRc= github.com/multiformats/go-multiaddr v0.4.1/go.mod h1:3afI9HfVW8csiF8UZqtpYRiDyew8pRX7qLIGHu9FLuM= -github.com/multiformats/go-multiaddr v0.5.0 h1:i/JuOoVg4szYQ4YEzDGtb2h0o8M7CG/Yq6cGlcjWZpM= github.com/multiformats/go-multiaddr v0.5.0/go.mod h1:3KAxNkUqLTJ20AAwN4XVX4kZar+bR+gh4zgbfr3SNug= +github.com/multiformats/go-multiaddr v0.6.0 h1:qMnoOPj2s8xxPU5kZ57Cqdr0hHhARz7mFsPMIiYNqzg= +github.com/multiformats/go-multiaddr v0.6.0/go.mod h1:F4IpaKZuPP360tOMn2Tpyu0At8w23aRyVqeK0DbFeGM= github.com/multiformats/go-multiaddr-dns v0.3.1 h1:QgQgR+LQVt3NPTjbrLLpsaT2ufAA2y0Mkk+QRVJbW3A= github.com/multiformats/go-multiaddr-dns v0.3.1/go.mod h1:G/245BRQ6FJGmryJCrOuTdB37AMA5AMOVuO6NY3JwTk= github.com/multiformats/go-multiaddr-fmt v0.1.0 h1:WLEFClPycPkp4fnIzoFoV9FVd49/eQsuaL3/CWe167E= diff --git a/p2p/net/swarm/addrs.go b/p2p/net/swarm/addrs.go index 09f8df766c..392900e069 100644 --- a/p2p/net/swarm/addrs.go +++ b/p2p/net/swarm/addrs.go @@ -2,7 +2,7 @@ package swarm import ( ma "github.com/multiformats/go-multiaddr" - mamask "github.com/whyrusleeping/multiaddr-filter" + manet "github.com/multiformats/go-multiaddr/net" ) // http://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml @@ -26,10 +26,14 @@ func init() { "/ip4/203.0.113.0/ipcidr/24", "/ip4/240.0.0.0/ipcidr/4", } { - f, err := mamask.NewMask(p) + f, err := ma.NewMultiaddr(p) if err != nil { panic("error in lowTimeoutFilters init: " + err.Error()) } - lowTimeoutFilters.AddFilter(*f, ma.ActionDeny) + ipnet, err := manet.MultiaddrToIPNet(f) + if err != nil { + panic("error in lowTimeoutFilters init: " + err.Error()) + } + lowTimeoutFilters.AddFilter(*ipnet, ma.ActionDeny) } }