diff --git a/.env.example b/.env.example index 7a4201e..d54af82 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,7 @@ -LISTEN_ADDRES=0.0.0.0 -PORT=5733 +# Listen address and port +PORT=3344 +IP="0.0.0.0" -ROUTER_URL=https://127.0.0.1:7650 -ROUTER_PASSWORD=itoopie \ No newline at end of file +# Router url and password +PASSWORD="itoopie" +ROUTER=https://localhost:7650/ \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 43816de..9b2d4a5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,9 +7,9 @@ services: context: . container_name: i2pd-exporter environment: - - IP=${LISTEN_ADDRESS} + - IP=${IP} - PORT=${PORT} - - ROUTER=${ROUTER_URL} - - PASSWORD=${ROUTER_PASSWORD} + - ROUTER=${ROUTER} + - PASSWORD=${PASSWORD} ports: - "${PORT}:${PORT}" diff --git a/readme.md b/readme.md index 71cbd5f..2595128 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,6 @@ # I2PD exporter -A basic prometheus exporter that exports miscellaneous data using the i2pcontrol protocol such as peers, data sent & received and so on... -Right now there are some problems with using exporter as the options for i2pd in nixpkgs are wrong... Therefore upon starting the program will error out with `InvalidPassword`. But it works alright on other systems +A basic prometheus exporter that exports miscellaneous data using the i2pcontrol protocol such as peers, data sent & received and so on... ## How to use (Nix) diff --git a/src/api.rs b/src/api.rs index 2aa0ce7..8dd5b32 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1,4 +1,3 @@ -use std::{default, f32::consts::E}; use derive_builder::Builder; use serde::Deserialize; @@ -14,8 +13,8 @@ pub struct I2PControl { #[builder(default = "false")] authenticated: bool, - #[builder(default = "0")] - token: i64, + + token: String, password: String, } @@ -59,15 +58,12 @@ impl I2PControl { Err(_) => return Err(I2PControlError::InvalidResponse), }; - match data.result.pointer("/token") { + match data.result.pointer("/Token") { None => return Err(I2PControlError::InvalidPassword), - Some(token) => match token.as_i64() { - Some(token) => { - self.authenticated = true; - self.token = token; - } - None => return Err(I2PControlError::InvalidResponse), - }, + Some(token) => { + self.authenticated = true; + self.token = token.to_string(); + } } return Ok(()); diff --git a/src/main.rs b/src/main.rs index fdf6a10..b70b927 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,16 +37,21 @@ async fn main() { ) .endpoint(Url::parse(&c.router).unwrap()) .password(c.password.into()) + .token("".to_string()) .build() .unwrap(); - loop { + loop { + thread::sleep(Duration::from_secs(1)); match client.auth().await { - Ok(_) => (), + Ok(_) => { + println!("Successfully authenticated"); + break + }, Err(error) => { - println!("Failed to authenticate: {:?}", error) + println!("Failed to authenticate: {:?}... retrying in 1 seconds", error) } }; }