2022-10-08 20:58:10 +02:00
|
|
|
#pragma once
|
|
|
|
|
2022-10-01 02:32:34 +02:00
|
|
|
#include <tox/tox.h>
|
|
|
|
|
2022-10-03 01:15:49 +02:00
|
|
|
#include "ngc_ext_common.h"
|
|
|
|
#include "ngc_hs1.h"
|
|
|
|
#include "ngc_ft1.h"
|
|
|
|
|
2022-10-01 02:32:34 +02:00
|
|
|
//#include <cstdint>
|
|
|
|
//#include <cassert>
|
|
|
|
//#include <new>
|
|
|
|
//#include <map>
|
|
|
|
//#include <list>
|
|
|
|
//#include <set>
|
|
|
|
//#include <optional>
|
|
|
|
//#include <algorithm>
|
|
|
|
#include <array>
|
|
|
|
|
|
|
|
enum _PacketType : uint8_t {
|
|
|
|
// TODO: why?
|
|
|
|
INVALID = 0u,
|
|
|
|
|
|
|
|
//TODO: make it possible to go further back
|
|
|
|
// request last (few) message_ids for a peer
|
|
|
|
// - peer_key bytes (peer key we want to know ids for)
|
|
|
|
// - 1 byte (uint8_t count ids, atleast 1)
|
2022-10-03 23:33:08 +02:00
|
|
|
HS1_REQUEST_LAST_IDS = 1u,
|
2022-10-01 02:32:34 +02:00
|
|
|
|
|
|
|
// respond to a request with 0 or more message ids, sorted by newest first
|
|
|
|
// - peer_key bytes (the msg_ids are from)
|
|
|
|
// - 1 byte (uint8_t count ids, can be 0)
|
|
|
|
// - array [
|
2022-10-08 00:15:51 +02:00
|
|
|
// - msg_id bytes (the message id)
|
2022-10-01 02:32:34 +02:00
|
|
|
// - ]
|
|
|
|
HS1_RESPONSE_LAST_IDS,
|
|
|
|
|
2022-10-01 21:11:28 +02:00
|
|
|
// request the other side to initiate a FT
|
|
|
|
// - 1 byte (file_kind)
|
|
|
|
// - X bytes (file_kind dependent id, differnt sizes)
|
2022-10-03 23:33:08 +02:00
|
|
|
FT1_REQUEST = 8u,
|
2022-10-01 21:11:28 +02:00
|
|
|
|
2022-10-06 02:24:23 +02:00
|
|
|
// TODO: request result negative, speed up not found
|
|
|
|
|
2022-10-01 21:11:28 +02:00
|
|
|
// tell the other side you want to start a FT
|
|
|
|
// TODO: might use id layer instead. with it, it would look similar to friends_ft
|
|
|
|
// - 1 byte (file_kind)
|
2022-10-06 02:24:23 +02:00
|
|
|
// - 8 bytes (data size, can be 0 if unknown, BUT files have to be atleast 1 byte)
|
2022-10-01 21:11:28 +02:00
|
|
|
// - 1 byte (temporary_file_tf_id, for this peer only, technically just a prefix to distinguish between simultainious fts)
|
2022-10-06 22:00:06 +02:00
|
|
|
// - X bytes (file_kind dependent id, differnt sizes)
|
2022-10-01 21:11:28 +02:00
|
|
|
FT1_INIT,
|
|
|
|
|
|
|
|
// acknowlage init (like an accept)
|
2022-10-06 02:24:23 +02:00
|
|
|
// like tox ft control continue
|
2022-10-08 00:15:51 +02:00
|
|
|
// - 1 byte (transfer_id)
|
2022-10-01 21:11:28 +02:00
|
|
|
FT1_INIT_ACK,
|
|
|
|
|
2022-10-06 02:24:23 +02:00
|
|
|
// TODO: init deny, speed up non acceptance
|
|
|
|
|
2022-10-01 21:11:28 +02:00
|
|
|
// data fragment
|
|
|
|
// - 1 byte (temporary_file_tf_id)
|
|
|
|
// - 2 bytes (sequece id)
|
|
|
|
// - X bytes (the data fragment)
|
|
|
|
// (size is implicit)
|
|
|
|
FT1_DATA,
|
|
|
|
|
|
|
|
// acknowlage data fragments
|
|
|
|
// TODO: last 3 should be sufficient, 5 should be generous, would eleminate the byte for size
|
|
|
|
// - 1 byte (temporary_file_tf_id)
|
2022-10-09 02:28:55 +02:00
|
|
|
// // this is implicit (pkg size)- 1 byte (number of sequence ids to ack, this kind of depends on window size)
|
2022-10-01 21:11:28 +02:00
|
|
|
// - array [ (of sequece ids)
|
|
|
|
// - 2 bytes (sequece id)
|
|
|
|
// - ]
|
|
|
|
FT1_DATA_ACK,
|
|
|
|
|
2022-10-14 22:07:25 +02:00
|
|
|
//// sender has gotten every data fragment acked, so we signal finish
|
|
|
|
//// - 1 byte (temporary_file_tf_id)
|
|
|
|
//FT1_DATA_FIN,
|
2022-10-01 21:11:28 +02:00
|
|
|
|
2022-10-14 22:07:25 +02:00
|
|
|
//// and we ack that, we need this, so file_id is not reused earlier
|
|
|
|
//// - 1 byte (temporary_file_tf_id)
|
|
|
|
//FT1_DATA_FIN_ACK,
|
2022-10-01 02:32:34 +02:00
|
|
|
};
|
|
|
|
|
2022-10-03 03:54:16 +02:00
|
|
|
struct _GroupKey {
|
|
|
|
std::array<uint8_t, TOX_GROUP_CHAT_ID_SIZE> data;
|
|
|
|
|
|
|
|
_GroupKey(void) = default;
|
|
|
|
_GroupKey(const _GroupKey& other) : data(other.data) {}
|
|
|
|
_GroupKey(_GroupKey&&) = delete;
|
|
|
|
bool operator<(const _GroupKey& rhs) const;
|
|
|
|
bool operator==(const _GroupKey& rhs) const;
|
|
|
|
size_t size(void) const { return data.size(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _PeerKey {
|
|
|
|
std::array<uint8_t, TOX_GROUP_PEER_PUBLIC_KEY_SIZE> data;
|
|
|
|
|
|
|
|
_PeerKey(void) = default;
|
|
|
|
_PeerKey(const _PeerKey& other) : data(other.data) {}
|
|
|
|
_PeerKey(_PeerKey&&) = delete;
|
|
|
|
bool operator<(const _PeerKey& rhs) const;
|
|
|
|
bool operator==(const _PeerKey& rhs) const;
|
|
|
|
size_t size(void) const { return data.size(); }
|
|
|
|
};
|
|
|
|
|
2022-10-03 01:15:49 +02:00
|
|
|
using handle_group_custom_packet_cb = void(*)(
|
|
|
|
Tox* tox,
|
|
|
|
NGC_EXT_CTX* ngc_ext_ctx,
|
|
|
|
|
|
|
|
uint32_t group_number,
|
|
|
|
uint32_t peer_number,
|
|
|
|
|
|
|
|
const uint8_t *data,
|
|
|
|
size_t length
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
struct NGC_EXT_CTX {
|
|
|
|
std::array<handle_group_custom_packet_cb, 256> callbacks;
|
|
|
|
NGC_HS1* ngc_hs1_ctx = nullptr;
|
|
|
|
NGC_FT1* ngc_ft1_ctx = nullptr;
|
|
|
|
};
|
|
|
|
|
2022-10-03 23:33:08 +02:00
|
|
|
[[maybe_unused]] static const char* _pkgid2str(_PacketType type) {
|
|
|
|
#define _EXT_CASE(x) case (x): return #x;
|
|
|
|
switch (type) {
|
|
|
|
_EXT_CASE(INVALID)
|
|
|
|
|
|
|
|
_EXT_CASE(HS1_REQUEST_LAST_IDS)
|
|
|
|
_EXT_CASE(HS1_RESPONSE_LAST_IDS)
|
|
|
|
|
|
|
|
_EXT_CASE(FT1_REQUEST)
|
|
|
|
_EXT_CASE(FT1_INIT)
|
|
|
|
_EXT_CASE(FT1_INIT_ACK)
|
|
|
|
_EXT_CASE(FT1_DATA)
|
|
|
|
_EXT_CASE(FT1_DATA_ACK)
|
2022-10-26 02:58:42 +02:00
|
|
|
//_EXT_CASE(FT1_DATA_FIN)
|
|
|
|
//_EXT_CASE(FT1_DATA_FIN_ACK)
|
2022-10-03 23:33:08 +02:00
|
|
|
|
|
|
|
default: return "<unk>";
|
|
|
|
}
|
|
|
|
#undef _EXT_CASE
|
|
|
|
}
|
|
|
|
|