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

Broadcast Duplicates Messages Internally to the Library #526

Open
gatoWololo opened this issue Apr 23, 2024 · 0 comments
Open

Broadcast Duplicates Messages Internally to the Library #526

gatoWololo opened this issue Apr 23, 2024 · 0 comments
Labels
tech-debt Something works but could be better

Comments

@gatoWololo
Copy link

Background

This library exposes a simple API with the main function process_message. This function takes a message (from another participant) as input and outputs either:

  • Nothing. If the Participant needs more messages before making progress.
  • Vec<Messages>. Messages which the caller needs to send to the other participants.
  • A sub-protocol output. When the sub-protocol has successfully completed.

This makes it easy for the calling application to write a loop that loops over process_message until the sub-protocol completes. The caller can iterate over the Vec<Messages> routing them to the correct participant.

The library has support for messages that need to be broadcasted. This broadcast is implemented as follows: The library calls the message_for_other_participants method which generates n - 1 Messages, where n is the number of participants. These messages are returned from the library as part of the Vec<Messages> mentioned above. While this works, the message duplication is not always desirable.

Proposal

We could image a system that wants to handle broadcast in a different manner:

  • We think it would be more flexible if the library outputted a single message on broadcast.
  • This message should still contain some broadcast tag, but it is up to the calling application to duplicate this message and send it to all participants.

[ ] Change all uses of broadcast with message_for_other_participants to return a single message.

Appendix

Our current implementation of message duplication is simple:

/// Returns a Result[`Vec<Message>`] which are intended for the other
    /// participants.
    fn message_for_other_participants<T: Serialize>(
        &self,
        message_type: MessageType,
        data: T,
    ) -> Result<Vec<Message>> {
        self.other_ids()
            .iter()
            .map(|&other_participant_id| {
                Message::new(
                    message_type,
                    self.sid(),
                    self.id(),
                    other_participant_id,
                    &data,
                )
            })
            .collect()
    }
@gatoWololo gatoWololo added the tech-debt Something works but could be better label Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tech-debt Something works but could be better
Projects
None yet
Development

No branches or pull requests

1 participant