mirror of
https://github.com/Green-Sky/tox_ngc_ft1.git
synced 2025-12-07 04:06:35 +01:00
file kind refactor, backwards incompatible
This commit is contained in:
61
ngc_ft1.h
61
ngc_ft1.h
@@ -18,7 +18,7 @@ typedef struct NGC_FT1 NGC_FT1;
|
||||
|
||||
struct NGC_FT1_options {
|
||||
// TODO
|
||||
size_t acks_per_packet; // 5
|
||||
size_t acks_per_packet; // 3
|
||||
|
||||
float init_retry_timeout_after; // 10sec
|
||||
|
||||
@@ -28,15 +28,16 @@ struct NGC_FT1_options {
|
||||
size_t packet_window_size; // 2
|
||||
};
|
||||
|
||||
// uint16_t ?
|
||||
// uint32_t - same as tox friend ft
|
||||
// ffs c does not allow types
|
||||
typedef enum NGC_FT1_file_kind /*: uint8_t*/ {
|
||||
//INVALID = 0u,
|
||||
typedef enum NGC_FT1_file_kind /*: uint32_t*/ {
|
||||
//INVALID = 0u, // DATA?
|
||||
|
||||
// id:
|
||||
// group (implicit)
|
||||
// peer pub key + msg_id
|
||||
NGC_HS1_MESSAGE_BY_ID = 1u, // history sync PoC 1
|
||||
// TODO: oops, 1 should be avatar v1
|
||||
|
||||
// id: TOX_FILE_ID_LENGTH (32) bytes
|
||||
// this is basically and id and probably not a hash, like the tox friend api
|
||||
@@ -48,32 +49,54 @@ typedef enum NGC_FT1_file_kind /*: uint8_t*/ {
|
||||
// draft: (for single file)
|
||||
// - 256 bytes | filename
|
||||
// - 8bytes | file size
|
||||
// - 4bytes | chunk size
|
||||
// - array of chunk hashes (ids) [
|
||||
// - SHA1 bytes (20)
|
||||
// - ]
|
||||
HASH_SHA1_INFO,
|
||||
// draft: (for single file) v2
|
||||
// - c-string | filename
|
||||
// - 8bytes | file size
|
||||
// - 4bytes | chunk size
|
||||
// - array of chunk hashes (ids) [
|
||||
// - SHA1 bytes (20)
|
||||
// - ]
|
||||
HASH_SHA1_INFO2,
|
||||
// draft: multiple files
|
||||
// - 4bytes | number of filenames
|
||||
// - array of filenames (variable length c-strings) [
|
||||
// - c-string | filename (including path and '/' as dir seperator)
|
||||
// - ]
|
||||
// - 256 bytes | filename
|
||||
// - 8bytes | file size
|
||||
// - fixed chunk size of 4kb
|
||||
// - array of chunk hashes (ids) [
|
||||
// - SHAX bytes
|
||||
// - ]
|
||||
HASH_SHA1_INFO,
|
||||
HASH_SHA2_INFO,
|
||||
HASH_SHA1_INFO3,
|
||||
HASH_SHA2_INFO, // hm?
|
||||
|
||||
// id: hash of the content
|
||||
// TODO: fixed chunk size or variable (defined in info)
|
||||
// if "variable" sized, it can be aliased with TORRENT_VX_CHUNK in the implementation
|
||||
// if "variable" sized, it can be aliased with TORRENT_V1_CHUNK in the implementation
|
||||
HASH_SHA1_CHUNK,
|
||||
HASH_SHA2_CHUNK,
|
||||
|
||||
// :)
|
||||
// draft for fun and profit
|
||||
// TODO: should we even support v1?
|
||||
// TODO: design the same thing again for tox? (msg_pack instead of bencode?)
|
||||
// id: infohash
|
||||
TORRENT_V1_METAINFO,
|
||||
// id: sha1
|
||||
TORRENT_V1_CHUNK, // alias with SHA1_CHUNK?
|
||||
TORRENT_V1_PIECE, // alias with SHA1_CHUNK?
|
||||
|
||||
// id: infohash
|
||||
TORRENT_V2_METAINFO, // meta info is kind of more complicated than that <.<
|
||||
// in v2, metainfo contains only the root hashes of the merkletree(s)
|
||||
TORRENT_V2_METAINFO,
|
||||
// id: root hash
|
||||
// contains all the leaf hashes for a file root hash
|
||||
TORRENT_V2_FILE_HASHES,
|
||||
// id: sha256
|
||||
TORRENT_V2_CHUNK,
|
||||
// always of size 16KiB, except if last piece in file
|
||||
TORRENT_V2_PIECE,
|
||||
} NGC_FT1_file_kind;
|
||||
|
||||
// ========== init / kill ==========
|
||||
@@ -93,7 +116,7 @@ void NGC_FT1_iterate(Tox *tox, NGC_FT1* ngc_ft1_ctx, float time_delta);
|
||||
void NGC_FT1_send_request_private(
|
||||
Tox *tox, NGC_FT1* ngc_ft1_ctx,
|
||||
uint32_t group_number, uint32_t peer_number,
|
||||
NGC_FT1_file_kind file_kind,
|
||||
uint32_t file_kind,
|
||||
const uint8_t* file_id, size_t file_id_size
|
||||
);
|
||||
|
||||
@@ -106,7 +129,7 @@ typedef void NGC_FT1_recv_request_cb(
|
||||
|
||||
void NGC_FT1_register_callback_recv_request(
|
||||
NGC_FT1* ngc_ft1_ctx,
|
||||
NGC_FT1_file_kind file_kind,
|
||||
uint32_t file_kind,
|
||||
NGC_FT1_recv_request_cb* callback,
|
||||
void* user_data
|
||||
);
|
||||
@@ -117,7 +140,7 @@ void NGC_FT1_register_callback_recv_request(
|
||||
bool NGC_FT1_send_init_private(
|
||||
Tox *tox, NGC_FT1* ngc_ft1_ctx,
|
||||
uint32_t group_number, uint32_t peer_number,
|
||||
NGC_FT1_file_kind file_kind,
|
||||
uint32_t file_kind,
|
||||
const uint8_t* file_id, size_t file_id_size,
|
||||
size_t file_size,
|
||||
uint8_t* transfer_id
|
||||
@@ -135,7 +158,7 @@ typedef bool NGC_FT1_recv_init_cb(
|
||||
|
||||
void NGC_FT1_register_callback_recv_init(
|
||||
NGC_FT1* ngc_ft1_ctx,
|
||||
NGC_FT1_file_kind file_kind,
|
||||
uint32_t file_kind,
|
||||
NGC_FT1_recv_init_cb* callback,
|
||||
void* user_data
|
||||
);
|
||||
@@ -155,7 +178,7 @@ typedef void NGC_FT1_recv_data_cb(
|
||||
|
||||
void NGC_FT1_register_callback_recv_data(
|
||||
NGC_FT1* ngc_ft1_ctx,
|
||||
NGC_FT1_file_kind file_kind,
|
||||
uint32_t file_kind,
|
||||
NGC_FT1_recv_data_cb* callback,
|
||||
void* user_data
|
||||
);
|
||||
@@ -174,7 +197,7 @@ typedef void NGC_FT1_send_data_cb(
|
||||
|
||||
void NGC_FT1_register_callback_send_data(
|
||||
NGC_FT1* ngc_ft1_ctx,
|
||||
NGC_FT1_file_kind file_kind,
|
||||
uint32_t file_kind,
|
||||
NGC_FT1_send_data_cb* callback,
|
||||
void* user_data
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user