101 lines
2.1 KiB
C++
101 lines
2.1 KiB
C++
|
#include <tox/tox.h>
|
||
|
|
||
|
//#include <cstdint>
|
||
|
//#include <cassert>
|
||
|
//#include <new>
|
||
|
//#include <map>
|
||
|
//#include <list>
|
||
|
//#include <set>
|
||
|
//#include <optional>
|
||
|
//#include <algorithm>
|
||
|
#include <array>
|
||
|
|
||
|
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 {
|
||
|
for (size_t i = 0; i < data.size(); i++) {
|
||
|
if (data[i] < rhs.data[i]) {
|
||
|
return true;
|
||
|
} else if (data[i] > rhs.data[i]) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
return false; // equal
|
||
|
}
|
||
|
|
||
|
bool operator==(const _GroupKey& rhs) const {
|
||
|
for (size_t i = 0; i < data.size(); i++) {
|
||
|
if (data[i] != rhs.data[i]) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
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 {
|
||
|
for (size_t i = 0; i < data.size(); i++) {
|
||
|
if (data[i] < rhs.data[i]) {
|
||
|
return true;
|
||
|
} else if (data[i] > rhs.data[i]) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
return false; // equal
|
||
|
}
|
||
|
|
||
|
bool operator==(const _PeerKey& rhs) const {
|
||
|
for (size_t i = 0; i < data.size(); i++) {
|
||
|
if (data[i] != rhs.data[i]) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
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)
|
||
|
HS1_REQUEST_LAST_IDS,
|
||
|
|
||
|
// 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 [
|
||
|
// - msg_id bytes (the message id
|
||
|
// - ]
|
||
|
HS1_RESPONSE_LAST_IDS,
|
||
|
|
||
|
};
|
||
|
|
||
|
static const char* _pkgid2str(_PacketType type) {
|
||
|
#define _HS1_CASE(x) case (x): return #x;
|
||
|
switch (type) {
|
||
|
_HS1_CASE(INVALID)
|
||
|
_HS1_CASE(HS1_REQUEST_LAST_IDS)
|
||
|
_HS1_CASE(HS1_RESPONSE_LAST_IDS)
|
||
|
default: return "<unk>";
|
||
|
}
|
||
|
#undef _HS1_CASE
|
||
|
}
|
||
|
|