2026-04-26 13:48:26 +02:00
|
|
|
use proxy_common::{ProxyStartupParam, RNEX_ACCESS_KEY};
|
2026-07-14 17:27:30 +02:00
|
|
|
use prudpv1::prudp::{router::Router, secure::Secure};
|
2026-07-14 16:27:50 +02:00
|
|
|
use rnex_prudp::virtual_port::VirtualPort;
|
|
|
|
|
use rnex_server::ConnectionInitData;
|
2026-07-14 17:27:30 +02:00
|
|
|
use rnex_server::rmc::serialization::RmcSerialize;
|
|
|
|
|
use rnex_util::account::Account;
|
2026-07-14 16:27:50 +02:00
|
|
|
use rnex_util::{UnitPacketRead, UnitPacketWrite};
|
2026-06-17 17:33:09 +02:00
|
|
|
use std::ops::Deref;
|
2025-06-29 11:40:42 +02:00
|
|
|
use std::time::Duration;
|
2025-10-07 20:39:52 +02:00
|
|
|
use tokio::net::TcpStream;
|
2025-06-13 12:36:28 +02:00
|
|
|
use tokio::task;
|
2025-06-29 11:40:42 +02:00
|
|
|
use tokio::time::sleep;
|
2026-07-14 17:27:30 +02:00
|
|
|
use tracing::error;
|
2025-06-29 12:01:31 +02:00
|
|
|
|
2026-04-26 13:48:26 +02:00
|
|
|
pub async fn start(param: ProxyStartupParam) {
|
|
|
|
|
let (router_secure, _) = Router::new(param.self_private)
|
2025-06-13 12:36:28 +02:00
|
|
|
.await
|
|
|
|
|
.expect("unable to start router");
|
|
|
|
|
|
|
|
|
|
let mut socket_secure = router_secure
|
2026-01-31 13:48:06 +01:00
|
|
|
.add_socket(
|
|
|
|
|
VirtualPort::new(1, 10),
|
2026-07-14 17:27:30 +02:00
|
|
|
Secure(
|
|
|
|
|
RNEX_ACCESS_KEY,
|
|
|
|
|
Account::from_nexact(2, "Quazal Rendez-Vous")
|
|
|
|
|
.await
|
|
|
|
|
.expect("failed to get account"),
|
|
|
|
|
),
|
2026-01-31 13:48:06 +01:00
|
|
|
)
|
2025-06-13 12:36:28 +02:00
|
|
|
.await
|
|
|
|
|
.expect("unable to add socket");
|
|
|
|
|
|
|
|
|
|
loop {
|
|
|
|
|
let Some(mut conn) = socket_secure.accept().await else {
|
|
|
|
|
error!("server crashed");
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
task::spawn(async move {
|
2026-07-14 17:27:30 +02:00
|
|
|
// todo: add support for checking this to nex-account
|
|
|
|
|
/*
|
2026-04-26 19:08:08 +02:00
|
|
|
let Ok(mut c) = rnex_core::grpc::account::Client::new().await else {
|
|
|
|
|
error!("failed to initialize gql client");
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let v = match c.get_user_level(conn.user_id).await {
|
|
|
|
|
Ok(v) => v,
|
|
|
|
|
Err(e) => {
|
|
|
|
|
error!("failed to get user level: {}", e);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if v < 0 {
|
|
|
|
|
warn!("person with too low account level joined");
|
|
|
|
|
return;
|
2026-07-14 17:27:30 +02:00
|
|
|
} */
|
2026-04-26 19:08:08 +02:00
|
|
|
|
2026-04-26 13:48:26 +02:00
|
|
|
let mut stream = match TcpStream::connect(param.forward_destination).await {
|
2025-06-30 10:53:10 +02:00
|
|
|
Ok(v) => v,
|
|
|
|
|
Err(e) => {
|
|
|
|
|
error!("unable to connect: {}", e);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-06-30 10:47:48 +02:00
|
|
|
};
|
2025-06-13 12:36:28 +02:00
|
|
|
|
2026-01-31 13:48:06 +01:00
|
|
|
if let Err(e) = stream
|
|
|
|
|
.send_buffer(
|
|
|
|
|
&ConnectionInitData {
|
2026-07-14 17:27:30 +02:00
|
|
|
addr: conn.socket_addr.regular_socket_addr,
|
2026-01-31 13:48:06 +01:00
|
|
|
pid: conn.user_id,
|
|
|
|
|
}
|
|
|
|
|
.to_data()
|
|
|
|
|
.unwrap(),
|
|
|
|
|
)
|
|
|
|
|
.await
|
|
|
|
|
{
|
2025-06-13 12:36:28 +02:00
|
|
|
error!("error connecting to backend: {}", e);
|
|
|
|
|
return;
|
|
|
|
|
};
|
2025-06-13 10:05:38 +02:00
|
|
|
|
2026-05-10 00:21:12 +02:00
|
|
|
'a: loop {
|
2025-06-13 12:36:28 +02:00
|
|
|
tokio::select! {
|
|
|
|
|
data = conn.recv() => {
|
|
|
|
|
let Some(data) = data else {
|
2026-05-10 00:21:12 +02:00
|
|
|
break 'a;
|
2025-06-13 12:36:28 +02:00
|
|
|
};
|
2025-06-13 10:05:38 +02:00
|
|
|
|
2025-06-13 12:36:28 +02:00
|
|
|
if let Err(e) = stream.send_buffer(&data[..]).await{
|
|
|
|
|
error!("error sending data to backend: {}", e);
|
2026-05-10 00:21:12 +02:00
|
|
|
break 'a;
|
2025-06-13 12:36:28 +02:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
data = stream.read_buffer() => {
|
|
|
|
|
let data = match data{
|
|
|
|
|
Ok(d) => d,
|
|
|
|
|
Err(e) => {
|
|
|
|
|
error!("error reveiving data from backend: {}", e);
|
2026-05-10 00:21:12 +02:00
|
|
|
break 'a;
|
2025-06-13 12:36:28 +02:00
|
|
|
}
|
|
|
|
|
};
|
2026-01-31 13:48:06 +01:00
|
|
|
|
2025-06-13 12:36:28 +02:00
|
|
|
if conn.send(data).await == None{
|
2026-05-10 00:21:12 +02:00
|
|
|
break 'a;
|
2025-06-13 12:36:28 +02:00
|
|
|
}
|
|
|
|
|
},
|
2025-06-29 11:40:42 +02:00
|
|
|
_ = sleep(Duration::from_secs(10)) => {
|
|
|
|
|
conn.send([0,0,0,0,0].to_vec()).await;
|
|
|
|
|
}
|
2025-06-13 12:36:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
2026-06-17 17:33:09 +02:00
|
|
|
conn.deref().close_connection().await;
|
2025-06-13 12:36:28 +02:00
|
|
|
});
|
|
|
|
|
}
|
2026-01-31 13:48:06 +01:00
|
|
|
}
|