can transmit info, very hacky
This commit is contained in:
parent
599b0a19cb
commit
ae714fcedc
@ -12,6 +12,7 @@
|
|||||||
#include "./hash_utils.hpp"
|
#include "./hash_utils.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
namespace Components {
|
namespace Components {
|
||||||
|
|
||||||
@ -27,6 +28,10 @@ namespace Components {
|
|||||||
|
|
||||||
} // 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(
|
SHA1_NGCFT1::SHA1_NGCFT1(
|
||||||
Contact3Registry& cr,
|
Contact3Registry& cr,
|
||||||
RegistryMessageModel& rmm,
|
RegistryMessageModel& rmm,
|
||||||
@ -74,14 +79,19 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_request& e) {
|
|||||||
|
|
||||||
assert(msg.all_of<Components::FT1InfoSHA1Data>());
|
assert(msg.all_of<Components::FT1InfoSHA1Data>());
|
||||||
|
|
||||||
// assume we have the info, send init
|
uint8_t transfer_id {0};
|
||||||
_nft.NGC_FT1_send_init_private(
|
_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,
|
||||||
msg.get<Components::FT1InfoSHA1Data>().data.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;
|
return false;
|
||||||
@ -101,9 +111,32 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_data& e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_send_data& e) {
|
bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_send_data& e) {
|
||||||
|
if (!_sending_transfers.count(combineIds(e.group_number, e.peer_number))) {
|
||||||
return false;
|
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) {
|
bool SHA1_NGCFT1::sendFilePath(const Contact3 c, std::string_view file_name, std::string_view file_path) {
|
||||||
if (
|
if (
|
||||||
// TODO: add support of offline queuing
|
// TODO: add support of offline queuing
|
||||||
|
@ -9,6 +9,9 @@
|
|||||||
#include "./ngcft1.hpp"
|
#include "./ngcft1.hpp"
|
||||||
|
|
||||||
#include "./ft1_sha1_info.hpp"
|
#include "./ft1_sha1_info.hpp"
|
||||||
|
#include "entt/container/dense_map.hpp"
|
||||||
|
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
class SHA1_NGCFT1 : public RegistryMessageModelEventI, public NGCFT1EventI {
|
class SHA1_NGCFT1 : public RegistryMessageModelEventI, public NGCFT1EventI {
|
||||||
Contact3Registry& _cr;
|
Contact3Registry& _cr;
|
||||||
@ -19,6 +22,20 @@ class SHA1_NGCFT1 : public RegistryMessageModelEventI, public NGCFT1EventI {
|
|||||||
// limit this to each group?
|
// limit this to each group?
|
||||||
entt::dense_map<SHA1Digest, Message3Handle> _info_to_message;
|
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:
|
public:
|
||||||
SHA1_NGCFT1(
|
SHA1_NGCFT1(
|
||||||
Contact3Registry& cr,
|
Contact3Registry& cr,
|
||||||
|
Loading…
Reference in New Issue
Block a user