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

Allow peer to be in Relay ONLY mode for a topic #208

Conversation

aarshkshah1992
Copy link
Contributor

For #28

@aschmahmann As discussed, this PR will allow a peer to 'Relay' for a topic without having to 'subscribe'/'consume' messages for that topic. However, a 'Subscriber' will always be a
'Relayer'.

Please let me know if the tests make sense/we need more tests.

// We do NOT allow subscription without Relay.
// Note that Join is not an instanteneous operation. It may take some time
// before it is processed by the pubsub main loop and propagated to our peers.
func (p *PubSub) Join(topic string, opts ...RelayOpt) (*Relay, error) {
Copy link
Contributor Author

@aarshkshah1992 aarshkshah1992 Oct 11, 2019

Choose a reason for hiding this comment

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

Since Subscribe = Join + subscription specific stuff, we need to create a Relay object every time Join is called in order to reference count subscribers so we can announce we are leaving the topic if we have no more subscribers & "un-cancelled" RelayOnly objects pending.

However, this means that will create multiple Relay objects even if the PubSub client/peer directly calls Join(without calling Subscribe) more than once in order to become a Relayer. I'm not sure if that makes sense because a peer is either RelayOnly or not. Should I add a comment saying that Join should ONLY be called once by the client?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should have a single relay object and reference count; Subscribing increases the reference count, unsubscribe decreases.
In fact, I am not even sure we need a relay object at all, just a reference count in the topic map.

Copy link
Contributor

Choose a reason for hiding this comment

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

In fact, I am not even sure we need a relay object at all, just a reference count in the topic map.

I don't even think we need a reference count at all. If we take the strategy from #198 and #184 (comment) then there should really only be one topic handle and that topic handle should be able to optionally be a relay.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, that's a valid strategy.

@@ -363,6 +363,145 @@ func TestGossipsubGossip(t *testing.T) {
time.Sleep(time.Second * 2)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to add some tests for Floodsub as well.

func TestGossipsubGossipWithSomeRelayOnlyPeers(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
hosts := getNetHosts(t, ctx, 15)
Copy link
Contributor Author

@aarshkshah1992 aarshkshah1992 Oct 11, 2019

Choose a reason for hiding this comment

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

Change number of hosts to 20 for consistency.

@aschmahmann
Copy link
Contributor

@aarshkshah1992 thanks so much for taking a stab at this!

Brief initial thoughts (which I hope to expand on when I've got a little more time) are that this seems a little overkill. Granted this is likely because you did the natural thing and emulated what the rest of the code looks like, but since the relay option (as @vyzo and @raulk specified in #28) seems to really just be about not allocating the Subscription message buffer we could probably significantly shrink the scope.

Perhaps it would make sense to just add a flag to subscription like receiveMsgs and then have some if statements that don't instantiate the channel (or send to it) if the flag is false. We could even wrap a Relay struct around a Subscription and just not expose the Next function. This would also give us events for Relays, which we could also have an option to turn off if we wanted.

@vyzo any thoughts?

@vyzo
Copy link
Collaborator

vyzo commented Oct 12, 2019

I don't think we need a flag in the subscription -- we can simply not have a subscription object at all when we are only relaying.

@aschmahmann
Copy link
Contributor

we can simply not have a subscription object at all when we are only relaying.

@vyzo the flag helps cut down on the complexity of managing another struct (the relay struct) and adding many more lines of boilerplate code to pubsub. However, if you really prefer that approach I'm not going to block on it.

@vyzo
Copy link
Collaborator

vyzo commented Oct 14, 2019

That's not what I meant -- I don't think we need either a relay object or to instantiate a subscription object for this.

@raulk
Copy link
Member

raulk commented Oct 18, 2019

Sorry to put a stick on the wheels, but I think #198 comes before this. Once that design is implemented, it will make marking a topic as relay only much more natural.

@Stebalien
Copy link
Member

Topic handles now exist.

@aarshkshah1992
Copy link
Contributor Author

aarshkshah1992 commented Nov 15, 2019

Starting work on this again now that the amazing work on Topic handlers has landed.

@aarshkshah1992
Copy link
Contributor Author

Closing this in favour of #229

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.

5 participants