highlevel sceleton
This commit is contained in:
parent
80791626c7
commit
0459b43b64
@ -30,6 +30,22 @@ target_link_libraries(ngcft1 PUBLIC
|
|||||||
|
|
||||||
########################################
|
########################################
|
||||||
|
|
||||||
|
add_library(sha1_ngcft1 STATIC
|
||||||
|
./hash_utils.hpp
|
||||||
|
./hash_utils.cpp
|
||||||
|
|
||||||
|
./sha1_ngcft1.hpp
|
||||||
|
./sha1_ngcft1.cpp
|
||||||
|
)
|
||||||
|
target_link_libraries(sha1_ngcft1 PUBLIC
|
||||||
|
ngcft1
|
||||||
|
sha1::sha1
|
||||||
|
solanaceae_tox_contacts
|
||||||
|
solanaceae_message3
|
||||||
|
)
|
||||||
|
|
||||||
|
########################################
|
||||||
|
|
||||||
add_library(plugin_ngcft1 SHARED
|
add_library(plugin_ngcft1 SHARED
|
||||||
./plugin_ngcft1.cpp
|
./plugin_ngcft1.cpp
|
||||||
)
|
)
|
||||||
@ -38,6 +54,7 @@ target_link_libraries(plugin_ngcft1 PUBLIC
|
|||||||
solanaceae_plugin
|
solanaceae_plugin
|
||||||
ngcext
|
ngcext
|
||||||
ngcft1
|
ngcft1
|
||||||
|
sha1_ngcft1
|
||||||
)
|
)
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
|
26
src/hash_utils.cpp
Normal file
26
src/hash_utils.cpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#include "./hash_utils.hpp"
|
||||||
|
|
||||||
|
#include <sha1.h>
|
||||||
|
|
||||||
|
// returns the 20bytes sha1 hash
|
||||||
|
std::vector<uint8_t> hash_sha1(const uint8_t* data, size_t size) {
|
||||||
|
SHA1_CTX ctx;
|
||||||
|
SHA1Init(&ctx);
|
||||||
|
|
||||||
|
{ // lib only takes uint32_t sizes, so chunk it
|
||||||
|
constexpr size_t hash_block_size {0xffffffff};
|
||||||
|
size_t i = 0;
|
||||||
|
for (; i + hash_block_size < size; i += hash_block_size) {
|
||||||
|
SHA1Update(&ctx, reinterpret_cast<const uint8_t*>(data) + i, hash_block_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i < size) {
|
||||||
|
SHA1Update(&ctx, reinterpret_cast<const uint8_t*>(data) + i, size - i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<uint8_t> sha1_hash(20);
|
||||||
|
SHA1Final(sha1_hash.data(), &ctx);
|
||||||
|
return sha1_hash;
|
||||||
|
}
|
||||||
|
|
10
src/hash_utils.hpp
Normal file
10
src/hash_utils.hpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
// returns the 20bytes sha1 hash
|
||||||
|
std::vector<uint8_t> hash_sha1(const uint8_t* data, size_t size);
|
||||||
|
|
||||||
|
inline std::vector<uint8_t> hash_sha1(const char* data, size_t size) { return hash_sha1(reinterpret_cast<const uint8_t*>(data), size); }
|
||||||
|
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "./ngcext.hpp"
|
#include "./ngcext.hpp"
|
||||||
#include "./ngcft1.hpp"
|
#include "./ngcft1.hpp"
|
||||||
|
#include "./sha1_ngcft1.hpp"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -15,6 +16,7 @@
|
|||||||
static std::unique_ptr<NGCEXTEventProvider> g_ngcextep = nullptr;
|
static std::unique_ptr<NGCEXTEventProvider> g_ngcextep = nullptr;
|
||||||
// TODO: make sep plug
|
// TODO: make sep plug
|
||||||
static std::unique_ptr<NGCFT1> g_ngcft1 = nullptr;
|
static std::unique_ptr<NGCFT1> g_ngcft1 = nullptr;
|
||||||
|
static std::unique_ptr<SHA1_NGCFT1> g_sha1_ngcft1 = nullptr;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
@ -35,10 +37,14 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
|
|||||||
|
|
||||||
ToxI* tox_i = nullptr;
|
ToxI* tox_i = nullptr;
|
||||||
ToxEventProviderI* tox_event_provider_i = nullptr;
|
ToxEventProviderI* tox_event_provider_i = nullptr;
|
||||||
|
RegistryMessageModel* rmm = nullptr;
|
||||||
|
ToxContactModel2* tcm = nullptr;
|
||||||
|
|
||||||
{ // make sure required types are loaded
|
{ // make sure required types are loaded
|
||||||
tox_i = RESOLVE_INSTANCE(ToxI);
|
tox_i = RESOLVE_INSTANCE(ToxI);
|
||||||
tox_event_provider_i = RESOLVE_INSTANCE(ToxEventProviderI);
|
tox_event_provider_i = RESOLVE_INSTANCE(ToxEventProviderI);
|
||||||
|
rmm = RESOLVE_INSTANCE(RegistryMessageModel);
|
||||||
|
tcm = RESOLVE_INSTANCE(ToxContactModel2);
|
||||||
|
|
||||||
if (tox_i == nullptr) {
|
if (tox_i == nullptr) {
|
||||||
std::cerr << "PLUGIN NGCEXT missing ToxI\n";
|
std::cerr << "PLUGIN NGCEXT missing ToxI\n";
|
||||||
@ -49,12 +55,23 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
|
|||||||
std::cerr << "PLUGIN NGCEXT missing ToxEventProviderI\n";
|
std::cerr << "PLUGIN NGCEXT missing ToxEventProviderI\n";
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rmm == nullptr) {
|
||||||
|
std::cerr << "PLUGIN NGCEXT missing RegistryMessageModel\n";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tcm == nullptr) {
|
||||||
|
std::cerr << "PLUGIN NGCEXT missing ToxContactModel2\n";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// static store, could be anywhere tho
|
// static store, could be anywhere tho
|
||||||
// construct with fetched dependencies
|
// construct with fetched dependencies
|
||||||
g_ngcextep = std::make_unique<NGCEXTEventProvider>(*tox_event_provider_i);
|
g_ngcextep = std::make_unique<NGCEXTEventProvider>(*tox_event_provider_i);
|
||||||
g_ngcft1 = std::make_unique<NGCFT1>(*tox_i, *tox_event_provider_i, *g_ngcextep.get());
|
g_ngcft1 = std::make_unique<NGCFT1>(*tox_i, *tox_event_provider_i, *g_ngcextep.get());
|
||||||
|
g_sha1_ngcft1 = std::make_unique<SHA1_NGCFT1>(*rmm, *g_ngcft1.get(), *tcm);
|
||||||
|
|
||||||
// register types
|
// register types
|
||||||
PROVIDE_INSTANCE(NGCEXTEventProviderI, "NGCEXT", g_ngcextep.get());
|
PROVIDE_INSTANCE(NGCEXTEventProviderI, "NGCEXT", g_ngcextep.get());
|
||||||
@ -62,12 +79,15 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
|
|||||||
PROVIDE_INSTANCE(NGCFT1EventProviderI, "NGCEXT", g_ngcft1.get());
|
PROVIDE_INSTANCE(NGCFT1EventProviderI, "NGCEXT", g_ngcft1.get());
|
||||||
PROVIDE_INSTANCE(NGCFT1, "NGCEXT", g_ngcft1.get());
|
PROVIDE_INSTANCE(NGCFT1, "NGCEXT", g_ngcft1.get());
|
||||||
|
|
||||||
|
PROVIDE_INSTANCE(SHA1_NGCFT1, "NGCEXT", g_sha1_ngcft1.get());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void) {
|
SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void) {
|
||||||
std::cout << "PLUGIN NGCEXT STOP()\n";
|
std::cout << "PLUGIN NGCEXT STOP()\n";
|
||||||
|
|
||||||
|
g_sha1_ngcft1.reset();
|
||||||
g_ngcft1.reset();
|
g_ngcft1.reset();
|
||||||
g_ngcextep.reset();
|
g_ngcextep.reset();
|
||||||
}
|
}
|
||||||
|
49
src/sha1_ngcft1.cpp
Normal file
49
src/sha1_ngcft1.cpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#include "./sha1_ngcft1.hpp"
|
||||||
|
|
||||||
|
#include <solanaceae/toxcore/utils.hpp>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
SHA1_NGCFT1::SHA1_NGCFT1(
|
||||||
|
RegistryMessageModel& rmm,
|
||||||
|
NGCFT1EventProviderI& nftep,
|
||||||
|
ToxContactModel2& tcm
|
||||||
|
) :
|
||||||
|
_rmm(rmm),
|
||||||
|
_nftep(nftep),
|
||||||
|
_tcm(tcm)
|
||||||
|
{
|
||||||
|
_nftep.subscribe(this, NGCFT1_Event::recv_request);
|
||||||
|
_nftep.subscribe(this, NGCFT1_Event::recv_init);
|
||||||
|
_nftep.subscribe(this, NGCFT1_Event::recv_data);
|
||||||
|
_nftep.subscribe(this, NGCFT1_Event::send_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_request& e) {
|
||||||
|
// only interested in sha1
|
||||||
|
if (e.file_kind != NGCFT1_file_kind::HASH_SHA1_INFO && e.file_kind != NGCFT1_file_kind::HASH_SHA1_CHUNK) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//std::cout << "SHA1_NGCFT1: FT1_REQUEST fk:" << int(e.file_kind) << " [" << bin2hex({e.file_id, e.file_id+e.file_id_size}) << "]\n";
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_init& e) {
|
||||||
|
// only interested in sha1
|
||||||
|
if (e.file_kind != NGCFT1_file_kind::HASH_SHA1_INFO && e.file_kind != NGCFT1_file_kind::HASH_SHA1_CHUNK) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_data& e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_send_data& e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
30
src/sha1_ngcft1.hpp
Normal file
30
src/sha1_ngcft1.hpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// solanaceae port of sha1 fts for NGCFT1
|
||||||
|
|
||||||
|
#include <solanaceae/message3/registry_message_model.hpp>
|
||||||
|
#include <solanaceae/tox_contacts/tox_contact_model2.hpp>
|
||||||
|
|
||||||
|
#include "./ngcft1.hpp"
|
||||||
|
|
||||||
|
class SHA1_NGCFT1 : public RegistryMessageModelEventI, public NGCFT1EventI {
|
||||||
|
RegistryMessageModel& _rmm;
|
||||||
|
NGCFT1EventProviderI& _nftep;
|
||||||
|
ToxContactModel2& _tcm;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SHA1_NGCFT1(
|
||||||
|
RegistryMessageModel& rmm,
|
||||||
|
NGCFT1EventProviderI& nftep,
|
||||||
|
ToxContactModel2& tcm
|
||||||
|
);
|
||||||
|
|
||||||
|
//void 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; // const?
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user