2023-07-20 14:25:25 -04:00
|
|
|
use clap::Parser;
|
2023-03-13 18:05:52 -04:00
|
|
|
use futures::future;
|
2022-11-15 19:11:16 -05:00
|
|
|
use hyper::{
|
2023-01-25 15:23:28 -05:00
|
|
|
server::conn::AddrStream,
|
2023-01-25 15:34:43 -05:00
|
|
|
service::{make_service_fn, service_fn},
|
2023-05-11 11:11:57 -04:00
|
|
|
Body, Request, Response, Server,
|
2022-11-15 19:11:16 -05:00
|
|
|
};
|
2023-04-04 19:34:35 -04:00
|
|
|
|
2023-10-25 13:58:24 -04:00
|
|
|
use prometheus_client::registry::Registry;
|
2023-09-27 18:45:40 -04:00
|
|
|
use rdsys_backend::{proto::ResourceState, request_resources};
|
2023-05-11 11:11:57 -04:00
|
|
|
use serde::Deserialize;
|
2023-07-21 16:11:10 -04:00
|
|
|
|
2023-03-03 17:25:43 -05:00
|
|
|
use std::{
|
2023-10-25 13:58:24 -04:00
|
|
|
convert::Infallible,
|
|
|
|
fs::File,
|
|
|
|
io::BufReader,
|
|
|
|
net::{IpAddr, Ipv4Addr, SocketAddr},
|
|
|
|
path::PathBuf,
|
|
|
|
time::Duration,
|
2023-03-03 17:25:43 -05:00
|
|
|
};
|
2023-03-22 19:14:56 -04:00
|
|
|
|
2023-08-03 18:22:39 -04:00
|
|
|
mod db_handler;
|
2023-09-07 16:22:06 -04:00
|
|
|
use db_handler::DB;
|
2023-04-04 19:34:35 -04:00
|
|
|
mod lox_context;
|
2023-10-30 12:54:59 -04:00
|
|
|
mod metrics;
|
2023-10-25 13:58:24 -04:00
|
|
|
use metrics::Metrics;
|
2023-05-11 11:11:57 -04:00
|
|
|
mod request_handler;
|
|
|
|
use request_handler::handle;
|
|
|
|
mod resource_parser;
|
2023-08-28 14:14:41 -04:00
|
|
|
use resource_parser::{parse_into_bridgelines, parse_into_buckets};
|
2023-04-04 19:34:35 -04:00
|
|
|
|
2023-03-15 15:21:03 -04:00
|
|
|
use tokio::{
|
2023-03-20 12:42:40 -04:00
|
|
|
signal, spawn,
|
2023-03-17 10:41:32 -04:00
|
|
|
sync::{broadcast, mpsc, oneshot},
|
2023-08-25 11:21:38 -04:00
|
|
|
time::{interval, sleep},
|
2023-03-15 15:21:03 -04:00
|
|
|
};
|
2022-11-15 19:11:16 -05:00
|
|
|
|
2023-01-30 18:14:22 -05:00
|
|
|
async fn shutdown_signal() {
|
|
|
|
tokio::signal::ctrl_c()
|
|
|
|
.await
|
|
|
|
.expect("failed to listen for ctrl+c signal");
|
2023-03-17 10:41:32 -04:00
|
|
|
println!("Shut down Lox Server");
|
|
|
|
}
|
|
|
|
|
2023-07-20 14:25:25 -04:00
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
#[command(author, version, about, long_about = None)]
|
|
|
|
struct Args {
|
2023-07-21 13:11:21 -04:00
|
|
|
/// Name/path of the configuration file
|
2023-07-20 14:25:25 -04:00
|
|
|
#[arg(short, long, default_value = "config.json")]
|
|
|
|
config: PathBuf,
|
|
|
|
|
2023-08-21 14:17:04 -04:00
|
|
|
// Optional Date/time to roll back to as a %Y-%m-%d_%H:%M:%S string
|
|
|
|
// This argument should be passed if the lox_context should be rolled back to a
|
|
|
|
// previous state due to, for example, a mass blocking event that is likely not
|
|
|
|
// due to Lox user behaviour. If the exact roll back date/time is not known, the
|
|
|
|
// last db entry within 24 hours from the passed roll_back_date will be used or else
|
|
|
|
// the program will fail gracefully.
|
2023-07-28 14:04:23 -04:00
|
|
|
#[arg(short, long, verbatim_doc_comment)]
|
2023-08-21 14:17:04 -04:00
|
|
|
roll_back_date: Option<String>,
|
2023-07-20 14:25:25 -04:00
|
|
|
}
|
|
|
|
|
2023-08-01 15:09:46 -04:00
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
struct Config {
|
2023-08-03 18:22:39 -04:00
|
|
|
db: DbConfig,
|
2023-10-25 13:58:24 -04:00
|
|
|
metrics_port: u16,
|
2023-08-28 19:33:19 -04:00
|
|
|
bridge_config: BridgeConfig,
|
2023-08-01 15:09:46 -04:00
|
|
|
rtype: ResourceInfo,
|
2023-08-03 18:22:39 -04:00
|
|
|
}
|
|
|
|
|
2023-08-28 14:14:41 -04:00
|
|
|
// Path of the lox database
|
2023-08-03 18:22:39 -04:00
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
pub struct DbConfig {
|
|
|
|
// The path for the lox_context database, default is "lox_db"
|
|
|
|
db_path: String,
|
|
|
|
}
|
2023-08-01 15:09:46 -04:00
|
|
|
|
2023-08-03 18:22:39 -04:00
|
|
|
impl Default for DbConfig {
|
|
|
|
fn default() -> DbConfig {
|
|
|
|
DbConfig {
|
|
|
|
db_path: "lox_db".to_owned(),
|
|
|
|
}
|
|
|
|
}
|
2023-08-01 15:09:46 -04:00
|
|
|
}
|
2023-08-03 18:22:39 -04:00
|
|
|
|
2023-08-28 14:14:41 -04:00
|
|
|
// Config information for how bridges should be allocated to buckets
|
2023-08-28 19:33:19 -04:00
|
|
|
#[derive(Debug, Default, Deserialize)]
|
2023-08-28 14:14:41 -04:00
|
|
|
pub struct BridgeConfig {
|
2023-11-01 13:53:58 -04:00
|
|
|
// A list of regions (as ISO 3166 country codes) that Lox will monitor resources for.
|
|
|
|
// Any region indicated here that is listed in the `blocked_in` field of a resource will be marked as
|
|
|
|
// blocked by Lox's bridge authority.
|
|
|
|
watched_blockages: Vec<String>,
|
2023-08-28 14:14:41 -04:00
|
|
|
// The percentage of buckets (made up of MAX_BRIDGES_PER_BUCKET bridges)
|
|
|
|
// that should be allocated as spare buckets
|
|
|
|
// This will be calculated as the floor of buckets.len() * percent_spares / 100
|
|
|
|
percent_spares: i32,
|
|
|
|
}
|
|
|
|
|
2023-04-04 19:34:35 -04:00
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
struct ResourceInfo {
|
|
|
|
endpoint: String,
|
|
|
|
name: String,
|
|
|
|
token: String,
|
|
|
|
types: Vec<String>,
|
|
|
|
}
|
|
|
|
// Populate Bridgedb from rdsys
|
|
|
|
|
2023-11-07 00:10:38 -05:00
|
|
|
// Rdsys sender creates a Resource request with the api_endpoint, resource token and type specified
|
2023-03-24 11:31:01 -04:00
|
|
|
// in the config.json file.
|
2023-11-07 00:10:38 -05:00
|
|
|
async fn rdsys_request_creator(
|
2023-03-20 12:42:40 -04:00
|
|
|
rtype: ResourceInfo,
|
2023-09-27 18:45:40 -04:00
|
|
|
tx: mpsc::Sender<ResourceState>,
|
2023-03-20 12:42:40 -04:00
|
|
|
mut kill: broadcast::Receiver<()>,
|
|
|
|
) {
|
2023-08-25 11:21:38 -04:00
|
|
|
tokio::select! {
|
|
|
|
start_resource_request = rdsys_request(rtype, tx) => start_resource_request,
|
2023-08-28 19:33:19 -04:00
|
|
|
_ = kill.recv() => {println!("Shut down rdsys request loop")},
|
2023-03-24 11:31:01 -04:00
|
|
|
|
2023-08-25 11:21:38 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-07 00:10:38 -05:00
|
|
|
// Makes a request to rdsys for the full set of Resources assigned to lox every interval
|
|
|
|
// (defined in the function)
|
2023-09-27 18:45:40 -04:00
|
|
|
async fn rdsys_request(rtype: ResourceInfo, tx: mpsc::Sender<ResourceState>) {
|
2023-10-16 17:47:08 -04:00
|
|
|
let mut interval = interval(Duration::from_secs(5));
|
2023-08-25 11:21:38 -04:00
|
|
|
loop {
|
|
|
|
interval.tick().await;
|
|
|
|
let resources = request_resources(
|
|
|
|
rtype.endpoint.clone(),
|
|
|
|
rtype.name.clone(),
|
|
|
|
rtype.token.clone(),
|
|
|
|
rtype.types.clone(),
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
tx.send(resources).await.unwrap();
|
2023-03-13 18:05:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-07 00:10:38 -05:00
|
|
|
// Parse bridges received from rdsys and sync with Lox context
|
2023-03-20 12:42:40 -04:00
|
|
|
async fn rdsys_bridge_parser(
|
|
|
|
rdsys_tx: mpsc::Sender<Command>,
|
2023-09-27 18:45:40 -04:00
|
|
|
rx: mpsc::Receiver<ResourceState>,
|
2023-03-20 12:42:40 -04:00
|
|
|
mut kill: broadcast::Receiver<()>,
|
|
|
|
) {
|
|
|
|
tokio::select! {
|
2023-03-17 10:41:32 -04:00
|
|
|
start_bridge_parser = parse_bridges(rdsys_tx, rx) => start_bridge_parser ,
|
2023-03-24 13:16:26 -04:00
|
|
|
_ = kill.recv() => {println!("Shut down bridge_parser");},
|
2023-03-17 10:41:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-16 17:47:08 -04:00
|
|
|
// Parse Bridges receives the resources from rdsys and sends it to the
|
|
|
|
// Context Manager to be parsed and added to the Lox BridgeDB
|
2023-09-27 18:45:40 -04:00
|
|
|
async fn parse_bridges(rdsys_tx: mpsc::Sender<Command>, mut rx: mpsc::Receiver<ResourceState>) {
|
2023-03-13 18:05:52 -04:00
|
|
|
loop {
|
2023-08-25 11:21:38 -04:00
|
|
|
let resources = rx.recv().await.unwrap();
|
|
|
|
let cmd = Command::Rdsys { resources };
|
2023-03-13 18:05:52 -04:00
|
|
|
rdsys_tx.send(cmd).await.unwrap();
|
2023-03-15 15:21:03 -04:00
|
|
|
sleep(Duration::from_secs(1)).await;
|
2023-03-13 18:05:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-07 00:10:38 -05:00
|
|
|
// Create a prometheus metrics server
|
2023-10-26 12:19:28 -04:00
|
|
|
async fn start_metrics_collector(
|
|
|
|
metrics_addr: SocketAddr,
|
|
|
|
registry: Registry,
|
|
|
|
mut kill: broadcast::Receiver<()>,
|
|
|
|
) {
|
2023-10-25 13:58:24 -04:00
|
|
|
tokio::select! {
|
|
|
|
lox_metrics = metrics::start_metrics_server(metrics_addr, registry) => lox_metrics,
|
|
|
|
_ = kill.recv() => {println!("Shut down metrics server");},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-20 12:42:40 -04:00
|
|
|
async fn create_context_manager(
|
2023-08-03 18:22:39 -04:00
|
|
|
db_config: DbConfig,
|
2023-08-28 14:14:41 -04:00
|
|
|
bridge_config: BridgeConfig,
|
2023-08-21 14:17:04 -04:00
|
|
|
roll_back_date: Option<String>,
|
2023-10-25 13:58:24 -04:00
|
|
|
metrics: Metrics,
|
2023-03-20 12:42:40 -04:00
|
|
|
context_rx: mpsc::Receiver<Command>,
|
|
|
|
mut kill: broadcast::Receiver<()>,
|
|
|
|
) {
|
|
|
|
tokio::select! {
|
2023-10-25 13:58:24 -04:00
|
|
|
create_context = context_manager(db_config, bridge_config, roll_back_date, metrics, context_rx) => create_context,
|
2023-03-24 13:16:26 -04:00
|
|
|
_ = kill.recv() => {println!("Shut down context_manager");},
|
2023-03-17 10:41:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-20 11:53:10 -04:00
|
|
|
// Context Manager handles the Lox BridgeDB and Bridge Authority, ensuring
|
|
|
|
// that the DB can be updated from the rdsys stream and client requests
|
|
|
|
// can be responded to with an updated BridgeDB state
|
2023-08-21 14:17:04 -04:00
|
|
|
async fn context_manager(
|
|
|
|
db_config: DbConfig,
|
2023-08-28 14:14:41 -04:00
|
|
|
bridge_config: BridgeConfig,
|
2023-08-21 14:17:04 -04:00
|
|
|
roll_back_date: Option<String>,
|
2023-10-25 13:58:24 -04:00
|
|
|
metrics: Metrics,
|
2023-08-21 14:17:04 -04:00
|
|
|
mut context_rx: mpsc::Receiver<Command>,
|
|
|
|
) {
|
2023-10-25 13:58:24 -04:00
|
|
|
let (mut lox_db, context) =
|
|
|
|
match DB::open_new_or_existing_db(db_config, roll_back_date, metrics) {
|
|
|
|
Ok((lox_db, context)) => (lox_db, context),
|
|
|
|
Err(e) => {
|
|
|
|
panic!("Error: {:?}", e);
|
|
|
|
}
|
|
|
|
};
|
2023-03-20 12:42:40 -04:00
|
|
|
|
|
|
|
while let Some(cmd) = context_rx.recv().await {
|
|
|
|
use Command::*;
|
|
|
|
match cmd {
|
2023-08-25 11:21:38 -04:00
|
|
|
Rdsys { resources } => {
|
2023-08-28 14:14:41 -04:00
|
|
|
// If the bridgetable is not being loaded from an existing database, we will populate the
|
2023-09-27 18:45:40 -04:00
|
|
|
// bridgetable with all of the working bridges received from rdsys.
|
2023-09-13 12:08:48 -04:00
|
|
|
if context.bridgetable_is_empty() {
|
2023-09-27 18:45:40 -04:00
|
|
|
if let Some(working_resources) = resources.working {
|
2023-11-01 13:53:58 -04:00
|
|
|
let (bridgelines, _) = parse_into_bridgelines(
|
|
|
|
bridge_config.watched_blockages.clone(),
|
|
|
|
working_resources,
|
|
|
|
);
|
2023-10-26 13:22:19 -04:00
|
|
|
context.metrics.new_bridges.inc_by(bridgelines.len() as u64);
|
2023-09-27 18:45:40 -04:00
|
|
|
let (buckets, leftovers) = parse_into_buckets(bridgelines);
|
|
|
|
for leftover in leftovers {
|
|
|
|
context.append_extra_bridges(leftover);
|
|
|
|
}
|
|
|
|
context.populate_bridgetable(buckets, bridge_config.percent_spares);
|
|
|
|
|
|
|
|
// otherwise, we need to sync the existing bridgetable with the resources we receive from
|
|
|
|
// rdsys and ensure that all functioning bridges are correctly placed in the bridgetable
|
|
|
|
// those that have changed are updated and those that have been failing tests for an extended
|
|
|
|
// period of time are removed.
|
|
|
|
// If bridges are labelled as blocked_in, we should also handle blocking behaviour.
|
2023-08-28 14:14:41 -04:00
|
|
|
}
|
|
|
|
} else {
|
2023-11-01 13:53:58 -04:00
|
|
|
context
|
|
|
|
.sync_with_bridgetable(bridge_config.watched_blockages.clone(), resources);
|
2023-03-20 12:42:40 -04:00
|
|
|
}
|
2023-08-28 19:33:19 -04:00
|
|
|
// Handle any bridges that are leftover in the bridge authority from the sync
|
2023-05-08 20:30:30 -04:00
|
|
|
context.allocate_leftover_bridges();
|
2023-03-20 12:42:40 -04:00
|
|
|
context.encrypt_table();
|
2023-09-07 16:22:06 -04:00
|
|
|
lox_db.write_context(context.clone());
|
2023-03-20 12:42:40 -04:00
|
|
|
sleep(Duration::from_millis(1)).await;
|
|
|
|
}
|
|
|
|
Request { req, sender } => {
|
|
|
|
let response = handle(context.clone(), req).await;
|
|
|
|
if let Err(e) = sender.send(response) {
|
|
|
|
eprintln!("Server Response Error: {:?}", e);
|
|
|
|
};
|
2023-09-13 14:21:15 -04:00
|
|
|
lox_db.write_context(context.clone());
|
2023-03-20 12:42:40 -04:00
|
|
|
sleep(Duration::from_millis(1)).await;
|
|
|
|
}
|
|
|
|
Shutdown { shutdown_sig } => {
|
2023-09-13 14:21:15 -04:00
|
|
|
lox_db.write_context(context.clone());
|
2023-03-20 11:53:10 -04:00
|
|
|
println!("Sending Shutdown Signal, all threads should shutdown.");
|
|
|
|
drop(shutdown_sig);
|
|
|
|
println!("Shutdown Sent.");
|
2023-03-20 12:42:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-17 10:41:32 -04:00
|
|
|
}
|
|
|
|
|
2023-03-20 11:53:10 -04:00
|
|
|
// Each of the commands that the Context Manager handles
|
2023-03-13 18:05:52 -04:00
|
|
|
#[derive(Debug)]
|
|
|
|
enum Command {
|
2023-03-15 15:21:03 -04:00
|
|
|
Rdsys {
|
2023-09-27 18:45:40 -04:00
|
|
|
resources: ResourceState,
|
2023-03-15 15:21:03 -04:00
|
|
|
},
|
2023-03-13 18:05:52 -04:00
|
|
|
Request {
|
2023-03-14 23:23:40 -04:00
|
|
|
req: Request<Body>,
|
2023-03-15 15:21:03 -04:00
|
|
|
sender: oneshot::Sender<Result<Response<Body>, Infallible>>,
|
|
|
|
},
|
2023-03-20 11:53:10 -04:00
|
|
|
Shutdown {
|
|
|
|
shutdown_sig: broadcast::Sender<()>,
|
2023-03-20 12:42:40 -04:00
|
|
|
},
|
2023-03-13 18:05:52 -04:00
|
|
|
}
|
2023-03-03 14:09:13 -05:00
|
|
|
|
2023-03-14 23:23:40 -04:00
|
|
|
#[tokio::main]
|
2022-11-15 19:11:16 -05:00
|
|
|
async fn main() {
|
2023-07-20 14:25:25 -04:00
|
|
|
let args: Args = Args::parse();
|
|
|
|
|
2023-07-28 14:04:23 -04:00
|
|
|
let file = File::open(&args.config).expect("Could not read config file");
|
2023-03-03 17:25:43 -05:00
|
|
|
let reader = BufReader::new(file);
|
|
|
|
// Read the JSON contents of the file as a ResourceInfo
|
2023-08-03 18:22:39 -04:00
|
|
|
let config: Config = serde_json::from_reader(reader).expect("Reading Config from JSON failed.");
|
2023-03-03 14:09:13 -05:00
|
|
|
|
2023-03-17 10:41:32 -04:00
|
|
|
let (rdsys_tx, context_rx) = mpsc::channel(32);
|
2023-03-15 15:21:03 -04:00
|
|
|
let request_tx = rdsys_tx.clone();
|
2023-03-20 11:53:10 -04:00
|
|
|
let shutdown_cmd_tx = rdsys_tx.clone();
|
2023-03-13 18:05:52 -04:00
|
|
|
|
2023-03-20 11:53:10 -04:00
|
|
|
// create the shutdown broadcast channel and clone for every thread
|
2023-03-20 12:42:40 -04:00
|
|
|
let (shutdown_tx, mut shutdown_rx) = broadcast::channel(16);
|
|
|
|
let kill_stream = shutdown_tx.subscribe();
|
2023-10-25 13:58:24 -04:00
|
|
|
let kill_metrics = shutdown_tx.subscribe();
|
2023-03-20 12:42:40 -04:00
|
|
|
let kill_parser = shutdown_tx.subscribe();
|
|
|
|
let kill_context = shutdown_tx.subscribe();
|
2023-03-17 10:41:32 -04:00
|
|
|
|
2023-03-20 12:42:40 -04:00
|
|
|
// Listen for ctrl_c, send signal to broadcast shutdown to all threads by dropping shutdown_tx
|
|
|
|
let shutdown_handler = spawn(async move {
|
2023-03-17 10:41:32 -04:00
|
|
|
tokio::select! {
|
|
|
|
_ = signal::ctrl_c() => {
|
2023-03-20 11:53:10 -04:00
|
|
|
let cmd = Command::Shutdown {
|
|
|
|
shutdown_sig: shutdown_tx,
|
|
|
|
};
|
|
|
|
shutdown_cmd_tx.send(cmd).await.unwrap();
|
|
|
|
sleep(Duration::from_secs(1)).await;
|
2023-03-17 10:41:32 -04:00
|
|
|
|
|
|
|
_ = shutdown_rx.recv().await;
|
2023-03-09 19:01:01 -05:00
|
|
|
}
|
2023-03-03 17:25:43 -05:00
|
|
|
}
|
2023-03-20 12:42:40 -04:00
|
|
|
});
|
2023-03-17 10:41:32 -04:00
|
|
|
|
2023-10-25 13:58:24 -04:00
|
|
|
let metrics = Metrics::default();
|
|
|
|
let registry = metrics.register();
|
2023-10-26 12:19:28 -04:00
|
|
|
let metrics_addr =
|
|
|
|
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), config.metrics_port);
|
2023-10-25 13:58:24 -04:00
|
|
|
let metrics_handler =
|
|
|
|
spawn(async move { start_metrics_collector(metrics_addr, registry, kill_metrics).await });
|
|
|
|
|
2023-08-21 14:17:04 -04:00
|
|
|
let context_manager = spawn(async move {
|
2023-08-28 14:14:41 -04:00
|
|
|
create_context_manager(
|
|
|
|
config.db,
|
2023-08-28 19:33:19 -04:00
|
|
|
config.bridge_config,
|
2023-08-28 14:14:41 -04:00
|
|
|
args.roll_back_date,
|
2023-10-25 13:58:24 -04:00
|
|
|
metrics,
|
2023-08-28 14:14:41 -04:00
|
|
|
context_rx,
|
|
|
|
kill_context,
|
|
|
|
)
|
|
|
|
.await
|
2023-08-21 14:17:04 -04:00
|
|
|
});
|
2023-03-10 16:54:31 -05:00
|
|
|
|
2023-03-20 11:53:10 -04:00
|
|
|
let (tx, rx) = mpsc::channel(32);
|
2023-11-07 00:10:38 -05:00
|
|
|
let rdsys_request_handler = spawn(async { rdsys_request_creator(config.rtype, tx, kill_stream).await });
|
2023-03-14 23:23:40 -04:00
|
|
|
|
2023-03-20 12:42:40 -04:00
|
|
|
let rdsys_resource_receiver =
|
|
|
|
spawn(async { rdsys_bridge_parser(rdsys_tx, rx, kill_parser).await });
|
2023-03-14 23:23:40 -04:00
|
|
|
|
2023-03-15 15:21:03 -04:00
|
|
|
let make_service = make_service_fn(move |_conn: &AddrStream| {
|
2023-03-14 23:23:40 -04:00
|
|
|
let request_tx = request_tx.clone();
|
2023-03-15 15:21:03 -04:00
|
|
|
let service = service_fn(move |req| {
|
2023-03-14 23:23:40 -04:00
|
|
|
let request_tx = request_tx.clone();
|
|
|
|
let (response_tx, response_rx) = oneshot::channel();
|
|
|
|
let cmd = Command::Request {
|
2023-03-24 13:16:26 -04:00
|
|
|
req,
|
2023-03-14 23:23:40 -04:00
|
|
|
sender: response_tx,
|
|
|
|
};
|
|
|
|
async move {
|
2023-03-15 15:21:03 -04:00
|
|
|
request_tx.send(cmd).await.unwrap();
|
|
|
|
response_rx.await.unwrap()
|
2023-03-14 23:23:40 -04:00
|
|
|
}
|
|
|
|
});
|
2023-01-25 15:23:28 -05:00
|
|
|
async move { Ok::<_, Infallible>(service) }
|
2022-11-15 19:11:16 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
let addr = SocketAddr::from(([127, 0, 0, 1], 8001));
|
2023-03-14 23:23:40 -04:00
|
|
|
let server = Server::bind(&addr).serve(make_service);
|
2023-03-17 10:41:32 -04:00
|
|
|
let graceful = server.with_graceful_shutdown(shutdown_signal());
|
|
|
|
println!("Listening on {}", addr);
|
|
|
|
if let Err(e) = graceful.await {
|
|
|
|
eprintln!("server error: {}", e);
|
|
|
|
}
|
2023-03-20 12:42:40 -04:00
|
|
|
future::join_all([
|
2023-10-25 13:58:24 -04:00
|
|
|
metrics_handler,
|
2023-09-07 11:00:34 -04:00
|
|
|
rdsys_request_handler,
|
2023-03-17 10:41:32 -04:00
|
|
|
rdsys_resource_receiver,
|
|
|
|
context_manager,
|
|
|
|
shutdown_handler,
|
|
|
|
])
|
|
|
|
.await;
|
2022-11-15 19:11:16 -05:00
|
|
|
}
|