From 6e058a7596c72cc0237121be8b0b098cf0bd2332 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Tue, 8 Aug 2023 13:21:38 +0200 Subject: [PATCH] move filekind --- src/CMakeLists.txt | 1 + src/ngcft1.hpp | 74 ++------------------------------------ src/ngcft1_file_kind.hpp | 76 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 72 deletions(-) create mode 100644 src/ngcft1_file_kind.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7adb1dd..e08fe19 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,7 @@ target_link_libraries(ngcext PUBLIC ######################################## add_library(ngcft1 STATIC + ./ngcft1_file_kind.hpp ./ngcft1.hpp ./ngcft1.cpp diff --git a/src/ngcft1.hpp b/src/ngcft1.hpp index 7fcf9d3..87b20a2 100644 --- a/src/ngcft1.hpp +++ b/src/ngcft1.hpp @@ -11,81 +11,11 @@ #include "./rcv_buf.hpp" #include "./snd_buf.hpp" +#include "./ngcft1_file_kind.hpp" + #include #include -// uint32_t - same as tox friend ft -// TODO: fill in toxfriend file kinds -enum class NGCFT1_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 - // this id can be unique between 2 peers - ID = 8u, - - // id: hash of the info, like a torrent infohash (using the same hash as the data) - // TODO: determain internal format - // 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_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_V1_CHUNK in the implementation - HASH_SHA1_CHUNK, - HASH_SHA2_CHUNK, - - // TODO: design the same thing again for tox? (msg_pack instead of bencode?) - // id: infohash - TORRENT_V1_METAINFO, - // id: sha1 - TORRENT_V1_PIECE, // alias with SHA1_CHUNK? - - // TODO: fix all the v2 stuff here - // id: infohash - // 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 - // always of size 16KiB, except if last piece in file - TORRENT_V2_PIECE, -}; - // TODO: events //typedef void NGC_FT1_recv_request_cb( //Tox *tox, diff --git a/src/ngcft1_file_kind.hpp b/src/ngcft1_file_kind.hpp new file mode 100644 index 0000000..e4427b7 --- /dev/null +++ b/src/ngcft1_file_kind.hpp @@ -0,0 +1,76 @@ +#pragma once + +#include + +// uint32_t - same as tox friend ft +// TODO: fill in toxfriend file kinds +enum class NGCFT1_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 + // this id can be unique between 2 peers + ID = 8u, + + // id: hash of the info, like a torrent infohash (using the same hash as the data) + // TODO: determain internal format + // 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_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_V1_CHUNK in the implementation + HASH_SHA1_CHUNK, + HASH_SHA2_CHUNK, + + // TODO: design the same thing again for tox? (msg_pack instead of bencode?) + // id: infohash + TORRENT_V1_METAINFO, + // id: sha1 + TORRENT_V1_PIECE, // alias with SHA1_CHUNK? + + // TODO: fix all the v2 stuff here + // id: infohash + // 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 + // always of size 16KiB, except if last piece in file + TORRENT_V2_PIECE, +}; +