Initial MeshPort SDK and cross-platform client
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
//! Isolated USB/adb-reverse fixture, not a production relay or user network.
|
||||
use easytier::instance::factory::create_native_instance;
|
||||
use easytier_core::config::toml::{ConfigLoader, TomlConfig};
|
||||
use easytier_core::instance::CoreInstanceConfig;
|
||||
use tokio::{
|
||||
io::{AsyncReadExt, AsyncWriteExt},
|
||||
net::{TcpListener, UdpSocket},
|
||||
};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let config = TomlConfig::new_from_str(
|
||||
"ipv4 = '10.253.83.2/24'\nlisteners = ['tcp://127.0.0.1:18080']\nstun_servers = []\nstun_servers_v6 = []\n[[proxy_network]]\ncidr = '127.0.0.0/24'\nmapped_cidr = '10.253.79.0/24'\n[network_identity]\nnetwork_name = 'android-validation'\nnetwork_secret = 'test-only'\n[flags]\nno_tun = true\nuse_smoltcp = true",
|
||||
)?;
|
||||
let server = create_native_instance(config.clone())?;
|
||||
server.start().await?;
|
||||
let tcp = TcpListener::bind("127.0.0.1:17007").await?;
|
||||
let udp = UdpSocket::bind("127.0.0.1:17007").await?;
|
||||
let control = TcpListener::bind("127.0.0.1:18081").await?;
|
||||
tokio::spawn(async move {
|
||||
while let Ok((mut stream, _)) = tcp.accept().await {
|
||||
tokio::spawn(async move {
|
||||
let mut buffer = [0; 4096];
|
||||
while let Ok(n) = stream.read(&mut buffer).await {
|
||||
if n == 0 || stream.write_all(&buffer[..n]).await.is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
tokio::spawn(async move {
|
||||
let mut buffer = [0; 4096];
|
||||
while let Ok((n, peer)) = udp.recv_from(&mut buffer).await {
|
||||
let _ = udp.send_to(&buffer[..n], peer).await;
|
||||
}
|
||||
});
|
||||
let gateway = server.clone();
|
||||
tokio::spawn(async move {
|
||||
while let Ok((mut stream, _)) = control.accept().await {
|
||||
let mut buffer = [0; 32];
|
||||
if stream.read(&mut buffer).await.is_ok() {
|
||||
config.clear_proxy_cidrs();
|
||||
let updated = CoreInstanceConfig::from_toml(&config).unwrap();
|
||||
gateway
|
||||
.update_runtime_config(
|
||||
easytier_core::config::runtime::CoreInstanceRuntimeConfig {
|
||||
services: updated.connectivity.runtime,
|
||||
peer: std::sync::Arc::new(updated.peer.snapshot),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let _ = stream.write_all(b"withdrawn\n").await;
|
||||
}
|
||||
}
|
||||
});
|
||||
println!("Android validation fixture ready on localhost:18080; echo subnet 10.253.79.0/24");
|
||||
tokio::signal::ctrl_c().await?;
|
||||
server.stop().await;
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user