p2p: simplify NewV4WithDNS function

This commit is contained in:
Lucas Vasconcelos 2024-11-27 20:16:05 -03:00
parent 2f8ab8080f
commit 7e9334861b

View file

@ -102,28 +102,16 @@ func NewV4(pubkey *ecdsa.PublicKey, ip net.IP, tcp, udp int) *Node {
} }
func NewV4WithDNS(pubkey *ecdsa.PublicKey, ip net.IP, dnsName string, tcp, udp int) *Node { func NewV4WithDNS(pubkey *ecdsa.PublicKey, ip net.IP, dnsName string, tcp, udp int) *Node {
var r enr.Record n := NewV4(pubkey, ip, tcp, udp)
if len(ip) > 0 {
r.Set(enr.IP(ip))
}
// Always set TCP/UDP ports regardless of IP // Always set TCP/UDP ports regardless of IP
// This is to ensure that the node is always // This is to ensure that the node is always
// considered valid even if the IP is not // considered valid even if the IP is not
// set. // set.
if tcp != 0 { if len(ip) == 0 {
r.Set(enr.TCP(tcp)) n.tcp = uint16(tcp)
} n.udp = uint16(udp)
if udp != 0 {
r.Set(enr.UDP(udp))
}
signV4Compat(&r, pubkey)
n, err := New(v4CompatID{}, &r)
if err != nil {
panic(err)
} }
n.dnsName = dnsName n.dnsName = dnsName
n.tcp = uint16(tcp)
n.udp = uint16(udp)
return n return n
} }