cleanup transfers if peer disconnects
This commit is contained in:
parent
7812e3a413
commit
80d0db546d
@ -332,6 +332,8 @@ NGCFT1::NGCFT1(
|
||||
_neep.subscribe(this, NGCEXT_Event::FT1_DATA);
|
||||
_neep.subscribe(this, NGCEXT_Event::FT1_DATA_ACK);
|
||||
_neep.subscribe(this, NGCEXT_Event::FT1_MESSAGE);
|
||||
|
||||
_tep.subscribe(this, Tox_Event::TOX_EVENT_GROUP_PEER_EXIT);
|
||||
}
|
||||
|
||||
void NGCFT1::iterate(float time_delta) {
|
||||
@ -645,3 +647,60 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_message& e) {
|
||||
);
|
||||
}
|
||||
|
||||
bool NGCFT1::onToxEvent(const Tox_Event_Group_Peer_Exit* e) {
|
||||
const auto group_number = tox_event_group_peer_exit_get_group_number(e);
|
||||
const auto peer_number = tox_event_group_peer_exit_get_peer_id(e);
|
||||
|
||||
// peer disconnected, end all transfers
|
||||
|
||||
if (!groups.count(group_number)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& group = groups.at(group_number);
|
||||
|
||||
if (!group.peers.count(peer_number)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& peer = group.peers.at(peer_number);
|
||||
|
||||
for (size_t i = 0; i < peer.send_transfers.size(); i++) {
|
||||
auto& it_opt = peer.send_transfers.at(i);
|
||||
if (!it_opt.has_value()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::cout << "NGCFT1: sending " << int(i) << " canceled bc peer offline\n";
|
||||
dispatch(
|
||||
NGCFT1_Event::send_done,
|
||||
Events::NGCFT1_send_done{
|
||||
group_number, peer_number,
|
||||
static_cast<uint8_t>(i),
|
||||
}
|
||||
);
|
||||
|
||||
it_opt.reset();
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < peer.recv_transfers.size(); i++) {
|
||||
auto& it_opt = peer.recv_transfers.at(i);
|
||||
if (!it_opt.has_value()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::cout << "NGCFT1: receiving " << int(i) << " canceled bc peer offline\n";
|
||||
dispatch(
|
||||
NGCFT1_Event::recv_done,
|
||||
Events::NGCFT1_recv_done{
|
||||
group_number, peer_number,
|
||||
static_cast<uint8_t>(i),
|
||||
}
|
||||
);
|
||||
|
||||
it_opt.reset();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -244,6 +244,7 @@ class NGCFT1 : public ToxEventI, public NGCEXTEventI, public NGCFT1EventProvider
|
||||
bool onEvent(const Events::NGCEXT_ft1_message&) override;
|
||||
|
||||
protected:
|
||||
bool onToxEvent(const Tox_Event_Group_Peer_Exit* e) override;
|
||||
//bool onToxEvent(const Tox_Event_Group_Custom_Packet* e) override;
|
||||
//bool onToxEvent(const Tox_Event_Group_Custom_Private_Packet* e) override;
|
||||
};
|
||||
|
@ -867,6 +867,8 @@ bool SHA1_NGCFT1::sendFilePath(const Contact3 c, std::string_view file_name, std
|
||||
ce.emplace<Message::Components::Transfer::BytesSent>(0u);
|
||||
}
|
||||
|
||||
ce.remove<Message::Components::Transfer::TagPaused>();
|
||||
|
||||
// we dont want the info anymore
|
||||
ce.remove<Components::ReRequestInfoTimer>();
|
||||
if (auto it = std::find(_queue_content_want_info.begin(), _queue_content_want_info.end(), ce); it != _queue_content_want_info.end()) {
|
||||
@ -917,7 +919,6 @@ bool SHA1_NGCFT1::sendFilePath(const Contact3 c, std::string_view file_name, std
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
const auto msg_e = reg_ptr->create();
|
||||
reg_ptr->emplace<Message::Components::ContactTo>(msg_e, c);
|
||||
reg_ptr->emplace<Message::Components::ContactFrom>(msg_e, c_self);
|
||||
|
Loading…
Reference in New Issue
Block a user