mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-19 11:20:45 +00:00
perf(node, p2p): avoid unnecessary check len of map (#1995)
This commit is contained in:
parent
9dba15a673
commit
67a6e34188
2 changed files with 7 additions and 13 deletions
|
|
@ -72,11 +72,9 @@ func (api *adminAPI) AddPeer(url string) (bool, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// reject the node which is in peer blacklist
|
// reject the node which is in peer blacklist
|
||||||
if len(server.BlackPeers) > 0 {
|
|
||||||
if _, ok := server.BlackPeers[node.ID]; ok {
|
if _, ok := server.BlackPeers[node.ID]; ok {
|
||||||
return false, fmt.Errorf("peer is in blacklist: %v, ID: %s", url, node.ID)
|
return false, fmt.Errorf("peer is in blacklist: %v, ID: %s", url, node.ID)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
server.AddPeer(node)
|
server.AddPeer(node)
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
@ -115,11 +113,9 @@ func (api *adminAPI) AddTrustedPeer(url string) (bool, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// reject the node which is in peer blacklist
|
// reject the node which is in peer blacklist
|
||||||
if len(server.BlackPeers) > 0 {
|
|
||||||
if _, ok := server.BlackPeers[node.ID]; ok {
|
if _, ok := server.BlackPeers[node.ID]; ok {
|
||||||
return false, fmt.Errorf("trusted peer is in blacklist: %v, ID: %s", url, node.ID)
|
return false, fmt.Errorf("trusted peer is in blacklist: %v, ID: %s", url, node.ID)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
server.AddTrustedPeer(node)
|
server.AddTrustedPeer(node)
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -905,12 +905,10 @@ func (srv *Server) setupConn(c *conn, flags connFlag, dialDest *discover.Node) e
|
||||||
return DiscNonWhitelistedPeer
|
return DiscNonWhitelistedPeer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(srv.BlackPeers) > 0 {
|
|
||||||
if _, ok := srv.BlackPeers[c.id]; ok {
|
if _, ok := srv.BlackPeers[c.id]; ok {
|
||||||
clog.Debug("Reject blacklisted peer")
|
clog.Debug("Reject blacklisted peer")
|
||||||
return DiscBlacklistedPeer
|
return DiscBlacklistedPeer
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// For dialed connections, check that the remote public key matches.
|
// For dialed connections, check that the remote public key matches.
|
||||||
if dialDest != nil && c.id != dialDest.ID {
|
if dialDest != nil && c.id != dialDest.ID {
|
||||||
clog.Trace("Dialed identity mismatch", "want", c, dialDest.ID)
|
clog.Trace("Dialed identity mismatch", "want", c, dialDest.ID)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue