Skip to content

Commit

Permalink
mastersrv: Add config file and hot-reloading of it
Browse files Browse the repository at this point in the history
This allows to add bans and port forward exceptions without restarting
the mastersrv itself.

It also allows reloading the locations database (with the important
caveat that it is mmap-ed, and as such must be removed before being
overridden in the file system).
  • Loading branch information
heinrich5991 committed Jan 14, 2025
1 parent ae91b32 commit 8c01dcf
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 45 deletions.
110 changes: 102 additions & 8 deletions src/mastersrv/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/mastersrv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ license = "Zlib"
[workspace]

[dependencies]
arc-swap = "1.7.1"
arrayvec = { version = "0.5.2", features = ["serde"] }
base64 = "0.13.0"
bytes = "1.1.0"
Expand All @@ -19,6 +20,7 @@ clap = { version = "2.34.0", default-features = false, features = [
env_logger = "0.8.3"
headers = "0.3.7"
hex = "0.4.3"
ipnet = "2.9.0"
libloc = "0.1.0"
log = "0.4.17"
mime = "0.3.16"
Expand All @@ -30,7 +32,13 @@ serde_json = { version = "1.0.64", features = [
"raw_value",
] }
sha2 = "0.10.0"
tokio = { version = "1.6.0", features = ["macros", "rt", "rt-multi-thread"] }
toml = "0.8.19"
tokio = { version = "1.6.0", features = [
"macros",
"rt",
"rt-multi-thread",
"signal",
] }
tokio-stream = { version = "0.1.8", features = ["net"] }
url = { version = "2.2.2", features = ["serde"] }
warp = { version = "0.3.1", default-features = false }
17 changes: 9 additions & 8 deletions src/mastersrv/src/locations.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use arrayvec::ArrayString;
use std::fmt;
use std::net::IpAddr;
use std::path::Path;

Expand All @@ -8,22 +9,22 @@ pub type Location = ArrayString<[u8; 12]>;
#[derive(Debug)]
pub struct LocationsError(String);

#[derive(Default)]
pub struct Locations {
inner: Option<libloc::Locations>,
}

impl Locations {
pub fn empty() -> Locations {
Locations {
inner: None,
}
impl fmt::Display for LocationsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}

impl Locations {
pub fn read(filename: &Path) -> Result<Locations, LocationsError> {
let inner = libloc::Locations::open(filename)
.map_err(|e| LocationsError(format!("error opening {:?}: {}", filename, e)))?;
Ok(Locations {
inner: Some(inner),
})
Ok(Locations { inner: Some(inner) })
}
pub fn lookup(&self, addr: IpAddr) -> Option<Location> {
self.inner.as_ref().and_then(|inner| {
Expand Down
Loading

0 comments on commit 8c01dcf

Please sign in to comment.