P2P PeerManager model #5938
Replies: 2 comments
-
|
Excellent summary and writeup @erikgrinaker! A common theme I noticed amongst all of these is that it's complex, some more than others, so I'm inclined to reason that we'd ought to pick the approach that (1) minimizes the complexity, (2) maintains a clean API (as much as possible), while (3) being as idiomatic as possible within the given constraints. That being said, I believe |
Beta Was this translation helpful? Give feedback.
-
|
Yeah, I think I agree. I'm a bit concerned that it might get somewhat more complicated, but I'll give it a shot and we'll see how it turns out. Thanks for the input! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Just dumping some thoughts on the P2P PeerManager API model. I think I prefer one of these approaches, which are likely to involve equivalent internal implementations with different external interfaces.
DialNext()andEvictNext()trivially cheap when there is nothing to do, such that they can be called in a tight loop with e.g. a 1ms interval.DialNext()andEvictNext()return channels with peer IDs to dial/evict.DialNext()andEvictNext()block until a peer is available, and take a context for cancellation.I'm leaning towards channels or blocking.
Below are the options I've been considering.
Polling
Current model, Router calls e.g. DialNext() in loop to check if there's another peer to dial, then Dialed() or DailFailed when dialed, before Ready() when set up, and Disconnected() when disconnected.
Positive:
Negative:
Director
The Router simply has methods for e.g. Dial(), Accept(), and Disconnect(). The PeerManager takes the Router as a parameter and controls it, doing peer scheduling itself, but the router manages the actual connections.
Positive:
Negative:
Event-driven
The Manager and Router communicate with each other using channels.
Positive:
Negative:
Pulling with channels
Keep the same model as polling, but instead of polling DialNext() and EvictNext() these return channels that dispense peers. Other events (e.g. Dialed or DialFailed) are called synchronously.
Positive:
Negative:
Pulling with context
Instead of DialNext() and EvictNext() returning channels, they instead block until there is a peer to return. A context is passed for cancellation (e.g. for Router shutdown).
Positive:
Negative:
Beta Was this translation helpful? Give feedback.
All reactions