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

Rework RequiredMessageParts API #85

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Protocol::verify_*_is_invalid()` are now mandatory to implement. ([#79])
- Removed the RNG parameter from `Round::receive_message()` and `Session::process_message()`. ([#83])
- Renamed `Round::entry_round()` to `entry_round_id()` and made it mandatory to implement. ([#84])
- Rework `RequiredMessageParts` API. ([#85])


### Added
Expand All @@ -40,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#79]: https://github.com/entropyxyz/manul/pull/79
[#83]: https://github.com/entropyxyz/manul/pull/83
[#84]: https://github.com/entropyxyz/manul/pull/84
[#85]: https://github.com/entropyxyz/manul/pull/85


## [0.1.0] - 2024-11-19
Expand Down
8 changes: 3 additions & 5 deletions examples/src/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ impl<Id> ProtocolError<Id> for SimpleProtocolError {

fn required_messages(&self) -> RequiredMessages {
match self {
Self::Round1InvalidPosition => {
RequiredMessages::new(RequiredMessageParts::direct_message_only(), None, None)
}
Self::Round1InvalidPosition => RequiredMessages::new(RequiredMessageParts::direct_message(), None, None),
Self::Round2InvalidPosition => RequiredMessages::new(
RequiredMessageParts::direct_message_only(),
Some([(1.into(), RequiredMessageParts::direct_message_only())].into()),
RequiredMessageParts::direct_message(),
Some([(1.into(), RequiredMessageParts::direct_message())].into()),
Some([1.into()].into()),
),
}
Expand Down
32 changes: 21 additions & 11 deletions manul/src/protocol/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,25 +215,35 @@ impl RequiredMessageParts {
}
}

/// Store all parts of the message (echo broadcast, normal broadcast, direct message).
pub fn all() -> Self {
Self::new(true, true, true)
}

/// Store echo broadcast only.
pub fn echo_broadcast_only() -> Self {
/// Store echo broadcast
pub fn echo_broadcast() -> Self {
Self::new(true, false, false)
}

/// Store normal broadcast only.
pub fn normal_broadcast_only() -> Self {
/// Store normal broadcast
pub fn normal_broadcast() -> Self {
Self::new(false, true, false)
}

/// Store direct message only.
pub fn direct_message_only() -> Self {
/// Store direct message
pub fn direct_message() -> Self {
Self::new(false, false, true)
}

/// Store echo broadcast in addition to what is already stored.
pub fn and_echo_broadcast(&self) -> Self {
Self::new(true, self.normal_broadcast, self.direct_message)
}

/// Store normal broadcast in addition to what is already stored.
pub fn and_normal_broadcast(&self) -> Self {
Self::new(self.echo_broadcast, true, self.direct_message)
}

/// Store direct message in addition to what is already stored.
pub fn and_direct_message(&self) -> Self {
Self::new(self.echo_broadcast, self.normal_broadcast, true)
}
}

/// Declares which messages from this and previous rounds
Expand Down
Loading