Compare commits

...

3 Commits

Author SHA1 Message Date
4aab6e489d
fix uint64 cast to size_t 2024-10-23 14:11:26 +02:00
5e884fd3ee
dont delay recv_done and check on init info 2024-10-23 13:46:00 +02:00
9a4be575ba
minor stuff and logging 2024-10-23 12:51:22 +02:00
4 changed files with 34 additions and 19 deletions

View File

@ -78,7 +78,7 @@ bool NGCEXTEventProvider::parse_ft1_init(
e.file_size = 0u; e.file_size = 0u;
_DATA_HAVE(sizeof(e.file_size), std::cerr << "NGCEXT: packet too small, missing file_size\n"; return false) _DATA_HAVE(sizeof(e.file_size), std::cerr << "NGCEXT: packet too small, missing file_size\n"; return false)
for (size_t i = 0; i < sizeof(e.file_size); i++, curser++) { for (size_t i = 0; i < sizeof(e.file_size); i++, curser++) {
e.file_size |= size_t(data[curser]) << (i*8); e.file_size |= uint64_t(data[curser]) << (i*8);
} }
// - 1 byte (temporary_file_tf_id) // - 1 byte (temporary_file_tf_id)

View File

@ -30,6 +30,7 @@ namespace Events {
uint32_t peer_number; uint32_t peer_number;
// respond to a request with 0 or more message ids, sorted by newest first // respond to a request with 0 or more message ids, sorted by newest first
// - peer_key bytes (the msg_ids are from) // - peer_key bytes (the msg_ids are from)
ToxKey peer_key; ToxKey peer_key;
@ -47,6 +48,7 @@ namespace Events {
uint32_t peer_number; uint32_t peer_number;
// request the other side to initiate a FT // request the other side to initiate a FT
// - 4 byte (file_kind) // - 4 byte (file_kind)
uint32_t file_kind; uint32_t file_kind;
@ -59,6 +61,7 @@ namespace Events {
uint32_t peer_number; uint32_t peer_number;
// tell the other side you want to start a FT // tell the other side you want to start a FT
// - 4 byte (file_kind) // - 4 byte (file_kind)
uint32_t file_kind; uint32_t file_kind;
@ -88,6 +91,7 @@ namespace Events {
uint32_t peer_number; uint32_t peer_number;
// data fragment // data fragment
// - 1 byte (temporary_file_tf_id) // - 1 byte (temporary_file_tf_id)
uint8_t transfer_id; uint8_t transfer_id;

View File

@ -210,13 +210,13 @@ void NGCFT1::iteratePeer(float time_delta, uint32_t group_number, uint32_t peer_
if (transfer.state == Group::Peer::RecvTransfer::State::FINISHING) { if (transfer.state == Group::Peer::RecvTransfer::State::FINISHING) {
transfer.finishing_timer -= time_delta; transfer.finishing_timer -= time_delta;
if (transfer.finishing_timer <= 0.f) { if (transfer.finishing_timer <= 0.f) {
dispatch( //dispatch(
NGCFT1_Event::recv_done, // NGCFT1_Event::recv_done,
Events::NGCFT1_recv_done{ // Events::NGCFT1_recv_done{
group_number, peer_number, // group_number, peer_number,
uint8_t(idx) // uint8_t(idx)
} // }
); //);
peer.recv_transfers.at(idx).reset(); peer.recv_transfers.at(idx).reset();
} }
@ -543,7 +543,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: got FT1_DATA\n"; //std::cout << "NGCFT1: got FT1_DATA " << e.sequence_id << "\n";
#endif #endif
if (e.data.empty()) { if (e.data.empty()) {
@ -602,6 +602,14 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_data& e) {
// TODO: keep around for remote timeout + delay + offset, so we can be sure all acks where received // TODO: keep around for remote timeout + delay + offset, so we can be sure all acks where received
// or implement a dedicated finished that needs to be acked // or implement a dedicated finished that needs to be acked
transfer.finishing_timer = 0.5f; // TODO: we are receiving, we dont know delay transfer.finishing_timer = 0.5f; // TODO: we are receiving, we dont know delay
dispatch(
NGCFT1_Event::recv_done,
Events::NGCFT1_recv_done{
e.group_number, e.peer_number,
e.transfer_id
}
);
} }
return true; return true;

View File

@ -687,21 +687,21 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_request& e) {
// TODO: queue instead // TODO: queue instead
//queueUpRequestInfo(e.group_number, e.peer_number, info_hash); //queueUpRequestInfo(e.group_number, e.peer_number, info_hash);
uint8_t transfer_id {0}; uint8_t transfer_id {0};
_nft.NGC_FT1_send_init_private( if (_nft.NGC_FT1_send_init_private(
e.group_number, e.peer_number, e.group_number, e.peer_number,
static_cast<uint32_t>(e.file_kind), static_cast<uint32_t>(e.file_kind),
e.file_id, e.file_id_size, e.file_id, e.file_id_size,
o.get<Components::FT1InfoSHA1Data>().data.size(), o.get<Components::FT1InfoSHA1Data>().data.size(),
&transfer_id &transfer_id
); )) {
_sending_transfers.emplaceInfo(
_sending_transfers.emplaceInfo( e.group_number, e.peer_number,
e.group_number, e.peer_number, transfer_id,
transfer_id, SendingTransfers::Entry::Info{
SendingTransfers::Entry::Info{ o.get<Components::FT1InfoSHA1Data>().data
o.get<Components::FT1InfoSHA1Data>().data }
} );
); }
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 _tox_peer_to_contact[combine_ids(e.group_number, e.peer_number)] = c; // workaround
@ -855,6 +855,7 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_init& e) {
bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_data& e) { bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_data& e) {
if (!_receiving_transfers.containsPeerTransfer(e.group_number, e.peer_number, e.transfer_id)) { if (!_receiving_transfers.containsPeerTransfer(e.group_number, e.peer_number, e.transfer_id)) {
std::cerr << "SHA1_NGCFT1 waring: unknown transfer " << e.transfer_id << " from " << e.group_number << ":" << e.peer_number << "\n";
return false; return false;
} }
@ -862,6 +863,7 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_data& e) {
transfer.time_since_activity = 0.f; transfer.time_since_activity = 0.f;
if (transfer.isInfo()) { if (transfer.isInfo()) {
std::cout << "SHA1_NGCFT1: got info data " << e.data_size << "@" << e.data_offset << " from " << e.group_number << ":" << e.peer_number << "\n";
auto& info_data = transfer.getInfo().info_data; auto& info_data = transfer.getInfo().info_data;
for (size_t i = 0; i < e.data_size && i + e.data_offset < info_data.size(); i++) { for (size_t i = 0; i < e.data_size && i + e.data_offset < info_data.size(); i++) {
info_data[i+e.data_offset] = e.data[i]; info_data[i+e.data_offset] = e.data[i];
@ -875,6 +877,7 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_data& e) {
auto* file2 = objGetFile2Write(o); auto* file2 = objGetFile2Write(o);
if (file2 == nullptr) { if (file2 == nullptr) {
std::cerr << "SHA1_NGCFT1 error: writing file failed, no file object\n";
return false; // early out return false; // early out
} }
if (!file2->write({e.data, e.data_size}, offset_into_file + e.data_offset)) { if (!file2->write({e.data, e.data_size}, offset_into_file + e.data_offset)) {