work around missing contact events (better now)
fix missing ft event on reset (oops) hard assert sending transfers can not time out higher level
This commit is contained in:
parent
e0b278b168
commit
92373d34f7
@ -60,8 +60,14 @@ void NGCFT1::updateSendTransfer(float time_delta, uint32_t group_number, uint32_
|
|||||||
});
|
});
|
||||||
if (tf.time_since_activity >= sending_give_up_after) {
|
if (tf.time_since_activity >= sending_give_up_after) {
|
||||||
// no ack after 30sec, close ft
|
// no ack after 30sec, close ft
|
||||||
// TODO: notify app
|
|
||||||
std::cerr << "NGCFT1 warning: sending ft finishing timed out, deleting\n";
|
std::cerr << "NGCFT1 warning: sending ft finishing timed out, deleting\n";
|
||||||
|
dispatch(
|
||||||
|
NGCFT1_Event::send_done,
|
||||||
|
Events::NGCFT1_send_done{
|
||||||
|
group_number, peer_number,
|
||||||
|
static_cast<uint8_t>(idx),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// clean up cca
|
// clean up cca
|
||||||
tf.ssb.for_each(time_delta, [&](uint16_t id, const std::vector<uint8_t>& data, float& time_since_activity) {
|
tf.ssb.for_each(time_delta, [&](uint16_t id, const std::vector<uint8_t>& data, float& time_since_activity) {
|
||||||
@ -155,8 +161,8 @@ void NGCFT1::updateSendTransfer(float time_delta, uint32_t group_number, uint32_
|
|||||||
break;
|
break;
|
||||||
default: // invalid state, delete
|
default: // invalid state, delete
|
||||||
std::cerr << "NGCFT1 error: ft in invalid state, deleting\n";
|
std::cerr << "NGCFT1 error: ft in invalid state, deleting\n";
|
||||||
|
assert(false && "ft in invalid state");
|
||||||
tf_opt.reset();
|
tf_opt.reset();
|
||||||
//continue;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -333,7 +339,7 @@ bool NGCFT1::NGC_FT1_send_message_public(
|
|||||||
|
|
||||||
bool NGCFT1::onEvent(const Events::NGCEXT_ft1_request& e) {
|
bool NGCFT1::onEvent(const Events::NGCEXT_ft1_request& e) {
|
||||||
//#if !NDEBUG
|
//#if !NDEBUG
|
||||||
std::cout << "NGCFT1: FT1_REQUEST fk:" << e.file_kind << " [" << bin2hex(e.file_id) << "]\n";
|
std::cout << "NGCFT1: got FT1_REQUEST fk:" << e.file_kind << " [" << bin2hex(e.file_id) << "]\n";
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
// .... just rethrow??
|
// .... just rethrow??
|
||||||
@ -350,7 +356,7 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_request& e) {
|
|||||||
|
|
||||||
bool NGCFT1::onEvent(const Events::NGCEXT_ft1_init& e) {
|
bool NGCFT1::onEvent(const Events::NGCEXT_ft1_init& e) {
|
||||||
//#if !NDEBUG
|
//#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";
|
std::cout << "NGCFT1: got FT1_INIT fk:" << e.file_kind << " fs:" << e.file_size << " tid:" << int(e.transfer_id) << " [" << bin2hex(e.file_id) << "]\n";
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
bool accept = false;
|
bool accept = false;
|
||||||
@ -394,7 +400,7 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_init& e) {
|
|||||||
|
|
||||||
bool NGCFT1::onEvent(const Events::NGCEXT_ft1_init_ack& e) {
|
bool NGCFT1::onEvent(const Events::NGCEXT_ft1_init_ack& e) {
|
||||||
//#if !NDEBUG
|
//#if !NDEBUG
|
||||||
std::cout << "NGCFT1: FT1_INIT_ACK mds:" << e.max_lossy_data_size << "\n";
|
std::cout << "NGCFT1: got FT1_INIT_ACK mds:" << e.max_lossy_data_size << "\n";
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
// we now should start sending data
|
// we now should start sending data
|
||||||
@ -445,7 +451,7 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_init_ack& e) {
|
|||||||
|
|
||||||
bool NGCFT1::onEvent(const Events::NGCEXT_ft1_data& e) {
|
bool NGCFT1::onEvent(const Events::NGCEXT_ft1_data& e) {
|
||||||
#if !NDEBUG
|
#if !NDEBUG
|
||||||
//std::cout << "NGCFT1: FT1_DATA\n";
|
//std::cout << "NGCFT1: got FT1_DATA\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (e.data.empty()) {
|
if (e.data.empty()) {
|
||||||
@ -519,7 +525,7 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_data& e) {
|
|||||||
|
|
||||||
bool NGCFT1::onEvent(const Events::NGCEXT_ft1_data_ack& e) {
|
bool NGCFT1::onEvent(const Events::NGCEXT_ft1_data_ack& e) {
|
||||||
#if !NDEBUG
|
#if !NDEBUG
|
||||||
//std::cout << "NGCFT1: FT1_DATA_ACK\n";
|
//std::cout << "NGCFT1: got FT1_DATA_ACK\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!groups.count(e.group_number)) {
|
if (!groups.count(e.group_number)) {
|
||||||
@ -572,7 +578,7 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_data_ack& e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool NGCFT1::onEvent(const Events::NGCEXT_ft1_message& e) {
|
bool NGCFT1::onEvent(const Events::NGCEXT_ft1_message& e) {
|
||||||
std::cout << "NGCFT1: FT1_MESSAGE mid:" << e.message_id << " fk:" << e.file_kind << " [" << bin2hex(e.file_id) << "]\n";
|
std::cout << "NGCFT1: got FT1_MESSAGE mid:" << e.message_id << " fk:" << e.file_kind << " [" << bin2hex(e.file_id) << "]\n";
|
||||||
|
|
||||||
// .... just rethrow??
|
// .... just rethrow??
|
||||||
// TODO: dont
|
// TODO: dont
|
||||||
|
@ -243,6 +243,7 @@ float SHA1_NGCFT1::iterate(float delta) {
|
|||||||
// TODO: do we really need this if we get events?
|
// TODO: do we really need this if we get events?
|
||||||
if (it->second.time_since_activity >= 120.f) {
|
if (it->second.time_since_activity >= 120.f) {
|
||||||
std::cerr << "SHA1_NGCFT1 warning: sending tansfer timed out " << "." << int(it->first) << "\n";
|
std::cerr << "SHA1_NGCFT1 warning: sending tansfer timed out " << "." << int(it->first) << "\n";
|
||||||
|
assert(false);
|
||||||
it = peer_it->second.erase(it);
|
it = peer_it->second.erase(it);
|
||||||
} else {
|
} else {
|
||||||
it++;
|
it++;
|
||||||
@ -295,8 +296,8 @@ float SHA1_NGCFT1::iterate(float delta) {
|
|||||||
for (auto it = ftchunk_requested.chunks.begin(); it != ftchunk_requested.chunks.end();) {
|
for (auto it = ftchunk_requested.chunks.begin(); it != ftchunk_requested.chunks.end();) {
|
||||||
it->second.timer += delta;
|
it->second.timer += delta;
|
||||||
|
|
||||||
// 15sec, TODO: config
|
// TODO: config
|
||||||
if (it->second.timer >= 15.f) {
|
if (it->second.timer >= 60.f) {
|
||||||
it = ftchunk_requested.chunks.erase(it);
|
it = ftchunk_requested.chunks.erase(it);
|
||||||
} else {
|
} else {
|
||||||
_peer_open_requests[it->second.c] += 1;
|
_peer_open_requests[it->second.c] += 1;
|
||||||
@ -705,6 +706,9 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_request& e) {
|
|||||||
[combine_ids(e.group_number, e.peer_number)]
|
[combine_ids(e.group_number, e.peer_number)]
|
||||||
[transfer_id]
|
[transfer_id]
|
||||||
.v = SendingTransfer::Info{content.get<Components::FT1InfoSHA1Data>().data};
|
.v = SendingTransfer::Info{content.get<Components::FT1InfoSHA1Data>().data};
|
||||||
|
|
||||||
|
const auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number);
|
||||||
|
_tox_peer_to_contact[combine_ids(e.group_number, e.peer_number)] = c; // workaround
|
||||||
} else if (e.file_kind == NGCFT1_file_kind::HASH_SHA1_CHUNK) {
|
} else if (e.file_kind == NGCFT1_file_kind::HASH_SHA1_CHUNK) {
|
||||||
if (e.file_id_size != 20) {
|
if (e.file_id_size != 20) {
|
||||||
// error
|
// error
|
||||||
@ -722,6 +726,7 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_request& e) {
|
|||||||
|
|
||||||
{ // they advertise interest in the content
|
{ // they advertise interest in the content
|
||||||
const auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number);
|
const auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number);
|
||||||
|
_tox_peer_to_contact[combine_ids(e.group_number, e.peer_number)] = c; // workaround
|
||||||
if (addParticipation(c, o)) {
|
if (addParticipation(c, o)) {
|
||||||
// something happend, update chunk picker
|
// something happend, update chunk picker
|
||||||
assert(static_cast<bool>(c));
|
assert(static_cast<bool>(c));
|
||||||
@ -780,6 +785,9 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_init& e) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
e.accept = true;
|
e.accept = true;
|
||||||
|
|
||||||
|
const auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number);
|
||||||
|
_tox_peer_to_contact[combine_ids(e.group_number, e.peer_number)] = c; // workaround
|
||||||
} else if (e.file_kind == NGCFT1_file_kind::HASH_SHA1_CHUNK) {
|
} else if (e.file_kind == NGCFT1_file_kind::HASH_SHA1_CHUNK) {
|
||||||
SHA1Digest sha1_chunk_hash {e.file_id, e.file_id_size};
|
SHA1Digest sha1_chunk_hash {e.file_id, e.file_id_size};
|
||||||
|
|
||||||
@ -792,6 +800,7 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_init& e) {
|
|||||||
|
|
||||||
{ // they have the content (probably, might be fake, should move this to done)
|
{ // they have the content (probably, might be fake, should move this to done)
|
||||||
const auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number);
|
const auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number);
|
||||||
|
_tox_peer_to_contact[combine_ids(e.group_number, e.peer_number)] = c; // workaround
|
||||||
if (addParticipation(c, o)) {
|
if (addParticipation(c, o)) {
|
||||||
// something happend, update chunk picker
|
// something happend, update chunk picker
|
||||||
assert(static_cast<bool>(c));
|
assert(static_cast<bool>(c));
|
||||||
@ -1126,6 +1135,7 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_message& e) {
|
|||||||
uint64_t ts = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
uint64_t ts = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||||
|
|
||||||
const auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number);
|
const auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number);
|
||||||
|
_tox_peer_to_contact[combine_ids(e.group_number, e.peer_number)] = c; // workaround
|
||||||
const auto self_c = c.get<Contact::Components::Self>().self;
|
const auto self_c = c.get<Contact::Components::Self>().self;
|
||||||
|
|
||||||
auto* reg_ptr = _rmm.get(c);
|
auto* reg_ptr = _rmm.get(c);
|
||||||
@ -1523,7 +1533,13 @@ bool SHA1_NGCFT1::onToxEvent(const Tox_Event_Group_Peer_Exit* e) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
// FIXME: this does not work, tcm just delteded the relation ship
|
// FIXME: this does not work, tcm just delteded the relation ship
|
||||||
auto c = _tcm.getContactGroupPeer(group_number, peer_number);
|
//auto c = _tcm.getContactGroupPeer(group_number, peer_number);
|
||||||
|
|
||||||
|
const auto c_it = _tox_peer_to_contact.find(combine_ids(group_number, peer_number));
|
||||||
|
if (c_it == _tox_peer_to_contact.end()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auto c = c_it->second;
|
||||||
if (!static_cast<bool>(c)) {
|
if (!static_cast<bool>(c)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1579,6 +1595,7 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCEXT_ft1_have& e) {
|
|||||||
const size_t num_total_chunks = o.get<Components::FT1InfoSHA1>().chunks.size();
|
const size_t num_total_chunks = o.get<Components::FT1InfoSHA1>().chunks.size();
|
||||||
|
|
||||||
const auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number);
|
const auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number);
|
||||||
|
_tox_peer_to_contact[combine_ids(e.group_number, e.peer_number)] = c; // workaround
|
||||||
|
|
||||||
// we might not know yet
|
// we might not know yet
|
||||||
if (addParticipation(c, o)) {
|
if (addParticipation(c, o)) {
|
||||||
@ -1663,6 +1680,7 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCEXT_ft1_bitset& e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number);
|
const auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number);
|
||||||
|
_tox_peer_to_contact[combine_ids(e.group_number, e.peer_number)] = c; // workaround
|
||||||
|
|
||||||
// we might not know yet
|
// we might not know yet
|
||||||
if (addParticipation(c, o)) {
|
if (addParticipation(c, o)) {
|
||||||
@ -1721,6 +1739,7 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCEXT_pc1_announce& e) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SHA1Digest hash{e.id.data()+sizeof(file_kind), 20};
|
SHA1Digest hash{e.id.data()+sizeof(file_kind), 20};
|
||||||
|
|
||||||
// if have use hash(-info) for file, add to participants
|
// if have use hash(-info) for file, add to participants
|
||||||
@ -1734,6 +1753,7 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCEXT_pc1_announce& e) {
|
|||||||
|
|
||||||
// add to participants
|
// add to participants
|
||||||
const auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number);
|
const auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number);
|
||||||
|
_tox_peer_to_contact[combine_ids(e.group_number, e.peer_number)] = c; // workaround
|
||||||
auto o = itc_it->second;
|
auto o = itc_it->second;
|
||||||
if (addParticipation(c, o)) {
|
if (addParticipation(c, o)) {
|
||||||
// something happend, update chunk picker
|
// something happend, update chunk picker
|
||||||
|
@ -74,6 +74,10 @@ class SHA1_NGCFT1 : public ToxEventI, public RegistryMessageModelEventI, public
|
|||||||
// makes request rotate around open content
|
// makes request rotate around open content
|
||||||
std::deque<ObjectHandle> _queue_content_want_info;
|
std::deque<ObjectHandle> _queue_content_want_info;
|
||||||
|
|
||||||
|
// workaround missing contact events
|
||||||
|
// only used to remove participation on peer exit
|
||||||
|
entt::dense_map<uint64_t, Contact3Handle> _tox_peer_to_contact;
|
||||||
|
|
||||||
std::atomic_bool _info_builder_dirty {false};
|
std::atomic_bool _info_builder_dirty {false};
|
||||||
std::mutex _info_builder_queue_mutex;
|
std::mutex _info_builder_queue_mutex;
|
||||||
using InfoBuilderEntry = std::function<void(void)>;
|
using InfoBuilderEntry = std::function<void(void)>;
|
||||||
@ -86,7 +90,7 @@ class SHA1_NGCFT1 : public ToxEventI, public RegistryMessageModelEventI, public
|
|||||||
public: // TODO: config
|
public: // TODO: config
|
||||||
bool _udp_only {false};
|
bool _udp_only {false};
|
||||||
|
|
||||||
size_t _max_concurrent_in {4};
|
size_t _max_concurrent_in {4}; // info only
|
||||||
size_t _max_concurrent_out {3*4}; // HACK: allow ideal number for 4 peers
|
size_t _max_concurrent_out {3*4}; // HACK: allow ideal number for 4 peers
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user