Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute arbitrary function when DHT message is received #331

Open
gpestana opened this issue May 3, 2019 · 5 comments
Open

Execute arbitrary function when DHT message is received #331

gpestana opened this issue May 3, 2019 · 5 comments
Labels
exp/expert Having worked on the specific codebase is important kind/enhancement A net-new feature or improvement to an existing feature P4 Very low priority

Comments

@gpestana
Copy link
Contributor

gpestana commented May 3, 2019

As a developer I'd like to execute arbitrary functions when a host receives a dht message. For example, when the node processes an incoming GET_VALUE message, I'd like to spawn a new go routine alongside handleGetValue(...).

I can't think of any way of doing this without changing the current handlers logic to accept a channel that accepts events that can be handled in the main go routine. This solution feels a bit clumsy and probably adds unnecessary complexity for a 'niche' case. But on the other hand, that feature would be nice for developers who need to develop protocols based on the dht node's behaviour.

Any suggestions/thoughts about this?

edit

For context, I'd like to implement a MVP of a coin flipping request delegation to work with libp2p, something like this: gpestana/notes#23

@gpestana
Copy link
Contributor Author

gpestana commented May 6, 2019

I'm now thinking about implementing a datastore which maintains a set of handler functions that are triggered when datastore.Get() and datastore.Put() are called. The rationale is based on the fact that dht.datastore.Get(dskey) is called when handleGetValue handlers kicks in. So we can delegate the datastore to execute the "arbitrary function" without changing the go-libp2p-kad-dht package. I'm not sure if this would have any side effects (ie datastore.Get() may be called other times besides when there is a GetValue request).

@raulk
Copy link
Member

raulk commented May 6, 2019

Hey @gpestana! I think the key question here is whether you want values to be transformed or not.

In other words, could we satisfy this requirement with an event bus where the DHT and other components publish events to notify of others of what's happening?

Components like yours could subscribe to certain event types and react to those.

Or were you looking to modify the data that's actually being stored in the local view of the DHT? This would be pretty unsafe.

@gpestana
Copy link
Contributor Author

gpestana commented May 6, 2019

An event pipeline would be great, since the idea is not to change the protocol itself but to augment it. Are there any plans/discussions for implementing such event bus?

@raulk
Copy link
Member

raulk commented May 6, 2019

We've discussed some of this in libp2p/go-libp2p#467 which is mostly about the service-based host abstraction. @vyzo is putting together a technical description and proposal.

The eventbus will come at a later stage, although with the go-libp2p-core refactor, it could be moved forward because one no longer depends on the other.

Is this something you'd like to hack on? ;-)

@gpestana
Copy link
Contributor Author

gpestana commented May 6, 2019

yeah, definitely. I'd love to see this feature in since I've got a couple of ideas for integrating p3lib with libp2p that could use something like the event bus!

@jacobheun jacobheun added exp/expert Having worked on the specific codebase is important kind/enhancement A net-new feature or improvement to an existing feature P4 Very low priority labels Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exp/expert Having worked on the specific codebase is important kind/enhancement A net-new feature or improvement to an existing feature P4 Very low priority
Projects
None yet
Development

No branches or pull requests

3 participants