eth, p2p: use truncated names (#21698)
* peer: return localAddr instead of name to prevent spam We currently use the name (which can be freely set by the peer) in several log messages. This enables malicious actors to write spam into your geth log. This commit returns the localAddr instead of the freely settable name. * p2p: reduce usage of peer.Name in warn messages * eth, p2p: use truncated names * Update peer.go Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de> Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
parent
5c6155f9f4
commit
7a5a822905
13
p2p/peer.go
13
p2p/peer.go
@ -138,8 +138,17 @@ func (p *Peer) Node() *enode.Node {
|
|||||||
return p.rw.node
|
return p.rw.node
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name returns the node name that the remote node advertised.
|
// Name returns an abbreviated form of the name
|
||||||
func (p *Peer) Name() string {
|
func (p *Peer) Name() string {
|
||||||
|
s := p.rw.name
|
||||||
|
if len(s) > 20 {
|
||||||
|
return s[:20] + "..."
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fullname returns the node name that the remote node advertised.
|
||||||
|
func (p *Peer) Fullname() string {
|
||||||
return p.rw.name
|
return p.rw.name
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -463,7 +472,7 @@ func (p *Peer) Info() *PeerInfo {
|
|||||||
info := &PeerInfo{
|
info := &PeerInfo{
|
||||||
Enode: p.Node().URLv4(),
|
Enode: p.Node().URLv4(),
|
||||||
ID: p.ID().String(),
|
ID: p.ID().String(),
|
||||||
Name: p.Name(),
|
Name: p.Fullname(),
|
||||||
Caps: caps,
|
Caps: caps,
|
||||||
Protocols: make(map[string]interface{}),
|
Protocols: make(map[string]interface{}),
|
||||||
}
|
}
|
||||||
|
@ -757,7 +757,7 @@ running:
|
|||||||
// The handshakes are done and it passed all checks.
|
// The handshakes are done and it passed all checks.
|
||||||
p := srv.launchPeer(c)
|
p := srv.launchPeer(c)
|
||||||
peers[c.node.ID()] = p
|
peers[c.node.ID()] = p
|
||||||
srv.log.Debug("Adding p2p peer", "peercount", len(peers), "id", p.ID(), "conn", c.flags, "addr", p.RemoteAddr(), "name", truncateName(c.name))
|
srv.log.Debug("Adding p2p peer", "peercount", len(peers), "id", p.ID(), "conn", c.flags, "addr", p.RemoteAddr(), "name", p.Name())
|
||||||
srv.dialsched.peerAdded(c)
|
srv.dialsched.peerAdded(c)
|
||||||
if p.Inbound() {
|
if p.Inbound() {
|
||||||
inboundCount++
|
inboundCount++
|
||||||
@ -996,13 +996,6 @@ func nodeFromConn(pubkey *ecdsa.PublicKey, conn net.Conn) *enode.Node {
|
|||||||
return enode.NewV4(pubkey, ip, port, port)
|
return enode.NewV4(pubkey, ip, port, port)
|
||||||
}
|
}
|
||||||
|
|
||||||
func truncateName(s string) string {
|
|
||||||
if len(s) > 20 {
|
|
||||||
return s[:20] + "..."
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// checkpoint sends the conn to run, which performs the
|
// checkpoint sends the conn to run, which performs the
|
||||||
// post-handshake checks for the stage (posthandshake, addpeer).
|
// post-handshake checks for the stage (posthandshake, addpeer).
|
||||||
func (srv *Server) checkpoint(c *conn, stage chan<- *conn) error {
|
func (srv *Server) checkpoint(c *conn, stage chan<- *conn) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user