This library implements multiparty session types in Rust for three participants. It relies on sesh. An other library is coming soon to extend to any number of participants.
Add this to your Cargo.toml
:
toml
[dependencies]
mpstthree = "0.0.1"
Here a way to create a simple protocol involving 3 participants, A, B and C. A sends a payoad to B, then receives an other from C. Upon receiving the payload from A, B sends a payload to C. This protocol can be written as A!B.A?C.B!C. To implement this example, first, get the right components from the library.
```rust extern crate mpstthree;
use std::boxed::Box; use std::error::Error;
use mpstthree::binary::{End, Recv, Send}; use mpstthree::run_processes; use mpstthree::sessionmpst::SessionMpst;
use mpstthree::functionmpst::close::close_mpst;
use mpstthree::role::atob::RoleAtoB; use mpstthree::role::atoc::RoleAtoC; use mpstthree::role::btoa::RoleBtoA; use mpstthree::role::btoc::RoleBtoC; use mpstthree::role::ctoa::RoleCtoA; use mpstthree::role::ctob::RoleCtoB; use mpstthree::role::end::RoleEnd;
use mpstthree::functionmpst::recv::recvmpstatoc; use mpstthree::functionmpst::recv::recvmpstbtoa; use mpstthree::functionmpst::recv::recvmpstctob;
use mpstthree::functionmpst::send::sendmpstatob; use mpstthree::functionmpst::send::sendmpstbtoc; use mpstthree::functionmpst::send::sendmpstctoa; ```
Then, you have to create the binary session types defining the interactions for each pair of participants.
```rust
/// Creating the binary sessions
type AtoB
type BtoA
type CtoA
Add the queues, which give the correct order of the operations for each participants.
rust
/// Queues
type QueueA = RoleAtoB<RoleAtoC<RoleEnd>>;
type QueueB = RoleBtoA<RoleBtoC<RoleEnd>>;
type QueueC = RoleCtoA<RoleCtoB<RoleEnd>>;
You can now encapsulate those binary session types and queues into SessionMpst for each participant.
rust
/// Creating the MP sessions
type EndpointA<N> = SessionMpst<AtoB<N>, AtoC<N>, QueueA>;
type EndpointB<N> = SessionMpst<BtoA<N>, BtoC<N>, QueueB>;
type EndpointC<N> = SessionMpst<CtoA<N>, CtoB<N>, QueueC>;
To check to the protocol is correct, it is mandatory to detail the behaviour of the participants with functions which input the Endpoints defined above.
```rust
/// Endpoint for A
fn simpletripleendpointa(s: EndpointA
close_mpst(s)?;
Ok(())
}
/// Endpoint for B
fn simpletripleendpointb(s: EndpointB
close_mpst(s)?;
Ok(())
}
/// Endpoint for C
fn simpletripleendpointc(s: EndpointC
close_mpst(s)?;
Ok(())
} ```
In the end, you have to link the threads, related to the functions above, together with run_processes(). Do not forget to unwrap() the returned threads.
```rust /// Fork all endpoints fn simpletripleendpoints() { let (threada, threadb, threadc) = runprocesses( simpletripleendpointa, simpletripleendpointb, simpletripleendpoint_c, );
thread_a.unwrap();
thread_b.unwrap();
thread_c.unwrap();
} ```
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
You need to have Rust. You should get cargo
installed.
For building the library, run this code.
sh
$ cargo build
For running the library, run this code.
sh
$ cargo run
For running the tests, run this code.
sh
$ cargo test
Tests are divided in 4 files:
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning.
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE file for details.
This project is part of my current PhD under the supervision of Nobuko Yoshida, that I would like to thank. I was also helped by my colleagues from Imperial College London.