mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-21 22:36:42 +00:00

* add p2p v5 which is currently identical to v4 * set all internal imports to v5 * wip * set default version to 5 * protobuf gen for new ibd chain locator * wire for new ibd chain locator types * new ibd shared block algo -- only basic test passing * address the case where pruning points disagree, now both IBD tests pass * protobuf gen for new past diff request message * wire for new request past diff message * handle and flow for new request past diff message - logic unimplemented yet * implement ibd sync past diff of relay and selected tip * go fmt * remove unused methods * missed one err check * addressing simple comments * apply the traversal limit logic and sort headers * rename pastdiff -> anticone * apply Don't relay blocks in virtual anticone #1970 to v5 * go fmt * Fixed minor comments * Limit the number of chain negotiation restarts
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package ping
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/app/appmessage"
|
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
|
)
|
|
|
|
// ReceivePingsContext is the interface for the context needed for the ReceivePings flow.
|
|
type ReceivePingsContext interface {
|
|
}
|
|
|
|
type receivePingsFlow struct {
|
|
ReceivePingsContext
|
|
incomingRoute, outgoingRoute *router.Route
|
|
}
|
|
|
|
// ReceivePings handles all ping messages coming through incomingRoute.
|
|
// This function assumes that incomingRoute will only return MsgPing.
|
|
func ReceivePings(context ReceivePingsContext, incomingRoute *router.Route, outgoingRoute *router.Route) error {
|
|
flow := &receivePingsFlow{
|
|
ReceivePingsContext: context,
|
|
incomingRoute: incomingRoute,
|
|
outgoingRoute: outgoingRoute,
|
|
}
|
|
return flow.start()
|
|
}
|
|
|
|
func (flow *receivePingsFlow) start() error {
|
|
for {
|
|
message, err := flow.incomingRoute.Dequeue()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
pingMessage := message.(*appmessage.MsgPing)
|
|
|
|
pongMessage := appmessage.NewMsgPong(pingMessage.Nonce)
|
|
err = flow.outgoingRoute.Enqueue(pongMessage)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|