libp2p / libp2p/go-libp2p-pubsub
Add Function to Enable Application Layer to Send Direct Control Messages
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 364
- Forks
- 221
- PR merge metrics
- No merged PRs in 30d
Description
### Description
**Proposal**: Introduce a new function, `SendControl`, to the `GossipSubRouter` that allows the application layer to send direct control messages to a peer. This feature will primarily be used to develop finer-grained testing. [Flow blockchain](https://github.com/onflow/flow-go/blob/master/insecure/corruptlibp2p/gossipsub_spammer.go#L69-L73) currently uses this feature quite extensively.
### Proposed Function
```go
// SendControl dispatches the given set of control messages to the given peer.
func (gs *GossipSubRouter) SendControl(p peer.ID, ctl *pb.ControlMessage, msgs ...*pb.Message) bool {
out := rpcWithControl(msgs, ctl.Ihave, ctl.Iwant, ctl.Graft, ctl.Prune)
return gs.sendRPC(p, out)
}
```
Sample implementation on my [forked](https://github.com/yhassanzadeh13/go-libp2p-pubsub/blob/master/gossipsub.go#L1930-L1934) version.
### Rationale
Adding this function does not break encapsulation drastically. It is available at the router-level, meaning it is only accessible if the application layer [creates a router and passes it to a pubsub](https://github.com/yhassanzadeh13/go-libp2p-pubsub/blob/master/gossipsub.go#L215-L217) instance, rather than creating a [gossipsub](https://github.com/yhassanzadeh13/go-libp2p-pubsub/blob/master/gossipsub.go#L208-L212) instance directly. This ensures controlled usage and maintains the integrity of the encapsulation.
### Benefits
- Enables finer-grained testing.
- Provides more control for application layer developers.
- Maintains encapsulation integrity by limiting accessibility.
I can make the PR upon a soft approval.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in gossipsub.go at GossipSubRouter and review the proposed SendControl entry point, along with rpcWithControl and sendRPC. Compare the linked fork implementation and identify the relevant existing tests or control-message paths; done means the router can dispatch the supplied control messages directly to the requested peer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- networking
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100