Correct issue with pushing address messages.

The code to send an address messages in batches was previously clearing
all addresses from the existing message after queueing it to be sent.
Since the message is a pointer, this means it was removing the addresses
from the same message which might not have already been sent yet (from
another goroutine) which led to a race.

This commit modifies the code to create a new address message for each
batch as intended.

Fixes #58.
This commit is contained in:
Dave Collins 2013-12-10 09:05:26 -06:00
parent 9e44506fdc
commit c8e88d383e

View File

@ -773,7 +773,11 @@ func (p *peer) pushAddrMsg(addresses []*btcwire.NetAddress) error {
// Split into multiple messages as needed.
if numAdded > 0 && numAdded%btcwire.MaxAddrPerMsg == 0 {
p.QueueMessage(msg, nil)
msg.ClearAddresses()
// NOTE: This needs to be a new address message and not
// simply call ClearAddresses since the message is a
// pointer and queueing it does not make a copy.
msg = btcwire.NewMsgAddr()
}
}