This commit is contained in:
2024-08-02 20:15:52 +02:00
commit f66873a57a
7 changed files with 215 additions and 0 deletions

20
src/CMakeLists.txt Normal file
View File

@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.9...3.24 FATAL_ERROR)
project(solanaceae)
add_library(solanaceae_tox_p2prng
./solanaceae/tox_p2prng/p2prng.hpp
./solanaceae/tox_p2prng/tox_p2prng.hpp
./solanaceae/tox_p2prng/tox_p2prng.cpp
)
target_include_directories(solanaceae_tox_p2prng PUBLIC .)
target_compile_features(solanaceae_tox_p2prng PUBLIC cxx_std_17)
target_link_libraries(solanaceae_tox_p2prng PUBLIC
solanaceae_util
solanaceae_tox_contacts
p2prng
)
########################################

View File

@@ -0,0 +1,18 @@
#pragma once
#include <solanaceae/contact/contact_model3.hpp>
#include <solanaceae/util/span.hpp>
#include <cstdint>
#include <vector>
// general p2prng interface
struct P2PRNGI {
// returns unique id, you can then use when listen to events
// chooses peers depending on C, if C is a group it (tries?) to use everyone?
virtual std::vector<uint8_t> newGernation(Contact3Handle c, const ByteSpan initial_state_user_data) = 0;
// manually tell it which peers to use
virtual std::vector<uint8_t> newGernationPeers(const std::vector<Contact3Handle>& c_vec, const ByteSpan initial_state_user_data) = 0;
// TODO: events
};

View File

@@ -0,0 +1,17 @@
#include "./tox_p2prng.hpp"
ToxP2PRNG::ToxP2PRNG(ToxContactModel2& tcm) : _tcm(tcm) {
}
ToxP2PRNG::~ToxP2PRNG(void) {
}
std::vector<uint8_t> ToxP2PRNG::newGernation(Contact3Handle c, const ByteSpan initial_state_user_data) {
return {};
}
std::vector<uint8_t> newGernationPeers(const std::vector<Contact3Handle>& c_vec, const ByteSpan initial_state_user_data) {
return {};
}

View File

@@ -0,0 +1,17 @@
#pragma once
#include "./p2prng.hpp"
#include <solanaceae/tox_contacts/tox_contact_model2.hpp>
class ToxP2PRNG : public P2PRNGI {
ToxContactModel2& _tcm;
public:
ToxP2PRNG(ToxContactModel2& tcm);
~ToxP2PRNG();
public: // p2prng
std::vector<uint8_t> newGernation(Contact3Handle c, const ByteSpan initial_state_user_data) override;
std::vector<uint8_t> newGernationPeers(const std::vector<Contact3Handle>& c_vec, const ByteSpan initial_state_user_data) override;
};