can transmit info, very hacky

This commit is contained in:
Green Sky 2023-08-09 00:25:08 +02:00
parent 599b0a19cb
commit ae714fcedc
No known key found for this signature in database
2 changed files with 53 additions and 3 deletions

View File

@ -12,6 +12,7 @@
#include "./hash_utils.hpp"
#include <iostream>
#include <variant>
namespace Components {
@ -27,6 +28,10 @@ namespace Components {
} // Components
uint64_t SHA1_NGCFT1::combineIds(const uint32_t group_number, const uint32_t peer_number) {
return (uint64_t(group_number) << 32) | peer_number;
}
SHA1_NGCFT1::SHA1_NGCFT1(
Contact3Registry& cr,
RegistryMessageModel& rmm,
@ -74,14 +79,19 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_request& e) {
assert(msg.all_of<Components::FT1InfoSHA1Data>());
// assume we have the info, send init
uint8_t transfer_id {0};
_nft.NGC_FT1_send_init_private(
e.group_number, e.peer_number,
static_cast<uint32_t>(e.file_kind),
e.file_id, e.file_id_size,
msg.get<Components::FT1InfoSHA1Data>().data.size(),
nullptr
&transfer_id
);
_sending_transfers
[combineIds(e.group_number, e.peer_number)]
[transfer_id]
.v = SendingTransfer::Info{msg.get<Components::FT1InfoSHA1Data>().data};
}
return false;
@ -101,7 +111,30 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_data& e) {
}
bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_send_data& e) {
return false;
if (!_sending_transfers.count(combineIds(e.group_number, e.peer_number))) {
return false;
}
auto& peer = _sending_transfers.at(combineIds(e.group_number, e.peer_number));
if (!peer.count(e.transfer_id)) {
return false;
}
auto& transfer = peer.at(e.transfer_id);
if (std::holds_alternative<SendingTransfer::Info>(transfer.v)) {
auto& info_transfer = std::get<SendingTransfer::Info>(transfer.v);
for (size_t i = 0; i < e.data_size && (i + e.data_offset) < info_transfer.info_data.size(); i++) {
e.data[i] = info_transfer.info_data[i + e.data_offset];
}
if (e.data_offset + e.data_size >= info_transfer.info_data.size()) {
// was last read (probably TODO: add transfer destruction event)
peer.erase(e.transfer_id);
}
}
return true;
}
bool SHA1_NGCFT1::sendFilePath(const Contact3 c, std::string_view file_name, std::string_view file_path) {

View File

@ -9,6 +9,9 @@
#include "./ngcft1.hpp"
#include "./ft1_sha1_info.hpp"
#include "entt/container/dense_map.hpp"
#include <variant>
class SHA1_NGCFT1 : public RegistryMessageModelEventI, public NGCFT1EventI {
Contact3Registry& _cr;
@ -19,6 +22,20 @@ class SHA1_NGCFT1 : public RegistryMessageModelEventI, public NGCFT1EventI {
// limit this to each group?
entt::dense_map<SHA1Digest, Message3Handle> _info_to_message;
struct SendingTransfer {
struct Info {
// copy of info data
// too large?
std::vector<uint8_t> info_data;
};
std::variant<Info> v;
};
// key is groupid + peerid
entt::dense_map<uint64_t, entt::dense_map<uint8_t, SendingTransfer>> _sending_transfers;
static uint64_t combineIds(const uint32_t group_number, const uint32_t peer_number);
public:
SHA1_NGCFT1(
Contact3Registry& cr,