forked from sine-fdn/tandem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.rs
62 lines (56 loc) · 2.3 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! HTTP server for the Tandem SMPC engine.
//!
//! This crate provides an HTTP server acting as the `contributor` and running the Tandem Multi-Party
//! Computation engine. A connecting HTTP client is expected to act as the `evaluator`.
//!
//! This crate can be used as either a library or a binary.
//!
//! As a library, it provides a [`build`] function, which can be used to construct a server with
//! custom logic for choosing its input.
//!
//! In order to use this crate as a binary, the crate must be compiled with the `bin` feature. The
//! server binary supports two modes of execution:
//!
//! If the server is started without any configuration, it acts as a simple 'echo server' and
//! expects the contributor's input to be supplied by the client (as plaintext metadata). This can
//! be used to test different programs without re-deploying servers.
//!
//! Alternatively, a static configuration can be provided during server startup, as `Tandem.json` or
//! `Tandem.toml`, describing which MPC function and which contributor input to use based on the
//! plaintext metadata supplied by the client. These must be stored in the directory from which the
//! server is going to be started. The directory must also contain a file named `program.garble.rs`
//! with the program to run on the SMPC engine.
//!
//! As the sample server is based on the [Rocket](https://rocket.rs) framework, it is possible to
//! configure it according to the official [Rocket
//! documentation](https://rocket.rs/v0.5-rc/guide/configuration/#configuration).
//!
//! Example configuration through env vars:
//!
//! ```sh
//! # make the server listen at port 8080
//! ROCKET_PORT=8080 tandem_http_server
//!
//! # listen at 127.0.0.1 for HTTP requests
//! ROCKET_ADDRESS=127.0.0.1 tandem_http_server
//! ```
#![deny(unsafe_code)]
#![deny(missing_docs)]
#![deny(rustdoc::broken_intra_doc_links)]
use engine::{stage, Cors};
use rocket::{Build, Rocket};
pub use types::{HandleMpcRequestFn, MpcRequest, MpcSession};
#[macro_use]
extern crate rocket;
mod engine;
mod msg_queue;
mod requests;
mod responses;
mod state;
mod types;
#[cfg(test)]
mod tests;
/// Starts a Tandem server, responding to requests using the specified custom handler logic.
pub fn build(handler: HandleMpcRequestFn) -> Rocket<Build> {
rocket::build().attach(stage(handler)).attach(Cors)
}