2025-10-07 20:39:52 +02:00
|
|
|
use log::error;
|
2026-01-20 20:26:44 +01:00
|
|
|
use prudpv1::executables::common::{EDGE_NODE_HOLDER, FORWARD_DESTINATION};
|
2025-09-21 15:59:27 +02:00
|
|
|
use prudpv1::prudp::router::Router;
|
|
|
|
|
use prudpv1::prudp::unsecure::Unsecure;
|
|
|
|
|
use rnex_core::common::setup;
|
|
|
|
|
use rnex_core::executables::common::{OWN_IP_PRIVATE, OWN_IP_PUBLIC, SERVER_PORT};
|
|
|
|
|
use rnex_core::prudp::virtual_port::VirtualPort;
|
|
|
|
|
use rnex_core::reggie::EdgeNodeHolderConnectOption::Register;
|
|
|
|
|
use rnex_core::reggie::RemoteEdgeNodeHolder;
|
2026-01-20 20:26:44 +01:00
|
|
|
use rnex_core::reggie::UnitPacketRead;
|
|
|
|
|
use rnex_core::reggie::UnitPacketWrite;
|
|
|
|
|
use rnex_core::rmc::protocols::{OnlyRemote, new_rmc_gateway_connection};
|
|
|
|
|
use rnex_core::rmc::structures::RmcSerialize;
|
2025-09-21 15:59:27 +02:00
|
|
|
use rnex_core::rnex_proxy_common::ConnectionInitData;
|
|
|
|
|
use rnex_core::util::SplittableBufferConnection;
|
2026-01-20 20:26:44 +01:00
|
|
|
use std::net::SocketAddrV4;
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
use std::time::Duration;
|
|
|
|
|
use tokio::net::TcpStream;
|
|
|
|
|
use tokio::task;
|
|
|
|
|
use tokio::time::sleep;
|
2025-06-13 10:05:38 +02:00
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
|
async fn main() {
|
|
|
|
|
setup();
|
|
|
|
|
|
2026-01-20 20:26:44 +01:00
|
|
|
let conn = tokio::net::TcpStream::connect(&*EDGE_NODE_HOLDER)
|
|
|
|
|
.await
|
|
|
|
|
.unwrap();
|
2025-06-29 11:40:42 +02:00
|
|
|
|
2025-07-30 21:39:54 +02:00
|
|
|
let conn: SplittableBufferConnection = conn.into();
|
|
|
|
|
|
2026-01-20 20:26:44 +01:00
|
|
|
conn.send(
|
|
|
|
|
Register(SocketAddrV4::new(*OWN_IP_PUBLIC, *SERVER_PORT))
|
|
|
|
|
.to_data()
|
|
|
|
|
.unwrap(),
|
|
|
|
|
)
|
|
|
|
|
.await;
|
2025-07-30 21:39:54 +02:00
|
|
|
|
2026-01-20 20:26:44 +01:00
|
|
|
let conn = new_rmc_gateway_connection(conn, |r| {
|
|
|
|
|
Arc::new(OnlyRemote::<RemoteEdgeNodeHolder>::new(r))
|
|
|
|
|
});
|
2025-06-29 11:40:42 +02:00
|
|
|
|
2025-06-13 10:05:38 +02:00
|
|
|
let (router_secure, _) = Router::new(SocketAddrV4::new(*OWN_IP_PRIVATE, *SERVER_PORT))
|
|
|
|
|
.await
|
|
|
|
|
.expect("unable to start router");
|
|
|
|
|
|
|
|
|
|
let mut socket_secure = router_secure
|
2026-01-20 20:26:44 +01:00
|
|
|
.add_socket(VirtualPort::new(1, 10), Unsecure("6f599f81"))
|
2025-06-13 10:05:38 +02:00
|
|
|
.await
|
|
|
|
|
.expect("unable to add socket");
|
|
|
|
|
|
|
|
|
|
// let conn = socket_secure.connect(auth_sockaddr).await.unwrap();
|
|
|
|
|
|
|
|
|
|
loop {
|
|
|
|
|
let Some(mut conn) = socket_secure.accept().await else {
|
|
|
|
|
error!("server crashed");
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
task::spawn(async move {
|
2026-01-20 20:26:44 +01:00
|
|
|
let mut stream = match TcpStream::connect(*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 10:05:38 +02:00
|
|
|
|
2026-01-20 20:26:44 +01:00
|
|
|
if let Err(e) = stream
|
|
|
|
|
.send_buffer(
|
|
|
|
|
&ConnectionInitData {
|
|
|
|
|
prudpsock_addr: conn.socket_addr,
|
|
|
|
|
pid: conn.user_id,
|
|
|
|
|
}
|
|
|
|
|
.to_data()
|
|
|
|
|
.unwrap(),
|
|
|
|
|
)
|
|
|
|
|
.await
|
|
|
|
|
{
|
2025-06-13 10:05:38 +02:00
|
|
|
error!("error connecting to backend: {}", e);
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
loop {
|
|
|
|
|
tokio::select! {
|
|
|
|
|
data = conn.recv() => {
|
|
|
|
|
let Some(data) = data else {
|
2025-11-08 17:04:32 +00:00
|
|
|
return;
|
2025-06-13 10:05:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if let Err(e) = stream.send_buffer(&data[..]).await{
|
|
|
|
|
error!("error sending data to backend: {}", e);
|
2025-11-08 17:04:32 +00:00
|
|
|
return;
|
2025-06-13 10:05:38 +02:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
data = stream.read_buffer() => {
|
|
|
|
|
let data = match data{
|
|
|
|
|
Ok(d) => d,
|
|
|
|
|
Err(e) => {
|
|
|
|
|
error!("error reveiving data from backend: {}", e);
|
2025-11-08 17:04:32 +00:00
|
|
|
return;
|
2025-06-13 10:05:38 +02:00
|
|
|
}
|
|
|
|
|
};
|
2026-01-20 20:26:44 +01:00
|
|
|
|
2025-06-13 10:05:38 +02:00
|
|
|
if conn.send(data).await == None{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
},
|
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 10:05:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-10-07 20:39:52 +02:00
|
|
|
drop(conn);
|
2026-01-20 20:26:44 +01:00
|
|
|
}
|