p2p/enode: improve IPv6 support, add ENR text representation (#19663)
* p2p/enr: add entries for for IPv4/IPv6 separation This adds entry types for "ip6", "udp6", "tcp6" keys. The IP type stays around because removing it would break a lot of code and force everyone to care about the distinction. * p2p/enode: track IPv4 and IPv6 address separately LocalNode predicts the local node's UDP endpoint and updates the record. This change makes it predict IPv4 and IPv6 endpoints separately since they can now be in the record at the same time. * p2p/enode: implement base64 text format * all: switch to enode.Parse(...) This allows passing base64-encoded node records to all the places that previously accepted enode:// URLs. The URL format is still supported. * cmd/bootnode, p2p: log node URL instead of ENR ...and return the base64 record in NodeInfo.
This commit is contained in:
@ -39,7 +39,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/p2p/enr"
|
||||
"github.com/ethereum/go-ethereum/p2p/nat"
|
||||
"github.com/ethereum/go-ethereum/p2p/netutil"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -602,7 +601,7 @@ type dialer interface {
|
||||
}
|
||||
|
||||
func (srv *Server) run(dialstate dialer) {
|
||||
srv.log.Info("Started P2P networking", "self", srv.localnode.Node())
|
||||
srv.log.Info("Started P2P networking", "self", srv.localnode.Node().URLv4())
|
||||
defer srv.loopWG.Done()
|
||||
defer srv.nodedb.Close()
|
||||
|
||||
@ -1034,7 +1033,7 @@ func (srv *Server) NodeInfo() *NodeInfo {
|
||||
node := srv.Self()
|
||||
info := &NodeInfo{
|
||||
Name: srv.Name,
|
||||
Enode: node.String(),
|
||||
Enode: node.URLv4(),
|
||||
ID: node.ID().String(),
|
||||
IP: node.IP().String(),
|
||||
ListenAddr: srv.ListenAddr,
|
||||
@ -1042,9 +1041,7 @@ func (srv *Server) NodeInfo() *NodeInfo {
|
||||
}
|
||||
info.Ports.Discovery = node.UDP()
|
||||
info.Ports.Listener = node.TCP()
|
||||
if enc, err := rlp.EncodeToBytes(node.Record()); err == nil {
|
||||
info.ENR = "0x" + hex.EncodeToString(enc)
|
||||
}
|
||||
info.ENR = node.String()
|
||||
|
||||
// Gather all the running protocol infos (only once per protocol type)
|
||||
for _, proto := range srv.Protocols {
|
||||
|
Reference in New Issue
Block a user