Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter peers using non-std ports #17

Merged
merged 1 commit into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion zcash/address_book.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions zcash/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down