Skip to main content

Module keepalive

Module keepalive 

Source
Expand description

§VCL Keepalive

Automatic keepalive for maintaining connections through NAT and firewalls.

§Why keepalive matters for VPN

Client ──── NAT ──── Internet ──── Server

NAT table entry:
  client:4500 → server:4500   TTL: 30s (mobile), 120s (home), 300s (corporate)

Without keepalive:
  30s of silence → NAT drops entry → connection dead

With keepalive:
  Every 25s → tiny ping → NAT entry refreshed → connection alive

§Example

use vcl_protocol::keepalive::{KeepaliveConfig, KeepaliveManager};
use std::time::Duration;

let config = KeepaliveConfig::aggressive(); // 25s interval, for mobile NAT
let mut manager = KeepaliveManager::new(config);

// Call this in your main loop
if manager.should_send_keepalive() {
    // send ping here
    manager.record_keepalive_sent();
}

// When pong arrives
manager.record_pong_received();

Structs§

KeepaliveConfig
Configuration for the keepalive mechanism.
KeepaliveManager
Manages keepalive timing, miss counting, and adaptive interval adjustment.

Enums§

KeepaliveAction
The result of a keepalive check — what action to take.
KeepalivePreset
Preset keepalive strategies for different network environments.