summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornamilsk <namilsk@namilsk.tech>2026-03-14 19:15:14 +0300
committernamilsk <namilsk@namilsk.tech>2026-03-14 19:17:16 +0300
commitbc8bc0c2e4fb09070d82aab1f922ef8160c66528 (patch)
treec7d36233840007a638bffe3ffa9e503325a51794 /src
parent7019867411cdca87b394f38dfc589958e09a2b73 (diff)
First minimal commit
Diffstat (limited to 'src')
-rw-r--r--src/config.rs33
-rw-r--r--src/geoparsers/geoip2.rs41
-rw-r--r--src/geoparsers/mod.rs1
-rw-r--r--src/main.rs6
-rw-r--r--src/routing.rs0
-rw-r--r--src/sniffing/headers.rs0
-rw-r--r--src/sniffing/metadata.rs0
7 files changed, 81 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs
new file mode 100644
index 0000000..85f4e81
--- /dev/null
+++ b/src/config.rs
@@ -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,
+ }
+ }
+}
+
+
diff --git a/src/geoparsers/geoip2.rs b/src/geoparsers/geoip2.rs
new file mode 100644
index 0000000..9e8f29d
--- /dev/null
+++ b/src/geoparsers/geoip2.rs
@@ -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!();
+}
+
diff --git a/src/geoparsers/mod.rs b/src/geoparsers/mod.rs
new file mode 100644
index 0000000..9f95b8f
--- /dev/null
+++ b/src/geoparsers/mod.rs
@@ -0,0 +1 @@
+mod geoip2;
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..438b85e
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,6 @@
+mod config;
+mod geoparsers;
+
+fn main() {
+ println!("Hello, world!");
+}
diff --git a/src/routing.rs b/src/routing.rs
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/routing.rs
diff --git a/src/sniffing/headers.rs b/src/sniffing/headers.rs
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/sniffing/headers.rs
diff --git a/src/sniffing/metadata.rs b/src/sniffing/metadata.rs
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/sniffing/metadata.rs