diff --git a/Cargo.lock b/Cargo.lock index 3110c0c..2c1cf4d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", +] diff --git a/chorus-bin/Cargo.toml b/chorus-bin/Cargo.toml index fde599a..12158b5 100644 --- a/chorus-bin/Cargo.toml +++ b/chorus-bin/Cargo.toml @@ -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] diff --git a/chorus-bin/src/bin/dump.rs b/chorus-bin/src/bin/dump.rs index 2495317..c9ed1fa 100644 --- a/chorus-bin/src/bin/dump.rs +++ b/chorus-bin/src/bin/dump.rs @@ -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."); diff --git a/chorus-bin/src/main.rs b/chorus-bin/src/main.rs index 52e1c7f..a3a78db 100644 --- a/chorus-bin/src/main.rs +++ b/chorus-bin/src/main.rs @@ -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."); diff --git a/chorus-lib/Cargo.toml b/chorus-lib/Cargo.toml index 38f2793..98b8882 100644 --- a/chorus-lib/Cargo.toml +++ b/chorus-lib/Cargo.toml @@ -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] diff --git a/chorus-lib/src/error.rs b/chorus-lib/src/error.rs index 26ee33c..b8dd10e 100644 --- a/chorus-lib/src/error.rs +++ b/chorus-lib/src/error.rs @@ -44,7 +44,7 @@ pub enum ChorusError { ChannelSend(tokio::sync::broadcast::error::SendError), // Config - Config(ron::error::SpannedError), + Config(toml::de::Error), // Crypto Crypto(secp256k1::Error), @@ -292,9 +292,9 @@ impl From> for Error { } } -impl From for Error { +impl From 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(), diff --git a/contrib/chorus-direct.service b/contrib/chorus-direct.service index 686e17e..688e113 100644 --- a/contrib/chorus-direct.service +++ b/contrib/chorus-direct.service @@ -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 diff --git a/contrib/chorus-proxied.service b/contrib/chorus-proxied.service index 85904ae..0288313 100644 --- a/contrib/chorus-proxied.service +++ b/contrib/chorus-proxied.service @@ -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 diff --git a/contrib/chorus.ron b/contrib/chorus.ron deleted file mode 100644 index 8a7ccbd..0000000 --- a/contrib/chorus.ron +++ /dev/null @@ -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, -) \ No newline at end of file diff --git a/contrib/chorus.toml b/contrib/chorus.toml new file mode 100644 index 0000000..5791300 --- /dev/null +++ b/contrib/chorus.toml @@ -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 diff --git a/docs/CONFIG.md b/docs/CONFIG.md index 4257a4c..21bc4a5 100644 --- a/docs/CONFIG.md +++ b/docs/CONFIG.md @@ -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 diff --git a/docs/DEPLOYING.md b/docs/DEPLOYING.md index 02891e6..97fe1f9 100644 --- a/docs/DEPLOYING.md +++ b/docs/DEPLOYING.md @@ -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: diff --git a/run_sample.sh b/run_sample.sh index 9a7df83..eddaac5 100755 --- a/run_sample.sh +++ b/run_sample.sh @@ -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 diff --git a/sample/sample.config.ron b/sample/sample.config.ron deleted file mode 100644 index b4777ac..0000000 --- a/sample/sample.config.ron +++ /dev/null @@ -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, -) \ No newline at end of file diff --git a/sample/sample.config.toml b/sample/sample.config.toml new file mode 100644 index 0000000..a2c46d1 --- /dev/null +++ b/sample/sample.config.toml @@ -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