libp2p / go-libp2p-pubsub

The PubSub implementation for go-libp2p
https://github.com/libp2p/specs/tree/master/pubsub
Other
328 stars 186 forks source link

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

Open yhassanzadeh13 opened 4 months ago

yhassanzadeh13 commented 4 months ago

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

I can make the PR upon a soft approval.

vyzo commented 4 months ago

In principle this is fine, as it can allow application specific extensions to the protocol; this is useful for testing and early adoption as a path to standarization. It is also in line with the philosophy of extensibility in the protocol.

However, i think that just sending control messages is insufficient. We also need a way to process incoming custom control messages.

yhassanzadeh13 commented 4 months ago

In principle this is fine, as it can allow application specific extensions to the protocol; this is useful for testing and early adoption as a path to standarization. It is also in line with the philosophy of extensibility in the protocol.

Thanks, I'll then proceed with the PR.

We also need a way to process incoming custom control messages.

I believe processing incoming messages has already been implemented through the RPC inspector set by the application layer, as shown in this link: https://github.com/libp2p/go-libp2p-pubsub/pull/509. Are you considering a different functionality?

vyzo commented 4 months ago

Oh right, i forgot! No, i think it is sufficient.

yhassanzadeh13 commented 4 months ago

Created the PR: https://github.com/libp2p/go-libp2p-pubsub/pull/562

yhassanzadeh13 commented 1 month ago

@vyzo a gentle reminder for this issue; the PR is ready pending a review; thanks! https://github.com/libp2p/go-libp2p-pubsub/pull/562

vyzo commented 1 month ago

ah sorry, i forgot!

yhassanzadeh13 commented 2 weeks ago

Is it possible to have a tagged release of the master head (inclusive of https://github.com/libp2p/go-libp2p-pubsub/pull/562)?

vyzo commented 2 weeks ago

sure, will make a patch release.