export get_edge
This commit is contained in:
parent
8a450fba3f
commit
2052dec944
@ -8,6 +8,7 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
|
pub use network::get_edge;
|
||||||
use network::{async_main, init_edge, NodeConfig};
|
use network::{async_main, init_edge, NodeConfig};
|
||||||
use tokio::sync::mpsc::Receiver;
|
use tokio::sync::mpsc::Receiver;
|
||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
@ -20,9 +21,14 @@ use sdlan_sn_rs::{
|
|||||||
utils::{create_or_load_uuid, get_sdlan_sock_from_socketaddr, Result, SDLanError},
|
utils::{create_or_load_uuid, get_sdlan_sock_from_socketaddr, Result, SDLanError},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub async fn run_sdlan(args: CommandLine, start_stop_chan: Receiver<String>) -> Result<()> {
|
pub async fn run_sdlan(
|
||||||
|
args: CommandLine,
|
||||||
|
// start_stop_sender: Sender<String>,
|
||||||
|
// start_stop_receiver: Receiver<String>,
|
||||||
|
) -> Result<()> {
|
||||||
let _guard = log::init_log();
|
let _guard = log::init_log();
|
||||||
|
|
||||||
|
let (start_stop_sender, start_stop_chan) = channel(20);
|
||||||
let edge_uuid = create_or_load_uuid("")?;
|
let edge_uuid = create_or_load_uuid("")?;
|
||||||
let node_conf = parse_config(edge_uuid, &args).await?;
|
let node_conf = parse_config(edge_uuid, &args).await?;
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ use sdlan_sn_rs::config::{AF_INET, AF_INET6};
|
|||||||
use std::sync::atomic::{AtomicBool, AtomicU32, AtomicU64, AtomicU8, Ordering};
|
use std::sync::atomic::{AtomicBool, AtomicU32, AtomicU64, AtomicU8, Ordering};
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use tokio::io::AsyncReadExt;
|
use tokio::io::AsyncReadExt;
|
||||||
|
use tokio::sync::mpsc::Sender;
|
||||||
|
|
||||||
use crate::pb::{encode_to_tcp_message, SdlEmpty};
|
use crate::pb::{encode_to_tcp_message, SdlEmpty};
|
||||||
use crate::tcp::{get_tcp_conn, PacketType};
|
use crate::tcp::{get_tcp_conn, PacketType};
|
||||||
@ -22,7 +23,12 @@ use sdlan_sn_rs::utils::{Result, SDLanError};
|
|||||||
|
|
||||||
static EDGE: OnceCell<Node> = OnceCell::new();
|
static EDGE: OnceCell<Node> = OnceCell::new();
|
||||||
|
|
||||||
pub async fn init_edge(token: &str, node_conf: NodeConfig, tos: u32) -> Result<()> {
|
pub async fn init_edge(
|
||||||
|
token: &str,
|
||||||
|
node_conf: NodeConfig,
|
||||||
|
tos: u32,
|
||||||
|
start_stop: Sender<String>,
|
||||||
|
) -> Result<()> {
|
||||||
if token.len() == 0 {
|
if token.len() == 0 {
|
||||||
println!("failed to load token");
|
println!("failed to load token");
|
||||||
return Err(SDLanError::NormalError("no token is specified"));
|
return Err(SDLanError::NormalError("no token is specified"));
|
||||||
@ -58,6 +64,7 @@ pub async fn init_edge(token: &str, node_conf: NodeConfig, tos: u32) -> Result<(
|
|||||||
token,
|
token,
|
||||||
privatekey,
|
privatekey,
|
||||||
tcp_pong.clone(),
|
tcp_pong.clone(),
|
||||||
|
start_stop,
|
||||||
);
|
);
|
||||||
do_init_edge(edge)?;
|
do_init_edge(edge)?;
|
||||||
|
|
||||||
@ -86,6 +93,8 @@ pub struct Node {
|
|||||||
|
|
||||||
pub tcp_pong: Arc<AtomicU64>,
|
pub tcp_pong: Arc<AtomicU64>,
|
||||||
|
|
||||||
|
start_stop_sender: Sender<String>,
|
||||||
|
|
||||||
// user token info
|
// user token info
|
||||||
pub _token: String,
|
pub _token: String,
|
||||||
|
|
||||||
@ -125,6 +134,14 @@ pub struct Node {
|
|||||||
unsafe impl Sync for Node {}
|
unsafe impl Sync for Node {}
|
||||||
|
|
||||||
impl Node {
|
impl Node {
|
||||||
|
pub async fn start(&self, token: String) {
|
||||||
|
self.start_stop_sender.send(token).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn stop(&self) {
|
||||||
|
self.start_stop_sender.send("".to_owned()).await;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new(
|
pub fn new(
|
||||||
pubkey: String,
|
pubkey: String,
|
||||||
config: NodeConfig,
|
config: NodeConfig,
|
||||||
@ -133,12 +150,15 @@ impl Node {
|
|||||||
token: &str,
|
token: &str,
|
||||||
private: RsaPrivateKey,
|
private: RsaPrivateKey,
|
||||||
tcp_pong: Arc<AtomicU64>,
|
tcp_pong: Arc<AtomicU64>,
|
||||||
|
start_stop: Sender<String>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
packet_id: AtomicU32::new(1),
|
packet_id: AtomicU32::new(1),
|
||||||
network_id: AtomicU32::new(0),
|
network_id: AtomicU32::new(0),
|
||||||
_token: token.to_owned(),
|
_token: token.to_owned(),
|
||||||
|
|
||||||
|
start_stop_sender: start_stop,
|
||||||
|
|
||||||
tcp_pong,
|
tcp_pong,
|
||||||
|
|
||||||
device_config: DeviceConfig::new(),
|
device_config: DeviceConfig::new(),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user