mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
p2p: simplify NewV4WithDNS function
This commit is contained in:
parent
2f8ab8080f
commit
7e9334861b
1 changed files with 4 additions and 16 deletions
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue