cca leak fix and log reduction for release builds

This commit is contained in:
Green Sky 2023-08-19 19:51:40 +02:00
parent 211cce65de
commit 099abc3a09
No known key found for this signature in database
5 changed files with 29 additions and 15 deletions

@ -1 +1 @@
Subproject commit 70a234cdae751141f48b7a53a4e1cbedd84f31b2
Subproject commit dd596bdad8d71654ff21dd3a032d6eb2dd7139a8

View File

@ -182,7 +182,7 @@ void NGCFT1::updateSendTransfer(float time_delta, uint32_t group_number, uint32_
if (timeouts_set.count({idx, id})) {
// TODO: can fail
sendPKG_FT1_DATA(group_number, peer_number, idx, id, data.data(), data.size());
peer.cca.onLoss({idx, id}, false);
peer.cca->onLoss({idx, id}, false);
time_since_activity = 0.f;
timeouts_set.erase({idx, id});
}
@ -201,7 +201,7 @@ void NGCFT1::updateSendTransfer(float time_delta, uint32_t group_number, uint32_
// 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);
peer.cca->onLoss({idx, id}, true);
timeouts_set.erase({idx, id});
});
@ -212,7 +212,7 @@ void NGCFT1::updateSendTransfer(float time_delta, uint32_t group_number, uint32_
// if chunks in flight < window size (2)
//while (tf.ssb.size() < ngc_ft1_ctx->options.packet_window_size) {
int64_t can_packet_size {static_cast<int64_t>(peer.cca.canSend())};
int64_t can_packet_size {static_cast<int64_t>(peer.cca->canSend())};
//if (can_packet_size) {
//std::cerr << "FT: can_packet_size: " << can_packet_size;
//}
@ -226,7 +226,7 @@ void NGCFT1::updateSendTransfer(float time_delta, uint32_t group_number, uint32_
size_t chunk_size = std::min<size_t>({
//496u,
//996u,
peer.cca.MAXIMUM_SEGMENT_DATA_SIZE,
peer.cca->MAXIMUM_SEGMENT_DATA_SIZE,
static_cast<size_t>(can_packet_size),
tf.file_size - tf.file_size_current
});
@ -259,7 +259,7 @@ void NGCFT1::updateSendTransfer(float time_delta, uint32_t group_number, uint32_
uint16_t seq_id = tf.ssb.add(std::move(new_data));
sendPKG_FT1_DATA(group_number, peer_number, idx, seq_id, tf.ssb.entries.at(seq_id).data.data(), tf.ssb.entries.at(seq_id).data.size());
peer.cca.onSent({idx, seq_id}, chunk_size);
peer.cca->onSent({idx, seq_id}, chunk_size);
#if defined(EXTRA_LOGGING) && EXTRA_LOGGING == 1
fprintf(stderr, "FT: sent data size: %ld (seq %d)\n", chunk_size, seq_id);
@ -280,7 +280,7 @@ void NGCFT1::updateSendTransfer(float time_delta, uint32_t group_number, uint32_
//if (time_since_activity >= ngc_ft1_ctx->options.sending_resend_without_ack_after) {
if (timeouts_set.count({idx, id})) {
sendPKG_FT1_DATA(group_number, peer_number, idx, id, data.data(), data.size());
peer.cca.onLoss({idx, id}, false);
peer.cca->onLoss({idx, id}, false);
time_since_activity = 0.f;
timeouts_set.erase({idx, id});
}
@ -292,7 +292,7 @@ void NGCFT1::updateSendTransfer(float time_delta, uint32_t group_number, uint32_
// 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);
peer.cca->onLoss({idx, id}, true);
timeouts_set.erase({idx, id});
});
@ -308,7 +308,7 @@ void NGCFT1::updateSendTransfer(float time_delta, uint32_t group_number, uint32_
}
void NGCFT1::iteratePeer(float time_delta, uint32_t group_number, uint32_t peer_number, Group::Peer& peer) {
auto timeouts = peer.cca.getTimeouts();
auto timeouts = peer.cca->getTimeouts();
std::set<LEDBAT::SeqIDType> timeouts_set{timeouts.cbegin(), timeouts.cend()};
for (size_t idx = 0; idx < peer.send_transfers.size(); idx++) {
@ -425,7 +425,9 @@ bool NGCFT1::NGC_FT1_send_message_public(
}
bool NGCFT1::onEvent(const Events::NGCEXT_ft1_request& e) {
//#if !NDEBUG
std::cout << "NGCFT1: FT1_REQUEST fk:" << e.file_kind << " [" << bin2hex(e.file_id) << "]\n";
//#endif
// .... just rethrow??
// TODO: dont
@ -440,7 +442,9 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_request& e) {
}
bool NGCFT1::onEvent(const Events::NGCEXT_ft1_init& e) {
//#if !NDEBUG
std::cout << "NGCFT1: FT1_INIT fk:" << e.file_kind << " fs:" << e.file_size << " tid:" << int(e.transfer_id) << " [" << bin2hex(e.file_id) << "]\n";
//#endif
bool accept = false;
dispatch(
@ -466,7 +470,7 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_init& e) {
auto& peer = groups[e.group_number].peers[e.peer_number];
if (peer.recv_transfers[e.transfer_id].has_value()) {
std::cerr << "NGCFT1 warning: overwriting existing recv_transfer " << e.transfer_id << "\n";
std::cerr << "NGCFT1 warning: overwriting existing recv_transfer " << int(e.transfer_id) << "\n";
}
peer.recv_transfers[e.transfer_id] = Group::Peer::RecvTransfer{
@ -482,7 +486,9 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_init& e) {
}
bool NGCFT1::onEvent(const Events::NGCEXT_ft1_init_ack& e) {
//#if !NDEBUG
std::cout << "NGCFT1: FT1_INIT_ACK\n";
//#endif
// we now should start sending data
@ -513,7 +519,9 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_init_ack& e) {
}
bool NGCFT1::onEvent(const Events::NGCEXT_ft1_data& e) {
#if !NDEBUG
std::cout << "NGCFT1: FT1_DATA\n";
#endif
if (e.data.empty()) {
std::cerr << "NGCFT1 error: data of size 0!\n";
@ -579,7 +587,9 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_data& e) {
}
bool NGCFT1::onEvent(const Events::NGCEXT_ft1_data_ack& e) {
#if !NDEBUG
std::cout << "NGCFT1: FT1_DATA_ACK\n";
#endif
if (!groups.count(e.group_number)) {
std::cerr << "NGCFT1 warning: data_ack for unknown group\n";
@ -613,7 +623,7 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_data_ack& e) {
seqs.push_back({e.transfer_id, it});
transfer.ssb.erase(it);
}
peer.cca.onAck(seqs);
peer.cca->onAck(seqs);
// delete if all packets acked
if (transfer.file_size == transfer.file_size_current && transfer.ssb.size() == 0) {
@ -701,6 +711,9 @@ bool NGCFT1::onToxEvent(const Tox_Event_Group_Peer_Exit* e) {
it_opt.reset();
}
// reset cca
peer.cca = std::make_unique<LEDBAT>(500-4); // TODO: replace with tox_group_max_custom_lossy_packet_length()-4
return false;
}

View File

@ -15,6 +15,7 @@
#include <map>
#include <set>
#include <memory>
namespace Events {
@ -138,7 +139,7 @@ class NGCFT1 : public ToxEventI, public NGCEXTEventI, public NGCFT1EventProvider
struct Group {
struct Peer {
LEDBAT cca{500-4}; // TODO: replace with tox_group_max_custom_lossy_packet_length()-4
std::unique_ptr<LEDBAT> cca = std::make_unique<LEDBAT>(500-4); // TODO: replace with tox_group_max_custom_lossy_packet_length()-4
struct RecvTransfer {
uint32_t file_kind;

View File

@ -885,7 +885,7 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_done& e) {
cc.have_count += 1;
if (cc.have_count == info.chunks.size()) {
// debug check
for (const bool it : cc.have_chunk) {
for ([[maybe_unused]] const bool it : cc.have_chunk) {
assert(it);
}

View File

@ -102,8 +102,8 @@ class SHA1_NGCFT1 : public RegistryMessageModelEventI, public NGCFT1EventI {
public: // TODO: config
bool _udp_only {false};
size_t _max_concurrent_in {8};
size_t _max_concurrent_out {4};
size_t _max_concurrent_in {4};
size_t _max_concurrent_out {6};
public:
SHA1_NGCFT1(