export get_edge
This commit is contained in:
parent
8a450fba3f
commit
2052dec944
@ -8,6 +8,7 @@ use std::time::Duration;
|
||||
|
||||
use std::net::SocketAddr;
|
||||
|
||||
pub use network::get_edge;
|
||||
use network::{async_main, init_edge, NodeConfig};
|
||||
use tokio::sync::mpsc::Receiver;
|
||||
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},
|
||||
};
|
||||
|
||||
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 (start_stop_sender, start_stop_chan) = channel(20);
|
||||
let edge_uuid = create_or_load_uuid("")?;
|
||||
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::{Arc, RwLock};
|
||||
use tokio::io::AsyncReadExt;
|
||||
use tokio::sync::mpsc::Sender;
|
||||
|
||||
use crate::pb::{encode_to_tcp_message, SdlEmpty};
|
||||
use crate::tcp::{get_tcp_conn, PacketType};
|
||||
@ -22,7 +23,12 @@ use sdlan_sn_rs::utils::{Result, SDLanError};
|
||||
|
||||
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 {
|
||||
println!("failed to load token");
|
||||
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,
|
||||
privatekey,
|
||||
tcp_pong.clone(),
|
||||
start_stop,
|
||||
);
|
||||
do_init_edge(edge)?;
|
||||
|
||||
@ -86,6 +93,8 @@ pub struct Node {
|
||||
|
||||
pub tcp_pong: Arc<AtomicU64>,
|
||||
|
||||
start_stop_sender: Sender<String>,
|
||||
|
||||
// user token info
|
||||
pub _token: String,
|
||||
|
||||
@ -125,6 +134,14 @@ pub struct Node {
|
||||
unsafe impl Sync for 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(
|
||||
pubkey: String,
|
||||
config: NodeConfig,
|
||||
@ -133,12 +150,15 @@ impl Node {
|
||||
token: &str,
|
||||
private: RsaPrivateKey,
|
||||
tcp_pong: Arc<AtomicU64>,
|
||||
start_stop: Sender<String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
packet_id: AtomicU32::new(1),
|
||||
network_id: AtomicU32::new(0),
|
||||
_token: token.to_owned(),
|
||||
|
||||
start_stop_sender: start_stop,
|
||||
|
||||
tcp_pong,
|
||||
|
||||
device_config: DeviceConfig::new(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user