feat: add network.ping_interval setting

Add a ping interval setting that allows you to customize the websocket
ping interval. The default of 5 minutes may be too high for some proxy
servers that disconnect connections that are held open for too long.
This commit is contained in:
William Casarin 2022-11-04 17:58:28 -07:00 committed by Greg Heartsfield
parent a6cb6f8486
commit 50577b2dfa
3 changed files with 6 additions and 1 deletions

View File

@ -51,6 +51,9 @@ port = 8080
#remote_ip_header = "x-forwarded-for"
#remote_ip_header = "cf-connecting-ip"
# Websocket ping interval in seconds, defaults to 5 minutes
#ping_interval = 300
[options]
# Reject events that have timestamps greater than this many seconds in
# the future. Recommended to reject anything greater than 30 minutes

View File

@ -29,6 +29,7 @@ pub struct Network {
pub port: u16,
pub address: String,
pub remote_ip_header: Option<String>, // retrieve client IP from this HTTP header if present
pub ping_interval: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@ -207,6 +208,7 @@ impl Default for Settings {
},
network: Network {
port: 8080,
ping_interval: 300,
address: "0.0.0.0".to_owned(),
remote_ip_header: None,
},

View File

@ -427,7 +427,7 @@ async fn nostr_server(
let mut last_message_time = Instant::now();
// ping interval (every 5 minutes)
let default_ping_dur = Duration::from_secs(300);
let default_ping_dur = Duration::from_secs(settings.network.ping_interval.into());
// disconnect after 20 minutes without a ping response or event.
let max_quiet_time = Duration::from_secs(60 * 20);