2022-10-08 20:58:10 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "./ngc_hs1.h"
|
|
|
|
|
|
|
|
#include "ngc_ext_common.hpp"
|
|
|
|
#include "ngc_ft1.h"
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <map>
|
|
|
|
#include <list>
|
|
|
|
#include <set>
|
2022-10-26 02:58:42 +02:00
|
|
|
#include <vector>
|
2022-10-08 20:58:10 +02:00
|
|
|
#include <optional>
|
|
|
|
|
|
|
|
struct NGC_HS1 {
|
|
|
|
NGC_HS1_options options;
|
|
|
|
|
|
|
|
// callbacks
|
|
|
|
//tox_group_message_cb* client_tox_msg_callback;
|
2023-01-12 03:04:20 +01:00
|
|
|
NGC_HS1_group_message_cb* cb_group_message {nullptr};
|
2022-10-08 20:58:10 +02:00
|
|
|
|
|
|
|
// key - key - key - value store
|
|
|
|
// group pubkey - peer pubkey - msg_id - message(type + text)
|
|
|
|
struct Message {
|
|
|
|
uint32_t msg_id{};
|
|
|
|
Tox_Message_Type type{};
|
|
|
|
std::string text{};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Peer {
|
|
|
|
std::optional<uint32_t> id;
|
|
|
|
std::map<uint32_t, Message> dict;
|
|
|
|
std::list<uint32_t> order; // ordered list of message ids
|
|
|
|
|
|
|
|
// msg_ids we have only heard of, with peer_number of who we heard it from
|
|
|
|
std::map<uint32_t, std::set<uint32_t>> heard_of;
|
|
|
|
|
|
|
|
struct PendingFTRequest {
|
|
|
|
uint32_t peer_number; // the peer we requested the message from
|
|
|
|
float time_since_ft_activity {0.f};
|
|
|
|
};
|
|
|
|
std::map<uint32_t, PendingFTRequest> pending; // key msg_id
|
|
|
|
|
|
|
|
// dont start immediatly
|
|
|
|
float time_since_last_request_sent {0.f};
|
|
|
|
|
|
|
|
void append(uint32_t msg_id, Tox_Message_Type type, const std::string& text);
|
|
|
|
|
|
|
|
// returns if new (from that peer)
|
|
|
|
bool hear(uint32_t msg_id, uint32_t peer_number);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Group {
|
|
|
|
std::map<_PeerKey, Peer> peers;
|
2022-10-14 22:07:25 +02:00
|
|
|
|
|
|
|
struct FileTransfers {
|
|
|
|
_PeerKey msg_peer;
|
|
|
|
uint32_t msg_id;
|
2023-01-12 02:36:29 +01:00
|
|
|
float time_since_ft_activity {0.f};
|
2022-10-14 22:07:25 +02:00
|
|
|
std::vector<uint8_t> recv_buffer; // message gets dumped into here
|
2023-01-12 02:36:29 +01:00
|
|
|
size_t file_size {0};
|
2022-10-14 22:07:25 +02:00
|
|
|
};
|
|
|
|
// key: peer_number + transfer_id
|
|
|
|
std::map<std::pair<uint32_t, uint8_t>, FileTransfers> transfers;
|
|
|
|
|
2023-01-12 02:36:29 +01:00
|
|
|
struct Sending {
|
|
|
|
_PeerKey msg_peer;
|
|
|
|
uint32_t msg_id;
|
|
|
|
};
|
|
|
|
std::map<std::pair<uint32_t, uint8_t>, Sending> sending;
|
2022-10-08 20:58:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
std::map<_GroupKey, Group> history;
|
|
|
|
};
|
|
|
|
|
|
|
|
void _handle_HS1_REQUEST_LAST_IDS(
|
|
|
|
Tox* tox,
|
|
|
|
NGC_EXT_CTX* ngc_ext_ctx,
|
|
|
|
|
|
|
|
uint32_t group_number,
|
|
|
|
uint32_t peer_number,
|
|
|
|
|
|
|
|
const uint8_t *data,
|
|
|
|
size_t length
|
|
|
|
);
|
|
|
|
|
|
|
|
void _handle_HS1_RESPONSE_LAST_IDS(
|
|
|
|
Tox* tox,
|
|
|
|
NGC_EXT_CTX* ngc_ext_ctx,
|
|
|
|
|
|
|
|
uint32_t group_number,
|
|
|
|
uint32_t peer_number,
|
|
|
|
|
|
|
|
const uint8_t *data,
|
|
|
|
size_t length
|
|
|
|
);
|
|
|
|
|
|
|
|
void _handle_HS1_ft_request_message(
|
|
|
|
Tox *tox, NGC_EXT_CTX* ngc_ext_ctx,
|
|
|
|
uint32_t group_number,
|
|
|
|
uint32_t peer_number,
|
|
|
|
const uint8_t* file_id, size_t file_id_size
|
|
|
|
);
|
|
|
|
|
|
|
|
bool _handle_HS1_ft_init_message(
|
|
|
|
Tox *tox, NGC_EXT_CTX* ngc_ext_ctx,
|
|
|
|
uint32_t group_number,
|
|
|
|
uint32_t peer_number,
|
|
|
|
const uint8_t* file_id, size_t file_id_size,
|
|
|
|
const uint8_t transfer_id,
|
|
|
|
const size_t file_size
|
|
|
|
);
|
|
|
|
|