[BREAKING] Switch to TOML config format

This commit is contained in:
Mike Dilger 2024-02-21 12:35:02 +13:00
parent a26e69248c
commit c098195a1c
15 changed files with 138 additions and 70 deletions

84
Cargo.lock generated
View File

@ -155,7 +155,6 @@ dependencies = [
"lazy_static",
"log",
"mmap-append",
"ron",
"rustls-pemfile",
"secp256k1",
"serde",
@ -163,6 +162,7 @@ dependencies = [
"textnonce",
"tokio",
"tokio-rustls",
"toml",
"url",
]
@ -179,7 +179,6 @@ dependencies = [
"lazy_static",
"log",
"mmap-append",
"ron",
"rustls-pemfile",
"secp256k1",
"serde",
@ -187,6 +186,7 @@ dependencies = [
"textnonce",
"tokio",
"tokio-rustls",
"toml",
"url",
]
@ -275,6 +275,12 @@ dependencies = [
"termcolor",
]
[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "errno"
version = "0.3.8"
@ -574,6 +580,16 @@ dependencies = [
"unicode-normalization",
]
[[package]]
name = "indexmap"
version = "2.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "233cf39063f058ea2caae4091bf4a3ef70a653afbc026f5c4a4135d114e3c177"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]]
name = "is-terminal"
version = "0.4.12"
@ -945,18 +961,6 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "ron"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94"
dependencies = [
"base64 0.21.7",
"bitflags 2.4.2",
"serde",
"serde_derive",
]
[[package]]
name = "rustc-demangle"
version = "0.1.23"
@ -1080,6 +1084,15 @@ dependencies = [
"serde",
]
[[package]]
name = "serde_spanned"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1"
dependencies = [
"serde",
]
[[package]]
name = "sha1"
version = "0.10.6"
@ -1275,6 +1288,40 @@ dependencies = [
"tungstenite",
]
[[package]]
name = "toml"
version = "0.8.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a9aad4a3066010876e8dcf5a8a06e70a558751117a145c6ce2b82c2e2054290"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit",
]
[[package]]
name = "toml_datetime"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.22.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c1b5fd4128cc8d3e0cb74d4ed9a9cc7c7284becd4df68f5f940e1ad123606f6"
dependencies = [
"indexmap",
"serde",
"serde_spanned",
"toml_datetime",
"winnow",
]
[[package]]
name = "tower-service"
version = "0.3.2"
@ -1564,3 +1611,12 @@ name = "windows_x86_64_msvc"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
[[package]]
name = "winnow"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a4191c47f15cc3ec71fcb4913cb83d58def65dd3787610213c649283b5ce178"
dependencies = [
"memchr",
]

View File

@ -18,13 +18,13 @@ hyper-tungstenite = "0.11"
lazy_static = "1.4"
log = "0.4"
mmap-append = { git = "https://github.com/mikedilger/mmap-append", rev = "0d20e193e7f13a442865a4a40a5da9a120e87411" }
ron = "0.8"
rustls-pemfile = "1.0"
secp256k1 = { version = "0.28", features = [ "hashes", "global-context", "rand-std" ] }
serde = { version = "1.0", features = ["derive"] }
textnonce = "1"
tokio = { version = "1", features = [ "full" ] }
tokio-rustls = "0.24"
toml = "0.8"
url = "2.5"
[dev-dependencies]

View File

@ -25,7 +25,7 @@ fn main() -> Result<(), Error> {
let mut file = OpenOptions::new().read(true).open(config_path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
let friendly_config: FriendlyConfig = ron::from_str(&contents)?;
let friendly_config: FriendlyConfig = toml::from_str(&contents)?;
let mut config: Config = friendly_config.into_config()?;
log::debug!("Loaded config file.");

View File

@ -54,7 +54,7 @@ async fn main() -> Result<(), Error> {
let mut file = OpenOptions::new().read(true).open(config_path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
let friendly_config: FriendlyConfig = ron::from_str(&contents)?;
let friendly_config: FriendlyConfig = toml::from_str(&contents)?;
let config: Config = friendly_config.into_config()?;
log::debug!("Loaded config file.");

View File

@ -17,13 +17,13 @@ hyper-tungstenite = "0.11"
lazy_static = "1.4"
log = "0.4"
mmap-append = { git = "https://github.com/mikedilger/mmap-append", rev = "0d20e193e7f13a442865a4a40a5da9a120e87411" }
ron = "0.8"
rustls-pemfile = "1.0"
secp256k1 = { version = "0.28", features = [ "hashes", "global-context", "rand-std" ] }
serde = { version = "1.0", features = ["derive"] }
textnonce = "1"
tokio = { version = "1", features = [ "full" ] }
tokio-rustls = "0.24"
toml = "0.8"
url = "2.5"
[dev-dependencies]

View File

@ -44,7 +44,7 @@ pub enum ChorusError {
ChannelSend(tokio::sync::broadcast::error::SendError<usize>),
// Config
Config(ron::error::SpannedError),
Config(toml::de::Error),
// Crypto
Crypto(secp256k1::Error),
@ -292,9 +292,9 @@ impl From<tokio::sync::broadcast::error::SendError<usize>> for Error {
}
}
impl From<ron::error::SpannedError> for Error {
impl From<toml::de::Error> for Error {
#[track_caller]
fn from(err: ron::error::SpannedError) -> Self {
fn from(err: toml::de::Error) -> Self {
Error {
inner: ChorusError::Config(err),
location: std::panic::Location::caller(),

View File

@ -12,7 +12,7 @@ AmbientCapabilities=CAP_NET_BIND_SERVICE
ExecStartPre=+cp -H /etc/letsencrypt/live/chorus.example.com/fullchain.pem /opt/chorus/etc/tls/
ExecStartPre=+cp -H /etc/letsencrypt/live/chorus.example.com/privkey.pem /opt/chorus/etc/tls/
ExecStartPre=+chown chorus /opt/chorus/etc/tls/fullchain.pem /opt/chorus/etc/tls/privkey.pem
ExecStart=/opt/chorus/sbin/chorus /opt/chorus/etc/chorus.ron
ExecStart=/opt/chorus/sbin/chorus /opt/chorus/etc/chorus.toml
Restart=always
RestartSec=5

View File

@ -8,7 +8,7 @@ Environment="RUST_BACKTRACE=1"
Environment="RUST_LOG=info"
WorkingDirectory=/opt/chorus
User=chorus
ExecStart=/opt/chorus/sbin/chorus /opt/chorus/etc/chorus.ron
ExecStart=/opt/chorus/sbin/chorus /opt/chorus/etc/chorus.toml
Restart=always
RestartSec=5

View File

@ -1,20 +0,0 @@
FriendlyConfig(
data_directory: "/opt/chorus/var/chorus",
ip_address: "127.0.0.1",
port: 443,
hostname: "localhost",
use_tls: true,
certchain_pem_path: "/opt/chorus/etc/tls/fullchain.pem",
key_pem_path: "/opt/chorus/etc/tls/privkey.pem",
name: Some("Chorus Default"),
description: Some("A default config of the Chorus relay"),
contact: None,
public_key_hex: None,
user_hex_keys: [
],
verify_events: true,
allow_scraping: false,
max_subscriptions: 32,
serve_ephemeral: true,
serve_relay_lists: true,
)

27
contrib/chorus.toml Normal file
View File

@ -0,0 +1,27 @@
data_directory = "/opt/chorus/var/chorus"
ip_address = "127.0.0.1"
port = 443
hostname = "localhost"
use_tls = true
certchain_pem_path = "/opt/chorus/etc/tls/fullchain.pem"
key_pem_path = "/opt/chorus/etc/tls/privkey.pem"
name = "Chorus Default"
description = "A default config of the Chorus relay"
# contact =
# public_key_hex =
user_hex_keys = []
verify_events = true
# This is a bad idea in production, but useful for testing or for dumping
# your entire relay
allow_scraping = false
max_subscriptions = 32
serve_ephemeral = true
serve_relay_lists = true

View File

@ -2,7 +2,7 @@
The chorus binary requires one command line parameter which specifies the config file path.
The config file must be in RON format. See the [RON documentation](https://docs.rs/ron/latest/ron/)
The config file must be in TOML format. See the [TOML documentation](https://github.com/toml-lang/toml)
## Configuration Variables

View File

@ -74,7 +74,7 @@ sudo install --mode=0700 --owner=chorus ./target/release/chorus /opt/chorus/sbin
Now let's create our config file
```bash
sudo -u chorus cp /opt/chorus/src/chorus/contrib/chorus.ron /opt/chorus/etc/
sudo -u chorus cp /opt/chorus/src/chorus/contrib/chorus.toml /opt/chorus/etc/
```
Go ahead and edit that file to your liking. In particular:

View File

@ -3,4 +3,4 @@
export RUST_LOG='info,chorus=debug'
cargo build --release && \
./target/release/chorus ./sample/sample.config.ron
./target/release/chorus ./sample/sample.config.toml

View File

@ -1,24 +0,0 @@
FriendlyConfig(
data_directory: "./sample",
ip_address: "127.0.0.1",
port: 8080,
hostname: "localhost",
use_tls: false,
certchain_pem_path: "tls/fullchain.pem",
key_pem_path: "tls/privkey.pem",
name: Some("Chorus Sample"),
description: Some("A sample run of the Chorus relay"),
contact: None,
public_key_hex: None,
user_hex_keys: [
"ee11a5dff40c19a555f41fe42b48f00e618c91225622ae37b6c2bb67b76c4e49"
],
verify_events: true,
// This is a bad idea in production, but useful for testing or for dumping
// your entire relay
allow_scraping: false,
max_subscriptions: 32,
serve_ephemeral: true,
serve_relay_lists: true,
)

29
sample/sample.config.toml Normal file
View File

@ -0,0 +1,29 @@
data_directory = "./sample"
ip_address = "127.0.0.1"
port = 8080
hostname = "localhost"
use_tls = false
certchain_pem_path = "tls/fullchain.pem"
key_pem_path = "tls/privkey.pem"
name = "Chorus Sample"
description = "A sample run of the Chorus relay"
#contact =
#public_key_hex =
user_hex_keys = [
"ee11a5dff40c19a555f41fe42b48f00e618c91225622ae37b6c2bb67b76c4e49"
]
verify_events = true
# This is a bad idea in production, but useful for testing or for dumping
# your entire relay
allow_scraping = false
max_subscriptions = 32
serve_ephemeral = true
serve_relay_lists = true