mirror of
https://github.com/btcsuite/btcd.git
synced 2025-02-23 22:47:01 +01:00
server: add new peers within OnVerAck instead of within OnVersion
This change is needed as part of requiring peers to also send a verack message following their version message during protocol negotiation. Peers were previously added to the SyncManager before their message queues were started, causing the server to stall if a peer didn't provide a timely verack response following their version. We now do this within OnVerAck, which happens shortly before peer message queues are started.
This commit is contained in:
parent
11b84f5cb5
commit
a1a5bfa819
1 changed files with 7 additions and 2 deletions
|
@ -494,11 +494,15 @@ func (sp *serverPeer) OnVersion(_ *peer.Peer, msg *wire.MsgVersion) *wire.MsgRej
|
||||||
// is received.
|
// is received.
|
||||||
sp.setDisableRelayTx(msg.DisableRelayTx)
|
sp.setDisableRelayTx(msg.DisableRelayTx)
|
||||||
|
|
||||||
// Add valid peer to the server.
|
|
||||||
sp.server.AddPeer(sp)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OnVerAck is invoked when a peer receives a verack bitcoin message and is used
|
||||||
|
// to kick start communication with them.
|
||||||
|
func (sp *serverPeer) OnVerAck(_ *peer.Peer, _ *wire.MsgVerAck) {
|
||||||
|
sp.server.AddPeer(sp)
|
||||||
|
}
|
||||||
|
|
||||||
// OnMemPool is invoked when a peer receives a mempool bitcoin message.
|
// OnMemPool is invoked when a peer receives a mempool bitcoin message.
|
||||||
// It creates and sends an inventory message with the contents of the memory
|
// It creates and sends an inventory message with the contents of the memory
|
||||||
// pool up to the maximum inventory allowed per message. When the peer has a
|
// pool up to the maximum inventory allowed per message. When the peer has a
|
||||||
|
@ -1966,6 +1970,7 @@ func newPeerConfig(sp *serverPeer) *peer.Config {
|
||||||
return &peer.Config{
|
return &peer.Config{
|
||||||
Listeners: peer.MessageListeners{
|
Listeners: peer.MessageListeners{
|
||||||
OnVersion: sp.OnVersion,
|
OnVersion: sp.OnVersion,
|
||||||
|
OnVerAck: sp.OnVerAck,
|
||||||
OnMemPool: sp.OnMemPool,
|
OnMemPool: sp.OnMemPool,
|
||||||
OnTx: sp.OnTx,
|
OnTx: sp.OnTx,
|
||||||
OnBlock: sp.OnBlock,
|
OnBlock: sp.OnBlock,
|
||||||
|
|
Loading…
Add table
Reference in a new issue