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

Per peer msg handling #3

Open
Wondertan opened this issue Oct 2, 2021 · 0 comments
Open

Per peer msg handling #3

Wondertan opened this issue Oct 2, 2021 · 0 comments

Comments

@Wondertan
Copy link
Member

Context

Messenger only provides Send and Receive for msg handling and both methods are unified for any peer. This forces protocols to be implemented in one way only, where msgs are sent or rcvd in only one place. However, there are protocols that would benefit from splitting logic per each peer independently.

Design

// The peer structure stores required channels to send/recv msgs
type Peer struct {}
// Send mimics Messenger's Send but without peer id.
func (p *Peer) Send(context.Context, serde.Message) <-chan err
// Receive mimics Messenger's Receive but without peer id.
// Multiple Receive users will compete for msgs, as they are not duplicated.
func (p *Peer) Receive(context.Context) serde.Message
// Events chan will only return event's of the peer.
func (p *Peer) Events() <-chan PeerEvent

// Add a new method to the Messenger to return a Peer.
// Once a Peer instantiated, new msgs incoming from the peer can only be rcvd through Peer.Receive. 
// Messenger.Receive will still be able to receive new msgs from other peers, but not from this one.
func (m *Messenger Peer(peer.ID) *Peer
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

No branches or pull requests

1 participant