Skip to content

Commit 2d9d047

Browse files
committed
Add DERP userspace keepalives
Signed-off-by: Daniel Fetti <[email protected]>
1 parent 30ad414 commit 2d9d047

File tree

7 files changed

+357
-75
lines changed

7 files changed

+357
-75
lines changed

.unreleased/LLT-5639

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add DERP userspace keepalives

crates/telio-model/src/features.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ pub struct FeatureDerp {
327327
pub tcp_keepalive: Option<u32>,
328328
/// Derp will send empty messages after this many seconds of not sending/receiving any data [default 60s]
329329
pub derp_keepalive: Option<u32>,
330+
/// Poll Keepalive: Application level keepalives meant to replace the TCP keepalives
331+
pub poll_keepalive: Option<u32>,
330332
/// Enable polling of remote peer states to reduce derp traffic
331333
pub enable_polling: Option<bool>,
332334
/// Use Mozilla's root certificates instead of OS ones [default false]
@@ -536,6 +538,7 @@ mod tests {
536538
"derp": {
537539
"tcp_keepalive": 13,
538540
"derp_keepalive": 14,
541+
"poll_keepalive": 15,
539542
"enable_polling": true,
540543
"use_built_in_root_certificates": true
541544
},
@@ -626,6 +629,7 @@ mod tests {
626629
derp: Some(FeatureDerp {
627630
tcp_keepalive: Some(13),
628631
derp_keepalive: Some(14),
632+
poll_keepalive: Some(15),
629633
enable_polling: Some(true),
630634
use_built_in_root_certificates: true,
631635
}),

crates/telio-relay/src/derp.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,35 +127,41 @@ struct State {
127127
/// Keepalive values that help keeping Derp connection in conntrack alive,
128128
/// so server can send traffic after being silent for a while
129129
/// *derp_keepalive* is also used as an interval for retrieving remote peer states.
130+
/// TODO: Update comments for Poll Keepalives
130131
#[derive(Debug, Clone, PartialEq, Eq)]
131132
pub struct DerpKeepaliveConfig {
132133
tcp_keepalive: u32,
133134
derp_keepalive: u32,
135+
poll_keepalive: Option<u32>,
134136
}
135137

136138
impl From<&Option<FeatureDerp>> for DerpKeepaliveConfig {
137139
fn from(derp: &Option<FeatureDerp>) -> Self {
138140
let mut tcp_keepalive = proto::DERP_TCP_KEEPALIVE_INTERVAL;
139141
let mut derp_keepalive = proto::DERP_KEEPALIVE_INTERVAL;
142+
let mut poll_keepalive = None;
140143
if let Some(derp) = derp {
141144
if let Some(tcp_ka) = derp.tcp_keepalive {
142145
tcp_keepalive = tcp_ka;
143146
}
144147
if let Some(derp_ka) = derp.derp_keepalive {
145148
derp_keepalive = derp_ka;
146149
}
150+
poll_keepalive = derp.poll_keepalive;
147151
}
148152

149153
DerpKeepaliveConfig {
150154
tcp_keepalive,
151155
derp_keepalive,
156+
poll_keepalive,
152157
}
153158
}
154159
}
155160

156161
const DEFAULT_SERVER_KEEPALIVE_CONFIG: DerpKeepaliveConfig = DerpKeepaliveConfig {
157162
tcp_keepalive: proto::DERP_TCP_KEEPALIVE_INTERVAL,
158163
derp_keepalive: proto::DERP_KEEPALIVE_INTERVAL,
164+
poll_keepalive: None,
159165
};
160166

161167
/// Derp configuration
@@ -726,8 +732,9 @@ impl Runtime for State {
726732
},
727733
// On tick send derp poll request to derp stream
728734
Some((permit, _)) = wait_for_tx(&c.comms_direct.tx, poll_timer_tick) => {
729-
if config.enable_polling {
735+
if config.enable_polling || config.server_keepalives.poll_keepalive.is_some() {
730736
self.derp_poll_session = self.derp_poll_session.wrapping_add(1);
737+
telio_log_debug!("Sending DerpPollRequest with session {}", self.derp_poll_session);
731738
Self::handle_outcoming_payload_direct(permit, PacketControl::DerpPollRequest(DerpPollRequestMsg::new(
732739
self.derp_poll_session, &config.meshnet_peers
733740
))).await;

0 commit comments

Comments
 (0)