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) {
|
||||
// no ack after 30sec, close ft
|
||||
// TODO: notify app
|
||||
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
|
||||
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;
|
||||
default: // invalid state, delete
|
||||
std::cerr << "NGCFT1 error: ft in invalid state, deleting\n";
|
||||
assert(false && "ft in invalid state");
|
||||
tf_opt.reset();
|
||||
//continue;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -333,7 +339,7 @@ bool NGCFT1::NGC_FT1_send_message_public(
|
||||
|
||||
bool NGCFT1::onEvent(const Events::NGCEXT_ft1_request& e) {
|
||||
//#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
|
||||
|
||||
// .... just rethrow??
|
||||
@ -350,7 +356,7 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_request& e) {
|
||||
|
||||
bool NGCFT1::onEvent(const Events::NGCEXT_ft1_init& e) {
|
||||
//#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
|
||||
|
||||
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) {
|
||||
//#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
|
||||
|
||||
// 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) {
|
||||
#if !NDEBUG
|
||||
//std::cout << "NGCFT1: FT1_DATA\n";
|
||||
//std::cout << "NGCFT1: got FT1_DATA\n";
|
||||
#endif
|
||||
|
||||
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) {
|
||||
#if !NDEBUG
|
||||
//std::cout << "NGCFT1: FT1_DATA_ACK\n";
|
||||
//std::cout << "NGCFT1: got FT1_DATA_ACK\n";
|
||||
#endif
|
||||
|
||||
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) {
|
||||
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??
|
||||
// TODO: dont
|
||||
|
@ -243,6 +243,7 @@ float SHA1_NGCFT1::iterate(float delta) {
|
||||
// TODO: do we really need this if we get events?
|
||||
if (it->second.time_since_activity >= 120.f) {
|
||||
std::cerr << "SHA1_NGCFT1 warning: sending tansfer timed out " << "." << int(it->first) << "\n";
|
||||
assert(false);
|
||||
it = peer_it->second.erase(it);
|
||||
} else {
|
||||
it++;
|
||||
@ -295,8 +296,8 @@ float SHA1_NGCFT1::iterate(float delta) {
|
||||
for (auto it = ftchunk_requested.chunks.begin(); it != ftchunk_requested.chunks.end();) {
|
||||
it->second.timer += delta;
|
||||
|
||||
// 15sec, TODO: config
|
||||
if (it->second.timer >= 15.f) {
|
||||
// TODO: config
|
||||
if (it->second.timer >= 60.f) {
|
||||
it = ftchunk_requested.chunks.erase(it);
|
||||
} else {
|
||||
_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)]
|
||||
[transfer_id]
|
||||
.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) {
|
||||
if (e.file_id_size != 20) {
|
||||
// error
|
||||
@ -722,6 +726,7 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_request& e) {
|
||||
|
||||
{ // they advertise interest in the content
|
||||
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)) {
|
||||
// something happend, update chunk picker
|
||||
assert(static_cast<bool>(c));
|
||||
@ -780,6 +785,9 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_init& e) {
|
||||
);
|
||||
|
||||
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) {
|
||||
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)
|
||||
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)) {
|
||||
// something happend, update chunk picker
|
||||
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();
|
||||
|
||||
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;
|
||||
|
||||
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
|
||||
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)) {
|
||||
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 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
|
||||
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);
|
||||
_tox_peer_to_contact[combine_ids(e.group_number, e.peer_number)] = c; // workaround
|
||||
|
||||
// we might not know yet
|
||||
if (addParticipation(c, o)) {
|
||||
@ -1721,6 +1739,7 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCEXT_pc1_announce& e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
SHA1Digest hash{e.id.data()+sizeof(file_kind), 20};
|
||||
|
||||
// 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
|
||||
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;
|
||||
if (addParticipation(c, o)) {
|
||||
// something happend, update chunk picker
|
||||
|
@ -74,6 +74,10 @@ class SHA1_NGCFT1 : public ToxEventI, public RegistryMessageModelEventI, public
|
||||
// makes request rotate around open content
|
||||
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::mutex _info_builder_queue_mutex;
|
||||
using InfoBuilderEntry = std::function<void(void)>;
|
||||
@ -86,7 +90,7 @@ class SHA1_NGCFT1 : public ToxEventI, public RegistryMessageModelEventI, public
|
||||
public: // TODO: config
|
||||
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
|
||||
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user