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()
}
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:Participant
needs more messages before making progress.Vec<Messages>
. Messages which the caller needs to send to the other participants.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 theVec<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 - 1Messages
, wheren
is the number of participants. These messages are returned from the library as part of theVec<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:
[ ] Change all uses of broadcast with
message_for_other_participants
to return a single message.Appendix
Our current implementation of message duplication is simple: