filter peers using non-std ports

This commit is contained in:
Conrado Gouvea 2022-06-02 16:57:03 -03:00
parent e9a2d22878
commit e4bfa060be
2 changed files with 10 additions and 3 deletions

View File

@ -224,7 +224,7 @@ func (bk *AddressBook) waitForAddresses(n int, done chan struct{}) {
// GetAddressList returns a slice of n valid addresses in random order.
// If there aren't enough known addresses, it returns as many as we have.
func (bk *AddressBook) shuffleAddressList(n int, v6 bool) []net.IP {
func (bk *AddressBook) shuffleAddressList(n int, v6 bool, defaultPort string) []net.IP {
bk.addrState.RLock()
defer bk.addrState.RUnlock()
@ -246,6 +246,13 @@ func (bk *AddressBook) shuffleAddressList(n int, v6 bool) []net.IP {
continue
}
if strconv.Itoa(int(v.netaddr.Port)) != defaultPort {
// The DNS seeder is only able to return IP addresses, and it can't report
// ports. For this reason, we can only return addresses that are using
// the standard port.
continue
}
resp = append(resp, v.netaddr.IP)
}

View File

@ -543,12 +543,12 @@ func (s *Seeder) Ready() bool {
// Addresses returns a slice of n IPv4 addresses or as many as we have if it's less than that.
func (s *Seeder) Addresses(n int) []net.IP {
return s.addrBook.shuffleAddressList(n, false)
return s.addrBook.shuffleAddressList(n, false, s.GetNetworkDefaultPort())
}
// AddressesV6 returns a slice of n IPv6 addresses or as many as we have if it's less than that.
func (s *Seeder) AddressesV6(n int) []net.IP {
return s.addrBook.shuffleAddressList(n, true)
return s.addrBook.shuffleAddressList(n, true, s.GetNetworkDefaultPort())
}
// GetPeerCount returns how many valid peers we know about.