diff options
| author | Namilskyy <alive6863@gmail.com> | 2025-12-27 22:26:52 +0300 |
|---|---|---|
| committer | Namilskyy <alive6863@gmail.com> | 2025-12-27 22:26:52 +0300 |
| commit | 007ee0bc3534218b2d084f368444d96c16d9d7f9 (patch) | |
| tree | 4de58305c0d57daa226b4cff7eee3b6055e1c6c3 /src | |
| parent | 12528fcaf99763fc25df694d31208a6fa729d0a3 (diff) | |
An integrated i2p router is being developed
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 3 | ||||
| -rw-r--r-- | src/openpgp/signatures.rs | 2 | ||||
| -rw-r--r-- | src/pkgtoolkit/build.rs | 20 | ||||
| -rw-r--r-- | src/pkgtoolkit/types.rs | 9 | ||||
| -rw-r--r-- | src/router/mod.rs | 2 | ||||
| -rw-r--r-- | src/router/router.rs | 92 |
6 files changed, 118 insertions, 10 deletions
diff --git a/src/main.rs b/src/main.rs index 0e3a80c..bbd4187 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,10 +2,11 @@ mod cfg; mod net; mod openpgp; mod pkgtoolkit; +mod router; use crate::cfg::config::Config; use crate::net::{http_package::HTTPPackage, i2p_package::I2PPackage}; -use crate::openpgp::trusted::ScanResult; +use crate::openpgp::trusted; use crate::pkgtoolkit::Package; use crate::pkgtoolkit::archive::ArchiveOperations; use crate::pkgtoolkit::build::BuildOperations; diff --git a/src/openpgp/signatures.rs b/src/openpgp/signatures.rs index 74bbe86..ac21d2b 100644 --- a/src/openpgp/signatures.rs +++ b/src/openpgp/signatures.rs @@ -1 +1 @@ -// Worker with signs-db +// Worker with signs-db diff --git a/src/pkgtoolkit/build.rs b/src/pkgtoolkit/build.rs index a37cb05..8c5119c 100644 --- a/src/pkgtoolkit/build.rs +++ b/src/pkgtoolkit/build.rs @@ -110,7 +110,6 @@ impl BuildOperations for Package { Ok(()) } - /// Finds the build system file (e.g. Makefile, meson.build, CMakeLists.txt, Cargo.toml) /// based on the build system specified in the build metadata. /// @@ -123,19 +122,25 @@ impl BuildOperations for Package { /// /// A `Result` containing an `Option<PathBuf>` which is `Some` if the build /// system file is found, and `None` otherwise. - fn find_makefile(&self, build_meta: &Build, search_dir: &Path) -> std::io::Result<Option<PathBuf>> { + fn find_makefile( + &self, + build_meta: &Build, + search_dir: &Path, + ) -> std::io::Result<Option<PathBuf>> { let (patterns, recursive) = match build_meta.build_system { BuildSystems::Make => (vec!["Makefile", "makefile", "GNUmakefile"], false), BuildSystems::Meson => (vec!["meson.build", "meson_options.txt"], true), BuildSystems::CMake => (vec!["CMakeLists.txt"], true), BuildSystems::Cargo => (vec!["Cargo.toml"], false), - _ => return Ok(None), }; for pattern in &patterns { - let glob_pattern = if recursive { - search_dir.join("**").join(pattern).to_string_lossy().into_owned() + search_dir + .join("**") + .join(pattern) + .to_string_lossy() + .into_owned() } else { search_dir.join(pattern).to_string_lossy().into_owned() }; @@ -144,13 +149,14 @@ impl BuildOperations for Package { .map_err(|e| std::io::Error::other(format!("Invalid glob pattern: {}", e)))?; for entry in entries { - let path = entry.map_err(|e| std::io::Error::other(format!("Glob error: {}", e)))?; + let path = + entry.map_err(|e| std::io::Error::other(format!("Glob error: {}", e)))?; return Ok(Some(path)); } } Ok(None) -} + } /// Execute the build script for the package. /// diff --git a/src/pkgtoolkit/types.rs b/src/pkgtoolkit/types.rs index 83f47a3..0439175 100644 --- a/src/pkgtoolkit/types.rs +++ b/src/pkgtoolkit/types.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; +use std::fmt; -#[derive(Serialize, Debug, Deserialize, Clone)] +#[derive(Serialize, Debug, Deserialize, Clone, PartialEq)] pub enum Archs { X86_64, Aarch64, @@ -90,3 +91,9 @@ impl Archs { } } } + +impl fmt::Display for Archs { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.as_str()) + } +} diff --git a/src/router/mod.rs b/src/router/mod.rs new file mode 100644 index 0000000..772c177 --- /dev/null +++ b/src/router/mod.rs @@ -0,0 +1,2 @@ +pub mod router; + diff --git a/src/router/router.rs b/src/router/router.rs new file mode 100644 index 0000000..c438d75 --- /dev/null +++ b/src/router/router.rs @@ -0,0 +1,92 @@ +use emissary_util::storage::{Storage, StorageBundle}; +use emissary_util::reseeder::Reseeder; +use std::path::PathBuf; + + +pub trait RouterConfigUtils { + async fn config(&mut self) -> Result<(StorageBundle, Storage), Box<dyn std::error::Error>>; + async fn prepare_router(&mut self) -> Result<(), Box<dyn std::error::Error>>; + async fn reseed(&mut self, config: &StorageBundle, storage: &Storage) -> Result<(), Box<dyn std::error::Error>>; +} + +pub struct EmissaryConfig { + Storage: Option<PathBuf>, + AutoUpdate: Option<bool>, + HttpProxtPort: Option<u16>, + SocksProxyPort: Option<u16>, +} + +impl RouterConfigUtils for EmissaryConfig { + /// Configures the router with the given configuration. + /// + /// If the `Storage` field is `None`, it will be set to `/var/lib/mesk/router/`. + /// + /// # Errors + /// + /// Returns an error if there's an issue while configuring the router. + async fn config(&mut self) -> Result<(StorageBundle, Storage), Box<dyn std::error::Error>> { + self.Storage.get_or_insert_with(|| PathBuf::from("/var/lib/mesk/router/")); + self.AutoUpdate.get_or_insert(true); + self.HttpProxtPort.get_or_insert(4445); + self.SocksProxyPort.get_or_insert(4446); + + let storage = Storage::new(self.Storage.clone().into()).await?; + + let StorageBundle { + ntcp2_iv, + ntcp2_key, + profiles, + router_info, + routers, + signing_key, + static_key, + ssu2_intro_key, + ssu2_static_key, + } = storage.load().await; + + Ok((StorageBundle { + ntcp2_iv, + ntcp2_key, + profiles, + router_info, + routers, + signing_key, + static_key, + ssu2_intro_key, + ssu2_static_key, + }, storage)) + } + + async fn reseed(&mut self, config: &StorageBundle, storage: &Storage) -> Result<(), Box<dyn std::error::Error>> { + let mut routers = config.routers.clone(); + + + if routers.is_empty() { + match Reseeder::reseed(None, false).await { + Ok(reseed_routers) => { + for info in reseed_routers { + let _ = storage + .store_router_info(info.name.to_string(), info.router_info.clone()) + .await; + routers.push(info.router_info); + } + } + Err(_) if routers.is_empty() => { + return Err("Could not reseed routers.".into()); + } + Err(error) => { + log::warn!( + "Failed to reseed routers: {} - using existing routers", error.to_string(), + ); + } + } + } + Ok(()) + } + + async fn prepare_router(&mut self) -> Result<(), Box<dyn std::error::Error>> { + + + Ok(()) + } +}
\ No newline at end of file |
