client id and mac are passed as values
This commit is contained in:
parent
8645b65534
commit
8902c27b1d
@ -72,6 +72,8 @@ async fn main() {
|
||||
println!("hostname = {:?}", hostname);
|
||||
|
||||
let _ = run_sdlan(
|
||||
client_id,
|
||||
mac,
|
||||
CommandLine {
|
||||
sn: server.clone()+":1265",
|
||||
tcp: server.clone()+":18083",
|
||||
@ -85,7 +87,7 @@ async fn main() {
|
||||
tos: 0,
|
||||
local_port: cmd.port,
|
||||
token: cmd.token.clone(),
|
||||
network_code: cmd.network_code.clone(),
|
||||
// network_code: cmd.network_code.clone(),
|
||||
allow_p2p: true,
|
||||
},
|
||||
tx,
|
||||
|
||||
12
src/lib.rs
12
src/lib.rs
@ -13,7 +13,7 @@ use std::net::{SocketAddr, ToSocketAddrs};
|
||||
pub use network::get_edge;
|
||||
pub use network::get_install_channel;
|
||||
pub use network::{async_main, init_arp, init_edge, NodeConfig, restore_dns};
|
||||
use sdlan_sn_rs::utils::save_to_file;
|
||||
use sdlan_sn_rs::utils::{Mac, save_to_file};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::net::UdpSocket;
|
||||
use tokio::sync::mpsc::{channel, Sender};
|
||||
@ -44,6 +44,9 @@ pub enum ConnectionState {
|
||||
}
|
||||
|
||||
pub async fn run_sdlan(
|
||||
edge_uuid: String,
|
||||
mac: Mac,
|
||||
|
||||
args: CommandLine,
|
||||
sender: std::sync::mpsc::Sender<bool>,
|
||||
install_channel: &str,
|
||||
@ -55,7 +58,7 @@ pub async fn run_sdlan(
|
||||
// start_stop_receiver: Receiver<String>,
|
||||
) -> Result<()> {
|
||||
let (start_stop_sender, start_stop_chan) = channel(20);
|
||||
let edge_uuid = create_or_load_uuid(&format!("{}/.id", get_base_dir()), None)?;
|
||||
// let edge_uuid = create_or_load_uuid(&format!("{}/.id", get_base_dir()), None)?;
|
||||
let node_conf = parse_config(edge_uuid, &args).await?;
|
||||
|
||||
let hostfile = format!("{}/.host", get_base_dir());
|
||||
@ -69,8 +72,9 @@ pub async fn run_sdlan(
|
||||
let sock = Arc::new(UdpSocket::bind("0.0.0.0:0").await?);
|
||||
|
||||
if let Err(e) = init_edge(
|
||||
&args.token,
|
||||
&args.network_code,
|
||||
// &args.token,
|
||||
// &args.network_code,
|
||||
mac,
|
||||
node_conf,
|
||||
args.tos,
|
||||
start_stop_sender,
|
||||
|
||||
@ -8,21 +8,21 @@ use crate::utils::generate_mac_address;
|
||||
|
||||
pub struct DeviceConfig {
|
||||
pub mtu: u32,
|
||||
pub mac: RwLock<Mac>,
|
||||
pub mac: Mac,
|
||||
pub ip: IpSubnet,
|
||||
|
||||
pub dns_mac: Mac,
|
||||
}
|
||||
|
||||
impl DeviceConfig {
|
||||
pub fn new(mtu: u32) -> Self {
|
||||
let mac = generate_mac_address();
|
||||
pub fn new(mac: Mac, mtu: u32) -> Self {
|
||||
// let mac = generate_mac_address();
|
||||
let dns_mac = generate_mac_address();
|
||||
println!("self mac: {}", mac_to_string(&mac));
|
||||
debug!("self mac: {}", mac_to_string(&mac));
|
||||
DeviceConfig {
|
||||
mtu,
|
||||
mac: RwLock::new(mac),
|
||||
mac: mac,
|
||||
ip: IpSubnet::new(0, 0),
|
||||
dns_mac,
|
||||
}
|
||||
@ -47,7 +47,7 @@ impl DeviceConfig {
|
||||
}
|
||||
|
||||
pub fn get_mac(&self) -> Mac {
|
||||
let mac = *self.mac.read().unwrap();
|
||||
let mac = self.mac;
|
||||
mac
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,8 +34,9 @@ use sdlan_sn_rs::utils::{Result, SDLanError};
|
||||
static EDGE: OnceCell<Node> = OnceCell::new();
|
||||
|
||||
pub async fn init_edge(
|
||||
token: &str,
|
||||
network_code: &str,
|
||||
// token: &str,
|
||||
// network_code: &str,
|
||||
mac: Mac,
|
||||
node_conf: NodeConfig,
|
||||
tos: u32,
|
||||
start_stop: Sender<StartStopInfo>,
|
||||
@ -77,6 +78,7 @@ pub async fn init_edge(
|
||||
// let tcpsock = TCPSocket::build("121.4.79.234:1234").await?;
|
||||
let tcp_pong = Arc::new(AtomicU64::new(0));
|
||||
let edge = Node::new(
|
||||
mac,
|
||||
pubkey,
|
||||
node_conf,
|
||||
sock_v4,
|
||||
@ -266,7 +268,7 @@ impl Node {
|
||||
self.access_token.set(access_token);
|
||||
self.device_config.ip.net_addr.store(ip_net, Ordering::Relaxed);
|
||||
self.device_config.ip.net_bit_len.store(ip_net_bit_len, Ordering::Relaxed);
|
||||
*self.device_config.mac.write().unwrap() = create_or_load_mac();
|
||||
// *self.device_config.mac.write().unwrap() = create_or_load_mac();
|
||||
self.network_id.store(network_id, Ordering::Relaxed);
|
||||
self.network_domain.write().unwrap().clone_from(network_domain);
|
||||
// self.network_domain = network_domain;
|
||||
@ -309,7 +311,7 @@ impl Node {
|
||||
self.access_token.set(access_token);
|
||||
self.device_config.ip.net_addr.store(ip_net, Ordering::Relaxed);
|
||||
self.device_config.ip.net_bit_len.store(ip_net_bit_len, Ordering::Relaxed);
|
||||
*self.device_config.mac.write().unwrap() = create_or_load_mac();
|
||||
// *self.device_config.mac.write().unwrap() = create_or_load_mac();
|
||||
self.network_id.store(network_id, Ordering::Relaxed);
|
||||
self.network_domain.write().unwrap().clone_from(network_domain);
|
||||
|
||||
@ -356,6 +358,7 @@ impl Node {
|
||||
}
|
||||
|
||||
pub fn new(
|
||||
mac: Mac,
|
||||
pubkey: String,
|
||||
config: NodeConfig,
|
||||
sock: Socket,
|
||||
@ -404,7 +407,7 @@ impl Node {
|
||||
|
||||
nat_type: Mutex::new(NatType::Blocked),
|
||||
|
||||
device_config: DeviceConfig::new(mtu),
|
||||
device_config: DeviceConfig::new(mac, mtu),
|
||||
device: new_iface("dev", mode),
|
||||
|
||||
authorized: AtomicBool::new(false),
|
||||
|
||||
@ -92,8 +92,8 @@ pub struct CommandLine {
|
||||
#[structopt(long = "token", default_value = "")]
|
||||
pub token: String,
|
||||
|
||||
#[structopt(long = "code", default_value = "")]
|
||||
pub network_code: String,
|
||||
// #[structopt(long = "code", default_value = "")]
|
||||
// pub network_code: String,
|
||||
|
||||
#[structopt(short = "p")]
|
||||
pub allow_p2p: bool,
|
||||
@ -115,7 +115,7 @@ impl Clone for CommandLine {
|
||||
name: self.name.clone(),
|
||||
tos: self.tos,
|
||||
token: self.token.clone(),
|
||||
network_code: self.network_code.clone(),
|
||||
// network_code: self.network_code.clone(),
|
||||
allow_p2p: self.allow_p2p,
|
||||
nat_server1: self.nat_server1.clone(),
|
||||
nat_server2: self.nat_server2.clone(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user