Skip to content

Commit c06df2f

Browse files
authored
Add Function to Enable Application Layer to Send Direct Control Messages (#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.
1 parent f71345c commit c06df2f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

gossipsub.go

+17
Original file line numberDiff line numberDiff line change
@@ -2121,6 +2121,23 @@ func (gs *GossipSubRouter) WithDefaultTagTracer() Option {
21212121
return WithRawTracer(gs.tagTracer)
21222122
}
21232123

2124+
// SendControl dispatches the given set of control messages to the given peer.
2125+
// The control messages are sent as a single RPC, with the given (optional) messages.
2126+
// Args:
2127+
//
2128+
// p: the peer to send the control messages to.
2129+
// ctl: the control messages to send.
2130+
// msgs: the messages to send in the same RPC (optional).
2131+
// The control messages are piggybacked on the messages.
2132+
//
2133+
// Returns:
2134+
//
2135+
// nothing.
2136+
func (gs *GossipSubRouter) SendControl(p peer.ID, ctl *pb.ControlMessage, msgs ...*pb.Message) {
2137+
out := rpcWithControl(msgs, ctl.Ihave, ctl.Iwant, ctl.Graft, ctl.Prune, ctl.Idontwant)
2138+
gs.sendRPC(p, out, false)
2139+
}
2140+
21242141
func peerListToMap(peers []peer.ID) map[peer.ID]struct{} {
21252142
pmap := make(map[peer.ID]struct{})
21262143
for _, p := range peers {

0 commit comments

Comments
 (0)