init ft (no ack or data yet)
This commit is contained in:
94
ngc_hs1.cpp
94
ngc_hs1.cpp
@@ -116,6 +116,22 @@ static void _handle_HS1_RESPONSE_LAST_IDS(
|
||||
size_t length
|
||||
);
|
||||
|
||||
static 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
|
||||
);
|
||||
|
||||
static 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
|
||||
);
|
||||
|
||||
bool NGC_HS1_init(NGC_EXT_CTX* ngc_ext_ctx, const struct NGC_HS1_options* options) {
|
||||
ngc_ext_ctx->ngc_hs1_ctx = new NGC_HS1;
|
||||
ngc_ext_ctx->ngc_hs1_ctx->options = *options;
|
||||
@@ -123,6 +139,9 @@ bool NGC_HS1_init(NGC_EXT_CTX* ngc_ext_ctx, const struct NGC_HS1_options* option
|
||||
ngc_ext_ctx->callbacks[HS1_REQUEST_LAST_IDS] = _handle_HS1_REQUEST_LAST_IDS;
|
||||
ngc_ext_ctx->callbacks[HS1_RESPONSE_LAST_IDS] = _handle_HS1_RESPONSE_LAST_IDS;
|
||||
|
||||
NGC_FT1_register_callback_recv_request(ngc_ext_ctx, NGC_FT1_file_kind::NGC_HS1_MESSAGE_BY_ID, _handle_HS1_ft_request_message);
|
||||
NGC_FT1_register_callback_recv_init(ngc_ext_ctx, NGC_FT1_file_kind::NGC_HS1_MESSAGE_BY_ID, _handle_HS1_ft_init_message);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -217,7 +236,7 @@ static void _iterate_group(Tox *tox, NGC_EXT_CTX* ngc_ext_ctx, uint32_t group_nu
|
||||
}
|
||||
|
||||
// send request
|
||||
NGC_FT1_request_private(
|
||||
NGC_FT1_send_request_private(
|
||||
tox, ngc_ext_ctx,
|
||||
group_number, remote_peer_number,
|
||||
NGC_FT1_file_kind::NGC_HS1_MESSAGE_BY_ID,
|
||||
@@ -230,8 +249,8 @@ static void _iterate_group(Tox *tox, NGC_EXT_CTX* ngc_ext_ctx, uint32_t group_nu
|
||||
}
|
||||
}
|
||||
}
|
||||
assert(ngc_hs1_ctx->history.size() != 0);
|
||||
|
||||
assert(ngc_hs1_ctx->history.size() != 0);
|
||||
assert(ngc_hs1_ctx->history.count(g_id));
|
||||
}
|
||||
|
||||
@@ -376,6 +395,77 @@ void NGC_HS1_record_message(
|
||||
ngc_hs1_ctx->history[g_id].peers[p_id].append(message_id, type, std::string{message, message+length});
|
||||
}
|
||||
|
||||
static 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
|
||||
) {
|
||||
assert(file_id_size == TOX_GROUP_PEER_PUBLIC_KEY_SIZE+sizeof(uint32_t));
|
||||
|
||||
// get peer_key from file_id
|
||||
_PeerKey peer_key;
|
||||
std::copy(file_id, file_id+peer_key.size(), peer_key.data.begin());
|
||||
|
||||
// get msg_id from file_id
|
||||
// HACK: little endian
|
||||
uint32_t msg_id;
|
||||
uint8_t* tmp_ptr = reinterpret_cast<uint8_t*>(&msg_id);
|
||||
std::copy(file_id+TOX_GROUP_PEER_PUBLIC_KEY_SIZE, file_id+TOX_GROUP_PEER_PUBLIC_KEY_SIZE+sizeof(uint32_t), tmp_ptr);
|
||||
|
||||
fprintf(stderr, "got a ft request for xxx msg_id %08X\n", msg_id);
|
||||
|
||||
// get group id
|
||||
_GroupKey group_id{};
|
||||
{ // TODO: error
|
||||
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;
|
||||
|
||||
// do we have that message
|
||||
|
||||
if (!peers.count(peer_key)) {
|
||||
fprintf(stderr, "got ft request for unknown peer\n");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& peer = peers.at(peer_key);
|
||||
if (!peer.dict.count(msg_id)) {
|
||||
fprintf(stderr, "got ft request for unknown message_id %08X\n", msg_id);
|
||||
return;
|
||||
}
|
||||
|
||||
// yes we do. now we need to init ft?
|
||||
|
||||
//fprintf(stderr, "TODO: init ft for %08X\n", msg_id);
|
||||
|
||||
// filesize is
|
||||
// - 1 byte msg_type (normal / action)
|
||||
// - x bytes msg_text
|
||||
// msg_id is part of file_id
|
||||
const auto& msg = peer.dict.at(msg_id);
|
||||
size_t file_size = 1 + msg.text.size();
|
||||
|
||||
NGC_FT1_send_init_private(
|
||||
tox, ngc_ext_ctx,
|
||||
group_number, peer_number,
|
||||
NGC_HS1_MESSAGE_BY_ID,
|
||||
file_id, file_id_size,
|
||||
file_size
|
||||
);
|
||||
}
|
||||
|
||||
static 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
|
||||
) {
|
||||
return false; // deny
|
||||
}
|
||||
|
||||
#define _HS1_HAVE(x, error) if ((length - curser) < (x)) { error; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user