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

Subscribe to PubSub topic before Publishing #30

Merged
merged 2 commits into from
May 3, 2019

Conversation

aschmahmann
Copy link
Contributor

@aschmahmann aschmahmann commented May 3, 2019

This PR adds a PubSub Subscribe into the PutValue function before calling PubSub's Publish.

The reason is that the PubSubValueStore is a persistent single writer data store as indicated by its use of a cache for GetValue and its use of the isBetter function to determine what value to return. Were this node to Put a value that was not "better" than the value already on the network that would likely be a mistake. As a result it should Subscribe so that it has the current "best" value and can compare with that before sending out PubSub requests.

While there are scenarios in which the extra inbound messages could be deemed "not worth it" to the Publisher, I think you would be hard pressed to find them in this particular scenario. This is even more evident when noting that this router is mostly used by IPNS which plans to use the LWW PubSub implementation under development at libp2p/go-libp2p-pubsub#171.

@vyzo @raulk How does this sound to you?

@Stebalien
Copy link
Member

The reason is that the PubSubValueStore is a persistent single writer data store as indicated by its use of a cache for GetValue and its use of the isBetter function to determine what value to return. Were this node to Put a value that was not "better" than the value already on the network that would likely be a mistake. As a result it should Subscribe so that it has the current "best" value and can compare with that before sending out PubSub requests.

For IPNS, at least, we assume a single writer. However, I can't see this causing any issues.

pubsub.go Outdated
@@ -94,6 +94,10 @@ func (p *PubsubValueStore) PutValue(ctx context.Context, key string, value []byt
p.mx.Unlock()
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove the above bootstrapping lines if we're going to do it this way.

Copy link
Contributor Author

@aschmahmann aschmahmann May 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Stebalien done. #28 is also now glaringly obvious now, since we see that the context passed in is just ignored.

If you think it makes sense I could wrap the insides of this function (Subscribe + Publish) in a gofunc + channel wait wrapper, but I'm inclined to just leave that until we implement the Discovery in PubSub, per #28 .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd leave it as-is. Subscribe shouldn't block anyways.

@Stebalien Stebalien merged commit 76fb692 into libp2p:master May 3, 2019
@aschmahmann aschmahmann deleted the feat/subscribeOnPut branch May 5, 2019 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants