summaryrefslogtreecommitdiff
path: root/src/geoparsers/geoip2.rs
blob: af5d03efb78ef7185dea6377a054b05083c4515c (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
use ipnet::IpNet;
use crate::config::Config;

/// 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 Rules = Vec<Rule>;

/// 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<Rules, Box<dyn std::error::Error>> {
    let reader = maxminddb::Reader::open_readfile(config.geo_files[0].clone())?;

    // Ok(())
    todo!();
}