erpc_analysis/
args.rs

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
use anyhow;
use clap::Parser;

/// erpc-analysis: A tool for analyzing Tor network data from eRPC.
#[derive(Parser)]
pub struct Args {
    /// Path to the configuration TOML file.
    #[arg(short, long, default_value = "config/primary/Config.toml")]
    pub config: String,

    /// Path to the log4rs YAML configuration file.
    #[arg(long, default_value = "erpc-analysis/src/log_config.yml")]
    pub log_config: String,

    /// Path to the analysis-specific configuration TOML file.
    #[arg(long, default_value = "erpc-analysis/analysis_config.toml")]
    pub analysis_config: String,

    /// Specific analysis task to run. If not specified, runs
    /// default analysis workflow.
    #[arg(short, long)]
    pub task: Option<String>,

    /// Force recreation of graph projection if it already exists.
    #[arg(long)]
    pub force: bool,
}

impl Args {
    /// Setup method that handles validation
    pub fn setup(&self) -> anyhow::Result<()> {
        self.validate_arguments()?;
        Ok(())
    }

    pub fn validate_arguments(&self) -> anyhow::Result<()> {
        use std::path::Path;

        // Check for file existence
        for (file, description) in
            [(&self.config, "Config"), (&self.log_config, "Log Config")]
        {
            if !Path::new(file).exists() {
                return Err(anyhow::anyhow!(
                    "Error: {} file '{}' is missing",
                    description,
                    file
                ));
            }
        }

        // Validate task if specified
        if let Some(ref task) = self.task {
            let valid_tasks = [
                "projection-create",
                "projection-delete",
                "projection-exists",
                "metrics-basic",
                "metrics-degrees",
                "metrics-distribution",
                "components-analysis",
                "community-louvain-consensus",
                "community-lpa",
                "partition-classify-geography",
                "partition-classify-asn",
                "partition-classify-family",
                "partition-classify-all",
                "centrality-betweenness",
                "centrality-closeness",
                "centrality-combined",
                "path-connectivity",
                "advanced-path-analysis",
                "info-database",
                "web-server",
                "help",
            ];

            if !valid_tasks.contains(&task.as_str()) {
                return Err(anyhow::anyhow!(
                    "Error: Invalid task '{}'. Valid tasks are: {}\n\nFor \
                     detailed help, use: --task help",
                    task,
                    valid_tasks.join(", ")
                ));
            }
        }

        Ok(())
    }

    /// Get help text for available tasks
    pub fn task_help() -> &'static str {
        r#"Available tasks:
  projection-create                   Create a new graph projection
  projection-delete                   Delete an existing graph projection
  projection-exists                   Check if a projection exists
  metrics-basic                       Calculate basic graph metrics
  metrics-degrees                     Calculate node degree metrics
  metrics-distribution                Show degree distribution
  components-analysis                 Analyze network connectivity components
  community-louvain-consensus         Run Louvain multiple times to analyze stability (configurable runs)
  community-lpa                       Analyze communities using Label Propagation algorithm
  partition-classify-geography        Classify partitions by geographic location (country)
  partition-classify-asn              Classify partitions by Autonomous System Number (ASN)
  partition-classify-family           Classify partitions by relay family relationships
  partition-classify-all              Run all partition classification analyses
  centrality-betweenness              Calculate betweenness centrality for network nodes
  centrality-closeness                Calculate closeness centrality for network nodes
  centrality-combined                 Calculate both betweenness and closeness centrality
  path-connectivity                   Analyze internal connectivity within communities detected by Louvain algorithm
  advanced-path-analysis              Comprehensive path analysis using Louvain community detection and ASN-based classification
  info-database                       Show database information
  web-server                          Start the web server for visualization API

If no task is specified, runs the default analysis workflow."#
    }
}