#![allow(dead_code)] use mpstthree::binary::struct_trait::end::End; use mpstthree::binary::struct_trait::recv::Recv; use mpstthree::binary::struct_trait::send::Send; use mpstthree::role::broadcast::RoleBroadcast; use mpstthree::role::end::RoleEnd; use mpstthree::{ checker_concat, checker_concat_impl, create_meshedchannels, create_multiple_normal_name, create_multiple_normal_role, }; use petgraph::dot::Dot; use std::fs::read_to_string; // Create new MeshedChannels create_meshedchannels!(MeshedChannels, 4); // Create new roles create_multiple_normal_role!( RoleA, RoleADual | RoleB, RoleBDual | RoleC, RoleCDual | RoleD, RoleDDual | ); // Create new names create_multiple_normal_name!(NameA, NameB, NameC, NameD); // Payload types struct Update; struct Okay; // Types // A type Choose0fromAtoB = Send; type Choose0fromAtoC = Send; type Choose0fromAtoD = Send; type Choose1fromAtoB = Send; type Choose1fromAtoC = Send; type Choose1fromAtoD = Send; // B type Recurs0BfromA = Recv; enum Branches0BfromA { End(MeshedChannels), CommitForward( MeshedChannels, End, End, RoleA>, NameB>, ), } type Recurs1BfromA = Recv; enum Branches1BfromA { CommitBackward( MeshedChannels, End, End, RoleA>, NameB>, ), } // C type Recurs0CfromA = Recv; enum Branches0CfromA { End(MeshedChannels), CommitForward( MeshedChannels, End, End, RoleA>, NameC>, ), } type Recurs1CfromA = Recv; enum Branches1CfromA { CommitBackward( MeshedChannels, End, End, RoleA>, NameC>, ), } // D type Recurs0DfromA = Recv; enum Branches0DfromA { End(MeshedChannels), CommitForward( MeshedChannels, End, End, RoleA>, NameD>, ), } type Recurs1DfromA = Recv; enum Branches1DfromA { CommitBackward( MeshedChannels, End, End, RoleA>, NameD>, ), } // Creating the MP sessions // For A type EndpointAEnd = MeshedChannels; type EndpointACommitForward = MeshedChannels< Recv, Send, Send, RoleB>>, NameA, >; type EndpointACommitBackward = MeshedChannels< Send, Recv, Recv, RoleD>>, NameA, >; type EndpointAFull = MeshedChannels; // For B type EndpointBFull = MeshedChannels, NameB>; // For C type EndpointCFull = MeshedChannels, NameC>; // For D type EndpointDFull = MeshedChannels, NameD>; ///////////////////////////////////////// checker_concat_impl!( [ Branches0BfromA, CommitForward, Branches0CfromA, CommitForward, Branches0DfromA, CommitForward ], [ Branches1BfromA, CommitBackward, Branches1CfromA, CommitBackward, Branches1DfromA, CommitBackward ], [ Branches0BfromA, End, Branches0CfromA, End, Branches0DfromA, End ] ); pub fn main() { let (graphs, kmc) = checker_concat!( "commit_protocol", EndpointAFull, EndpointBFull, EndpointCFull, EndpointDFull => [ EndpointACommitForward, Branches0BfromA, CommitForward, Branches0CfromA, CommitForward, Branches0DfromA, CommitForward ], [ EndpointACommitBackward, Branches1BfromA, CommitBackward, Branches1CfromA, CommitBackward, Branches1DfromA, CommitBackward ], [ EndpointAEnd, Branches0BfromA, End, Branches0CfromA, End, Branches0DfromA, End ] ) .unwrap(); ////////////// Test graph A let graph_a = &graphs["RoleA"]; assert_eq!( format!("{:?}", Dot::new(&graph_a)), "digraph {\n \ 0 [ label = \"\\\"0\\\"\" ]\n \ 1 [ label = \"\\\"0.1\\\"\" ]\n \ 2 [ label = \"\\\"0.2\\\"\" ]\n \ 3 [ label = \"\\\"0.3\\\"\" ]\n \ 4 [ label = \"\\\"0.3.1\\\"\" ]\n \ 5 [ label = \"\\\"0.3.2\\\"\" ]\n \ 6 [ label = \"\\\"0.3.3\\\"\" ]\n \ 7 [ label = \"\\\"0.1\\\"\" ]\n \ 0 -> 1 [ label = \"\\\"RoleA?RoleB: Update\\\"\" ]\n \ 1 -> 2 [ label = \"\\\"RoleA!RoleC: Update\\\"\" ]\n \ 2 -> 3 [ label = \"\\\"RoleA!RoleD: Update\\\"\" ]\n \ 3 -> 4 [ label = \"\\\"RoleA?RoleD: Okay\\\"\" ]\n \ 4 -> 5 [ label = \"\\\"RoleA?RoleC: Okay\\\"\" ]\n \ 5 -> 6 [ label = \"\\\"RoleA!RoleB: Okay\\\"\" ]\n \ 6 -> 0 [ label = \"\\\"µ\\\"\" ]\n \ 0 -> 7 [ label = \"\\\"0\\\"\" ]\n\ }\n" ); ////////////// Test graph B let graph_b = &graphs["RoleB"]; assert_eq!( format!("{:?}", Dot::new(&graph_b)), "digraph {\n \ 0 [ label = \"\\\"0\\\"\" ]\n \ 1 [ label = \"\\\"0.1\\\"\" ]\n \ 2 [ label = \"\\\"0.1.1\\\"\" ]\n \ 3 [ label = \"\\\"0.1\\\"\" ]\n \ 0 -> 1 [ label = \"\\\"RoleB!RoleA: Update\\\"\" ]\n \ 1 -> 2 [ label = \"\\\"RoleB?RoleA: Okay\\\"\" ]\n \ 2 -> 0 [ label = \"\\\"µ\\\"\" ]\n \ 0 -> 3 [ label = \"\\\"0\\\"\" ]\n\ }\n" ); ////////////// Test graph C let graph_c = &graphs["RoleC"]; assert_eq!( format!("{:?}", Dot::new(&graph_c)), "digraph {\n \ 0 [ label = \"\\\"0\\\"\" ]\n \ 1 [ label = \"\\\"0.1\\\"\" ]\n \ 2 [ label = \"\\\"0.1.1\\\"\" ]\n \ 3 [ label = \"\\\"0.1\\\"\" ]\n \ 0 -> 1 [ label = \"\\\"RoleC?RoleA: Update\\\"\" ]\n \ 1 -> 2 [ label = \"\\\"RoleC!RoleA: Okay\\\"\" ]\n \ 2 -> 0 [ label = \"\\\"µ\\\"\" ]\n \ 0 -> 3 [ label = \"\\\"0\\\"\" ]\n\ }\n" ); ////////////// Test graph D let graph_d = &graphs["RoleD"]; assert_eq!( format!("{:?}", Dot::new(&graph_d)), "digraph {\n \ 0 [ label = \"\\\"0\\\"\" ]\n \ 1 [ label = \"\\\"0.1\\\"\" ]\n \ 2 [ label = \"\\\"0.1.1\\\"\" ]\n \ 3 [ label = \"\\\"0.1\\\"\" ]\n \ 0 -> 1 [ label = \"\\\"RoleD?RoleA: Update\\\"\" ]\n \ 1 -> 2 [ label = \"\\\"RoleD!RoleA: Okay\\\"\" ]\n \ 2 -> 0 [ label = \"\\\"µ\\\"\" ]\n \ 0 -> 3 [ label = \"\\\"0\\\"\" ]\n\ }\n" ); ////////////// Test KMC output assert_eq!( "CSA: \u{1b}[92mTrue\n\ \u{1b}[0mBasic: \u{1b}[92mTrue\n\ \u{1b}[0mreduced 1-exhaustive: \u{1b}[92mTrue\n\ \u{1b}[0mreduced 1-safe: \u{1b}[92mTrue\n\ \u{1b}[0m\n", read_to_string("outputs/commit_protocol_1_kmc.txt").unwrap() ); ////////////// Test KMC number assert_eq!(kmc, Some(1)); }