diff options
| author | Namilskyy <alive6863@gmail.com> | 2025-11-25 21:51:48 +0300 |
|---|---|---|
| committer | Namilskyy <alive6863@gmail.com> | 2025-11-25 21:52:22 +0300 |
| commit | 0a5663173b416301f84b9997d6e3905a4f7a579e (patch) | |
| tree | 512cbf80a96dbf014377a8fec0b64f8b78f39f22 | |
| parent | ff6d45b66652a22856aa1fc8ecdee68de2e4a94c (diff) | |
Started implementing i2p-part of package manager
| -rw-r--r-- | src/i2impl/mi2p.rs | 65 |
1 files changed, 62 insertions, 3 deletions
diff --git a/src/i2impl/mi2p.rs b/src/i2impl/mi2p.rs index 223c17f..5baff0f 100644 --- a/src/i2impl/mi2p.rs +++ b/src/i2impl/mi2p.rs @@ -1,7 +1,18 @@ use crate::cfg::config::Config; -use emissary_core::I2cpConfig; +use tokio; + +use emissary_core::runtime::{ + AsyncRead, + AsyncWrite, +}; + +use emissary_core::Profile; +use emissary_core::i2np::Message; +use tokio::io::AsyncWriteExt; +use yosemite::SessionOptions; +use yosemite::{Session, style::Stream}; /* use i2p_client::ClientType; @@ -11,7 +22,6 @@ use i2p_client::Session; struct I2PStatus { Connected: bool, - ConnectionType: ClientType, } impl I2PStatus { @@ -30,4 +40,53 @@ impl I2PStatus { Ok(true) } } -*/
\ No newline at end of file +*/ + +struct I2P<S> { + session: Option<Session<S>>, + connected: bool, + config: Config, + +} + +impl<S> I2P<S> { + /// Creates a new I2P object with the given configuration. + /// + /// # Returns + /// + /// A new I2P object with the given configuration. The session is initially set to None and the connected status is set to false. + pub fn new(config: Config) -> Self { + I2P { + session: None, + connected: false, + config: config, + } + } + + /// Fetches the list of packages from the repository specified in the configuration. + /// + /// This function connects to the repository specified in the configuration, sends a GET request for the repository list and returns true if the request is successful, false otherwise. + /// + /// # Errors + /// + /// Returns an error if the repository URL is invalid or if the request fails. + /// + async fn fetch_repo_list(&mut self) -> Result<bool, std::io::Error> { + let repo_url = &self.config.repo.repo_url; + + let mut session = Session::<Stream>::new(SessionOptions::default()).await.unwrap(); + let mut stream = session.connect(&self.config.repo.repo_url).await.unwrap(); + + let formatted_repo_url; + + if let Some(pos) = repo_url.find("/repo") { + let start_index = pos + "/repo".len(); + formatted_repo_url = repo_url[start_index..].to_string(); + } else { + return Err(std::io::Error::new(std::io::ErrorKind::NotFound, "Invalid repo URL")); + }; + stream.write_all(format!("GET {} HTTP/1.1\r\n\r\n", formatted_repo_url).as_bytes()).await.unwrap(); + + Ok(true) + } +}
\ No newline at end of file |
