diff --git a/src/runtime2/communication.rs b/src/runtime2/communication.rs index 50bd8692519941c659dcfbaff9bb0e3287631a12..1f5cbaca826bf937a6facc7a952e517388a04e74 100644 --- a/src/runtime2/communication.rs +++ b/src/runtime2/communication.rs @@ -2,10 +2,13 @@ use crate::protocol::eval::*; use super::runtime::*; use super::component::*; +// ----------------------------------------------------------------------------- +// Generic types +// ----------------------------------------------------------------------------- + #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct PortId(pub u32); - impl PortId { /// This value is not significant, it is chosen to make debugging easier: a /// very large port number is more likely to shine a light on bugs. @@ -20,7 +23,7 @@ pub struct Peer { pub(crate) handle: CompHandle, } -#[derive(Debug, PartialEq, Eq)] +#[derive(Debug, PartialEq, Eq, Clone, Copy)] pub enum PortKind { Putter, Getter, @@ -46,6 +49,10 @@ pub struct Channel { pub getter_id: PortId, } +// ----------------------------------------------------------------------------- +// Data messages +// ----------------------------------------------------------------------------- + #[derive(Debug)] pub struct DataMessage { pub data_header: MessageDataHeader, @@ -53,19 +60,78 @@ pub struct DataMessage { pub content: ValueGroup, } -#[derive(Debug)] -pub struct MessageSyncHeader { - pub sync_round: u32, -} - #[derive(Debug)] pub struct MessageDataHeader { - pub expected_mapping: Vec<(PortId, u32)>, + pub expected_mapping: Vec<(PortId, Option)>, pub new_mapping: u32, pub source_port: PortId, pub target_port: PortId, } +// ----------------------------------------------------------------------------- +// Sync messages +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub struct SyncMessage { + pub sync_header: MessageSyncHeader, + pub content: SyncMessageContent, +} + +pub struct SyncLocalSolutionEntry { + pub self_port_id: PortId, + pub peer_comp_id: CompId, + pub peer_port_id: PortId, + pub mapping: u32, + pub port_kind: PortKind, +} + +pub type SyncLocalSolution = Vec; + +pub struct SyncSolutionPort { + pub self_comp_id: CompId, + pub self_port_id: PortId, + pub peer_comp_id: CompId, + pub peer_port_id: PortId, + pub mapping: u32, + pub port_kind: PortKind, +} + +pub struct SyncSolutionChannel { + pub putter: Option, + pub getter: Option, +} + +#[derive(Copy, Clone)] +pub enum RoundDecision { + None, + Solution, + Failure, +} + +impl RoundDecision { + fn is_some(&self) +} + +pub struct SyncPartialSolution { + pub submissions_by: Vec<(CompId, bool)>, + pub channel_mapping: Vec, + pub decision: SyncRoundDecision, +} + +#[derive(Debug, Clone)] +pub enum SyncMessageContent { + NotificationOfLeader, + LocalSolution(CompId, SyncLocalSolution), // local solution of the specified component + PartialSolution(SyncPartialSolution), // partial solution of multiple components + GlobalSolution, + GlobalFailure, +} + +// ----------------------------------------------------------------------------- +// Control messages +// ----------------------------------------------------------------------------- + #[derive(Debug)] pub struct ControlMessage { pub(crate) id: ControlId, @@ -84,9 +150,21 @@ pub enum ControlMessageContent { PortPeerChangedUnblock(PortId, CompId), } +// ----------------------------------------------------------------------------- +// Messages (generic) +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub struct MessageSyncHeader { + pub sync_round: u32, + pub sending_id: CompId, + pub highest_id: CompId, +} + #[derive(Debug)] pub enum Message { Data(DataMessage), + Sync(SyncMessage), Control(ControlMessage), } @@ -97,6 +175,8 @@ impl Message { return Some(v.data_header.target_port), Message::Control(v) => return v.target_port_id, + Message::Sync(_) => + return None, } } }