From f429feaaa820140a729838fddb5d9df6482276fb Mon Sep 17 00:00:00 2001 From: Green Sky Date: Wed, 9 Aug 2023 23:49:28 +0200 Subject: [PATCH] handle transfer done event, now has propper speed --- src/ngcft1.cpp | 7 +++++++ src/sha1_ngcft1.cpp | 21 +++++++++++++++++++++ src/sha1_ngcft1.hpp | 2 ++ 3 files changed, 30 insertions(+) diff --git a/src/ngcft1.cpp b/src/ngcft1.cpp index 909e233..b0a7643 100644 --- a/src/ngcft1.cpp +++ b/src/ngcft1.cpp @@ -564,6 +564,13 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_data_ack& e) { // delete if all packets acked if (transfer.file_size == transfer.file_size_current && transfer.ssb.size() == 0) { std::cout << "NGCFT1: " << int(e.transfer_id) << " done\n"; + dispatch( + NGCFT1_Event::send_done, + Events::NGCFT1_send_done{ + e.group_number, e.peer_number, + e.transfer_id, + } + ); peer.send_transfers[e.transfer_id].reset(); } diff --git a/src/sha1_ngcft1.cpp b/src/sha1_ngcft1.cpp index 9b4b15b..dff90d3 100644 --- a/src/sha1_ngcft1.cpp +++ b/src/sha1_ngcft1.cpp @@ -104,6 +104,8 @@ SHA1_NGCFT1::SHA1_NGCFT1( _nft.subscribe(this, NGCFT1_Event::recv_init); _nft.subscribe(this, NGCFT1_Event::recv_data); _nft.subscribe(this, NGCFT1_Event::send_data); + _nft.subscribe(this, NGCFT1_Event::recv_done); + _nft.subscribe(this, NGCFT1_Event::send_done); //_rmm.subscribe(this, RegistryMessageModel_Event::message_construct); //_rmm.subscribe(this, RegistryMessageModel_Event::message_updated); @@ -354,6 +356,25 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_send_data& e) { return true; } +bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_done& e) { + return false; +} + +bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_send_done& e) { + if (!_sending_transfers.count(combineIds(e.group_number, e.peer_number))) { + return false; + } + + auto& peer_transfers = _sending_transfers.at(combineIds(e.group_number, e.peer_number)); + if (!peer_transfers.count(e.transfer_id)) { + return false; + } + + peer_transfers.erase(e.transfer_id); + + return true; +} + bool SHA1_NGCFT1::sendFilePath(const Contact3 c, std::string_view file_name, std::string_view file_path) { if ( // TODO: add support of offline queuing diff --git a/src/sha1_ngcft1.hpp b/src/sha1_ngcft1.hpp index dd92b1f..9c421b6 100644 --- a/src/sha1_ngcft1.hpp +++ b/src/sha1_ngcft1.hpp @@ -77,6 +77,8 @@ class SHA1_NGCFT1 : public RegistryMessageModelEventI, public NGCFT1EventI { bool onEvent(const Events::NGCFT1_recv_init&) override; bool onEvent(const Events::NGCFT1_recv_data&) override; bool onEvent(const Events::NGCFT1_send_data&) override; // const? + bool onEvent(const Events::NGCFT1_recv_done&) override; + bool onEvent(const Events::NGCFT1_send_done&) override; bool sendFilePath(const Contact3 c, std::string_view file_name, std::string_view file_path) override; };