mirror of
https://github.com/mikedilger/chorus.git
synced 2026-08-31 07:31:01 +00:00
Add configs for: banner_url, privacy_policy, terms_of_service (the latter 2 locally served)
This commit is contained in:
parent
3f15894aaa
commit
17f9687b4c
@ -94,10 +94,22 @@ This is an optional description for your relay, displayed in the NIP-11 response
|
||||
|
||||
Default is "A default config of the Chorus relay".
|
||||
|
||||
### banner_url
|
||||
|
||||
This is an optional URL for an graphical banner representing your relay, displayed in the NIP-11 response.
|
||||
|
||||
### icon_url
|
||||
|
||||
This is an optional URL for an graphical icon representing your relay, displayed in the NIP-11 response.
|
||||
|
||||
### privacy_policy
|
||||
|
||||
This is an optional privacy policy as a blob of text (not a URL, not HTML).
|
||||
|
||||
### terms_of_service
|
||||
|
||||
This is an optional terms of service document as a blob of text (not a URL, not HTML).
|
||||
|
||||
### contact
|
||||
|
||||
This is an optional administrative contact for your relay, displayed in the NIP-11 response.
|
||||
|
||||
@ -83,7 +83,8 @@ Go ahead and edit that file to your liking. In particular:
|
||||
- Change the `ip_address` to your internet-accessible IP address (if you are running directly)
|
||||
or to 127.0.0.1 with a local port like 8080 (if you are proxying behind nginx)
|
||||
- Change the port if necessary
|
||||
- Change the name, description, icon_url and contact (e.g. your email address) as desired
|
||||
- Change the name, description, banner_url, icon_url, privacy_policy, terms_of_service and
|
||||
contact (e.g. your email address) as desired
|
||||
- Set your contact_public_key_hex (it is an option, so use `Some()`)
|
||||
- Set hex keys of users for which this relay will act as a personal relay
|
||||
|
||||
|
||||
@ -10,6 +10,8 @@ certchain_pem_path = "tls/fullchain.pem"
|
||||
key_pem_path = "tls/privkey.pem"
|
||||
name = "Chorus Sample"
|
||||
description = "A sample run of the Chorus relay"
|
||||
privacy_policy = "This relay guarantees nothing. Privacy is your concern, not ours."
|
||||
terms_of_service = "This relay guarantees nothing. Use at your own risk."
|
||||
# icon_url =
|
||||
open_relay = false
|
||||
admin_hex_keys = [
|
||||
|
||||
@ -19,7 +19,10 @@ pub struct FriendlyConfig {
|
||||
pub key_pem_path: String,
|
||||
pub name: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub banner_url: Option<String>,
|
||||
pub icon_url: Option<String>,
|
||||
pub privacy_policy: Option<String>,
|
||||
pub terms_of_service: Option<String>,
|
||||
pub contact: Option<String>,
|
||||
#[serde(alias = "public_key_hex")]
|
||||
pub contact_public_key_hex: Option<String>,
|
||||
@ -60,7 +63,10 @@ impl Default for FriendlyConfig {
|
||||
key_pem_path: "/opt/chorus/etc/tls/privkey.pem".to_string(),
|
||||
name: Some("Chorus Default".to_string()),
|
||||
description: Some("A default config of the Chorus relay".to_string()),
|
||||
banner_url: None,
|
||||
icon_url: None,
|
||||
privacy_policy: None,
|
||||
terms_of_service: None,
|
||||
contact: None,
|
||||
contact_public_key_hex: None,
|
||||
open_relay: false,
|
||||
@ -102,7 +108,10 @@ impl FriendlyConfig {
|
||||
key_pem_path,
|
||||
name,
|
||||
description,
|
||||
banner_url,
|
||||
icon_url,
|
||||
privacy_policy,
|
||||
terms_of_service,
|
||||
contact,
|
||||
contact_public_key_hex,
|
||||
open_relay,
|
||||
@ -159,7 +168,10 @@ impl FriendlyConfig {
|
||||
key_pem_path,
|
||||
name,
|
||||
description,
|
||||
banner_url,
|
||||
icon_url,
|
||||
privacy_policy,
|
||||
terms_of_service,
|
||||
contact,
|
||||
contact_public_key,
|
||||
open_relay,
|
||||
@ -201,7 +213,10 @@ pub struct Config {
|
||||
pub key_pem_path: String,
|
||||
pub name: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub banner_url: Option<String>,
|
||||
pub icon_url: Option<String>,
|
||||
pub privacy_policy: Option<String>,
|
||||
pub terms_of_service: Option<String>,
|
||||
pub contact: Option<String>,
|
||||
pub contact_public_key: Option<Pubkey>,
|
||||
pub open_relay: bool,
|
||||
@ -238,6 +253,8 @@ impl Default for Config {
|
||||
}
|
||||
|
||||
impl Config {
|
||||
/// Get the URI for our server matching the inner Uri, overridden with either
|
||||
/// our base_url parts or our hostname/port.
|
||||
pub fn uri_parts(&self, inner: Uri, http: bool) -> Result<http::uri::Parts, Error> {
|
||||
let mut uri_parts = inner.into_parts();
|
||||
|
||||
|
||||
@ -180,9 +180,9 @@ async fn handle_http_request(
|
||||
}
|
||||
|
||||
let mut web_socket_config = WebSocketConfig::default();
|
||||
web_socket_config.max_write_buffer_size = 1024 * 1024; // 1 MB
|
||||
web_socket_config.max_write_buffer_size = 1024 * 1024; // 1 MB
|
||||
web_socket_config.max_message_size = Some(1024 * 1024); // 1 MB
|
||||
web_socket_config.max_frame_size = Some(1024 * 1024); // 1 MB
|
||||
web_socket_config.max_frame_size = Some(1024 * 1024); // 1 MB
|
||||
|
||||
let (mut response, websocket) =
|
||||
hyper_tungstenite::upgrade(&mut request, Some(web_socket_config))?;
|
||||
|
||||
@ -53,6 +53,36 @@ pub async fn serve_http(
|
||||
|
||||
let uri = request.uri().to_owned();
|
||||
|
||||
if p == "/privacy-policy" {
|
||||
let config = &*GLOBALS.config.read();
|
||||
if let Some(pp) = &config.privacy_policy {
|
||||
let response = Response::builder()
|
||||
.header("Access-Control-Allow-Origin", "*")
|
||||
.header("Access-Control-Allow-Headers", "Authorization, *")
|
||||
.header("Access-Control-Allow-Methods", "*")
|
||||
.header("Allow", "OPTIONS, GET, HEAD")
|
||||
.header("Content-Type", "text/plain")
|
||||
.status(StatusCode::OK)
|
||||
.body(Full::new(pp.clone().into()).map_err(|e| e.into()).boxed())?;
|
||||
return Ok(response);
|
||||
}
|
||||
}
|
||||
|
||||
if p == "/terms-of-service" {
|
||||
let config = &*GLOBALS.config.read();
|
||||
if let Some(tos) = &config.terms_of_service {
|
||||
let response = Response::builder()
|
||||
.header("Access-Control-Allow-Origin", "*")
|
||||
.header("Access-Control-Allow-Headers", "Authorization, *")
|
||||
.header("Access-Control-Allow-Methods", "*")
|
||||
.header("Allow", "OPTIONS, GET, HEAD")
|
||||
.header("Content-Type", "text/plain")
|
||||
.status(StatusCode::OK)
|
||||
.body(Full::new(tos.clone().into()).map_err(|e| e.into()).boxed())?;
|
||||
return Ok(response);
|
||||
}
|
||||
}
|
||||
|
||||
// Try blossom if enabled
|
||||
if GLOBALS.config.read().blossom_directory.is_some() {
|
||||
match blossom::handle(request).await {
|
||||
|
||||
@ -5,6 +5,7 @@ use crate::ip::HashedPeer;
|
||||
use http_body_util::combinators::BoxBody;
|
||||
use http_body_util::{BodyExt, Full};
|
||||
use hyper::body::Bytes;
|
||||
use hyper::http::uri::Uri;
|
||||
use hyper::{Response, StatusCode};
|
||||
|
||||
pub async fn serve_nip11(peer: HashedPeer) -> Result<Response<BoxBody<Bytes, Error>>, Error> {
|
||||
@ -80,18 +81,18 @@ fn build_rid(config: &Config) -> String {
|
||||
rid.push_str(description);
|
||||
rid.push('\"');
|
||||
}
|
||||
if let Some(banner_url) = &config.banner_url {
|
||||
rid.push(',');
|
||||
rid.push_str("\"banner\":\"");
|
||||
rid.push_str(banner_url);
|
||||
rid.push('\"');
|
||||
}
|
||||
if let Some(icon_url) = &config.icon_url {
|
||||
rid.push(',');
|
||||
rid.push_str("\"icon\":\"");
|
||||
rid.push_str(icon_url);
|
||||
rid.push('\"');
|
||||
}
|
||||
if let Some(contact) = &config.contact {
|
||||
rid.push(',');
|
||||
rid.push_str("\"contact\":\"");
|
||||
rid.push_str(contact);
|
||||
rid.push('\"');
|
||||
}
|
||||
if let Some(pubkey) = &config.contact_public_key {
|
||||
let mut pkh: [u8; 64] = [0; 64];
|
||||
pubkey.write_hex(&mut pkh).unwrap();
|
||||
@ -100,6 +101,44 @@ fn build_rid(config: &Config) -> String {
|
||||
rid.push_str(unsafe { std::str::from_utf8_unchecked(pkh.as_slice()) });
|
||||
rid.push('\"');
|
||||
}
|
||||
if let Some(contact) = &config.contact {
|
||||
rid.push(',');
|
||||
rid.push_str("\"contact\":\"");
|
||||
rid.push_str(contact);
|
||||
rid.push('\"');
|
||||
}
|
||||
if config.privacy_policy.is_some() {
|
||||
rid.push(',');
|
||||
rid.push_str("\"privacy_policy\":\"");
|
||||
let url = match config.uri_parts(
|
||||
Uri::from_static("https://authority-will-be-replaced/privacy-policy"),
|
||||
true,
|
||||
) {
|
||||
Ok(parts) => match Uri::from_parts(parts) {
|
||||
Ok(uri) => format!("{}", uri),
|
||||
Err(_) => "".to_owned(),
|
||||
},
|
||||
Err(_) => "".to_owned(),
|
||||
};
|
||||
rid.push_str(&url);
|
||||
rid.push('\"');
|
||||
}
|
||||
if config.terms_of_service.is_some() {
|
||||
rid.push(',');
|
||||
rid.push_str("\"terms_of_service\":\"");
|
||||
let url = match config.uri_parts(
|
||||
Uri::from_static("https://authority-will-be-replaced/terms-of-service"),
|
||||
true,
|
||||
) {
|
||||
Ok(parts) => match Uri::from_parts(parts) {
|
||||
Ok(uri) => format!("{}", uri),
|
||||
Err(_) => "".to_owned(),
|
||||
},
|
||||
Err(_) => "".to_owned(),
|
||||
};
|
||||
rid.push_str(&url);
|
||||
rid.push('\"');
|
||||
}
|
||||
|
||||
// Limitation
|
||||
rid.push(',');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user