From f6c8d214a4fd9216cbec131de860f9ce9853b1db Mon Sep 17 00:00:00 2001 From: Mike Dilger Date: Tue, 12 Mar 2024 10:52:44 +1300 Subject: [PATCH] config.open_relay optionally run as an open public relay --- chorus-bin/src/nostr.rs | 22 ++++++++++++++++------ chorus-lib/src/config.rs | 5 +++++ contrib/chorus.toml | 7 +++++++ docs/CONFIG.md | 6 ++++++ docs/PERSONAL_RELAY.md | 4 ++++ sample/sample.config.toml | 1 + 6 files changed, 39 insertions(+), 6 deletions(-) diff --git a/chorus-bin/src/nostr.rs b/chorus-bin/src/nostr.rs index 85a0157..8f76c50 100644 --- a/chorus-bin/src/nostr.rs +++ b/chorus-bin/src/nostr.rs @@ -401,6 +401,11 @@ async fn screen_incoming_event( } } + // Accept if an open relay + if GLOBALS.config.get().unwrap().open_relay { + return Ok(true); + } + // Accept anything from authenticated authorized users if authorized_user { return Ok(true); @@ -448,6 +453,17 @@ pub fn screen_outgoing_event( event_flags: &EventFlags, authorized_user: bool, ) -> bool { + // Forbid if it is a private event (DM or GiftWrap) and theey are neither the recipient + // nor the author + if event.kind() == Kind(4) || event.kind() == Kind(1059) { + return event_flags.tags_current_user || event_flags.author_is_current_user; + } + + // Allow if an open relay + if GLOBALS.config.get().unwrap().open_relay { + return true; + } + // Allow Relay Lists if event.kind() == Kind(10002) && GLOBALS.config.get().unwrap().serve_relay_lists { return true; @@ -458,12 +474,6 @@ pub fn screen_outgoing_event( return true; } - // Forbid if it is a private event (DM or GiftWrap) and theey are neither the recipient - // nor the author - if event.kind() == Kind(4) || event.kind() == Kind(1059) { - return event_flags.tags_current_user || event_flags.author_is_current_user; - } - // Allow if an authorized_user is asking if authorized_user { return true; diff --git a/chorus-lib/src/config.rs b/chorus-lib/src/config.rs index 4ee3aab..c385f46 100644 --- a/chorus-lib/src/config.rs +++ b/chorus-lib/src/config.rs @@ -18,6 +18,7 @@ pub struct FriendlyConfig { pub description: Option, pub contact: Option, pub public_key_hex: Option, + pub open_relay: bool, pub user_hex_keys: Vec, pub verify_events: bool, pub allow_scraping: bool, @@ -45,6 +46,7 @@ impl Default for FriendlyConfig { description: None, contact: None, public_key_hex: None, + open_relay: false, user_hex_keys: vec![], verify_events: true, allow_scraping: false, @@ -74,6 +76,7 @@ impl FriendlyConfig { description, contact, public_key_hex, + open_relay, user_hex_keys, verify_events, allow_scraping, @@ -118,6 +121,7 @@ impl FriendlyConfig { description, contact, public_key, + open_relay, user_keys, user_hex_keys, verify_events, @@ -147,6 +151,7 @@ pub struct Config { pub description: Option, pub contact: Option, pub public_key: Option, + pub open_relay: bool, pub user_keys: Vec, pub user_hex_keys: Vec, pub verify_events: bool, diff --git a/contrib/chorus.toml b/contrib/chorus.toml index 74649f0..9a5c74d 100644 --- a/contrib/chorus.toml +++ b/contrib/chorus.toml @@ -95,6 +95,13 @@ key_pem_path = "/opt/chorus/etc/tls/privkey.pem" # public_key_hex = +# If open_relay is true, the relay behaves as an open public relay. +# +# Default is false. +# +# open_relay = false + + # These are the public keys (hex format) of your relay's authorized users. See BEHAVIOR.md # to understand how chorus uses these. # diff --git a/docs/CONFIG.md b/docs/CONFIG.md index f94d3b7..7e0679c 100644 --- a/docs/CONFIG.md +++ b/docs/CONFIG.md @@ -89,6 +89,12 @@ This is an optional public key (hex format) for your relay, displayed in the NIP Default is None. +### open_relay + +If open_relay true, the relay behaves as an open public relay. + +Default is false. + ### user_hex_keys These are the public keys (hex format) of your relay's authorized users. See [BEHAVIOR.md](BEHAVIOR.md) to understand how chorus uses these. diff --git a/docs/PERSONAL_RELAY.md b/docs/PERSONAL_RELAY.md index aabbbc2..a4357cd 100644 --- a/docs/PERSONAL_RELAY.md +++ b/docs/PERSONAL_RELAY.md @@ -23,3 +23,7 @@ they will need to setup SSL connections to far too many relays. It may be better for others if people were to use a smaller number of larger relay services. But who am I to say? You are the sovereign. Here is your personal relay. + +## Open Relay + +You can run chorus as an open public relay. Just set `open_relay` to true in the config. diff --git a/sample/sample.config.toml b/sample/sample.config.toml index fcb6a92..658af33 100644 --- a/sample/sample.config.toml +++ b/sample/sample.config.toml @@ -9,6 +9,7 @@ certchain_pem_path = "tls/fullchain.pem" key_pem_path = "tls/privkey.pem" name = "Chorus Sample" description = "A sample run of the Chorus relay" +open_relay = false user_hex_keys = [ "ee11a5dff40c19a555f41fe42b48f00e618c91225622ae37b6c2bb67b76c4e49" ]