Compare commits

..

No commits in common. "b5227a988713832618cd6fb6a04e609428a0659e" and "9d0a5289ea4f6d60fdfdd844d244ab485f65ff1d" have entirely different histories.

9 changed files with 18 additions and 51 deletions

View File

@ -1,4 +1,4 @@
{
"rust-analyzer.cargo.target": "x86_64-pc-windows-gnu",
// "rust-analyzer.cargo.target": "x86_64-pc-windows-gnu",
// "rust-analyzer.cargo.features": ["tun"]
}

2
Cargo.lock generated
View File

@ -2244,7 +2244,7 @@ dependencies = [
[[package]]
name = "punchnet"
version = "1.2.1"
version = "1.0.5"
dependencies = [
"ahash",
"arc-swap",

View File

@ -1,6 +1,6 @@
[package]
name = "punchnet"
version = "1.2.1"
version = "1.0.5"
edition = "2021"
[dependencies]

View File

@ -5,7 +5,7 @@ use sdlan_sn_rs::utils::{Mac, Result, SDLanError};
use serde::{Deserialize, Serialize};
use md5::Md5;
pub const TEST_PREFIX: &'static str = "https://root.punchsky.com/api";
pub const TEST_PREFIX: &'static str = "https://punchnet.s5s8.com/api";
const DIGEST_KEY: &'static str = "H6p*2RfEu4ITcL";
type HmacMd5 = Hmac<Md5>;
@ -125,25 +125,19 @@ where T: Serialize + HMacCalculator,
return Err(SDLanError::IOError("failed to calculate hmac".to_owned()));
};
let response = match client
let Ok(response) = client
.post(url)
.header("X-sign", hmac)
.json(&data)
.send()
.await {
Ok(response) => {
response
}
Err(e) => {
return Err(SDLanError::IOError(format!("failed to do request: {}", e)));
}
.await else {
return Err(SDLanError::IOError("failed to do request".to_owned()));
};
// println!("status: {}", response.status());
let text = response.text().await.unwrap();
// println!("got test: {}", text);
println!("got test: {}", text);
let data = serde_json::from_str(&text).unwrap();
// println!("response: {}", response.text().await.unwrap());

View File

@ -64,7 +64,7 @@ const APP_TOKEN_ENV_NAME: &str = "PUNCH_TOKEN";
fn parse_connect_result(res: Result<ConnectResponse>) -> ConnectData {
match res {
Err(e) => {
eprintln!("failed to connect: {}", e.as_str());
eprintln!("failed to connect");
process::exit(-3);
}
Ok(data) => {
@ -123,7 +123,6 @@ async fn daemonize_me(
route_file: String,
route_str: String,
mac: Mac,
take_over_dns: bool,
) {
let _guard = log::init_log(&format!("{}/.output", get_base_dir()));
@ -185,7 +184,6 @@ async fn daemonize_me(
allow_p2p: true,
route_file,
route_str,
take_dns: take_over_dns,
},
tx,
&punchnet::get_install_channel(),
@ -264,7 +262,7 @@ async fn daemonize_me(
edge.quic_endpoint.close(0u32.into(), "bye".as_bytes());
println!("quic is quitting");
delete_pid_file();
let _ = restore_dns(edge.take_over_dns);
let _ = restore_dns();
debug!("restored dns");
}
Err(err) => {
@ -332,7 +330,6 @@ fn main() {
)
.await,
);
println!("login ok");
});
process::exit(0);
// TODO: do login with user
@ -344,7 +341,6 @@ fn main() {
login_with_token(TEST_PREFIX, &client_id, &tk.token, mac, system, version)
.await,
);
println!("login ok");
});
process::exit(0);
}
@ -497,7 +493,6 @@ fn run_it(
rtinfo.route_file.clone(),
rtinfo.route.clone(),
mac,
rtinfo.take_dns,
)
.await;
}),
@ -534,7 +529,6 @@ fn run_it(
tk.route_file.clone(),
tk.route.clone(),
mac,
tk.take_dns,
)
.await;
}),

View File

@ -127,7 +127,6 @@ pub async fn init_edge(
udp_sock_for_global_dns,
server_ip,
install_channel,
args.take_dns,
);
edge.route_table
@ -259,8 +258,6 @@ pub struct Node {
// store pending, and known peers
pub pending_peers: PeerMap,
pub take_over_dns: bool,
#[cfg(any(feature = "tun", target_os = "windows"))]
pub arp_table: ArpTable,
@ -441,7 +438,6 @@ impl Node {
udp_sock_for_global_dns: Arc<UdpSocket>,
server_ip: String,
install_channel: String,
take_over_dns: bool,
) -> Self {
let mode = if cfg!(not(feature = "tun")) {
Mode::Tap
@ -521,7 +517,6 @@ impl Node {
cookie_match: Queryer::new(),
server_ip,
install_channel,
take_over_dns,
}
}

View File

@ -196,7 +196,7 @@ impl Iface {
}
// TODO: set dns should be opened
if let Err(e) = set_dns(self, node.take_over_dns, &self.name, network_domain, &ip_to_string(&default_gw)) {
if let Err(e) = set_dns(self, &self.name, network_domain, &ip_to_string(&default_gw)) {
error!("failed to set dns: {}", e.as_str());
}
} else {
@ -223,7 +223,7 @@ impl Iface {
}
}
if let Err(e) = set_dns(self, node.take_over_dns, &self.name, network_domain, &ip_to_string(&default_gw)) {
if let Err(e) = set_dns(self, &self.name, network_domain, &ip_to_string(&default_gw)) {
error!("failed to set dns: {}", e.as_str());
}
}
@ -922,23 +922,21 @@ fn add_resolvectl(name: &str, network_domain: &str) -> Result<()> {
Ok(())
}
fn set_dns(iface: &Iface, take_over_dns: bool, name: &str, network_domain: &str, gw: &str) -> Result<()> {
fn set_dns(iface: &Iface, name: &str, network_domain: &str, gw: &str) -> Result<()> {
error!("network_domain = {}", network_domain);
if iface.has_resolvectl {
add_resolvectl(name, network_domain)?;
} else {
if take_over_dns {
backup_resolv_conf()?;
modify_resolv_conf(&vec!["100.100.100.100".to_owned()], network_domain, true)?;
}
backup_resolv_conf()?;
modify_resolv_conf(&vec!["100.100.100.100".to_owned()], network_domain, true)?;
}
add_dns_route(name)?;
Ok(())
}
pub fn restore_dns(take_over_dns: bool) -> Result<()> {
pub fn restore_dns() -> Result<()> {
let eee = get_edge();
if !eee.device.has_resolvectl && take_over_dns{
if !eee.device.has_resolvectl {
// should restore /etc/resolv.conf
restore_resolv_conf()?;
}

View File

@ -796,7 +796,7 @@ pub fn set_dns(name: &str, _network_domain: &str, gw: &str, ifidx: u32) -> Resul
Ok(())
}
pub fn restore_dns(take_over_dns: bool) {}
pub fn restore_dns() {}
pub fn del_route(net: &Ipv4Net, gw: &Ipv4Addr) -> Result<()> {
error!("deleting route: {} gw {}", net, gw);

View File

@ -63,10 +63,6 @@ pub struct StartArguments {
#[arg(short, long, default_value_t=false)]
pub allow_routing: bool,
// take over dns or not if change /etc/resolv.conf
#[arg(long)]
pub take_dns: bool,
}
#[derive(Args, Debug)]
@ -106,10 +102,6 @@ pub struct AutoRunArgument {
#[arg(short, long, default_value="")]
pub route_file: String,
// take over dns or not if change /etc/resolv.conf
#[arg(long)]
pub take_dns: bool,
}
#[derive(Args, Debug)]
@ -194,11 +186,6 @@ pub struct CommandLine {
#[structopt(long, default_value="")]
pub route_file: String,
// take over dns or not
#[structopt(long)]
pub take_dns: bool,
}
impl Clone for CommandLine {
@ -221,7 +208,6 @@ impl Clone for CommandLine {
nat_server2: self.nat_server2.clone(),
route_str: self.route_str.clone(),
route_file: self.route_file.clone(),
take_dns: self.take_dns,
}
}
}