Split logic in multiple files!
This commit is contained in:
parent
41caf6090c
commit
154546a7b4
3 changed files with 23 additions and 10 deletions
|
@ -1,18 +1,19 @@
|
|||
use igd::Gateway;
|
||||
use anyhow::{Result, Context};
|
||||
|
||||
use log::*;
|
||||
use crate::*;
|
||||
|
||||
pub struct DiplonatContext {
|
||||
pub config: config::DiplonatConfig,
|
||||
//pub gateway: igd::Gateway
|
||||
pub gateway: igd::aio::Gateway
|
||||
}
|
||||
|
||||
pub fn setup() -> Result<DiplonatContext> {
|
||||
return Ok(DiplonatContext {
|
||||
pub async fn setup() -> Result<DiplonatContext> {
|
||||
let ctx = DiplonatContext {
|
||||
config: config::load_env().context("Unable to read configuration from environment")?,
|
||||
//gateway: search_gateway(Default::default()).await
|
||||
});
|
||||
gateway: gw::get_gateway().await?
|
||||
};
|
||||
|
||||
return Ok(ctx);
|
||||
}
|
||||
|
||||
pub fn listen() -> bool {
|
||||
|
|
13
src/gw.rs
Normal file
13
src/gw.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
use igd::aio::Gateway;
|
||||
use igd::aio::search_gateway;
|
||||
use anyhow::{Result, Context};
|
||||
use log::*;
|
||||
|
||||
pub async fn get_gateway() -> Result<igd::aio::Gateway> {
|
||||
let gw = search_gateway(Default::default())
|
||||
.await
|
||||
.context("Failed to find gateway")?;
|
||||
|
||||
info!("Gateway: {}", gw);
|
||||
return Ok(gw);
|
||||
}
|
|
@ -3,17 +3,17 @@ use std::net::SocketAddrV4;
|
|||
|
||||
use log::*;
|
||||
|
||||
use igd::aio::search_gateway;
|
||||
use igd::PortMappingProtocol;
|
||||
|
||||
mod diplonat;
|
||||
mod config;
|
||||
mod gw;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
pretty_env_logger::init();
|
||||
|
||||
let ctx = diplonat::setup().expect("Setup failed");
|
||||
let ctx = diplonat::setup().await.expect("Setup failed");
|
||||
diplonat::listen();
|
||||
/*
|
||||
let url = format!("http://127.0.0.1:8500/v1/catalog/node/{}", config.consul_node_name);
|
||||
|
@ -28,7 +28,6 @@ async fn main() {
|
|||
Ok(g) => g,
|
||||
Err(err) => return println!("Faild to find IGD: {}", err),
|
||||
};
|
||||
info!("Gateway: {}", gateway);
|
||||
|
||||
let service = format!("{}:{}", config.private_ip, 1234);
|
||||
let service: SocketAddrV4 = service.parse().expect("Invalid socket address");
|
||||
|
|
Loading…
Reference in a new issue