aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.rs2
-rw-r--r--src/diplonat.rs23
-rw-r--r--src/gw.rs1
-rw-r--r--src/main.rs18
4 files changed, 22 insertions, 22 deletions
diff --git a/src/config.rs b/src/config.rs
index efc0112..c335e8d 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,5 +1,5 @@
use std::env;
-use anyhow::{Result, Context, Error, anyhow};
+use anyhow::{Result, Context, anyhow};
use log::*;
pub struct DiplonatConfig {
diff --git a/src/diplonat.rs b/src/diplonat.rs
index c209da5..3dd4e91 100644
--- a/src/diplonat.rs
+++ b/src/diplonat.rs
@@ -1,21 +1,22 @@
use anyhow::{Result, Context};
-use log::*;
use crate::*;
-pub struct DiplonatContext {
+pub struct Diplonat {
pub config: config::DiplonatConfig,
pub gateway: igd::aio::Gateway
}
-pub async fn setup() -> Result<DiplonatContext> {
- let ctx = DiplonatContext {
- config: config::load_env().context("Unable to read configuration from environment")?,
- gateway: gw::get_gateway().await?
- };
+impl Diplonat {
+ pub async fn new() -> Result<Self> {
+ let ctx = Self {
+ config: config::load_env().context("Unable to read configuration from environment")?,
+ gateway: gw::get_gateway().await?
+ };
- return Ok(ctx);
-}
+ return Ok(ctx);
+ }
-pub fn listen() -> bool {
- return true;
+ pub fn listen(&self) -> bool {
+ return true;
+ }
}
diff --git a/src/gw.rs b/src/gw.rs
index f716a3f..4489cf9 100644
--- a/src/gw.rs
+++ b/src/gw.rs
@@ -1,4 +1,3 @@
-use igd::aio::Gateway;
use igd::aio::search_gateway;
use anyhow::{Result, Context};
use log::*;
diff --git a/src/main.rs b/src/main.rs
index 91074d1..fee73aa 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,20 +1,20 @@
-use std::net::SocketAddrV4;
-//use std::collections::HashMap;
-
-use log::*;
-
-use igd::PortMappingProtocol;
-
mod diplonat;
mod config;
mod gw;
+//use std::net::SocketAddrV4;
+//use std::collections::HashMap;
+//use igd::PortMappingProtocol;
+use log::*;
+use diplonat::*;
+
#[tokio::main]
async fn main() {
pretty_env_logger::init();
+ info!("Starting Diplonat");
- let ctx = diplonat::setup().await.expect("Setup failed");
- diplonat::listen();
+ let diplo = Diplonat::new().await.expect("Setup failed");
+ diplo.listen();
/*
let url = format!("http://127.0.0.1:8500/v1/catalog/node/{}", config.consul_node_name);
let resp = reqwest::get(&url)