Skip to content

Commit

Permalink
Add Function to Enable Application Layer to Send Direct Control Messa…
Browse files Browse the repository at this point in the history
…ges (#562)

### PR Description

This PR addresses #561;
i.e., adding a new `SendControl` function to the `GossipSubRouter`. This
will allow the application layer to send direct control messages to
peers, facilitating finer-grained testing.
  • Loading branch information
yhassanzadeh13 authored Oct 18, 2024
1 parent f71345c commit c06df2f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions gossipsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -2121,6 +2121,23 @@ func (gs *GossipSubRouter) WithDefaultTagTracer() Option {
return WithRawTracer(gs.tagTracer)
}

// SendControl dispatches the given set of control messages to the given peer.
// The control messages are sent as a single RPC, with the given (optional) messages.
// Args:
//
// p: the peer to send the control messages to.
// ctl: the control messages to send.
// msgs: the messages to send in the same RPC (optional).
// The control messages are piggybacked on the messages.
//
// Returns:
//
// nothing.
func (gs *GossipSubRouter) SendControl(p peer.ID, ctl *pb.ControlMessage, msgs ...*pb.Message) {
out := rpcWithControl(msgs, ctl.Ihave, ctl.Iwant, ctl.Graft, ctl.Prune, ctl.Idontwant)
gs.sendRPC(p, out, false)
}

func peerListToMap(peers []peer.ID) map[peer.ID]struct{} {
pmap := make(map[peer.ID]struct{})
for _, p := range peers {
Expand Down

0 comments on commit c06df2f

Please sign in to comment.