-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #927 from iotaledger/fix/autopeering+inx
Autopeering and INX fixes
- Loading branch information
Showing
15 changed files
with
195 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package network | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/multiformats/go-multiaddr" | ||
mamask "github.com/whyrusleeping/multiaddr-filter" | ||
|
||
"github.com/iotaledger/hive.go/lo" | ||
) | ||
|
||
// Based on https://github.com/ipfs/kubo/blob/master/config/profile.go | ||
// defaultServerFilters has is a list of IPv4 and IPv6 prefixes that are private, local only, or unrouteable. | ||
// according to https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml | ||
// and https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml | ||
var reservedFilters = []string{ | ||
"/ip4/0.0.0.0/ipcidr/32", | ||
"/ip4/100.64.0.0/ipcidr/10", | ||
"/ip4/127.0.0.0/ipcidr/8", | ||
"/ip4/169.254.0.0/ipcidr/16", | ||
"/ip4/192.0.0.0/ipcidr/24", | ||
"/ip4/192.0.2.0/ipcidr/24", | ||
"/ip4/192.31.196.0/ipcidr/24", | ||
"/ip4/192.52.193.0/ipcidr/24", | ||
"/ip4/198.18.0.0/ipcidr/15", | ||
"/ip4/198.51.100.0/ipcidr/24", | ||
"/ip4/203.0.113.0/ipcidr/24", | ||
"/ip4/240.0.0.0/ipcidr/4", | ||
|
||
"/ip6/::/ipcidr/128", | ||
"/ip6/::1/ipcidr/128", | ||
"/ip6/100::/ipcidr/64", | ||
"/ip6/2001:2::/ipcidr/48", | ||
"/ip6/2001:db8::/ipcidr/32", | ||
} | ||
|
||
var localNetworks = []string{ | ||
"/ip4/10.0.0.0/ipcidr/8", | ||
"/ip4/172.16.0.0/ipcidr/12", | ||
"/ip4/192.168.0.0/ipcidr/16", | ||
|
||
"/ip6/fc00::/ipcidr/7", | ||
"/ip6/fe80::/ipcidr/10", | ||
} | ||
|
||
type AddressFilter = func([]multiaddr.Multiaddr) []multiaddr.Multiaddr | ||
|
||
func PublicOnlyAddressesFilter(allowLocalNetworks bool) AddressFilter { | ||
// Create a filter that blocks localhost and reserved addresses. | ||
filters := multiaddr.NewFilters() | ||
|
||
filtersToApply := reservedFilters | ||
if !allowLocalNetworks { | ||
filtersToApply = append(filtersToApply, localNetworks...) | ||
} | ||
|
||
for _, addr := range filtersToApply { | ||
f, err := mamask.NewMask(addr) | ||
if err != nil { | ||
panic(fmt.Sprintf("unable to parse ip mask filter %s: %s", addr, err)) | ||
} | ||
filters.AddFilter(*f, multiaddr.ActionDeny) | ||
} | ||
|
||
return func(addresses []multiaddr.Multiaddr) []multiaddr.Multiaddr { | ||
return lo.Filter(addresses, func(m multiaddr.Multiaddr) bool { | ||
return !filters.AddrBlocked(m) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.