mirror of https://github.com/ospab/ostp.git
fix: clamp padding size to prevent UDP fragmentation on LTE/cellular and dynamically report connection status
This commit is contained in:
parent
4384125bf8
commit
a0e38c462e
|
|
@ -661,8 +661,19 @@ impl Bridge {
|
|||
let throughput = incoming.saturating_add(outgoing);
|
||||
|
||||
tx.send(UiEvent::Traffic { incoming_bps: incoming, outgoing_bps: outgoing }).await.ok();
|
||||
|
||||
// Dynamically report connection status based on whether we have received server packets recently (last 10 seconds)
|
||||
let is_healthy = self.last_valid_recv.elapsed() < Duration::from_secs(10);
|
||||
let status = if is_healthy {
|
||||
self.metrics.connection_state.store(2, Ordering::Relaxed);
|
||||
ConnectionStatus::Established
|
||||
} else {
|
||||
self.metrics.connection_state.store(1, Ordering::Relaxed);
|
||||
ConnectionStatus::Handshaking
|
||||
};
|
||||
|
||||
tx.send(UiEvent::Metrics {
|
||||
status: ConnectionStatus::Established,
|
||||
status,
|
||||
rtt_ms: self.last_rtt_ms,
|
||||
throughput_bps: throughput,
|
||||
}).await.ok();
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ impl AdaptivePadder {
|
|||
}
|
||||
|
||||
pub fn padding_for_len(&self, payload_len: usize) -> usize {
|
||||
match self.strategy {
|
||||
let raw_pad = match self.strategy {
|
||||
PaddingStrategy::Fixed(target) => target.saturating_sub(payload_len),
|
||||
PaddingStrategy::Adaptive => {
|
||||
let base_bucket = 64;
|
||||
|
|
@ -69,7 +69,12 @@ impl AdaptivePadder {
|
|||
let target = prof.target_size(payload_len);
|
||||
target.saturating_sub(payload_len).min(self.max_pad)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Strict clamp to ensure total packet size (including overhead) never exceeds mtu_hint
|
||||
let overhead = 38;
|
||||
let max_allowed = self.mtu_hint.saturating_sub(payload_len).saturating_sub(overhead);
|
||||
raw_pad.min(max_allowed)
|
||||
}
|
||||
|
||||
pub fn build_padding(&self, payload_len: usize) -> Vec<u8> {
|
||||
|
|
|
|||
Loading…
Reference in New Issue