p2p: add ENR to PeerInfo (#19816)

ChrisChinchilla-patch-3
Kurkó Mihály 5 years ago committed by Felix Lange
parent e8c9579fb7
commit a1f8549262
  1. 6
      p2p/peer.go

@ -427,6 +427,7 @@ func (rw *protoRW) ReadMsg() (Msg, error) {
// peer. Sub-protocol independent fields are contained and initialized here, with // peer. Sub-protocol independent fields are contained and initialized here, with
// protocol specifics delegated to all connected sub-protocols. // protocol specifics delegated to all connected sub-protocols.
type PeerInfo struct { type PeerInfo struct {
ENR string `json:"enr,omitempty"` // Ethereum Node Record
Enode string `json:"enode"` // Node URL Enode string `json:"enode"` // Node URL
ID string `json:"id"` // Unique node identifier ID string `json:"id"` // Unique node identifier
Name string `json:"name"` // Name of the node, including client type, version, OS, custom data Name string `json:"name"` // Name of the node, including client type, version, OS, custom data
@ -450,12 +451,15 @@ func (p *Peer) Info() *PeerInfo {
} }
// Assemble the generic peer metadata // Assemble the generic peer metadata
info := &PeerInfo{ info := &PeerInfo{
Enode: p.Node().String(), Enode: p.Node().URLv4(),
ID: p.ID().String(), ID: p.ID().String(),
Name: p.Name(), Name: p.Name(),
Caps: caps, Caps: caps,
Protocols: make(map[string]interface{}), Protocols: make(map[string]interface{}),
} }
if p.Node().Seq() > 0 {
info.ENR = p.Node().String()
}
info.Network.LocalAddress = p.LocalAddr().String() info.Network.LocalAddress = p.LocalAddr().String()
info.Network.RemoteAddress = p.RemoteAddr().String() info.Network.RemoteAddress = p.RemoteAddr().String()
info.Network.Inbound = p.rw.is(inboundConn) info.Network.Inbound = p.rw.is(inboundConn)

Loading…
Cancel
Save