make ft1sha1 observe disconnects
This commit is contained in:
parent
c09f2e6f8f
commit
e9f22bc9ae
@ -185,7 +185,6 @@ void SHA1_NGCFT1::updateMessages(ObjectHandle ce) {
|
|||||||
|
|
||||||
std::optional<std::pair<uint32_t, uint32_t>> SHA1_NGCFT1::selectPeerForRequest(ObjectHandle ce) {
|
std::optional<std::pair<uint32_t, uint32_t>> SHA1_NGCFT1::selectPeerForRequest(ObjectHandle ce) {
|
||||||
// get a list of peers we can request this file from
|
// get a list of peers we can request this file from
|
||||||
// TODO: randomly request from non SuspectedParticipants
|
|
||||||
std::vector<std::pair<uint32_t, uint32_t>> tox_peers;
|
std::vector<std::pair<uint32_t, uint32_t>> tox_peers;
|
||||||
for (const auto c : ce.get<Components::SuspectedParticipants>().participants) {
|
for (const auto c : ce.get<Components::SuspectedParticipants>().participants) {
|
||||||
// TODO: sort by con state?
|
// TODO: sort by con state?
|
||||||
@ -203,6 +202,7 @@ std::optional<std::pair<uint32_t, uint32_t>> SHA1_NGCFT1::selectPeerForRequest(O
|
|||||||
// 1 in 20 chance to ask random peer instead
|
// 1 in 20 chance to ask random peer instead
|
||||||
// TODO: config + tweak
|
// TODO: config + tweak
|
||||||
// TODO: save group in content to avoid the tox_peers list build
|
// TODO: save group in content to avoid the tox_peers list build
|
||||||
|
// TODO: remove once pc1_announce is shipped
|
||||||
if (tox_peers.empty() || (_rng()%20) == 0) {
|
if (tox_peers.empty() || (_rng()%20) == 0) {
|
||||||
// meh
|
// meh
|
||||||
// HACK: determain group based on last tox_peers
|
// HACK: determain group based on last tox_peers
|
||||||
@ -250,13 +250,15 @@ SHA1_NGCFT1::SHA1_NGCFT1(
|
|||||||
Contact3Registry& cr,
|
Contact3Registry& cr,
|
||||||
RegistryMessageModel& rmm,
|
RegistryMessageModel& rmm,
|
||||||
NGCFT1& nft,
|
NGCFT1& nft,
|
||||||
ToxContactModel2& tcm
|
ToxContactModel2& tcm,
|
||||||
|
ToxEventProviderI& tep
|
||||||
) :
|
) :
|
||||||
_os(os),
|
_os(os),
|
||||||
_cr(cr),
|
_cr(cr),
|
||||||
_rmm(rmm),
|
_rmm(rmm),
|
||||||
_nft(nft),
|
_nft(nft),
|
||||||
_tcm(tcm)
|
_tcm(tcm),
|
||||||
|
_tep(tep)
|
||||||
{
|
{
|
||||||
// TODO: also create and destroy
|
// TODO: also create and destroy
|
||||||
_rmm.subscribe(this, RegistryMessageModel_Event::message_updated);
|
_rmm.subscribe(this, RegistryMessageModel_Event::message_updated);
|
||||||
@ -274,6 +276,8 @@ SHA1_NGCFT1::SHA1_NGCFT1(
|
|||||||
//_rmm.subscribe(this, RegistryMessageModel_Event::message_destroy);
|
//_rmm.subscribe(this, RegistryMessageModel_Event::message_destroy);
|
||||||
|
|
||||||
_rmm.subscribe(this, RegistryMessageModel_Event::send_file_path);
|
_rmm.subscribe(this, RegistryMessageModel_Event::send_file_path);
|
||||||
|
|
||||||
|
_tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_PEER_EXIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHA1_NGCFT1::iterate(float delta) {
|
void SHA1_NGCFT1::iterate(float delta) {
|
||||||
@ -319,7 +323,7 @@ void SHA1_NGCFT1::iterate(float delta) {
|
|||||||
it->second.time_since_activity += delta;
|
it->second.time_since_activity += delta;
|
||||||
|
|
||||||
// if we have not heard for 10sec, timeout
|
// if we have not heard for 10sec, timeout
|
||||||
if (it->second.time_since_activity >= 10.f) {
|
if (it->second.time_since_activity >= 20.f) {
|
||||||
std::cerr << "SHA1_NGCFT1 warning: receiving tansfer timed out " << "." << int(it->first) << "\n";
|
std::cerr << "SHA1_NGCFT1 warning: receiving tansfer timed out " << "." << int(it->first) << "\n";
|
||||||
// TODO: if info, requeue? or just keep the timer comp? - no, timer comp will continue ticking, even if loading
|
// TODO: if info, requeue? or just keep the timer comp? - no, timer comp will continue ticking, even if loading
|
||||||
//it->second.v
|
//it->second.v
|
||||||
@ -1426,3 +1430,36 @@ bool SHA1_NGCFT1::sendFilePath(const Contact3 c, std::string_view file_name, std
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SHA1_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
|
||||||
|
// - remove from all participantions
|
||||||
|
|
||||||
|
auto ch = _tcm.getContactGroupPeer(group_number, peer_number);
|
||||||
|
if (!static_cast<bool>(ch)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& [_, h] : _info_to_content) {
|
||||||
|
if (!h.all_of<Components::SuspectedParticipants>()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
h.get<Components::SuspectedParticipants>().participants.erase(ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
// - clear queues
|
||||||
|
|
||||||
|
for (auto it = _queue_requested_chunk.begin(); it != _queue_requested_chunk.end();) {
|
||||||
|
if (group_number == std::get<0>(*it) && peer_number == std::get<1>(*it)) {
|
||||||
|
it = _queue_requested_chunk.erase(it);
|
||||||
|
} else {
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -21,13 +21,14 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
class SHA1_NGCFT1 : public RegistryMessageModelEventI, public NGCFT1EventI {
|
class SHA1_NGCFT1 : public ToxEventI, public RegistryMessageModelEventI, public NGCFT1EventI {
|
||||||
ObjectStore2& _os;
|
ObjectStore2& _os;
|
||||||
// TODO: backend abstraction
|
// TODO: backend abstraction
|
||||||
Contact3Registry& _cr;
|
Contact3Registry& _cr;
|
||||||
RegistryMessageModel& _rmm;
|
RegistryMessageModel& _rmm;
|
||||||
NGCFT1& _nft;
|
NGCFT1& _nft;
|
||||||
ToxContactModel2& _tcm;
|
ToxContactModel2& _tcm;
|
||||||
|
ToxEventProviderI& _tep;
|
||||||
|
|
||||||
std::minstd_rand _rng {1337*11};
|
std::minstd_rand _rng {1337*11};
|
||||||
|
|
||||||
@ -122,7 +123,8 @@ class SHA1_NGCFT1 : public RegistryMessageModelEventI, public NGCFT1EventI {
|
|||||||
Contact3Registry& cr,
|
Contact3Registry& cr,
|
||||||
RegistryMessageModel& rmm,
|
RegistryMessageModel& rmm,
|
||||||
NGCFT1& nft,
|
NGCFT1& nft,
|
||||||
ToxContactModel2& tcm
|
ToxContactModel2& tcm,
|
||||||
|
ToxEventProviderI& tep
|
||||||
);
|
);
|
||||||
|
|
||||||
void iterate(float delta);
|
void iterate(float delta);
|
||||||
@ -140,5 +142,7 @@ class SHA1_NGCFT1 : public RegistryMessageModelEventI, public NGCFT1EventI {
|
|||||||
bool onEvent(const Events::NGCFT1_recv_message&) override;
|
bool onEvent(const Events::NGCFT1_recv_message&) override;
|
||||||
|
|
||||||
bool sendFilePath(const Contact3 c, std::string_view file_name, std::string_view file_path) override;
|
bool sendFilePath(const Contact3 c, std::string_view file_name, std::string_view file_path) override;
|
||||||
|
|
||||||
|
bool onToxEvent(const Tox_Event_Group_Peer_Exit* e) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user