mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2025-03-11 15:41:43 +01:00
59 lines
1.4 KiB
Rust
59 lines
1.4 KiB
Rust
|
#[macro_use]
|
||
|
extern crate slog;
|
||
|
|
||
|
mod access;
|
||
|
mod modules;
|
||
|
mod log;
|
||
|
mod api;
|
||
|
mod config;
|
||
|
mod error;
|
||
|
|
||
|
use api::api_capnp;
|
||
|
|
||
|
use futures::prelude::*;
|
||
|
use futures_signals::signal::Mutable;
|
||
|
use futures::task::LocalSpawn;
|
||
|
|
||
|
fn main() {
|
||
|
let log = log::init();
|
||
|
info!(log, "Starting");
|
||
|
|
||
|
let config = config::read().unwrap();
|
||
|
|
||
|
modules::init(log.new(o!()));
|
||
|
api::init();
|
||
|
|
||
|
let mut exec = futures::executor::LocalPool::new();
|
||
|
|
||
|
let enf = exec.run_until(async {
|
||
|
let e = access::init(&config).await.unwrap();
|
||
|
Mutable::new(e)
|
||
|
});
|
||
|
|
||
|
|
||
|
|
||
|
use std::net::ToSocketAddrs;
|
||
|
let args: Vec<String> = ::std::env::args().collect();
|
||
|
if args.len() != 2 {
|
||
|
println!("usage: {} ADDRESS[:PORT]", args[0]);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
let addr = args[1].to_socket_addrs().unwrap().next().expect("could not parse address");
|
||
|
|
||
|
|
||
|
let spawner = exec.spawner();
|
||
|
let result: Result<(), Box<dyn std::error::Error>> = exec.run_until(async move {
|
||
|
let listener = async_std::net::TcpListener::bind(&addr).await?;
|
||
|
let mut incoming = listener.incoming();
|
||
|
while let Some(socket) = incoming.next().await {
|
||
|
let socket = socket?;
|
||
|
let rpc_system = api::process_socket(enf.clone(), socket);
|
||
|
spawner.spawn_local_obj(
|
||
|
Box::pin(rpc_system.map_err(|e| println!("error: {:?}", e)).map(|_|())).into()).expect("spawn")
|
||
|
}
|
||
|
Ok(())
|
||
|
});
|
||
|
result.expect("main");
|
||
|
}
|