2023-08-24 17:22:45 +02:00
|
|
|
use std::net::SocketAddr;
|
|
|
|
|
2023-08-25 21:52:28 +02:00
|
|
|
use axum::{response::IntoResponse, routing::get, Router};
|
2023-08-24 17:22:45 +02:00
|
|
|
use clap::{Parser, Subcommand};
|
|
|
|
|
|
|
|
#[derive(Parser)]
|
|
|
|
#[command(author, version, about, long_about = None, subcommand_required = true)]
|
|
|
|
struct Command {
|
|
|
|
#[command(subcommand)]
|
|
|
|
command: Option<Commands>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subcommand)]
|
|
|
|
enum Commands {
|
|
|
|
Daemon {
|
|
|
|
#[arg(env = "CHURN_ADDR", long)]
|
|
|
|
host: SocketAddr,
|
|
|
|
},
|
|
|
|
|
|
|
|
Connect {
|
|
|
|
/// agent name is the hostname which other agents or servers can resolve and connect via. It should be unique
|
|
|
|
#[arg(env = "CHURN_AGENT_NAME", long)]
|
|
|
|
agent_name: String,
|
|
|
|
|
|
|
|
#[arg(env = "CHURN_ADDR", long)]
|
|
|
|
host: SocketAddr,
|
|
|
|
|
|
|
|
#[arg(env = "CHURN_TOKEN", long)]
|
|
|
|
token: String,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> anyhow::Result<()> {
|
|
|
|
dotenv::dotenv().ok();
|
|
|
|
tracing_subscriber::fmt::init();
|
|
|
|
|
|
|
|
let cli = Command::parse();
|
|
|
|
|
|
|
|
handle_command(cli).await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn handle_command(cmd: Command) -> anyhow::Result<()> {
|
|
|
|
match cmd.command {
|
|
|
|
Some(Commands::Daemon { host }) => {
|
2023-08-25 21:52:28 +02:00
|
|
|
tracing::info!("Starting churn server");
|
|
|
|
|
|
|
|
let app = Router::new().route("/ping", get(ping));
|
|
|
|
|
|
|
|
tracing::info!("churn server listening on {}", host);
|
|
|
|
axum::Server::bind(&host)
|
|
|
|
.serve(app.into_make_service())
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2023-08-24 17:22:45 +02:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
Some(Commands::Connect {
|
|
|
|
host,
|
|
|
|
token,
|
|
|
|
agent_name,
|
|
|
|
}) => todo!(),
|
|
|
|
None => todo!(),
|
|
|
|
}
|
|
|
|
}
|
2023-08-25 21:52:28 +02:00
|
|
|
|
|
|
|
async fn ping() -> impl IntoResponse {
|
|
|
|
"pong!"
|
|
|
|
}
|