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:
David Hill 2018-06-26 17:08:04 -04:00 committed by Dave Collins
parent 4bbb9bc414
commit 2f5e473712

View File

@ -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)
}