compiled again, some kinda bug still there
This commit is contained in:
parent
89f9610730
commit
f7313aa2bf
108
ngc_hs1.cpp
108
ngc_hs1.cpp
@ -49,38 +49,42 @@ bool NGC_HS1::Peer::hear(uint32_t msg_id, uint32_t peer_number) {
|
||||
}
|
||||
|
||||
void _handle_HS1_ft_recv_request(
|
||||
Tox *tox, NGC_EXT_CTX* ngc_ext_ctx,
|
||||
Tox *tox,
|
||||
uint32_t group_number,
|
||||
uint32_t peer_number,
|
||||
const uint8_t* file_id, size_t file_id_size
|
||||
const uint8_t* file_id, size_t file_id_size,
|
||||
void* user_data
|
||||
);
|
||||
|
||||
bool _handle_HS1_ft_recv_init(
|
||||
Tox *tox, NGC_EXT_CTX* ngc_ext_ctx,
|
||||
Tox *tox,
|
||||
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
|
||||
const size_t file_size,
|
||||
void* user_data
|
||||
);
|
||||
|
||||
void _handle_HS1_ft_recv_data(
|
||||
Tox *tox, NGC_EXT_CTX* ngc_ext_ctx,
|
||||
Tox *tox,
|
||||
uint32_t group_number,
|
||||
uint32_t peer_number,
|
||||
uint8_t transfer_id,
|
||||
size_t data_offset,
|
||||
const uint8_t* data, size_t data_size
|
||||
const uint8_t* data, size_t data_size,
|
||||
void* user_data
|
||||
);
|
||||
|
||||
void _handle_HS1_ft_send_data(
|
||||
Tox *tox, NGC_EXT_CTX* ngc_ext_ctx,
|
||||
Tox *tox,
|
||||
|
||||
uint32_t group_number,
|
||||
uint32_t peer_number,
|
||||
uint8_t transfer_id,
|
||||
|
||||
size_t data_offset, uint8_t* data, size_t data_size
|
||||
size_t data_offset, uint8_t* data, size_t data_size,
|
||||
void* user_data
|
||||
);
|
||||
|
||||
NGC_HS1* NGC_HS1_new(const struct NGC_HS1_options* options) {
|
||||
@ -100,10 +104,12 @@ bool NGC_HS1_register_ext(NGC_HS1* ngc_hs1_ctx, NGC_EXT_CTX* ngc_ext_ctx) {
|
||||
}
|
||||
|
||||
bool NGC_HS1_register_ft1(NGC_HS1* ngc_hs1_ctx, NGC_FT1* ngc_ft1_ctx) {
|
||||
NGC_FT1_register_callback_recv_request(ngc_ext_ctx, NGC_FT1_file_kind::NGC_HS1_MESSAGE_BY_ID, _handle_HS1_ft_recv_request);
|
||||
NGC_FT1_register_callback_recv_init(ngc_ext_ctx, NGC_FT1_file_kind::NGC_HS1_MESSAGE_BY_ID, _handle_HS1_ft_recv_init);
|
||||
NGC_FT1_register_callback_recv_data(ngc_ext_ctx, NGC_FT1_file_kind::NGC_HS1_MESSAGE_BY_ID, _handle_HS1_ft_recv_data);
|
||||
NGC_FT1_register_callback_send_data(ngc_ext_ctx, NGC_FT1_file_kind::NGC_HS1_MESSAGE_BY_ID, _handle_HS1_ft_send_data);
|
||||
ngc_hs1_ctx->ngc_ft1_ctx = ngc_ft1_ctx;
|
||||
NGC_FT1_register_callback_recv_request(ngc_ft1_ctx, NGC_FT1_file_kind::NGC_HS1_MESSAGE_BY_ID, _handle_HS1_ft_recv_request, ngc_hs1_ctx);
|
||||
NGC_FT1_register_callback_recv_init(ngc_ft1_ctx, NGC_FT1_file_kind::NGC_HS1_MESSAGE_BY_ID, _handle_HS1_ft_recv_init, ngc_hs1_ctx);
|
||||
NGC_FT1_register_callback_recv_data(ngc_ft1_ctx, NGC_FT1_file_kind::NGC_HS1_MESSAGE_BY_ID, _handle_HS1_ft_recv_data, ngc_hs1_ctx);
|
||||
NGC_FT1_register_callback_send_data(ngc_ft1_ctx, NGC_FT1_file_kind::NGC_HS1_MESSAGE_BY_ID, _handle_HS1_ft_send_data, ngc_hs1_ctx);
|
||||
return true;
|
||||
}
|
||||
|
||||
#if 0
|
||||
@ -134,9 +140,7 @@ void NGC_HS1_kill(NGC_EXT_CTX* ngc_ext_ctx) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static void _iterate_group(Tox *tox, NGC_HS1* ngc_hs1_ctx, /*NGC_EXT_CTX* ngc_ext_ctx,*/ uint32_t group_number, float time_delta) {
|
||||
//NGC_HS1* ngc_hs1_ctx = ngc_ext_ctx->ngc_hs1_ctx;
|
||||
|
||||
static void _iterate_group(Tox *tox, NGC_HS1* ngc_hs1_ctx, uint32_t group_number, float time_delta) {
|
||||
//fprintf(stderr, "g:%u\n", g_i);
|
||||
NGC_EXT::GroupKey g_id{};
|
||||
{ // TODO: error
|
||||
@ -233,7 +237,7 @@ static void _iterate_group(Tox *tox, NGC_HS1* ngc_hs1_ctx, /*NGC_EXT_CTX* ngc_ex
|
||||
|
||||
// send request
|
||||
NGC_FT1_send_request_private(
|
||||
tox, ngc_ext_ctx,
|
||||
tox, ngc_hs1_ctx->ngc_ft1_ctx,
|
||||
group_number, remote_peer_number,
|
||||
NGC_FT1_file_kind::NGC_HS1_MESSAGE_BY_ID,
|
||||
file_id.data(), file_id.size()
|
||||
@ -250,9 +254,9 @@ static void _iterate_group(Tox *tox, NGC_HS1* ngc_hs1_ctx, /*NGC_EXT_CTX* ngc_ex
|
||||
assert(ngc_hs1_ctx->history.count(g_id));
|
||||
}
|
||||
|
||||
void NGC_HS1_iterate(Tox *tox, NGC_EXT_CTX* ngc_ext_ctx/*, void *user_data*/) {
|
||||
assert(ngc_ext_ctx);
|
||||
assert(ngc_ext_ctx->ngc_hs1_ctx);
|
||||
void NGC_HS1_iterate(Tox *tox, NGC_HS1* ngc_hs1_ctx) {
|
||||
//void NGC_HS1_iterate(Tox *tox, NGC_EXT_CTX* ngc_ext_ctx/*, void *user_data*/) {
|
||||
assert(ngc_hs1_ctx);
|
||||
|
||||
//fprintf(stderr, "groups: %u\n", ngc_hs1_ctx->history.size());
|
||||
|
||||
@ -263,7 +267,7 @@ void NGC_HS1_iterate(Tox *tox, NGC_EXT_CTX* ngc_ext_ctx/*, void *user_data*/) {
|
||||
if (tox_group_is_connected(tox, g_i, &g_err)) {
|
||||
// valid and connected here
|
||||
// TODO: delta time, or other timers
|
||||
_iterate_group(tox, ngc_ext_ctx->ngc_hs1_ctx, g_i, 0.02f);
|
||||
_iterate_group(tox, ngc_hs1_ctx, g_i, 0.02f);
|
||||
g_c_done++;
|
||||
} else if (g_err != TOX_ERR_GROUP_IS_CONNECTED_GROUP_NOT_FOUND) {
|
||||
g_c_done++;
|
||||
@ -277,8 +281,7 @@ void NGC_HS1_iterate(Tox *tox, NGC_EXT_CTX* ngc_ext_ctx/*, void *user_data*/) {
|
||||
}
|
||||
}
|
||||
|
||||
void NGC_HS1_peer_online(Tox* tox, NGC_EXT_CTX* ngc_ext_ctx, uint32_t group_number, uint32_t peer_number, bool online) {
|
||||
NGC_HS1* ngc_hs1_ctx = ngc_ext_ctx->ngc_hs1_ctx;
|
||||
void NGC_HS1_peer_online(Tox* tox, NGC_HS1* ngc_hs1_ctx, uint32_t group_number, uint32_t peer_number, bool online) {
|
||||
// get group id
|
||||
NGC_EXT::GroupKey g_id{};
|
||||
{ // TODO: error
|
||||
@ -309,7 +312,7 @@ void NGC_HS1_peer_online(Tox* tox, NGC_EXT_CTX* ngc_ext_ctx, uint32_t group_numb
|
||||
|
||||
bool NGC_HS1_shim_group_send_message(
|
||||
const Tox *tox,
|
||||
NGC_EXT_CTX* ngc_ext_ctx,
|
||||
NGC_HS1* ngc_hs1_ctx,
|
||||
|
||||
uint32_t group_number,
|
||||
|
||||
@ -326,7 +329,7 @@ bool NGC_HS1_shim_group_send_message(
|
||||
|
||||
bool ret = tox_group_send_message(tox, group_number, type, message, length, msg_id_ptr, error);
|
||||
|
||||
NGC_HS1_record_own_message(tox, ngc_ext_ctx, group_number, type, message, length, *msg_id_ptr);
|
||||
NGC_HS1_record_own_message(tox, ngc_hs1_ctx, group_number, type, message, length, *msg_id_ptr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -334,13 +337,12 @@ bool NGC_HS1_shim_group_send_message(
|
||||
// record own msg
|
||||
void NGC_HS1_record_own_message(
|
||||
const Tox *tox,
|
||||
NGC_EXT_CTX* ngc_ext_ctx,
|
||||
NGC_HS1* ngc_hs1_ctx,
|
||||
|
||||
uint32_t group_number,
|
||||
|
||||
Tox_Message_Type type, const uint8_t *message, size_t length, uint32_t message_id
|
||||
) {
|
||||
NGC_HS1* ngc_hs1_ctx = ngc_ext_ctx->ngc_hs1_ctx;
|
||||
fprintf(stderr, "HS: record_own_message %08X\n", message_id);
|
||||
// get group id
|
||||
NGC_EXT::GroupKey g_id{};
|
||||
@ -359,24 +361,22 @@ void NGC_HS1_record_own_message(
|
||||
assert(ngc_hs1_ctx->history.count(g_id));
|
||||
}
|
||||
|
||||
void NGC_HS1_register_callback_group_message(NGC_EXT_CTX* ngc_ext_ctx, NGC_HS1_group_message_cb* callback) {
|
||||
assert(ngc_ext_ctx);
|
||||
assert(ngc_ext_ctx->ngc_hs1_ctx);
|
||||
void NGC_HS1_register_callback_group_message(NGC_HS1* ngc_hs1_ctx, NGC_HS1_group_message_cb* callback) {
|
||||
assert(ngc_hs1_ctx);
|
||||
|
||||
ngc_ext_ctx->ngc_hs1_ctx->cb_group_message = callback;
|
||||
ngc_hs1_ctx->cb_group_message = callback;
|
||||
}
|
||||
|
||||
// record others msg
|
||||
void NGC_HS1_record_message(
|
||||
const Tox *tox,
|
||||
NGC_EXT_CTX* ngc_ext_ctx,
|
||||
NGC_HS1* ngc_hs1_ctx,
|
||||
|
||||
uint32_t group_number,
|
||||
uint32_t peer_number,
|
||||
|
||||
Tox_Message_Type type, const uint8_t *message, size_t length, uint32_t message_id
|
||||
) {
|
||||
NGC_HS1* ngc_hs1_ctx = ngc_ext_ctx->ngc_hs1_ctx;
|
||||
if (!ngc_hs1_ctx->options.record_others) {
|
||||
return;
|
||||
}
|
||||
@ -398,11 +398,13 @@ void NGC_HS1_record_message(
|
||||
}
|
||||
|
||||
void _handle_HS1_ft_recv_request(
|
||||
Tox *tox, NGC_EXT_CTX* ngc_ext_ctx,
|
||||
Tox *tox,
|
||||
uint32_t group_number,
|
||||
uint32_t peer_number,
|
||||
const uint8_t* file_id, size_t file_id_size
|
||||
const uint8_t* file_id, size_t file_id_size,
|
||||
void* user_data
|
||||
) {
|
||||
NGC_HS1* ngc_hs1_ctx = static_cast<NGC_HS1*>(user_data);
|
||||
assert(file_id_size == TOX_GROUP_PEER_PUBLIC_KEY_SIZE+sizeof(uint32_t));
|
||||
|
||||
// get peer_key from file_id
|
||||
@ -423,7 +425,7 @@ void _handle_HS1_ft_recv_request(
|
||||
tox_group_get_chat_id(tox, group_number, group_id.data.data(), nullptr);
|
||||
}
|
||||
|
||||
const auto& peers = ngc_ext_ctx->ngc_hs1_ctx->history[group_id].peers;
|
||||
const auto& peers = ngc_hs1_ctx->history[group_id].peers;
|
||||
|
||||
// do we have that message
|
||||
|
||||
@ -452,7 +454,7 @@ void _handle_HS1_ft_recv_request(
|
||||
uint8_t transfer_id {0};
|
||||
|
||||
NGC_FT1_send_init_private(
|
||||
tox, ngc_ext_ctx,
|
||||
tox, ngc_hs1_ctx->ngc_ft1_ctx,
|
||||
group_number, peer_number,
|
||||
NGC_HS1_MESSAGE_BY_ID,
|
||||
file_id, file_id_size,
|
||||
@ -462,17 +464,19 @@ void _handle_HS1_ft_recv_request(
|
||||
|
||||
//TODO: can fail
|
||||
|
||||
ngc_ext_ctx->ngc_hs1_ctx->history[group_id].sending[std::make_pair(peer_number, transfer_id)] = {peer_key, msg_id};
|
||||
ngc_hs1_ctx->history[group_id].sending[std::make_pair(peer_number, transfer_id)] = {peer_key, msg_id};
|
||||
}
|
||||
|
||||
bool _handle_HS1_ft_recv_init(
|
||||
Tox *tox, NGC_EXT_CTX* ngc_ext_ctx,
|
||||
Tox *tox,
|
||||
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
|
||||
const size_t file_size,
|
||||
void* user_data
|
||||
) {
|
||||
NGC_HS1* ngc_hs1_ctx = static_cast<NGC_HS1*>(user_data);
|
||||
//fprintf(stderr, "HS: -------hs handle ft init\n");
|
||||
|
||||
// peer id and msg id from file id
|
||||
@ -497,7 +501,7 @@ bool _handle_HS1_ft_recv_init(
|
||||
tox_group_get_chat_id(tox, group_number, g_id.data.data(), nullptr);
|
||||
}
|
||||
|
||||
auto& group = ngc_ext_ctx->ngc_hs1_ctx->history[g_id];
|
||||
auto& group = ngc_hs1_ctx->history[g_id];
|
||||
|
||||
auto& pending = group.peers[peer_key].pending;
|
||||
|
||||
@ -534,20 +538,22 @@ bool _handle_HS1_ft_recv_init(
|
||||
}
|
||||
|
||||
void _handle_HS1_ft_recv_data(
|
||||
Tox *tox, NGC_EXT_CTX* ngc_ext_ctx,
|
||||
Tox *tox,
|
||||
uint32_t group_number,
|
||||
uint32_t peer_number,
|
||||
uint8_t transfer_id,
|
||||
size_t data_offset,
|
||||
const uint8_t* data, size_t data_size
|
||||
const uint8_t* data, size_t data_size,
|
||||
void* user_data
|
||||
) {
|
||||
NGC_HS1* ngc_hs1_ctx = static_cast<NGC_HS1*>(user_data);
|
||||
// get group id
|
||||
NGC_EXT::GroupKey g_id{};
|
||||
{ // TODO: error
|
||||
tox_group_get_chat_id(tox, group_number, g_id.data.data(), nullptr);
|
||||
}
|
||||
|
||||
auto& group = ngc_ext_ctx->ngc_hs1_ctx->history[g_id];
|
||||
auto& group = ngc_hs1_ctx->history[g_id];
|
||||
|
||||
// get based on transfer_id
|
||||
if (!group.transfers.count(std::make_pair(peer_number, transfer_id))) {
|
||||
@ -581,10 +587,10 @@ void _handle_HS1_ft_recv_data(
|
||||
peer.pending.erase(transfer.msg_id);
|
||||
peer.append(transfer.msg_id, static_cast<Tox_Message_Type>(transfer.recv_buffer.front()), std::string(reinterpret_cast<const char*>(transfer.recv_buffer.data()+1)));
|
||||
|
||||
assert(ngc_ext_ctx->ngc_hs1_ctx->cb_group_message);
|
||||
assert(ngc_hs1_ctx->cb_group_message);
|
||||
// we dont notify if we dont know the peer id. this kinda breaks some stuff
|
||||
if (peer.id.has_value()) {
|
||||
ngc_ext_ctx->ngc_hs1_ctx->cb_group_message(
|
||||
ngc_hs1_ctx->cb_group_message(
|
||||
tox,
|
||||
group_number, peer.id.value(),
|
||||
static_cast<Tox_Message_Type>(transfer.recv_buffer.front()),
|
||||
@ -599,21 +605,23 @@ void _handle_HS1_ft_recv_data(
|
||||
}
|
||||
|
||||
void _handle_HS1_ft_send_data(
|
||||
Tox *tox, NGC_EXT_CTX* ngc_ext_ctx,
|
||||
Tox *tox,
|
||||
|
||||
uint32_t group_number,
|
||||
uint32_t peer_number,
|
||||
uint8_t transfer_id,
|
||||
|
||||
size_t data_offset, uint8_t* data, size_t data_size
|
||||
size_t data_offset, uint8_t* data, size_t data_size,
|
||||
void* user_data
|
||||
) {
|
||||
NGC_HS1* ngc_hs1_ctx = static_cast<NGC_HS1*>(user_data);
|
||||
// get group id
|
||||
NGC_EXT::GroupKey g_id{};
|
||||
{ // TODO: error
|
||||
tox_group_get_chat_id(tox, group_number, g_id.data.data(), nullptr);
|
||||
}
|
||||
|
||||
auto& group = ngc_ext_ctx->ngc_hs1_ctx->history[g_id];
|
||||
auto& group = ngc_hs1_ctx->history[g_id];
|
||||
|
||||
if (!group.sending.count(std::make_pair(peer_number, transfer_id))) {
|
||||
fprintf(stderr, "HS: error, unknown sending transfer %d:%d\n", peer_number, transfer_id);
|
||||
@ -657,7 +665,7 @@ void _handle_HS1_REQUEST_LAST_IDS(
|
||||
size_t length,
|
||||
void* user_data
|
||||
) {
|
||||
NGC_HS1* ngc_hs1_ctx = ngc_ext_ctx->ngc_hs1_ctx;
|
||||
NGC_HS1* ngc_hs1_ctx = static_cast<NGC_HS1*>(user_data);
|
||||
size_t curser = 0;
|
||||
|
||||
NGC_EXT::PeerKey p_key;
|
||||
@ -731,7 +739,7 @@ void _handle_HS1_RESPONSE_LAST_IDS(
|
||||
size_t length,
|
||||
void* user_data
|
||||
) {
|
||||
NGC_HS1* ngc_hs1_ctx = ngc_ext_ctx->ngc_hs1_ctx;
|
||||
NGC_HS1* ngc_hs1_ctx = static_cast<NGC_HS1*>(user_data);
|
||||
size_t curser = 0;
|
||||
|
||||
NGC_EXT::PeerKey p_key;
|
||||
|
13
ngc_hs1.h
13
ngc_hs1.h
@ -48,11 +48,12 @@ void NGC_HS1_kill(NGC_HS1* ngc_hs1_ctx);
|
||||
//void NGC_HS1_kill(NGC_EXT_CTX* ngc_ext_ctx);
|
||||
|
||||
// ========== iterate ==========
|
||||
void NGC_HS1_iterate(Tox *tox, NGC_EXT_CTX* ngc_ext_ctx/*, void *user_data*/);
|
||||
void NGC_HS1_iterate(Tox *tox, NGC_HS1* ngc_hs1_ctx);
|
||||
//void NGC_HS1_iterate(Tox *tox, NGC_EXT_CTX* ngc_ext_ctx/*, void *user_data*/);
|
||||
|
||||
// ========== peer online/offline ==========
|
||||
|
||||
void NGC_HS1_peer_online(Tox* tox, NGC_EXT_CTX* ngc_ext_ctx, uint32_t group_number, uint32_t peer_number, bool online);
|
||||
void NGC_HS1_peer_online(Tox* tox, NGC_HS1* ngc_hs1_ctx, uint32_t group_number, uint32_t peer_number, bool online);
|
||||
|
||||
// ========== send ==========
|
||||
|
||||
@ -60,7 +61,7 @@ void NGC_HS1_peer_online(Tox* tox, NGC_EXT_CTX* ngc_ext_ctx, uint32_t group_numb
|
||||
// NGC_HS1_record_own_message()
|
||||
bool NGC_HS1_shim_group_send_message(
|
||||
const Tox *tox,
|
||||
NGC_EXT_CTX* ngc_ext_ctx,
|
||||
NGC_HS1* ngc_hs1_ctx,
|
||||
|
||||
uint32_t group_number,
|
||||
|
||||
@ -74,7 +75,7 @@ bool NGC_HS1_shim_group_send_message(
|
||||
// record own msg
|
||||
void NGC_HS1_record_own_message(
|
||||
const Tox *tox,
|
||||
NGC_EXT_CTX* ngc_ext_ctx,
|
||||
NGC_HS1* ngc_hs1_ctx,
|
||||
|
||||
uint32_t group_number,
|
||||
|
||||
@ -94,12 +95,12 @@ typedef void NGC_HS1_group_message_cb(
|
||||
);
|
||||
|
||||
// callback for when history sync has a new message
|
||||
void NGC_HS1_register_callback_group_message(NGC_EXT_CTX* ngc_ext_ctx, NGC_HS1_group_message_cb* callback);
|
||||
void NGC_HS1_register_callback_group_message(NGC_HS1* ngc_hs1_ctx, NGC_HS1_group_message_cb* callback); // TODO: userdata
|
||||
|
||||
// record others msg
|
||||
void NGC_HS1_record_message(
|
||||
const Tox *tox,
|
||||
NGC_EXT_CTX* ngc_ext_ctx,
|
||||
NGC_HS1* ngc_hs1_ctx,
|
||||
|
||||
uint32_t group_number,
|
||||
uint32_t peer_number,
|
||||
|
@ -15,8 +15,9 @@
|
||||
struct NGC_HS1 {
|
||||
NGC_HS1_options options;
|
||||
|
||||
NGC_FT1* ngc_ft1_ctx {nullptr};
|
||||
|
||||
// callbacks
|
||||
//tox_group_message_cb* client_tox_msg_callback;
|
||||
NGC_HS1_group_message_cb* cb_group_message {nullptr};
|
||||
|
||||
// key - key - key - value store
|
||||
|
Reference in New Issue
Block a user