start moving pkg sending to ngcext
wip, but working as far as its implemented
This commit is contained in:
parent
bcde244a3c
commit
b27107af4c
@ -3,7 +3,7 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
NGCEXTEventProvider::NGCEXTEventProvider(ToxEventProviderI& tep) : _tep(tep) {
|
NGCEXTEventProvider::NGCEXTEventProvider(ToxI& t, ToxEventProviderI& tep) : _t(t), _tep(tep) {
|
||||||
_tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_CUSTOM_PACKET);
|
_tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_CUSTOM_PACKET);
|
||||||
_tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_CUSTOM_PRIVATE_PACKET);
|
_tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_CUSTOM_PRIVATE_PACKET);
|
||||||
}
|
}
|
||||||
@ -432,6 +432,72 @@ bool NGCEXTEventProvider::handlePacket(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NGCEXTEventProvider::send_ft1_init(
|
||||||
|
uint32_t group_number, uint32_t peer_number,
|
||||||
|
uint32_t file_kind,
|
||||||
|
uint64_t file_size,
|
||||||
|
uint8_t transfer_id,
|
||||||
|
const uint8_t* file_id, size_t file_id_size
|
||||||
|
) {
|
||||||
|
// - 1 byte packet id
|
||||||
|
// - 4 byte (file_kind)
|
||||||
|
// - 8 bytes (data size)
|
||||||
|
// - 1 byte (temporary_file_tf_id, for this peer only, technically just a prefix to distinguish between simultainious fts)
|
||||||
|
// - X bytes (file_kind dependent id, differnt sizes)
|
||||||
|
|
||||||
|
std::vector<uint8_t> pkg;
|
||||||
|
pkg.push_back(static_cast<uint8_t>(NGCEXT_Event::FT1_INIT));
|
||||||
|
for (size_t i = 0; i < sizeof(file_kind); i++) {
|
||||||
|
pkg.push_back((file_kind>>(i*8)) & 0xff);
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < sizeof(file_size); i++) {
|
||||||
|
pkg.push_back((file_size>>(i*8)) & 0xff);
|
||||||
|
}
|
||||||
|
pkg.push_back(transfer_id);
|
||||||
|
for (size_t i = 0; i < file_id_size; i++) {
|
||||||
|
pkg.push_back(file_id[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// lossless
|
||||||
|
return _t.toxGroupSendCustomPrivatePacket(group_number, peer_number, true, pkg) == TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::vector<uint8_t> build_pc1_announce(const uint8_t* id_data, size_t id_size) {
|
||||||
|
// - 1 byte packet id
|
||||||
|
// - X bytes (id, differnt sizes)
|
||||||
|
|
||||||
|
std::vector<uint8_t> pkg;
|
||||||
|
pkg.push_back(static_cast<uint8_t>(NGCEXT_Event::PC1_ANNOUNCE));
|
||||||
|
for (size_t i = 0; i < id_size; i++) {
|
||||||
|
pkg.push_back(id_data[i]);
|
||||||
|
}
|
||||||
|
return pkg;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NGCEXTEventProvider::send_pc1_announce(
|
||||||
|
uint32_t group_number, uint32_t peer_number,
|
||||||
|
const uint8_t* id_data, size_t id_size
|
||||||
|
) {
|
||||||
|
auto pkg = build_pc1_announce(id_data, id_size);
|
||||||
|
|
||||||
|
std::cout << "NEEP: sending PC1_ANNOUNCE s:" << pkg.size() - sizeof(NGCEXT_Event::PC1_ANNOUNCE) << "\n";
|
||||||
|
|
||||||
|
// lossless?
|
||||||
|
return _t.toxGroupSendCustomPrivatePacket(group_number, peer_number, true, pkg) == TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NGCEXTEventProvider::send_all_pc1_announce(
|
||||||
|
uint32_t group_number,
|
||||||
|
const uint8_t* id_data, size_t id_size
|
||||||
|
) {
|
||||||
|
auto pkg = build_pc1_announce(id_data, id_size);
|
||||||
|
|
||||||
|
std::cout << "NEEP: sending all PC1_ANNOUNCE s:" << pkg.size() - sizeof(NGCEXT_Event::PC1_ANNOUNCE) << "\n";
|
||||||
|
|
||||||
|
// lossless?
|
||||||
|
return _t.toxGroupSendCustomPacket(group_number, true, pkg) == TOX_ERR_GROUP_SEND_CUSTOM_PACKET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
bool NGCEXTEventProvider::onToxEvent(const Tox_Event_Group_Custom_Packet* e) {
|
bool NGCEXTEventProvider::onToxEvent(const Tox_Event_Group_Custom_Packet* e) {
|
||||||
const auto group_number = tox_event_group_custom_packet_get_group_number(e);
|
const auto group_number = tox_event_group_custom_packet_get_group_number(e);
|
||||||
const auto peer_number = tox_event_group_custom_packet_get_peer_id(e);
|
const auto peer_number = tox_event_group_custom_packet_get_peer_id(e);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
// solanaceae port of tox_ngc_ext
|
// solanaceae port of tox_ngc_ext
|
||||||
|
|
||||||
#include <solanaceae/toxcore/tox_event_interface.hpp>
|
#include <solanaceae/toxcore/tox_event_interface.hpp>
|
||||||
|
#include <solanaceae/toxcore/tox_interface.hpp>
|
||||||
#include <solanaceae/util/event_provider.hpp>
|
#include <solanaceae/util/event_provider.hpp>
|
||||||
|
|
||||||
#include <solanaceae/toxcore/tox_key.hpp>
|
#include <solanaceae/toxcore/tox_key.hpp>
|
||||||
@ -287,10 +288,11 @@ struct NGCEXTEventI {
|
|||||||
using NGCEXTEventProviderI = EventProviderI<NGCEXTEventI>;
|
using NGCEXTEventProviderI = EventProviderI<NGCEXTEventI>;
|
||||||
|
|
||||||
class NGCEXTEventProvider : public ToxEventI, public NGCEXTEventProviderI {
|
class NGCEXTEventProvider : public ToxEventI, public NGCEXTEventProviderI {
|
||||||
|
ToxI& _t;
|
||||||
ToxEventProviderI& _tep;
|
ToxEventProviderI& _tep;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NGCEXTEventProvider(ToxEventProviderI& tep/*, ToxI& t*/);
|
NGCEXTEventProvider(ToxI& t, ToxEventProviderI& tep);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool parse_hs1_request_last_ids(
|
bool parse_hs1_request_last_ids(
|
||||||
@ -373,6 +375,25 @@ class NGCEXTEventProvider : public ToxEventI, public NGCEXTEventProviderI {
|
|||||||
const bool _private
|
const bool _private
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public: // send api
|
||||||
|
bool send_ft1_init(
|
||||||
|
uint32_t group_number, uint32_t peer_number,
|
||||||
|
uint32_t file_kind,
|
||||||
|
uint64_t file_size,
|
||||||
|
uint8_t transfer_id,
|
||||||
|
const uint8_t* file_id, size_t file_id_size
|
||||||
|
);
|
||||||
|
|
||||||
|
bool send_pc1_announce(
|
||||||
|
uint32_t group_number, uint32_t peer_number,
|
||||||
|
const uint8_t* id_data, size_t id_size
|
||||||
|
);
|
||||||
|
|
||||||
|
bool send_all_pc1_announce(
|
||||||
|
uint32_t group_number,
|
||||||
|
const uint8_t* id_data, size_t id_size
|
||||||
|
);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool onToxEvent(const Tox_Event_Group_Custom_Packet* e) override;
|
bool onToxEvent(const Tox_Event_Group_Custom_Packet* e) override;
|
||||||
bool onToxEvent(const Tox_Event_Group_Custom_Private_Packet* e) override;
|
bool onToxEvent(const Tox_Event_Group_Custom_Private_Packet* e) override;
|
||||||
|
@ -36,6 +36,7 @@ bool NGCFT1::sendPKG_FT1_REQUEST(
|
|||||||
return _t.toxGroupSendCustomPrivatePacket(group_number, peer_number, true, pkg) == TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_OK;
|
return _t.toxGroupSendCustomPrivatePacket(group_number, peer_number, true, pkg) == TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
bool NGCFT1::sendPKG_FT1_INIT(
|
bool NGCFT1::sendPKG_FT1_INIT(
|
||||||
uint32_t group_number, uint32_t peer_number,
|
uint32_t group_number, uint32_t peer_number,
|
||||||
uint32_t file_kind,
|
uint32_t file_kind,
|
||||||
@ -66,6 +67,8 @@ bool NGCFT1::sendPKG_FT1_INIT(
|
|||||||
return _t.toxGroupSendCustomPrivatePacket(group_number, peer_number, true, pkg) == TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_OK;
|
return _t.toxGroupSendCustomPrivatePacket(group_number, peer_number, true, pkg) == TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
bool NGCFT1::sendPKG_FT1_INIT_ACK(
|
bool NGCFT1::sendPKG_FT1_INIT_ACK(
|
||||||
uint32_t group_number, uint32_t peer_number,
|
uint32_t group_number, uint32_t peer_number,
|
||||||
uint8_t transfer_id
|
uint8_t transfer_id
|
||||||
@ -181,7 +184,8 @@ void NGCFT1::updateSendTransfer(float time_delta, uint32_t group_number, uint32_
|
|||||||
} else {
|
} else {
|
||||||
// timed out, resend
|
// timed out, resend
|
||||||
std::cerr << "NGCFT1 warning: ft init timed out, resending\n";
|
std::cerr << "NGCFT1 warning: ft init timed out, resending\n";
|
||||||
sendPKG_FT1_INIT(group_number, peer_number, tf.file_kind, tf.file_size, idx, tf.file_id.data(), tf.file_id.size());
|
//sendPKG_FT1_INIT(group_number, peer_number, tf.file_kind, tf.file_size, idx, tf.file_id.data(), tf.file_id.size());
|
||||||
|
_neep.send_ft1_init(group_number, peer_number, tf.file_kind, tf.file_size, idx, tf.file_id.data(), tf.file_id.size());
|
||||||
tf.inits_sent++;
|
tf.inits_sent++;
|
||||||
tf.time_since_activity = 0.f;
|
tf.time_since_activity = 0.f;
|
||||||
}
|
}
|
||||||
@ -338,7 +342,7 @@ void NGCFT1::iteratePeer(float time_delta, uint32_t group_number, uint32_t peer_
|
|||||||
NGCFT1::NGCFT1(
|
NGCFT1::NGCFT1(
|
||||||
ToxI& t,
|
ToxI& t,
|
||||||
ToxEventProviderI& tep,
|
ToxEventProviderI& tep,
|
||||||
NGCEXTEventProviderI& neep
|
NGCEXTEventProvider& neep
|
||||||
) : _t(t), _tep(tep), _neep(neep)
|
) : _t(t), _tep(tep), _neep(neep)
|
||||||
{
|
{
|
||||||
_neep.subscribe(this, NGCEXT_Event::FT1_REQUEST);
|
_neep.subscribe(this, NGCEXT_Event::FT1_REQUEST);
|
||||||
@ -433,7 +437,8 @@ bool NGCFT1::NGC_FT1_send_init_private(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: check return value
|
// TODO: check return value
|
||||||
sendPKG_FT1_INIT(group_number, peer_number, file_kind, file_size, idx, file_id, file_id_size);
|
//sendPKG_FT1_INIT(group_number, peer_number, file_kind, file_size, idx, file_id, file_id_size);
|
||||||
|
_neep.send_ft1_init(group_number, peer_number, file_kind, file_size, idx, file_id, file_id_size);
|
||||||
|
|
||||||
peer.send_transfers[idx] = Group::Peer::SendTransfer{
|
peer.send_transfers[idx] = Group::Peer::SendTransfer{
|
||||||
file_kind,
|
file_kind,
|
||||||
|
@ -131,7 +131,7 @@ using NGCFT1EventProviderI = EventProviderI<NGCFT1EventI>;
|
|||||||
class NGCFT1 : public ToxEventI, public NGCEXTEventI, public NGCFT1EventProviderI {
|
class NGCFT1 : public ToxEventI, public NGCEXTEventI, public NGCFT1EventProviderI {
|
||||||
ToxI& _t;
|
ToxI& _t;
|
||||||
ToxEventProviderI& _tep;
|
ToxEventProviderI& _tep;
|
||||||
NGCEXTEventProviderI& _neep;
|
NGCEXTEventProvider& _neep; // not the interface?
|
||||||
|
|
||||||
std::default_random_engine _rng{std::random_device{}()};
|
std::default_random_engine _rng{std::random_device{}()};
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ class NGCFT1 : public ToxEventI, public NGCEXTEventI, public NGCFT1EventProvider
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool sendPKG_FT1_REQUEST(uint32_t group_number, uint32_t peer_number, uint32_t file_kind, const uint8_t* file_id, size_t file_id_size);
|
bool sendPKG_FT1_REQUEST(uint32_t group_number, uint32_t peer_number, uint32_t file_kind, const uint8_t* file_id, size_t file_id_size);
|
||||||
bool sendPKG_FT1_INIT(uint32_t group_number, uint32_t peer_number, uint32_t file_kind, uint64_t file_size, uint8_t transfer_id, const uint8_t* file_id, size_t file_id_size);
|
//bool sendPKG_FT1_INIT(uint32_t group_number, uint32_t peer_number, uint32_t file_kind, uint64_t file_size, uint8_t transfer_id, const uint8_t* file_id, size_t file_id_size);
|
||||||
bool sendPKG_FT1_INIT_ACK(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id);
|
bool sendPKG_FT1_INIT_ACK(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id);
|
||||||
bool sendPKG_FT1_DATA(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, uint16_t sequence_id, const uint8_t* data, size_t data_size);
|
bool sendPKG_FT1_DATA(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, uint16_t sequence_id, const uint8_t* data, size_t data_size);
|
||||||
bool sendPKG_FT1_DATA_ACK(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, const uint16_t* seq_ids, size_t seq_ids_size);
|
bool sendPKG_FT1_DATA_ACK(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, const uint16_t* seq_ids, size_t seq_ids_size);
|
||||||
@ -215,7 +215,7 @@ class NGCFT1 : public ToxEventI, public NGCEXTEventI, public NGCFT1EventProvider
|
|||||||
NGCFT1(
|
NGCFT1(
|
||||||
ToxI& t,
|
ToxI& t,
|
||||||
ToxEventProviderI& tep,
|
ToxEventProviderI& tep,
|
||||||
NGCEXTEventProviderI& neep
|
NGCEXTEventProvider& neep
|
||||||
);
|
);
|
||||||
|
|
||||||
float iterate(float delta);
|
float iterate(float delta);
|
||||||
|
Loading…
Reference in New Issue
Block a user