Bind Discovery Using Neutral Network Version (#8359)

* fix it

* terence's review
This commit is contained in:
Nishant Das 2021-01-29 15:07:32 +08:00 committed by GitHub
parent d254f24a23
commit b74dd967af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -97,15 +97,11 @@ func (s *Service) createListener(
ipAddr net.IP,
privKey *ecdsa.PrivateKey,
) (*discover.UDPv5, error) {
// Listen to all network interfaces
// for both ip protocols.
var networkVersion string
// BindIP is used to specify the ip
// on which we will bind our listener on
// by default we will listen to all interfaces.
var bindIP net.IP
networkVersion = udpVersionFromIP(ipAddr)
switch networkVersion {
switch udpVersionFromIP(ipAddr) {
case "udp4":
bindIP = net.IPv4zero
case "udp6":
@ -121,12 +117,14 @@ func (s *Service) createListener(
return nil, errors.New("invalid local ip provided")
}
bindIP = ipAddr
networkVersion = udpVersionFromIP(ipAddr)
}
udpAddr := &net.UDPAddr{
IP: bindIP,
Port: int(s.cfg.UDPPort),
}
// Listen to all network interfaces
// for both ip protocols.
networkVersion := "udp"
conn, err := net.ListenUDP(networkVersion, udpAddr)
if err != nil {
return nil, errors.Wrap(err, "could not listen to UDP")