Multiparty session types for Rust
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.
Usage
Add this to your Cargo.toml:
[]
= "0.0.1"
Example
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.
extern crate mpstthree;
use Box;
use Error;
use ;
use run_processes;
use SessionMpst;
use close_mpst;
use RoleAtoB;
use RoleAtoC;
use RoleBtoA;
use RoleBtoC;
use c_to_aRoleCtoA;
use c_to_bRoleCtoB;
use RoleEnd;
use recv_mpst_a_to_c;
use recv_mpst_b_to_a;
use recv_mpst_c_to_b;
use send_mpst_a_to_b;
use send_mpst_b_to_c;
use send_mpst_c_to_a;
Then, you have to create the binary session types defining the interactions for each pair of participants.
/// Creating the binary sessions
type AtoB<N> = ;
type AtoC<N> = ;
type BtoA<N> = ;
type BtoC<N> = ;
type CtoA<N> = ;
type CtoB<N> = ;
Add the queues, which give the correct order of the operations for each participants.
/// Queues
type QueueA = ;
type QueueB = ;
type QueueC = ;
You can now encapsulate those binary session types and queues into SessionMpst for each participant.
/// Creating the MP sessions
type EndpointA<N> = ;
type EndpointB<N> = ;
type EndpointC<N> = ;
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.
/// Endpoint for A
/// Endpoint for B
/// Endpoint for C
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.
/// Fork all endpoints
Getting started
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
Prerequisites
You need to have Rust. You should get cargo installed.
Building
For building the library, run this code.
Running
For running the library, run this code.
Run test
For running the tests, run this code.
Tests are divided in 4 files:
- simple is the basic global protocol shown in Examples.
- choose checks that a protocol where a role B spreads a choice to the two other roles. For simplifying the test, role C is doing nothing. The protocol can be written as B→A:{B!A, B!A}.
- usecase is implementing the protocol given in 1, where Client → C, Authenticator → A and Server → B.
- usecase-recursive is implementing the protocol given in 2, where Client → C, Authenticator → A and Server → B.
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
Versioning
We use SemVer for versioning.
Authors
- Nicolas Lagaillardie - Initial work - NicolasLagaillardie
- Rumyana Neykova - Initial work - rumineykova
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgment
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.