Skip to content

Commit

Permalink
use multiaddr ipcidr to parse multiaddr filters
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Jun 22, 2022
1 parent 707100a commit c8bf86a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
10 changes: 7 additions & 3 deletions p2p/net/swarm/addrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}

0 comments on commit c8bf86a

Please sign in to comment.