mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
Fix IPV6 binding for Beacon Node (#8326)
Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
parent
d21365b882
commit
b2d6012371
@ -104,12 +104,14 @@ func (s *Service) createListener(
|
||||
// on which we will bind our listener on
|
||||
// by default we will listen to all interfaces.
|
||||
var bindIP net.IP
|
||||
if ipAddr.To4() != nil {
|
||||
networkVersion = "udp4"
|
||||
networkVersion = udpVersionFromIP(ipAddr)
|
||||
switch networkVersion {
|
||||
case "udp4":
|
||||
bindIP = net.IPv4zero
|
||||
} else {
|
||||
networkVersion = "udp6"
|
||||
case "udp6":
|
||||
bindIP = net.IPv6zero
|
||||
default:
|
||||
return nil, errors.New("invalid ip provided")
|
||||
}
|
||||
|
||||
// If local ip is specified then use that instead.
|
||||
@ -119,6 +121,7 @@ func (s *Service) createListener(
|
||||
return nil, errors.New("invalid local ip provided")
|
||||
}
|
||||
bindIP = ipAddr
|
||||
networkVersion = udpVersionFromIP(ipAddr)
|
||||
}
|
||||
udpAddr := &net.UDPAddr{
|
||||
IP: bindIP,
|
||||
@ -421,3 +424,10 @@ func multiAddrFromString(address string) (ma.Multiaddr, error) {
|
||||
}
|
||||
return addr.Multiaddr(), nil
|
||||
}
|
||||
|
||||
func udpVersionFromIP(ipAddr net.IP) string {
|
||||
if ipAddr.To4() != nil {
|
||||
return "udp4"
|
||||
}
|
||||
return "udp6"
|
||||
}
|
||||
|
@ -312,6 +312,15 @@ func TestMultipleDiscoveryAddresses(t *testing.T) {
|
||||
assert.Equal(t, true, ipv6Found, "IPv6 discovery address not found")
|
||||
}
|
||||
|
||||
func TestCorrectUDPVersion(t *testing.T) {
|
||||
assert.Equal(t, "udp4", udpVersionFromIP(net.IPv4zero), "incorrect network version")
|
||||
assert.Equal(t, "udp6", udpVersionFromIP(net.IPv6zero), "incorrect network version")
|
||||
assert.Equal(t, "udp4", udpVersionFromIP(net.IP{200, 20, 12, 255}), "incorrect network version")
|
||||
assert.Equal(t, "udp6", udpVersionFromIP(net.IP{22, 23, 24, 251, 17, 18, 0, 0, 0, 0, 12, 14, 212, 213, 16, 22}), "incorrect network version")
|
||||
// v4 in v6
|
||||
assert.Equal(t, "udp4", udpVersionFromIP(net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 212, 213, 16, 22}), "incorrect network version")
|
||||
}
|
||||
|
||||
// addPeer is a helper to add a peer with a given connection state)
|
||||
func addPeer(t *testing.T, p *peers.Status, state peerdata.PeerConnectionState) peer.ID {
|
||||
// Set up some peers with different states
|
||||
|
Loading…
Reference in New Issue
Block a user