mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-10 16:16:47 +00:00

* [NOD-1038] Give higher priority for requesting missing ancestors when sending a getdata message (#767) * [NOD-1060] Don't sync from peers that break the netsync protocol
31 lines
951 B
Go
31 lines
951 B
Go
package p2p
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/kaspanet/kaspad/peer"
|
|
"github.com/kaspanet/kaspad/wire"
|
|
)
|
|
|
|
// OnGetBlockLocator is invoked when a peer receives a getlocator kaspa
|
|
// message.
|
|
func (sp *Peer) OnGetBlockLocator(_ *peer.Peer, msg *wire.MsgGetBlockLocator) {
|
|
locator, err := sp.server.DAG.BlockLocatorFromHashes(msg.HighHash, msg.LowHash)
|
|
if err != nil || len(locator) == 0 {
|
|
if err != nil {
|
|
peerLog.Warnf("Couldn't build a block locator between blocks "+
|
|
"%s and %s that was requested from peer %s: %s", msg.HighHash, msg.LowHash, sp, err)
|
|
}
|
|
sp.AddBanScoreAndPushRejectMsg(msg.Command(), wire.RejectInvalid, nil,
|
|
peer.BanScoreInvalidMsgGetBlockLocator, 0,
|
|
fmt.Sprintf("couldn't build a block locator between blocks %s and %s", msg.HighHash, msg.LowHash))
|
|
return
|
|
}
|
|
|
|
err = sp.PushBlockLocatorMsg(locator)
|
|
if err != nil {
|
|
peerLog.Errorf("Failed to send block locator message to peer %s: %s",
|
|
sp, err)
|
|
return
|
|
}
|
|
}
|