summaryrefslogtreecommitdiff
path: root/src/net/emissary_i2p.rs
blob: b9e5967eede3eb447b2545a7e2b84d7e85ae53e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use emissary_core::{
    I2cpConfig, 
    Ntcp2Config
};


use crate::pkgtoolkit::pkgtools::Package; 
use crate::Config;

use indicatif::{ProgressBar, ProgressStyle};
use std::{collections::HashMap, path::Path};
use tokio::io::{AsyncReadExt, AsyncWriteExt, BufReader};

pub struct I2PPackage {
    pub config: Config,
    pub i2p_config: emissary_core::Config,
    pub index_packages: Option<HashMap<String, Package>>,
}

impl I2PPackage {
    pub fn new(cfg: Config, i2p_cfg: emissary_core::Config) -> Self {
        I2PPackage {
            config: cfg,
            i2p_config: i2p_cfg, 
            index_packages: None,
        }
    }

    pub async fn fetch_index(&mut self) -> Result<(), Box<dyn std::error::Error>> {
            let cfg =  Config::parse()?;

            let repo_url = &self.config.repo.repo_url;
            let cache_dir = &self.config.paths.cache_dir;

            let utl = url::Url::parse(repo_url).unwrap();
            let host = utl.host_str().ok_or("No host in URL")?;

            let request_path = utl.path();
            let request_path = if request_path.ends_with(".tar.gz") {
                request_path.to_string()
            } else {
                format!("{}/INDEX.tar.gz", request_path.trim_end_matches('/'))
            };

            
            let StorageBundle {
                ntcp2_iv,
                ntcp2_key,
                profiles,
                router_info,
                routers,
                signing_key,
                static_key,
                ssu2_intro_key,
                ssu2_static_key,
            } = storage.load().await;

            Ok(())
    }
}