From ee593536a2ffca056242ad543ef9a7b39038d3db Mon Sep 17 00:00:00 2001 From: Green Sky Date: Wed, 30 Oct 2024 17:12:05 +0100 Subject: [PATCH] boilerplate for hs2 --- CMakeLists.txt | 15 ++++ solanaceae/ngc_ft1/ngcft1_file_kind.hpp | 18 +++++ solanaceae/ngc_hs2/ngc_hs2.cpp | 91 +++++++++++++++++++++++++ solanaceae/ngc_hs2/ngc_hs2.hpp | 44 ++++++++++++ 4 files changed, 168 insertions(+) create mode 100644 solanaceae/ngc_hs2/ngc_hs2.cpp create mode 100644 solanaceae/ngc_hs2/ngc_hs2.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index deb61cc..0706aef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,21 @@ target_link_libraries(solanaceae_ngcft1 PUBLIC ######################################## +add_library(solanaceae_ngchs2 + ./solanaceae/ngc_hs2/ngc_hs2.hpp + ./solanaceae/ngc_hs2/ngc_hs2.cpp +) +target_include_directories(solanaceae_ngchs2 PUBLIC .) +target_compile_features(solanaceae_ngchs2 PUBLIC cxx_std_17) +target_link_libraries(solanaceae_ngchs2 PUBLIC + solanaceae_ngcft1 + solanaceae_tox_contacts + solanaceae_message3 + solanaceae_object_store +) + +######################################## + add_library(solanaceae_sha1_ngcft1 # hacky deps ./solanaceae/ngc_ft1_sha1/mio.hpp diff --git a/solanaceae/ngc_ft1/ngcft1_file_kind.hpp b/solanaceae/ngc_ft1/ngcft1_file_kind.hpp index e4427b7..b4936c0 100644 --- a/solanaceae/ngc_ft1/ngcft1_file_kind.hpp +++ b/solanaceae/ngc_ft1/ngcft1_file_kind.hpp @@ -72,5 +72,23 @@ enum class NGCFT1_file_kind : uint32_t { // id: sha256 // always of size 16KiB, except if last piece in file TORRENT_V2_PIECE, + + // https://gist.github.com/Green-Sky/440cd9817a7114786850eb4c62dc57c3 + // id: ts start, ts end + // content: + // - ts start (do we need this? when this is part of the id?) + // - ts end (same) + // - list size + // - ppk + // - mid + // - ts + HS2_INFO_RANGE_TIME = 0x00000f00, + // TODO: half open ranges + // TODO: id based + // TODO: ppk based? + + // id: ppk, mid, ts + HS2_SINGLE_MESSAGE, + // TODO: message pack }; diff --git a/solanaceae/ngc_hs2/ngc_hs2.cpp b/solanaceae/ngc_hs2/ngc_hs2.cpp new file mode 100644 index 0000000..e9b2640 --- /dev/null +++ b/solanaceae/ngc_hs2/ngc_hs2.cpp @@ -0,0 +1,91 @@ +#include "./ngc_hs2.hpp" + +#include + +NGCHS2::NGCHS2( + ToxContactModel2& tcm, + ToxEventProviderI& tep, + NGCFT1& nft +) : + _tcm(tcm), + _tep_sr(tep.newSubRef(this)), + _nft(nft), + _nftep_sr(_nft.newSubRef(this)) +{ + _tep_sr + .subscribe(TOX_EVENT_GROUP_PEER_JOIN) + .subscribe(TOX_EVENT_GROUP_PEER_EXIT) + ; + + _nftep_sr + .subscribe(NGCFT1_Event::recv_init) + .subscribe(NGCFT1_Event::recv_request) + .subscribe(NGCFT1_Event::recv_init) + .subscribe(NGCFT1_Event::recv_data) + .subscribe(NGCFT1_Event::send_data) + .subscribe(NGCFT1_Event::recv_done) + .subscribe(NGCFT1_Event::send_done) + ; +} + +NGCHS2::~NGCHS2(void) { +} + +float NGCHS2::iterate(float delta) { + return 1000.f; +} + +bool NGCHS2::onEvent(const Events::NGCFT1_recv_request& e) { + if ( + e.file_kind != NGCFT1_file_kind::HS2_INFO_RANGE_TIME && + e.file_kind != NGCFT1_file_kind::HS2_SINGLE_MESSAGE + ) { + return false; // not for us + } + + return false; +} + +bool NGCHS2::onEvent(const Events::NGCFT1_recv_init& e) { + if ( + e.file_kind != NGCFT1_file_kind::HS2_INFO_RANGE_TIME && + e.file_kind != NGCFT1_file_kind::HS2_SINGLE_MESSAGE + ) { + return false; // not for us + } + + return false; +} + +bool NGCHS2::onEvent(const Events::NGCFT1_recv_data&) { + return false; +} + +bool NGCHS2::onEvent(const Events::NGCFT1_send_data&) { + return false; +} + +bool NGCHS2::onEvent(const Events::NGCFT1_recv_done&) { + return false; +} + +bool NGCHS2::onEvent(const Events::NGCFT1_send_done&) { + return false; +} + +bool NGCHS2::onToxEvent(const Tox_Event_Group_Peer_Join* e) { + const auto group_number = tox_event_group_peer_join_get_group_number(e); + const auto peer_number = tox_event_group_peer_join_get_peer_id(e); + + const auto c = _tcm.getContactGroupPeer(group_number, peer_number); + assert(c); + + // add to check list with inital cooldown + + return false; +} + +bool NGCHS2::onToxEvent(const Tox_Event_Group_Peer_Exit* e) { + return false; +} + diff --git a/solanaceae/ngc_hs2/ngc_hs2.hpp b/solanaceae/ngc_hs2/ngc_hs2.hpp new file mode 100644 index 0000000..771203f --- /dev/null +++ b/solanaceae/ngc_hs2/ngc_hs2.hpp @@ -0,0 +1,44 @@ +#pragma once + +//#include +#include + +//#include + +#include + +// fwd +class ToxContactModel2; + +class NGCHS2 : public ToxEventI, public NGCFT1EventI { + ToxContactModel2& _tcm; + //Contact3Registry& _cr; + //RegistryMessageModelI& _rmm; + ToxEventProviderI::SubscriptionReference _tep_sr; + NGCFT1& _nft; + NGCFT1EventProviderI::SubscriptionReference _nftep_sr; + + public: + NGCHS2( + ToxContactModel2& tcm, + ToxEventProviderI& tep, + NGCFT1& nf + ); + + ~NGCHS2(void); + + float iterate(float delta); + + protected: + bool onEvent(const Events::NGCFT1_recv_request&) override; + bool onEvent(const Events::NGCFT1_recv_init&) override; + bool onEvent(const Events::NGCFT1_recv_data&) override; + bool onEvent(const Events::NGCFT1_send_data&) override; + bool onEvent(const Events::NGCFT1_recv_done&) override; + bool onEvent(const Events::NGCFT1_send_done&) override; + + protected: + bool onToxEvent(const Tox_Event_Group_Peer_Join* e) override; + bool onToxEvent(const Tox_Event_Group_Peer_Exit* e) override; +}; +