network: speculatively set GetAddrSent status

Otherwise we routinely get "unexpected addr received" error.
This commit is contained in:
Roman Khimov 2022-10-11 17:44:13 +03:00
parent e80c60a3b9
commit 8b26d9475b

View file

@ -1367,11 +1367,11 @@ func (s *Server) iteratePeersWithSendMsg(msg *Message, send func(Peer, context.C
var ctx, cancel = context.WithTimeout(context.Background(), s.TimePerBlock/2) var ctx, cancel = context.WithTimeout(context.Background(), s.TimePerBlock/2)
for _, peer := range peers { for _, peer := range peers {
go func(p Peer, ctx context.Context, pkt []byte) { go func(p Peer, ctx context.Context, pkt []byte) {
err := send(p, ctx, pkt) // Do this before packet is sent, reader thread can get the reply before this routine wakes up.
if err == nil && msg.Command == CMDGetAddr { if msg.Command == CMDGetAddr {
p.AddGetAddrSent() p.AddGetAddrSent()
} }
replies <- err replies <- send(p, ctx, pkt)
}(peer, ctx, pkt) }(peer, ctx, pkt)
} }
for r := range replies { for r := range replies {