mirror of
https://codeberg.org/slatian/service.echoip-slatecave.git
synced 2025-09-06 23:38:59 +02:00
Use a PathBuf instead of a String for storing the mmdb locations
This commit is contained in:
@@ -3,6 +3,7 @@ use serde::Deserialize;
|
|||||||
|
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
mod dns;
|
mod dns;
|
||||||
|
|
||||||
@@ -28,8 +29,8 @@ pub struct ServerConfig {
|
|||||||
|
|
||||||
#[derive(Deserialize, Clone)]
|
#[derive(Deserialize, Clone)]
|
||||||
pub struct GeoIpConfig {
|
pub struct GeoIpConfig {
|
||||||
pub asn_database: Option<String>,
|
pub asn_database: Option<PathBuf>,
|
||||||
pub location_database: Option<String>,
|
pub location_database: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone)]
|
#[derive(Deserialize, Clone)]
|
||||||
@@ -59,8 +60,8 @@ impl Default for ServerConfig {
|
|||||||
impl Default for GeoIpConfig {
|
impl Default for GeoIpConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
GeoIpConfig {
|
GeoIpConfig {
|
||||||
asn_database: Some("mmdb/GeoLite2-ASN.mmdb".to_string()),
|
asn_database: Some("mmdb/GeoLite2-ASN.mmdb".into()),
|
||||||
location_database: Some("mmdb/GeoLite2-City.mmdb".to_string()),
|
location_database: Some("mmdb/GeoLite2-City.mmdb".into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,7 @@ use parking_lot::RwLock;
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
/* Datatypes */
|
/* Datatypes */
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ pub struct AsnResult {
|
|||||||
pub struct MMDBCarrier {
|
pub struct MMDBCarrier {
|
||||||
pub mmdb: RwLock<Option<maxminddb::Reader<Vec<u8>>>>,
|
pub mmdb: RwLock<Option<maxminddb::Reader<Vec<u8>>>>,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub path: Option<String>,
|
pub path: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait QueryLocation {
|
pub trait QueryLocation {
|
||||||
@@ -227,7 +228,7 @@ impl QueryLocation for MMDBCarrier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MMDBCarrier {
|
impl MMDBCarrier {
|
||||||
pub fn new(name: String, path: Option<String>) -> MMDBCarrier {
|
pub fn new(name: String, path: Option<PathBuf>) -> MMDBCarrier {
|
||||||
MMDBCarrier {
|
MMDBCarrier {
|
||||||
mmdb: RwLock::new(None),
|
mmdb: RwLock::new(None),
|
||||||
name: name,
|
name: name,
|
||||||
@@ -237,7 +238,7 @@ impl MMDBCarrier {
|
|||||||
|
|
||||||
pub fn reload_database(&self) -> Result<(),maxminddb::MaxMindDbError> {
|
pub fn reload_database(&self) -> Result<(),maxminddb::MaxMindDbError> {
|
||||||
match &self.path {
|
match &self.path {
|
||||||
Some(path) => self.load_database_from_path(Path::new(&path)),
|
Some(path) => self.load_database_from_path(path),
|
||||||
None => Ok(()),
|
None => Ok(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user