First minimal commit
This commit is contained in:
parent
7019867411
commit
bc8bc0c2e4
10 changed files with 1051 additions and 1 deletions
33
src/config.rs
Normal file
33
src/config.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Deserialize, Serialize, Default)]
|
||||
pub enum RunTypes {
|
||||
#[default]
|
||||
Tor,
|
||||
I2P,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct NSCConfig {
|
||||
/// Paths to v2ray `geosite.dat', `geoip.dat`
|
||||
pub geo_files: [String; 2],
|
||||
/// Routing settings similar to v2ray
|
||||
pub routing: String,
|
||||
/// TOR/I2P Proxies
|
||||
pub mode: RunTypes,
|
||||
}
|
||||
|
||||
impl Default for NSCConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
geo_files: [
|
||||
String::from("/etc/nsc/data/geoip.dat"),
|
||||
String::from("/etc/nsc/data/geosite.dat"),
|
||||
],
|
||||
routing: String::from("/etc/nsc/routing.toml"),
|
||||
mode: RunTypes::Tor,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
41
src/geoparsers/geoip2.rs
Normal file
41
src/geoparsers/geoip2.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
use ipnet::IpNet;
|
||||
use crate::config::NSCConfig;
|
||||
|
||||
/// Enum for declaring GeoSite/IP routing
|
||||
pub enum RouteType {
|
||||
/// GeoSite MMDB type, like `category-ads-all`
|
||||
GeoSite(String),
|
||||
/// Subnet
|
||||
GeoIp(IpNet),
|
||||
}
|
||||
|
||||
/// Routing actions
|
||||
pub enum RouteAction {
|
||||
Block,
|
||||
Proxy,
|
||||
Direct,
|
||||
}
|
||||
|
||||
/// Type for declaring the routing rules like:
|
||||
/// ```toml
|
||||
/// [rule]
|
||||
/// action = enum RouteAction
|
||||
/// target = enum RouteType
|
||||
///
|
||||
/// [rule]
|
||||
/// target = "geosite:category-ads-all"
|
||||
/// action = "block"
|
||||
/// ```
|
||||
pub struct Rule {
|
||||
pub target: RouteType,
|
||||
pub action: RouteAction,
|
||||
}
|
||||
|
||||
pub fn parse_ruleset(config: NSCConfig) -> Result<Vec<Rule>, Box<dyn std::error::Error>> {
|
||||
let reader = maxminddb::Reader::open_readfile(config.geo_files[0].clone())?;
|
||||
|
||||
|
||||
// Ok(())
|
||||
todo!();
|
||||
}
|
||||
|
||||
1
src/geoparsers/mod.rs
Normal file
1
src/geoparsers/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
mod geoip2;
|
||||
6
src/main.rs
Normal file
6
src/main.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
mod config;
|
||||
mod geoparsers;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
0
src/routing.rs
Normal file
0
src/routing.rs
Normal file
0
src/sniffing/headers.rs
Normal file
0
src/sniffing/headers.rs
Normal file
0
src/sniffing/metadata.rs
Normal file
0
src/sniffing/metadata.rs
Normal file
Loading…
Add table
Add a link
Reference in a new issue