Skip to content

Add Function to Enable Application Layer to Send Direct Control Messages #561

@thep2p

Description

@thep2p

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 currently uses this feature quite extensively.

Proposed Function

// 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 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 instance, rather than creating a gossipsub 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions