From ad918a3253bb942f2c62bdfbe0dad7a273ff3142 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Fri, 15 Dec 2023 15:31:32 +0100 Subject: [PATCH] add random cap (1020-1220) and tighten cubic rate limit more --- solanaceae/ngc_ft1/cubic.cpp | 8 ++++++-- solanaceae/ngc_ft1/ngcft1.cpp | 10 +++++++++- solanaceae/ngc_ft1/ngcft1.hpp | 3 +++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/solanaceae/ngc_ft1/cubic.cpp b/solanaceae/ngc_ft1/cubic.cpp index ce842e8..7fdb426 100644 --- a/solanaceae/ngc_ft1/cubic.cpp +++ b/solanaceae/ngc_ft1/cubic.cpp @@ -84,11 +84,15 @@ int64_t CUBIC::canSend(void) { // also limit to max sendrate per tick, which is usually smaller than window // this is mostly to prevent spikes on empty windows + const auto rate = window / getCurrentDelay(); + // assuming at most 20ms tick interval // TODO: pass down actual tick interval - const auto rate = window / getCurrentDelay(); + //const float time_delta = 0.02f; // 20ms + const float time_delta = 0.01666f; + // we dont want this limit to fall below atleast 1 segment - const int64_t max_bytes_per_tick = std::max(rate * 0.02f + 0.5f, MAXIMUM_SEGMENT_SIZE); + const int64_t max_bytes_per_tick = std::max(rate * time_delta + 0.5f, MAXIMUM_SEGMENT_SIZE); cspace_bytes = std::min(cspace_bytes, max_bytes_per_tick); // limit to whole packets diff --git a/solanaceae/ngc_ft1/ngcft1.cpp b/solanaceae/ngc_ft1/ngcft1.cpp index 39246c0..4b110bd 100644 --- a/solanaceae/ngc_ft1/ngcft1.cpp +++ b/solanaceae/ngc_ft1/ngcft1.cpp @@ -4,6 +4,7 @@ #include "./cubic.hpp" #include "./ledbat.hpp" +#include #include #include @@ -513,7 +514,14 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_init_ack& e) { const auto negotiated_packet_data_size = std::min(e.max_lossy_data_size, _t.toxGroupMaxCustomLossyPacketLength()-4); // TODO: reset cca with new pkg size if (!peer.cca) { - peer.max_packet_data_size = negotiated_packet_data_size; + // make random max of [1020-1220] + const uint32_t random_max_data_size = (1024-4) + _rng()%201; + const uint32_t randomized_negotiated_packet_data_size = std::min(negotiated_packet_data_size, random_max_data_size); + + peer.max_packet_data_size = randomized_negotiated_packet_data_size; + + std::cerr << "NGCFT1: creating cca with max:" << peer.max_packet_data_size << "\n"; + peer.cca = std::make_unique(peer.max_packet_data_size); //peer.cca = std::make_unique(peer.max_packet_data_size); //peer.cca = std::make_unique(peer.max_packet_data_size); diff --git a/solanaceae/ngc_ft1/ngcft1.hpp b/solanaceae/ngc_ft1/ngcft1.hpp index c0ac8ba..424c35a 100644 --- a/solanaceae/ngc_ft1/ngcft1.hpp +++ b/solanaceae/ngc_ft1/ngcft1.hpp @@ -17,6 +17,7 @@ #include #include #include +#include namespace Events { @@ -132,6 +133,8 @@ class NGCFT1 : public ToxEventI, public NGCEXTEventI, public NGCFT1EventProvider ToxEventProviderI& _tep; NGCEXTEventProviderI& _neep; + std::default_random_engine _rng{std::random_device{}()}; + // TODO: config size_t acks_per_packet {3u}; // 3 float init_retry_timeout_after {5.f}; // 10sec