added commandline parse, use structopt
This commit is contained in:
parent
cb251fba8a
commit
209b870942
@ -19,6 +19,7 @@ rsa = "0.9.6"
|
|||||||
serde = { version = "1.0.196", features = ["derive"] }
|
serde = { version = "1.0.196", features = ["derive"] }
|
||||||
serde_json = "1.0.113"
|
serde_json = "1.0.113"
|
||||||
serde_repr = "0.1.18"
|
serde_repr = "0.1.18"
|
||||||
|
structopt = "0.3.26"
|
||||||
tokio = { version = "1.36.0", features = ["full"] }
|
tokio = { version = "1.36.0", features = ["full"] }
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
tracing-appender = "0.2.3"
|
tracing-appender = "0.2.3"
|
||||||
|
|||||||
@ -3,11 +3,14 @@ use sdlan_sn_rs::packet;
|
|||||||
use sdlan_sn_rs::utils::Result;
|
use sdlan_sn_rs::utils::Result;
|
||||||
use tracing::{debug, error};
|
use tracing::{debug, error};
|
||||||
|
|
||||||
|
use std::net::Ipv4Addr;
|
||||||
//use std::io::Read;
|
//use std::io::Read;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::net::UdpSocket;
|
use tokio::net::UdpSocket;
|
||||||
|
|
||||||
|
use structopt::StructOpt;
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
@ -36,16 +39,24 @@ async fn client(address: &str) -> Result<()> {
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
|
// init log
|
||||||
let _guard = log::init_log();
|
let _guard = log::init_log();
|
||||||
debug!("main starts here");
|
debug!("main starts here");
|
||||||
|
|
||||||
// check license
|
// check license
|
||||||
license_ok()?;
|
license_ok()?;
|
||||||
|
|
||||||
let listener = UdpSocket::bind(SERVER).await?;
|
// parse command line argument
|
||||||
|
let args = utils::CommandLine::from_args();
|
||||||
|
debug!("args: {:?}", args);
|
||||||
|
// check the argument
|
||||||
|
let _: Ipv4Addr = args.address.parse().expect("invalid address found");
|
||||||
|
|
||||||
|
let server = format!("{}:{}", args.address, args.port);
|
||||||
|
let listener = UdpSocket::bind(server).await?;
|
||||||
|
|
||||||
let supernode = utils::SuperNode::new(listener);
|
let supernode = utils::SuperNode::new(listener);
|
||||||
utils::init_supernode(supernode);
|
utils::init_supernode(supernode).expect("failed to init supernode");
|
||||||
|
|
||||||
tokio::spawn(async {
|
tokio::spawn(async {
|
||||||
client(SERVER).await.unwrap();
|
client(SERVER).await.unwrap();
|
||||||
|
|||||||
@ -3,3 +3,6 @@ pub use sn::*;
|
|||||||
|
|
||||||
mod license;
|
mod license;
|
||||||
pub use license::*;
|
pub use license::*;
|
||||||
|
|
||||||
|
mod params;
|
||||||
|
pub use params::*;
|
||||||
|
|||||||
12
src/bin/sdlan-sn/utils/params.rs
Normal file
12
src/bin/sdlan-sn/utils/params.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
use structopt::StructOpt;
|
||||||
|
|
||||||
|
#[derive(StructOpt, Debug)]
|
||||||
|
pub struct CommandLine {
|
||||||
|
/// fedration, other sn
|
||||||
|
#[structopt(short = "f", long = "fedration", default_value = "")]
|
||||||
|
pub fedration: String,
|
||||||
|
#[structopt(short = "p", long = "port", default_value = "7655")]
|
||||||
|
pub port: u16,
|
||||||
|
#[structopt(short = "a", long = "addr", default_value = "0.0.0.0")]
|
||||||
|
pub address: String,
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user