Skip to content

Commit a1f8549

Browse files
kurkomisifjl
authored andcommitted
p2p: add ENR to PeerInfo (#19816)
1 parent e8c9579 commit a1f8549

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

p2p/peer.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,11 @@ func (rw *protoRW) ReadMsg() (Msg, error) {
427427
// peer. Sub-protocol independent fields are contained and initialized here, with
428428
// protocol specifics delegated to all connected sub-protocols.
429429
type PeerInfo struct {
430-
Enode string `json:"enode"` // Node URL
431-
ID string `json:"id"` // Unique node identifier
432-
Name string `json:"name"` // Name of the node, including client type, version, OS, custom data
433-
Caps []string `json:"caps"` // Protocols advertised by this peer
430+
ENR string `json:"enr,omitempty"` // Ethereum Node Record
431+
Enode string `json:"enode"` // Node URL
432+
ID string `json:"id"` // Unique node identifier
433+
Name string `json:"name"` // Name of the node, including client type, version, OS, custom data
434+
Caps []string `json:"caps"` // Protocols advertised by this peer
434435
Network struct {
435436
LocalAddress string `json:"localAddress"` // Local endpoint of the TCP data connection
436437
RemoteAddress string `json:"remoteAddress"` // Remote endpoint of the TCP data connection
@@ -450,12 +451,15 @@ func (p *Peer) Info() *PeerInfo {
450451
}
451452
// Assemble the generic peer metadata
452453
info := &PeerInfo{
453-
Enode: p.Node().String(),
454+
Enode: p.Node().URLv4(),
454455
ID: p.ID().String(),
455456
Name: p.Name(),
456457
Caps: caps,
457458
Protocols: make(map[string]interface{}),
458459
}
460+
if p.Node().Seq() > 0 {
461+
info.ENR = p.Node().String()
462+
}
459463
info.Network.LocalAddress = p.LocalAddr().String()
460464
info.Network.RemoteAddress = p.RemoteAddr().String()
461465
info.Network.Inbound = p.rw.is(inboundConn)

0 commit comments

Comments
 (0)