Compare commits

..

No commits in common. "95bfa2473c30c8a43e29199621398f1d4bb76ef4" and "e1b5dd20804503668572edf15ef1b2db2b1847b3" have entirely different histories.

4 changed files with 51 additions and 46 deletions

View File

@ -11,12 +11,15 @@
#include <iostream>
#include <limits>
// https://youtu.be/0HRwNSA-JYM
inline constexpr bool PLOTTING = false;
LEDBAT::LEDBAT(void) {
_time_start_offset = clock::now();
{ // add some high delay values
// spec want +inf
//_rtt_buffer.push_back(_base_delay);
//_rtt_buffer.push_back(_base_delay);
//_rtt_buffer.push_back(_base_delay);
}
}
size_t LEDBAT::canSend(void) const {
@ -24,6 +27,16 @@ size_t LEDBAT::canSend(void) const {
return 496u;
}
//const float time_since_last_sent {std::min(
//getTimeNow() - std::get<1>(_in_flight.back()),
//0.01f // 10ms max
//)};
//const float bps {std::min(
//(_cwnd / getCurrentDelay()),
//max_byterate_allowed
//)};
const int64_t cspace = _cwnd - _in_flight_bytes;
if (cspace < 496) {
return 0u;
@ -36,27 +49,24 @@ size_t LEDBAT::canSend(void) const {
size_t space = std::ceil(std::min(cspace, fspace) / 496.f) * 496.f;
// data size, no overhead
//const int64_t can_send_size {std::min<int64_t>(
//bps * time_since_last_sent - segment_overhead,
//maximum_segment_size - segment_overhead
//)};
//const int64_t can_send_size {static_cast<int64_t>(bps * time_since_last_sent - segment_overhead)};
//if (can_send_size < 100) {
//return 0;
//} else {
//return can_send_size;
//}
return space;
}
std::vector<LEDBAT::SeqIDType> LEDBAT::getTimeouts(void) const {
std::vector<LEDBAT::SeqIDType> list;
// after 2 delays we trigger timeout
const auto now_adjusted = getTimeNow() - getCurrentDelay()*2.f;
for (const auto& [seq, time_stamp, size] : _in_flight) {
if (now_adjusted > time_stamp) {
list.push_back(seq);
}
}
return list;
}
void LEDBAT::onSent(SeqIDType seq, size_t data_size) {
if (false) {
if (true) {
for (const auto& it : _in_flight) {
assert(std::get<0>(it) != seq);
}
@ -97,7 +107,12 @@ void LEDBAT::onAck(std::vector<SeqIDType> seqs) {
return; // not found, ignore
}
//addRTT(now - most_recent);
updateWindows();
// update cto - no? we dont handle timeouts
}
void LEDBAT::onLoss(SeqIDType seq, bool discard) {
@ -114,7 +129,7 @@ void LEDBAT::onLoss(SeqIDType seq, bool discard) {
// at most once per rtt?
if (PLOTTING) {
if (false) {
std::cerr << "CCA: onLoss: TIME: " << getTimeNow() << "\n";
}
@ -228,7 +243,7 @@ void LEDBAT::updateWindows(void) {
} // no else, we on point. very unlikely with float
}
if (PLOTTING) { // plotting
if (false) { // plotting
std::cerr << std::fixed << "CCA: onAck: TIME: " << now << " cwnd: " << _cwnd << "\n";
std::cerr << std::fixed << "CCA: onAck: TIME: " << now << " fwnd: " << _fwnd << "\n";
std::cerr << std::fixed << "CCA: onAck: TIME: " << now << " current_delay: " << current_delay << "\n";

View File

@ -29,17 +29,17 @@ struct LEDBAT {
static_assert(maximum_segment_size == 574); // mesured in wireshark
// ledbat++ says 60ms, we might need other values if relayed
//const float target_delay {0.060f};
const float target_delay {0.030f};
const float target_delay {0.060f};
//const float target_delay {0.030f};
//const float target_delay {0.120f}; // 2x if relayed?
// TODO: use a factor for multiple of rtt
static constexpr size_t current_delay_filter_window {16*4};
static constexpr size_t current_delay_filter_window {16*4*2};
//static constexpr size_t rtt_buffer_size_max {2000};
//float max_byterate_allowed {10*1024*1024}; // 10MiB/s
float max_byterate_allowed {1*1024*1024};
float max_byterate_allowed {10*1024*1024}; // 10MiB/s
//float max_byterate_allowed {2*1024*1024};
public:
LEDBAT(void);
@ -55,9 +55,6 @@ struct LEDBAT {
// respect max_byterate_allowed
size_t canSend(void) const;
// get the list of timed out seq_ids
std::vector<SeqIDType> getTimeouts(void) const;
public: // callbacks
// data size is without overhead
void onSent(SeqIDType seq, size_t data_size);

View File

@ -11,7 +11,6 @@
// TODO: should i really use both?
#include <unordered_map>
#include <map>
#include <set>
#include <optional>
#include <cassert>
#include <cstdio>
@ -217,12 +216,10 @@ void NGC_FT1_iterate(Tox *tox, NGC_FT1* ngc_ft1_ctx, float time_delta) {
for (auto& [group_number, group] : ngc_ft1_ctx->groups) {
for (auto& [peer_number, peer] : group.peers) {
auto timeouts = peer.cca.getTimeouts();
std::set<LEDBAT::SeqIDType> timeouts_set{timeouts.cbegin(), timeouts.cend()};
//for (auto& tf_opt : peer.send_transfers) {
for (size_t idx = 0; idx < peer.send_transfers.size(); idx++) {
auto& tf_opt = peer.send_transfers[idx];
if (tf_opt.has_value()) {
if (tf_opt) {
auto& tf = tf_opt.value();
tf.time_since_activity += time_delta;
@ -248,13 +245,11 @@ void NGC_FT1_iterate(Tox *tox, NGC_FT1* ngc_ft1_ctx, float time_delta) {
case State::SENDING: {
tf.ssb.for_each(time_delta, [&](uint16_t id, const std::vector<uint8_t>& data, float& time_since_activity) {
// no ack after 5 sec -> resend
//if (time_since_activity >= ngc_ft1_ctx->options.sending_resend_without_ack_after) {
if (timeouts_set.count({idx, id})) {
if (time_since_activity >= ngc_ft1_ctx->options.sending_resend_without_ack_after) {
// TODO: can fail
_send_pkg_FT1_DATA(tox, group_number, peer_number, idx, id, data.data(), data.size());
peer.cca.onLoss({idx, id}, false);
time_since_activity = 0.f;
timeouts_set.erase({idx, id});
}
});
@ -266,7 +261,6 @@ void NGC_FT1_iterate(Tox *tox, NGC_FT1* ngc_ft1_ctx, float time_delta) {
// clean up cca
tf.ssb.for_each(time_delta, [&](uint16_t id, const std::vector<uint8_t>& data, float& time_since_activity) {
peer.cca.onLoss({idx, id}, true);
timeouts_set.erase({idx, id});
});
tf_opt.reset();
@ -328,12 +322,10 @@ void NGC_FT1_iterate(Tox *tox, NGC_FT1* ngc_ft1_ctx, float time_delta) {
case State::FINISHING: // we still have unacked packets
tf.ssb.for_each(time_delta, [&](uint16_t id, const std::vector<uint8_t>& data, float& time_since_activity) {
// no ack after 5 sec -> resend
//if (time_since_activity >= ngc_ft1_ctx->options.sending_resend_without_ack_after) {
if (timeouts_set.count({idx, id})) {
if (time_since_activity >= ngc_ft1_ctx->options.sending_resend_without_ack_after) {
_send_pkg_FT1_DATA(tox, group_number, peer_number, idx, id, data.data(), data.size());
peer.cca.onLoss({idx, id}, false);
time_since_activity = 0.f;
timeouts_set.erase({idx, id});
}
});
if (tf.time_since_activity >= ngc_ft1_ctx->options.sending_give_up_after) {
@ -344,7 +336,6 @@ void NGC_FT1_iterate(Tox *tox, NGC_FT1* ngc_ft1_ctx, float time_delta) {
// clean up cca
tf.ssb.for_each(time_delta, [&](uint16_t id, const std::vector<uint8_t>& data, float& time_since_activity) {
peer.cca.onLoss({idx, id}, true);
timeouts_set.erase({idx, id});
});
tf_opt.reset();
@ -889,7 +880,7 @@ static void _handle_FT1_DATA_ACK(
// delete if all packets acked
if (transfer.file_size == transfer.file_size_current && transfer.ssb.size() == 0) {
fprintf(stderr, "FT: %d done\n", transfer_id);
peer.send_transfers[transfer_id].reset();
peer.send_transfers[transfer_id] = std::nullopt;
}
}

View File

@ -22,8 +22,10 @@ struct NGC_FT1_options {
float init_retry_timeout_after; // 10sec
//float sending_resend_without_ack_after; // 5sec
float sending_resend_without_ack_after; // 5sec
float sending_give_up_after; // 30sec
size_t packet_window_size; // 2
};
// uint32_t - same as tox friend ft