This commit is contained in:
Green Sky 2024-08-02 20:15:52 +02:00
commit f66873a57a
No known key found for this signature in database
7 changed files with 215 additions and 0 deletions

26
.gitignore vendored Normal file
View File

@ -0,0 +1,26 @@
.vs/
*.o
*.swp
~*
*~
.idea/
cmake-build-debug/
cmake-build-debugandtest/
cmake-build-release/
*.stackdump
*.coredump
compile_commands.json
/build*
/result*
.clangd
.cache
.DS_Store
.AppleDouble
.LSOverride
CMakeLists.txt.user*
CMakeCache.txt
*.tox
imgui.ini

72
CMakeLists.txt Normal file
View File

@ -0,0 +1,72 @@
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
# cmake setup begin
project(solanaceae_message_fragment_store)
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(SOLANACEAE_TOX_P2PRNG_STANDALONE ON)
else()
set(SOLANACEAE_TOX_P2PRNG_STANDALONE OFF)
endif()
message("II SOLANACEAE_TOX_P2PRNG_STANDALONE " ${SOLANACEAE_TOX_P2PRNG_STANDALONE})
option(SOLANACEAE_TOX_P2PRNG_BUILD_PLUGINS "Build the solanaceae_tox_p2prng plugins" ${SOLANACEAE_TOX_P2PRNG_STANDALONE})
if (SOLANACEAE_TOX_P2PRNG_STANDALONE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# defaulting to debug mode, if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
# setup my vim ycm :D
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# more paths
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
endif()
# external libs
add_subdirectory(./external EXCLUDE_FROM_ALL) # before increasing warn levels, sad :(
if (SOLANACEAE_TOX_P2PRNG_STANDALONE)
set(CMAKE_CXX_EXTENSIONS OFF)
# bump up warning levels appropriately for clang, gcc & msvc
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
add_compile_options(
-Wall -Wextra # Reasonable and standard
-Wpedantic # Warn if non-standard C++ is used
-Wunused # Warn on anything being unused
#-Wconversion # Warn on type conversions that may lose data
#-Wsign-conversion # Warn on sign conversions
-Wshadow # Warn if a variable declaration shadows one from a parent context
)
if (NOT WIN32)
#link_libraries(-fsanitize=address)
#link_libraries(-fsanitize=address,undefined)
#link_libraries(-fsanitize-address-use-after-scope)
#link_libraries(-fsanitize=undefined)
endif()
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
if (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
endif()
endif()
# cmake setup end
add_subdirectory(./src)
if (SOLANACEAE_TOX_P2PRNG_BUILD_PLUGINS)
#add_subdirectory(./plugins)
endif()

45
external/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,45 @@
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
include(FetchContent)
if (NOT TARGET solanaceae_util)
FetchContent_Declare(solanaceae_util
GIT_REPOSITORY https://github.com/Green-Sky/solanaceae_util.git
GIT_TAG master
)
FetchContent_MakeAvailable(solanaceae_util)
endif()
if (NOT TARGET solanaceae_plugin)
FetchContent_Declare(solanaceae_plugin
GIT_REPOSITORY https://github.com/Green-Sky/solanaceae_plugin.git
GIT_TAG master
)
FetchContent_MakeAvailable(solanaceae_plugin)
endif()
if (NOT TARGET solanaceae_contact)
FetchContent_Declare(solanaceae_contact
GIT_REPOSITORY https://github.com/Green-Sky/solanaceae_contact.git
GIT_TAG master
)
FetchContent_MakeAvailable(solanaceae_contact)
endif()
# only need the contact stuff
if (NOT TARGET solanaceae_tox_contacts)
FetchContent_Declare(solanaceae_tox
GIT_REPOSITORY https://github.com/Green-Sky/solanaceae_tox.git
GIT_TAG master
)
FetchContent_MakeAvailable(solanaceae_tox)
endif()
if (NOT TARGET p2prng)
FetchContent_Declare(p2prng
GIT_REPOSITORY https://github.com/Green-Sky/p2prng.git
GIT_TAG master
)
FetchContent_MakeAvailable(p2prng)
endif()

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;
};