add random cap (1020-1220) and tighten cubic rate limit more

This commit is contained in:
Green Sky 2023-12-15 15:31:32 +01:00
parent 70cea0d219
commit ad918a3253
No known key found for this signature in database
3 changed files with 18 additions and 3 deletions

View File

@ -84,11 +84,15 @@ int64_t CUBIC::canSend(void) {
// also limit to max sendrate per tick, which is usually smaller than window // also limit to max sendrate per tick, which is usually smaller than window
// this is mostly to prevent spikes on empty windows // this is mostly to prevent spikes on empty windows
const auto rate = window / getCurrentDelay();
// assuming at most 20ms tick interval // assuming at most 20ms tick interval
// TODO: pass down actual 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 // we dont want this limit to fall below atleast 1 segment
const int64_t max_bytes_per_tick = std::max<int64_t>(rate * 0.02f + 0.5f, MAXIMUM_SEGMENT_SIZE); const int64_t max_bytes_per_tick = std::max<int64_t>(rate * time_delta + 0.5f, MAXIMUM_SEGMENT_SIZE);
cspace_bytes = std::min<int64_t>(cspace_bytes, max_bytes_per_tick); cspace_bytes = std::min<int64_t>(cspace_bytes, max_bytes_per_tick);
// limit to whole packets // limit to whole packets

View File

@ -4,6 +4,7 @@
#include "./cubic.hpp" #include "./cubic.hpp"
#include "./ledbat.hpp" #include "./ledbat.hpp"
#include <cstdint>
#include <solanaceae/toxcore/utils.hpp> #include <solanaceae/toxcore/utils.hpp>
#include <sodium.h> #include <sodium.h>
@ -513,7 +514,14 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_init_ack& e) {
const auto negotiated_packet_data_size = std::min<uint32_t>(e.max_lossy_data_size, _t.toxGroupMaxCustomLossyPacketLength()-4); const auto negotiated_packet_data_size = std::min<uint32_t>(e.max_lossy_data_size, _t.toxGroupMaxCustomLossyPacketLength()-4);
// TODO: reset cca with new pkg size // TODO: reset cca with new pkg size
if (!peer.cca) { 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<CUBIC>(peer.max_packet_data_size); peer.cca = std::make_unique<CUBIC>(peer.max_packet_data_size);
//peer.cca = std::make_unique<LEDBAT>(peer.max_packet_data_size); //peer.cca = std::make_unique<LEDBAT>(peer.max_packet_data_size);
//peer.cca = std::make_unique<FlowOnly>(peer.max_packet_data_size); //peer.cca = std::make_unique<FlowOnly>(peer.max_packet_data_size);

View File

@ -17,6 +17,7 @@
#include <map> #include <map>
#include <set> #include <set>
#include <memory> #include <memory>
#include <random>
namespace Events { namespace Events {
@ -132,6 +133,8 @@ class NGCFT1 : public ToxEventI, public NGCEXTEventI, public NGCFT1EventProvider
ToxEventProviderI& _tep; ToxEventProviderI& _tep;
NGCEXTEventProviderI& _neep; NGCEXTEventProviderI& _neep;
std::default_random_engine _rng{std::random_device{}()};
// TODO: config // TODO: config
size_t acks_per_packet {3u}; // 3 size_t acks_per_packet {3u}; // 3
float init_retry_timeout_after {5.f}; // 10sec float init_retry_timeout_after {5.f}; // 10sec