;loud_sound: report all incoming connections over WebHook, for now
parent
33fe10ee27
commit
93be903b86
|
@ -147,6 +147,20 @@ pub async fn main (opt: Opt) -> anyhow::Result <()>
|
|||
});
|
||||
}
|
||||
|
||||
{
|
||||
let config = relay_state.config.load ();
|
||||
dbg! (&config.webhook_url);
|
||||
if let Some (webhook_url) = config.webhook_url.clone () {
|
||||
let j = json! ({
|
||||
"text": "Booting up",
|
||||
}).to_string ();
|
||||
let http_client = relay_state.http_client.clone ();
|
||||
tokio::spawn (async move {
|
||||
http_client.post (webhook_url).body (j).send ().await
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
tokio::select! {
|
||||
_val = task_quic_server => {
|
||||
eprintln! ("QUIC relay server exited, exiting");
|
||||
|
@ -186,17 +200,20 @@ struct RelayState {
|
|||
p4_server_proxies: Mutex <HashMap <PeerId, P4State>>,
|
||||
direc_cookies: Mutex <HashMap <Vec <u8>, DirecState>>,
|
||||
stats: Stats,
|
||||
http_client: reqwest::Client,
|
||||
}
|
||||
|
||||
#[derive (Default)]
|
||||
struct Config {
|
||||
ip_nicknames: BTreeMap <[u8; 4], String>,
|
||||
webhook_url: Option <String>,
|
||||
}
|
||||
|
||||
impl From <ConfigFile> for Config {
|
||||
fn from (x: ConfigFile) -> Self {
|
||||
Self {
|
||||
ip_nicknames: x.ip_nicknames.into_iter ().collect (),
|
||||
webhook_url: x.webhook_url,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -204,6 +221,7 @@ impl From <ConfigFile> for Config {
|
|||
#[derive (Deserialize)]
|
||||
struct ConfigFile {
|
||||
ip_nicknames: Vec <([u8; 4], String)>,
|
||||
webhook_url: Option <String>,
|
||||
}
|
||||
|
||||
struct DirecState {
|
||||
|
@ -351,6 +369,16 @@ async fn handle_quic_connection (
|
|||
|
||||
debug! ("EHG7NVUD Incoming QUIC connection {} from {:?} ({})", id, remote_addr, ip_nickname);
|
||||
|
||||
if let Some (webhook_url) = config.webhook_url.clone () {
|
||||
let j = json! ({
|
||||
"text": format! ("Incoming QUIC connection from {:?} ({})", remote_addr, ip_nickname),
|
||||
}).to_string ();
|
||||
let http_client = relay_state.http_client.clone ();
|
||||
tokio::spawn (async move {
|
||||
http_client.post (webhook_url).body (j).send ().await
|
||||
});
|
||||
}
|
||||
|
||||
let conn = conn.await?;
|
||||
|
||||
// Everyone who connects must identify themselves with the first
|
||||
|
|
|
@ -47,6 +47,7 @@ pub use rand::{
|
|||
};
|
||||
pub use rusty_ulid::Ulid;
|
||||
pub use serde::Deserialize;
|
||||
pub use serde_json::json;
|
||||
pub use tracing::{
|
||||
debug,
|
||||
error,
|
||||
|
|
Loading…
Reference in New Issue