mirror of
https://github.com/FlipsideCrypto/dcrd.git
synced 2026-02-06 10:56:47 +00:00
server: only call time.Now() once
When a peer sends an addr message, use the same time for each address sent. This saves up to wire.MaxAddrPerMsg-1 syscalls.
This commit is contained in:
parent
4bbb9bc414
commit
2f5e473712
@ -1018,6 +1018,7 @@ func (sp *serverPeer) OnAddr(p *peer.Peer, msg *wire.MsgAddr) {
|
||||
return
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
for _, na := range msg.AddrList {
|
||||
// Don't add more address if we're disconnecting.
|
||||
if !p.Connected() {
|
||||
@ -1027,7 +1028,6 @@ func (sp *serverPeer) OnAddr(p *peer.Peer, msg *wire.MsgAddr) {
|
||||
// Set the timestamp to 5 days ago if it's more than 24 hours
|
||||
// in the future so this address is one of the first to be
|
||||
// removed when space is needed.
|
||||
now := time.Now()
|
||||
if na.Timestamp.After(now.Add(time.Minute * 10)) {
|
||||
na.Timestamp = now.Add(-1 * time.Hour * 24 * 5)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user