diff --git a/ngc_ext_common.hpp b/ngc_ext_common.hpp index 629eb79..962eded 100644 --- a/ngc_ext_common.hpp +++ b/ngc_ext_common.hpp @@ -72,13 +72,13 @@ enum _PacketType : uint8_t { // - ] FT1_DATA_ACK, - // sender has gotten every data fragment acked, so we signal finish - // - 1 byte (temporary_file_tf_id) - FT1_DATA_FIN, + //// sender has gotten every data fragment acked, so we signal finish + //// - 1 byte (temporary_file_tf_id) + //FT1_DATA_FIN, - // and we ack that, we need this, so file_id is not reused earlier - // - 1 byte (temporary_file_tf_id) - FT1_DATA_FIN_ACK, + //// and we ack that, we need this, so file_id is not reused earlier + //// - 1 byte (temporary_file_tf_id) + //FT1_DATA_FIN_ACK, }; struct _GroupKey { diff --git a/ngc_hs1.cpp b/ngc_hs1.cpp index 0b4d2ca..7bf660d 100644 --- a/ngc_hs1.cpp +++ b/ngc_hs1.cpp @@ -71,14 +71,14 @@ void _handle_HS1_RESPONSE_LAST_IDS( size_t length ); -void _handle_HS1_ft_request_message( +void _handle_HS1_ft_recv_request( 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( +bool _handle_HS1_ft_recv_init( Tox *tox, NGC_EXT_CTX* ngc_ext_ctx, uint32_t group_number, uint32_t peer_number, @@ -87,6 +87,15 @@ bool _handle_HS1_ft_init_message( const size_t file_size ); +void _handle_HS1_ft_recv_data( + Tox *tox, NGC_EXT_CTX* ngc_ext_ctx, + uint32_t group_number, + uint32_t peer_number, + uint8_t transfer_id, + size_t data_offset, + const uint8_t* data, size_t data_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; @@ -94,8 +103,10 @@ 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); + 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_init_message); return true; } @@ -350,7 +361,7 @@ void NGC_HS1_record_message( ngc_hs1_ctx->history[g_id].peers[p_id].append(message_id, type, std::string{message, message+length}); } -void _handle_HS1_ft_request_message( +void _handle_HS1_ft_recv_request( Tox *tox, NGC_EXT_CTX* ngc_ext_ctx, uint32_t group_number, uint32_t peer_number, @@ -411,7 +422,7 @@ void _handle_HS1_ft_request_message( ); } -bool _handle_HS1_ft_init_message( +bool _handle_HS1_ft_recv_init( Tox *tox, NGC_EXT_CTX* ngc_ext_ctx, uint32_t group_number, uint32_t peer_number, @@ -460,12 +471,48 @@ bool _handle_HS1_ft_init_message( return false; // deny } + // TODO: if allready acked but got init again, they did not get the ack + // TODO: more? pending.at(msg_id).time_since_ft_activity = 0.f; + //pending.at(msg_id).transfer_acked; + group.transfers return true; // accept } +void _handle_HS1_ft_recv_data( + Tox *tox, NGC_EXT_CTX* ngc_ext_ctx, + uint32_t group_number, + uint32_t peer_number, + uint8_t transfer_id, + size_t data_offset, + const uint8_t* data, size_t data_size +) { + // get group id + _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& pending = group.peers[peer_key].pending; + // get based on transfer_id + if (!group.transfers.count(std::make_pair(peer_number, transfer_id))) { + if (data_offset != 0) { + fprintf(stderr, "!! got stray tf data from %d tid:%d\n", peer_number, transfer_id); + return; + } + + // new transfer? + fprintf(stderr, "!! got transfer from %d tid:%d\n", peer_number, transfer_id); + } + + // add data to tmp buffer + // TODO: data done? +} + #define _HS1_HAVE(x, error) if ((length - curser) < (x)) { error; } void _handle_HS1_REQUEST_LAST_IDS( diff --git a/ngc_hs1.hpp b/ngc_hs1.hpp index 948cccb..a4b304f 100644 --- a/ngc_hs1.hpp +++ b/ngc_hs1.hpp @@ -51,6 +51,17 @@ struct NGC_HS1 { struct Group { std::map<_PeerKey, Peer> peers; + + struct FileTransfers { + //uint32_t peer_number; // the peer we requested the message from + float time_since_ft_activity {0.f}; + _PeerKey msg_peer; + uint32_t msg_id; + std::vector recv_buffer; // message gets dumped into here + }; + // key: peer_number + transfer_id + std::map, FileTransfers> transfers; + }; std::map<_GroupKey, Group> history;