better receiving transfer cleanup (reduces log spam)

This commit is contained in:
Green Sky 2024-07-15 14:56:52 +02:00
parent 0b2fa40cb9
commit 1efae931d1
No known key found for this signature in database
2 changed files with 31 additions and 13 deletions

View File

@ -198,7 +198,30 @@ void NGCFT1::iteratePeer(float time_delta, uint32_t group_number, uint32_t peer_
}
}
// TODO: receiving tranfers?
//for (auto& transfer_opt : peer.recv_transfers) {
for (size_t idx = 0; idx < peer.recv_transfers.size(); idx++) {
if (!peer.recv_transfers.at(idx).has_value()) {
continue;
}
auto& transfer = peer.recv_transfers.at(idx).value();
// proper switch case?
if (transfer.state == Group::Peer::RecvTransfer::State::FINISHING) {
transfer.finishing_timer -= time_delta;
if (transfer.finishing_timer <= 0.f) {
dispatch(
NGCFT1_Event::recv_done,
Events::NGCFT1_recv_done{
group_number, peer_number,
uint8_t(idx)
}
);
peer.recv_transfers.at(idx).reset();
}
}
}
}
const CCAI* NGCFT1::getPeerCCA(
@ -573,20 +596,12 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_data& e) {
if (transfer.file_size_current == transfer.file_size) {
// TODO: set all data received, and clean up
//transfer.state = Group::Peer::RecvTransfer::State::RECV;
dispatch(
NGCFT1_Event::recv_done,
Events::NGCFT1_recv_done{
e.group_number, e.peer_number,
e.transfer_id
}
);
// all data received
transfer.state = Group::Peer::RecvTransfer::State::FINISHING;
// delete transfer
// TODO: keep around for remote timeout + delay + offset, so we can be sure all acks where received
// or implement a dedicated finished that needs to be acked
peer.recv_transfers[e.transfer_id].reset();
transfer.finishing_timer = 0.5f; // TODO: we are receiving, we dont know delay
}
return true;

View File

@ -155,12 +155,15 @@ class NGCFT1 : public ToxEventI, public NGCEXTEventI, public NGCFT1EventProvider
enum class State {
INITED, //init acked, but no data received yet (might be dropped)
RECV, // receiving data
FINISHING, // got all the data, but we wait for 2*delay, since its likely there is data still arriving
} state;
// float time_since_last_activity ?
size_t file_size {0};
size_t file_size_current {0};
// if state FINISHING and it reaches 0, delete
float finishing_timer {0.f};
// sequence id based reassembly
RecvSequenceBuffer rsb;
};