various fixes resulting in the first time running the code

This commit is contained in:
Green Sky 2024-12-08 16:08:30 +01:00
parent abdf6672bf
commit a139f412b1
No known key found for this signature in database
4 changed files with 79 additions and 18 deletions

View File

@ -308,13 +308,12 @@ float NGCFT1::iterate(float time_delta) {
} }
} }
void NGCFT1::NGC_FT1_send_request_private( bool NGCFT1::NGC_FT1_send_request_private(
uint32_t group_number, uint32_t peer_number, uint32_t group_number, uint32_t peer_number,
uint32_t file_kind, uint32_t file_kind,
const uint8_t* file_id, uint32_t file_id_size const uint8_t* file_id, uint32_t file_id_size
) { ) {
// TODO: error check return _neep.send_ft1_request(group_number, peer_number, file_kind, file_id, file_id_size);
_neep.send_ft1_request(group_number, peer_number, file_kind, file_id, file_id_size);
} }
bool NGCFT1::NGC_FT1_send_init_private( bool NGCFT1::NGC_FT1_send_init_private(

View File

@ -223,7 +223,7 @@ class NGCFT1 : public ToxEventI, public NGCEXTEventI, public NGCFT1EventProvider
float iterate(float delta); float iterate(float delta);
public: // ft1 api public: // ft1 api
void NGC_FT1_send_request_private( bool NGC_FT1_send_request_private(
uint32_t group_number, uint32_t peer_number, uint32_t group_number, uint32_t peer_number,
uint32_t file_kind, uint32_t file_kind,
const uint8_t* file_id, uint32_t file_id_size const uint8_t* file_id, uint32_t file_id_size

View File

@ -1,11 +1,11 @@
#include "./ngc_hs2_rizzler.hpp" #include "./ngc_hs2_rizzler.hpp"
#include "tox/tox_events.h"
#include <solanaceae/tox_contacts/tox_contact_model2.hpp> #include <solanaceae/tox_contacts/tox_contact_model2.hpp>
#include <solanaceae/tox_contacts/components.hpp>
#include <solanaceae/message3/registry_message_model.hpp> #include <solanaceae/message3/registry_message_model.hpp>
#include <solanaceae/tox_contacts/components.hpp>
#include <solanaceae/ngc_ft1/ngcft1_file_kind.hpp>
#include <solanaceae/util/span.hpp>
#include <iostream> #include <iostream>
@ -57,7 +57,7 @@ float NGCHS2Rizzler::iterate(float delta) {
// now in sec // now in sec
const uint64_t ts_now = Message::getTimeMS()/1000; const uint64_t ts_now = Message::getTimeMS()/1000;
if (sendRequest(group_number, peer_number, ts_now, ts_now-(60*48))) { if (sendRequest(group_number, peer_number, ts_now, ts_now-(60*60*48))) {
// TODO: requeue // TODO: requeue
// TODO: segment // TODO: segment
// TODO: dont request already received ranges // TODO: dont request already received ranges
@ -73,18 +73,41 @@ float NGCHS2Rizzler::iterate(float delta) {
//std::cout << "ZOX #### requeued request in " << it->second.delay << "s\n"; //std::cout << "ZOX #### requeued request in " << it->second.delay << "s\n";
it++;
} else { } else {
// on failure, assume disconnected // on failure, assume disconnected
}
// remove from request queue
it = _request_queue.erase(it); it = _request_queue.erase(it);
} }
// just choose something small, since we expect a response might arrive soon return 1000.f;
//min_interval = std::min(min_interval, _delay_between_syncs_min);
} }
template<typename Type>
static uint64_t deserlSimpleType(ByteSpan bytes) {
if (bytes.size < sizeof(Type)) {
throw int(1);
}
return 1000.f; Type value{};
for (size_t i = 0; i < sizeof(Type); i++) {
value |= Type(bytes[i]) << (i*8);
}
return value;
}
static uint64_t deserlTS(ByteSpan ts_bytes) {
return deserlSimpleType<uint64_t>(ts_bytes);
}
template<typename Type>
static void serlSimpleType(std::vector<uint8_t>& bytes, const Type& value) {
for (size_t i = 0; i < sizeof(Type); i++) {
bytes.push_back(uint8_t(value >> (i*8) & 0xff));
}
} }
bool NGCHS2Rizzler::sendRequest( bool NGCHS2Rizzler::sendRequest(
@ -92,10 +115,25 @@ bool NGCHS2Rizzler::sendRequest(
uint64_t ts_start, uint64_t ts_end uint64_t ts_start, uint64_t ts_end
) { ) {
std::cout << "NGCHS2Rizzler: sending request to " << group_number << ":" << peer_number << " (" << ts_start << "," << ts_end << ")\n"; std::cout << "NGCHS2Rizzler: sending request to " << group_number << ":" << peer_number << " (" << ts_start << "," << ts_end << ")\n";
return false;
// build fid
std::vector<uint8_t> fid;
fid.reserve(sizeof(uint64_t)+sizeof(uint64_t));
serlSimpleType(fid, ts_start);
serlSimpleType(fid, ts_end);
assert(fid.size() == sizeof(uint64_t)+sizeof(uint64_t));
return _nft.NGC_FT1_send_request_private(
group_number, peer_number,
(uint32_t)NGCFT1_file_kind::HS2_RANGE_TIME_MSGPACK,
fid.data(), fid.size() // fid
);
} }
bool NGCHS2Rizzler::onEvent(const Events::NGCFT1_recv_init&) { bool NGCHS2Rizzler::onEvent(const Events::NGCFT1_recv_init& e) {
std::cout << "NGCHS2Rizzler: recv_init " << e.group_number << ":" << e.peer_number << "." << (int)e.transfer_id << "\n";
return false; return false;
} }

View File

@ -30,10 +30,14 @@ void IncommingTimeRangeRequestQueue::queueRequest(const TimeRangeRequest& new_re
for (const auto& [time_range, _] : _queue) { for (const auto& [time_range, _] : _queue) {
if (time_range.ts_start == new_request.ts_start && time_range.ts_end == new_request.ts_end) { if (time_range.ts_start == new_request.ts_start && time_range.ts_end == new_request.ts_end) {
return; // already enqueued return; // already enqueued
// TODO: what about fid?
} }
} }
_queue.emplace_back(Entry{new_request, std::vector<uint8_t>{fid.cbegin(), fid.cend()}}); _queue.emplace_back(Entry{
new_request,
std::vector<uint8_t>{fid.cbegin(), fid.cend()}
});
} }
} // Components } // Components
@ -75,6 +79,11 @@ float NGCHS2Sigma::iterate(float delta) {
auto fn_iirq = [this](auto&& view) { auto fn_iirq = [this](auto&& view) {
for (auto&& [cv, iirq] : view.each()) { for (auto&& [cv, iirq] : view.each()) {
if (iirq._queue.empty()) {
// TODO: remove comp?
continue;
}
Contact3Handle c{_cr, cv}; Contact3Handle c{_cr, cv};
auto& iirr = c.get_or_emplace<Components::IncommingTimeRangeRequestRunning>(); auto& iirr = c.get_or_emplace<Components::IncommingTimeRangeRequestRunning>();
@ -164,7 +173,7 @@ static uint64_t deserlSimpleType(ByteSpan bytes) {
throw int(1); throw int(1);
} }
Type value; Type value{};
for (size_t i = 0; i < sizeof(Type); i++) { for (size_t i = 0; i < sizeof(Type); i++) {
value |= Type(bytes[i]) << (i*8); value |= Type(bytes[i]) << (i*8);
@ -205,6 +214,11 @@ void NGCHS2Sigma::handleTimeRange(Contact3Handle c, const Events::NGCFT1_recv_re
return; return;
} }
if (ts_end >= ts_start) {
std::cerr << "NGCHS2S error: end not < start\n";
return;
}
// dedupe insert into queue // dedupe insert into queue
// how much overlap do we allow? // how much overlap do we allow?
c.get_or_emplace<Components::IncommingTimeRangeRequestQueue>().queueRequest( c.get_or_emplace<Components::IncommingTimeRangeRequestQueue>().queueRequest(
@ -226,6 +240,13 @@ std::vector<uint8_t> NGCHS2Sigma::buildChatLogFileRange(Contact3Handle c, uint64
return {}; return {};
} }
std::cout << "NGCHS2Sigma: building chatlog for time range " << ts_start-ts_end << "s\n";
// convert seconds to milliseconds
// TODO: lift out?
ts_start *= 1000;
ts_end *= 1000;
//std::cout << "!!!! starting msg ts search, ts_start:" << ts_start << " ts_end:" << ts_end << "\n"; //std::cout << "!!!! starting msg ts search, ts_start:" << ts_start << " ts_end:" << ts_end << "\n";
auto ts_view = msg_reg.view<Message::Components::Timestamp>(); auto ts_view = msg_reg.view<Message::Components::Timestamp>();
@ -322,6 +343,8 @@ std::vector<uint8_t> NGCHS2Sigma::buildChatLogFileRange(Contact3Handle c, uint64
j_array.push_back(j_entry); j_array.push_back(j_entry);
} }
std::cout << "NGCHS2Sigma: built chat log with " << j_array.size() << " entries\n";
return nlohmann::json::to_msgpack(j_array); return nlohmann::json::to_msgpack(j_array);
} }
@ -399,6 +422,7 @@ bool NGCHS2Sigma::onEvent(const Events::NGCFT1_send_data& e) {
} }
bool NGCHS2Sigma::onEvent(const Events::NGCFT1_send_done& e) { bool NGCHS2Sigma::onEvent(const Events::NGCFT1_send_done& e) {
// TODO: this will return null if the peer just disconnected
auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number); auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number);
if (!c) { if (!c) {
return false; return false;