Compare commits

..

1 Commits

Author SHA1 Message Date
0324a203f1 enable debug symbols and small ngcft fixes
Some checks failed
ContinuousDelivery / windows (push) Waiting to run
ContinuousDelivery / release (push) Blocked by required conditions
ContinuousIntegration / macos (push) Waiting to run
ContinuousIntegration / windows (push) Waiting to run
ContinuousDelivery / linux-ubuntu (push) Failing after 15s
ContinuousIntegration / linux (push) Failing after 15s
ContinuousIntegration / android (push) Failing after 15s
2024-07-14 20:12:27 +02:00
35 changed files with 376 additions and 636 deletions

View File

@ -14,7 +14,7 @@ jobs:
linux-ubuntu:
timeout-minutes: 10
runs-on: ubuntu-22.04
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
@ -25,7 +25,7 @@ jobs:
run: sudo apt update && sudo apt -y install libsodium-dev
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_FLAGS=-gz -DCMAKE_CXX_FLAGS=-gz
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
@ -46,15 +46,15 @@ jobs:
- name: Compress artifacts
shell: bash
run: |
tar -czvf ${{ github.event.repository.name }}-${{ steps.tag.outputs.name }}-${{ runner.os }}-ubuntu22.04-x86_64.tar.gz -C ${{github.workspace}}/build/bin/ .
tar -czvf ${{ github.event.repository.name }}-${{ steps.tag.outputs.name }}-${{ runner.os }}-ubuntu20.04-x86_64.tar.gz -C ${{github.workspace}}/build/bin/ .
- uses: actions/upload-artifact@v4
with:
# TODO: simpler name?
name: ${{ github.event.repository.name }}-${{ steps.tag.outputs.name }}-${{ runner.os }}-ubuntu22.04-x86_64
name: ${{ github.event.repository.name }}-${{ steps.tag.outputs.name }}-${{ runner.os }}-ubuntu20.04-x86_64
# TODO: do propper packing
path: |
${{github.workspace}}/${{ github.event.repository.name }}-${{ steps.tag.outputs.name }}-${{ runner.os }}-ubuntu22.04-x86_64.tar.gz
${{github.workspace}}/${{ github.event.repository.name }}-${{ steps.tag.outputs.name }}-${{ runner.os }}-ubuntu20.04-x86_64.tar.gz
windows:
@ -67,17 +67,14 @@ jobs:
with:
submodules: recursive
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: update vcpkg
shell: bash
run: |
cd C:/vcpkg
git pull
- name: Install Dependencies
env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
run: vcpkg install pkgconf:x64-windows libsodium:x64-windows-static pthreads:x64-windows-static
run: vcpkg install libsodium:x64-windows-static pthreads:x64-windows-static
# setup vs env
- uses: ilammy/msvc-dev-cmd@v1
@ -85,7 +82,7 @@ jobs:
arch: amd64
- name: Configure CMake
run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static -DPKG_CONFIG_EXECUTABLE=C:/vcpkg/installed/x64-windows/tools/pkgconf/pkgconf.exe
run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
@ -103,12 +100,6 @@ jobs:
echo "name=dev-${SAFE_NAME}-${SHORT_HASH}" >> $GITHUB_OUTPUT
fi
- name: Clean temporary artifacts
# msvc sometimes produces .ilk files, which are used for linking only
shell: powershell
run: |
Remove-Item "${{github.workspace}}/build/bin/*.ilk"
- name: Compress artifacts
shell: powershell
run: |

View File

@ -39,26 +39,11 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
platform:
- vcpkg_toolkit: arm-neon-android-23
ndk_abi: armeabi-v7a
- vcpkg_toolkit: arm64-android-23
ndk_abi: arm64-v8a
- vcpkg_toolkit: x64-android-23
ndk_abi: x86_64
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/checkout@v4
with:
repository: 'Green-Sky/vcpkg_android_triplets'
path: 'vcpkg_android_triplets'
- uses: nttld/setup-ndk@v1
id: setup_ndk
with:
@ -70,27 +55,23 @@ jobs:
distribution: 'temurin'
java-version: '17'
- name: update vcpkg
run: |
git clone https://github.com/microsoft/vcpkg.git
- name: Install Dependencies (host)
run: sudo apt update && sudo apt -y install cmake pkg-config nasm
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Install Dependencies (target)
env:
ANDROID_NDK_HOME: ${{steps.setup_ndk.outputs.ndk-path}}
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
run: vcpkg install --overlay-triplets=vcpkg_android_triplets --triplet ${{matrix.platform.vcpkg_toolkit}} libsodium openssl
run: vcpkg install --triplet arm64-android --overlay-ports=vcpkg/ports libsodium openssl
# vcpkg scripts root /usr/local/share/vcpkg/scripts
- name: Configure CMake
env:
ANDROID_NDK_HOME: ${{steps.setup_ndk.outputs.ndk-path}}
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=${{matrix.platform.vcpkg_toolkit}} -DANDROID=1 -DANDROID_PLATFORM=23 -DANDROID_ABI=${{matrix.platform.ndk_abi}} -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=${{steps.setup_ndk.outputs.ndk-path}}/build/cmake/android.toolchain.cmake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=arm64-android -DANDROID=1 -DANDROID_PLATFORM=23 -DANDROID_ABI=arm64-v8a -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=${{steps.setup_ndk.outputs.ndk-path}}/build/cmake/android.toolchain.cmake
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
@ -98,14 +79,14 @@ jobs:
- name: Compress artifacts
shell: bash
run: |
tar -czvf ${{ github.event.repository.name }}-${{matrix.platform.vcpkg_toolkit}}.tar.gz -C ${{github.workspace}}/build/bin/ .
tar -czvf ${{ github.event.repository.name }}-android-arm64.tar.gz -C ${{github.workspace}}/build/bin/ .
- uses: actions/upload-artifact@v4
with:
name: ${{ github.event.repository.name }}-${{matrix.platform.vcpkg_toolkit}}
name: ${{ github.event.repository.name }}-android-arm64
# TODO: do propper packing
path: |
${{github.workspace}}/${{github.event.repository.name}}-${{matrix.platform.vcpkg_toolkit}}.tar.gz
${{github.workspace}}/${{github.event.repository.name}}-android-arm64.tar.gz
macos:
timeout-minutes: 10
@ -131,7 +112,7 @@ jobs:
run: ctest -C ${{env.BUILD_TYPE}}
windows:
timeout-minutes: 15
timeout-minutes: 10
runs-on: windows-latest
@ -140,17 +121,14 @@ jobs:
with:
submodules: recursive
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: update vcpkg
shell: bash
run: |
cd C:/vcpkg
git pull
- name: Install Dependencies
env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
run: vcpkg install pkgconf:x64-windows libsodium:x64-windows-static pthreads:x64-windows-static
run: vcpkg install libsodium:x64-windows-static pthreads:x64-windows-static
# setup vs env
- uses: ilammy/msvc-dev-cmd@v1
@ -158,7 +136,7 @@ jobs:
arch: amd64
- name: Configure CMake
run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DSOLANACEAE_ECOSYSTEM_BUILD_TESTING=ON -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static -DPKG_CONFIG_EXECUTABLE=C:/vcpkg/installed/x64-windows/tools/pkgconf/pkgconf.exe
run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DSOLANACEAE_ECOSYSTEM_BUILD_TESTING=ON -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 3

3
.gitmodules vendored
View File

@ -59,6 +59,3 @@
[submodule "external/solanaceae_message_fragment_store"]
path = external/solanaceae_message_fragment_store
url = https://github.com/Green-Sky/solanaceae_message_fragment_store.git
[submodule "external/solanaceae_tox_p2prng"]
path = external/solanaceae_tox_p2prng
url = https://github.com/Green-Sky/solanaceae_tox_p2prng.git

View File

@ -48,9 +48,6 @@ if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL
-Wshadow # Warn if a variable declaration shadows one from a parent context
)
add_compile_options(-fno-omit-frame-pointer)
add_link_options(-fno-omit-frame-pointer)
if (NOT WIN32)
#link_libraries(-fsanitize=address,undefined)
#link_libraries(-fsanitize=undefined)
@ -61,10 +58,6 @@ elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
# remove unreferenced objects, reducing binary and debugsymbol sizes
# does not work !!! (it actually slightly increased the file size by <1%)
# add_link_options("/OPT:REF")
endif()
# cmake setup end

21
LICENSE
View File

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2025 Erik Scholz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14...3.24 FATAL_ERROR)
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
set(SOLANACEAE_UTIL_BUILD_TESTING ${SOLANACEAE_ECOSYSTEM_BUILD_TESTING})
add_subdirectory(./solanaceae_util)
@ -6,15 +6,15 @@ add_subdirectory(./solanaceae_plugin)
add_subdirectory(./entt)
set(SOLANACEAE_OBJECT_STORE_BUILD_TESTING ${SOLANACEAE_ECOSYSTEM_BUILD_TESTING} CACHE BOOL "")
add_subdirectory(./solanaceae_object_store)
add_subdirectory(./solanaceae_contact)
add_subdirectory(./solanaceae_message3)
set(SOLANACEAE_BRIDGE_BUILD_PLUGINS ON CACHE BOOL "")
add_subdirectory(./solanaceae_bridge)
set(SOLANACEAE_OBJECT_STORE_BUILD_TESTING ${SOLANACEAE_ECOSYSTEM_BUILD_TESTING} CACHE BOOL "")
add_subdirectory(./solanaceae_object_store)
add_subdirectory(./solanaceae_message_serializer)
set(SOLANACEAE_MESSAGE_FRAGMENT_STORE_BUILD_PLUGINS ON CACHE BOOL "")
add_subdirectory(./solanaceae_message_fragment_store)
@ -26,12 +26,7 @@ add_subdirectory(./solanaceae_tox)
set(SOLANACEAE_TOX_UPNP_BUILD_PLUGINS ON CACHE BOOL "")
add_subdirectory(./solanaceae_tox_upnp)
set(SOLANACEAE_TOX_P2PRNG_BUILD_PLUGINS ON CACHE BOOL "")
add_subdirectory(./solanaceae_tox_p2prng)
set(SOLANACEAE_NGCFT1_BUILD_PLUGINS ON CACHE BOOL "")
set(SOLANACEAE_NGCFT1_SHA1_BUILD_TESTING ${SOLANACEAE_ECOSYSTEM_BUILD_TESTING} CACHE BOOL "")
set(SOLANACEAE_NGCHS2_BUILD_TESTING ${SOLANACEAE_ECOSYSTEM_BUILD_TESTING} CACHE BOOL "")
add_subdirectory(./solanaceae_ngc_ft1)
set(SOLANACEAE_ZOX_BUILD_PLUGINS ON CACHE BOOL "")

View File

@ -1,80 +1,215 @@
cmake_minimum_required(VERSION 3.13...3.16 FATAL_ERROR)
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
set(EXPERIMENTAL_API ON CACHE BOOL "" FORCE)
set(UNITTEST OFF CACHE BOOL "" FORCE)
set(BOOTSTRAP_DAEMON OFF CACHE BOOL "" FORCE)
#if (TOMATO_TOX_AV)
# set(BUILD_TOXAV ON CACHE BOOL "" FORCE)
# set(MUST_BUILD_TOXAV ON CACHE BOOL "" FORCE)
#endif()
add_subdirectory(./c-toxcore)
#message("II BUILD_TOXAV: ${BUILD_TOXAV}")
# the sad case
add_library(toxcore INTERFACE)
if (TARGET toxcore_static)
target_link_libraries(toxcore INTERFACE toxcore_static)
# the ideal case
#add_library(toxcore ALIAS toxcore_static)
else()
target_link_libraries(toxcore INTERFACE toxcore_shared)
# the ideal case
#add_library(toxcore ALIAS toxcore_shared)
endif()
# HACK: "install" api headers into binary dir
configure_file(
./c-toxcore/toxcore/tox.h
${CMAKE_CURRENT_BINARY_DIR}/include/tox/tox.h
@ONLY
)
configure_file(
./c-toxcore/toxcore/tox_events.h
${CMAKE_CURRENT_BINARY_DIR}/include/tox/tox_events.h
@ONLY
)
configure_file(
./c-toxcore/toxcore/tox_private.h
${CMAKE_CURRENT_BINARY_DIR}/include/tox/tox_private.h
@ONLY
)
configure_file(
./c-toxcore/toxencryptsave/toxencryptsave.h
${CMAKE_CURRENT_BINARY_DIR}/include/tox/toxencryptsave.h
@ONLY
)
#configure_file(
# ./c-toxcore/toxav/toxav.h
# ${CMAKE_CURRENT_BINARY_DIR}/include/tox/toxav.h
# @ONLY
#)
target_include_directories(toxcore INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/include/)
# HACK: support old libsodium find
# libs should handle this case themselfs
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(TOX_DIR "${CMAKE_CURRENT_SOURCE_DIR}/c-toxcore/")
# TODO: shared
add_library(toxcore STATIC
${TOX_DIR}third_party/cmp/cmp.c
${TOX_DIR}third_party/cmp/cmp.h
${TOX_DIR}toxcore/announce.c
${TOX_DIR}toxcore/announce.h
${TOX_DIR}toxcore/bin_pack.c
${TOX_DIR}toxcore/bin_pack.h
${TOX_DIR}toxcore/bin_unpack.c
${TOX_DIR}toxcore/bin_unpack.h
${TOX_DIR}toxcore/ccompat.c
${TOX_DIR}toxcore/ccompat.h
${TOX_DIR}toxcore/crypto_core.c
${TOX_DIR}toxcore/crypto_core.h
${TOX_DIR}toxcore/crypto_core_pack.c
${TOX_DIR}toxcore/crypto_core_pack.h
${TOX_DIR}toxcore/DHT.c
${TOX_DIR}toxcore/DHT.h
${TOX_DIR}toxcore/events/conference_connected.c
${TOX_DIR}toxcore/events/conference_invite.c
${TOX_DIR}toxcore/events/conference_message.c
${TOX_DIR}toxcore/events/conference_peer_list_changed.c
${TOX_DIR}toxcore/events/conference_peer_name.c
${TOX_DIR}toxcore/events/conference_title.c
${TOX_DIR}toxcore/events/dht_get_nodes_response.c
${TOX_DIR}toxcore/events/events_alloc.c
${TOX_DIR}toxcore/events/events_alloc.h
${TOX_DIR}toxcore/events/file_chunk_request.c
${TOX_DIR}toxcore/events/file_recv.c
${TOX_DIR}toxcore/events/file_recv_chunk.c
${TOX_DIR}toxcore/events/file_recv_control.c
${TOX_DIR}toxcore/events/friend_connection_status.c
${TOX_DIR}toxcore/events/friend_lossless_packet.c
${TOX_DIR}toxcore/events/friend_lossy_packet.c
${TOX_DIR}toxcore/events/friend_message.c
${TOX_DIR}toxcore/events/friend_name.c
${TOX_DIR}toxcore/events/friend_read_receipt.c
${TOX_DIR}toxcore/events/friend_request.c
${TOX_DIR}toxcore/events/friend_status.c
${TOX_DIR}toxcore/events/friend_status_message.c
${TOX_DIR}toxcore/events/friend_typing.c
${TOX_DIR}toxcore/events/self_connection_status.c
${TOX_DIR}toxcore/events/group_custom_packet.c
${TOX_DIR}toxcore/events/group_custom_private_packet.c
${TOX_DIR}toxcore/events/group_invite.c
${TOX_DIR}toxcore/events/group_join_fail.c
${TOX_DIR}toxcore/events/group_message.c
${TOX_DIR}toxcore/events/group_moderation.c
${TOX_DIR}toxcore/events/group_password.c
${TOX_DIR}toxcore/events/group_peer_exit.c
${TOX_DIR}toxcore/events/group_peer_join.c
${TOX_DIR}toxcore/events/group_peer_limit.c
${TOX_DIR}toxcore/events/group_peer_name.c
${TOX_DIR}toxcore/events/group_peer_status.c
${TOX_DIR}toxcore/events/group_privacy_state.c
${TOX_DIR}toxcore/events/group_private_message.c
${TOX_DIR}toxcore/events/group_self_join.c
${TOX_DIR}toxcore/events/group_topic.c
${TOX_DIR}toxcore/events/group_topic_lock.c
${TOX_DIR}toxcore/events/group_voice_state.c
${TOX_DIR}toxcore/forwarding.c
${TOX_DIR}toxcore/forwarding.h
${TOX_DIR}toxcore/friend_connection.c
${TOX_DIR}toxcore/friend_connection.h
${TOX_DIR}toxcore/friend_requests.c
${TOX_DIR}toxcore/friend_requests.h
${TOX_DIR}toxcore/group.c
${TOX_DIR}toxcore/group.h
${TOX_DIR}toxcore/group_announce.c
${TOX_DIR}toxcore/group_announce.h
${TOX_DIR}toxcore/group_moderation.c
${TOX_DIR}toxcore/group_moderation.h
${TOX_DIR}toxcore/group_chats.c
${TOX_DIR}toxcore/group_chats.h
${TOX_DIR}toxcore/group_common.h
${TOX_DIR}toxcore/group_connection.c
${TOX_DIR}toxcore/group_connection.h
${TOX_DIR}toxcore/group_onion_announce.c
${TOX_DIR}toxcore/group_onion_announce.h
${TOX_DIR}toxcore/group_pack.c
${TOX_DIR}toxcore/group_pack.h
${TOX_DIR}toxcore/LAN_discovery.c
${TOX_DIR}toxcore/LAN_discovery.h
${TOX_DIR}toxcore/list.c
${TOX_DIR}toxcore/list.h
${TOX_DIR}toxcore/logger.c
${TOX_DIR}toxcore/logger.h
${TOX_DIR}toxcore/Messenger.c
${TOX_DIR}toxcore/Messenger.h
${TOX_DIR}toxcore/mem.c
${TOX_DIR}toxcore/mem.h
${TOX_DIR}toxcore/mono_time.c
${TOX_DIR}toxcore/mono_time.h
${TOX_DIR}toxcore/net_crypto.c
${TOX_DIR}toxcore/net_crypto.h
${TOX_DIR}toxcore/network.c
${TOX_DIR}toxcore/network.h
${TOX_DIR}toxcore/onion_announce.c
${TOX_DIR}toxcore/onion_announce.h
${TOX_DIR}toxcore/onion.c
${TOX_DIR}toxcore/onion_client.c
${TOX_DIR}toxcore/onion_client.h
${TOX_DIR}toxcore/onion.h
${TOX_DIR}toxcore/ping_array.c
${TOX_DIR}toxcore/ping_array.h
${TOX_DIR}toxcore/ping.c
${TOX_DIR}toxcore/ping.h
${TOX_DIR}toxcore/shared_key_cache.c
${TOX_DIR}toxcore/shared_key_cache.h
${TOX_DIR}toxcore/state.c
${TOX_DIR}toxcore/state.h
${TOX_DIR}toxcore/TCP_client.c
${TOX_DIR}toxcore/TCP_client.h
${TOX_DIR}toxcore/TCP_common.c
${TOX_DIR}toxcore/TCP_common.h
${TOX_DIR}toxcore/TCP_connection.c
${TOX_DIR}toxcore/TCP_connection.h
${TOX_DIR}toxcore/TCP_server.c
${TOX_DIR}toxcore/TCP_server.h
${TOX_DIR}toxcore/timed_auth.c
${TOX_DIR}toxcore/timed_auth.h
${TOX_DIR}toxcore/tox_api.c
${TOX_DIR}toxcore/tox.c
${TOX_DIR}toxcore/tox_dispatch.c
${TOX_DIR}toxcore/tox_dispatch.h
${TOX_DIR}toxcore/tox_event.c
${TOX_DIR}toxcore/tox_event.h
${TOX_DIR}toxcore/tox_events.c
${TOX_DIR}toxcore/tox_events.h
${TOX_DIR}toxcore/tox.h
${TOX_DIR}toxcore/tox_private.c
${TOX_DIR}toxcore/tox_private.h
${TOX_DIR}toxcore/tox_pack.c
${TOX_DIR}toxcore/tox_pack.h
${TOX_DIR}toxcore/tox_unpack.c
${TOX_DIR}toxcore/tox_unpack.h
${TOX_DIR}toxcore/util.c
${TOX_DIR}toxcore/util.h
${TOX_DIR}toxencryptsave/defines.h
${TOX_DIR}toxencryptsave/toxencryptsave.c
${TOX_DIR}toxencryptsave/toxencryptsave.h
)
# HACK: "install" api headers into self
# this is dirty, should be binary dir
# TODO: add the others
configure_file(
${TOX_DIR}toxcore/tox.h
${TOX_DIR}tox/tox.h
@ONLY
)
configure_file(
${TOX_DIR}toxcore/tox_events.h
${TOX_DIR}tox/tox_events.h
@ONLY
)
configure_file(
${TOX_DIR}toxcore/tox_private.h
${TOX_DIR}tox/tox_private.h
@ONLY
)
target_include_directories(toxcore PRIVATE "${TOX_DIR}toxcore")
target_include_directories(toxcore PUBLIC "${TOX_DIR}")
target_compile_definitions(toxcore PUBLIC USE_IPV6=1)
#target_compile_definitions(toxcore PUBLIC MIN_LOGGER_LEVEL=LOGGER_LEVEL_DEBUG)
target_compile_definitions(toxcore PUBLIC MIN_LOGGER_LEVEL=LOGGER_LEVEL_INFO)
find_package(unofficial-sodium CONFIG QUIET)
find_package(sodium QUIET)
if(unofficial-sodium_FOUND) # vcpkg
if(TARGET unofficial-sodium::sodium)
target_link_libraries(toxcore INTERFACE unofficial-sodium::sodium)
target_link_libraries(toxcore unofficial-sodium::sodium)
endif()
if(TARGET unofficial-sodium::sodium_config_public)
target_link_libraries(toxcore INTERFACE unofficial-sodium::sodium_config_public)
target_link_libraries(toxcore unofficial-sodium::sodium_config_public)
endif()
elseif(sodium_FOUND)
target_link_libraries(toxcore INTERFACE sodium)
target_link_libraries(toxcore sodium)
else()
message(SEND_ERROR "missing libsodium")
endif()
#if(BUILD_TOXAV)
# set_target_properties(toxcore PROPERTIES TOX_HAS_TOXAV ON)
#endif()
if(WIN32)
target_link_libraries(toxcore ws2_32 iphlpapi)
endif()
find_package(pthreads QUIET)
if(TARGET PThreads4W::PThreads4W)
target_link_libraries(toxcore PThreads4W::PThreads4W)
else()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(toxcore Threads::Threads)
endif()
add_executable(DHT_Bootstrap EXCLUDE_FROM_ALL
${TOX_DIR}other/DHT_bootstrap.c
${TOX_DIR}other/bootstrap_node_packets.h
${TOX_DIR}other/bootstrap_node_packets.c
${TOX_DIR}testing/misc_tools.h
${TOX_DIR}testing/misc_tools.c
)
target_link_libraries(DHT_Bootstrap toxcore)

View File

@ -1,5 +1,23 @@
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
add_library(plugin_ngcft1 MODULE
./plugin_ngcft1.cpp
)
set_target_properties(plugin_ngcft1 PROPERTIES
C_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON # do we need this?
)
target_compile_definitions(plugin_ngcft1 PUBLIC ENTT_API_IMPORT)
target_link_libraries(plugin_ngcft1 PUBLIC
solanaceae_plugin
solanaceae_ngcext
solanaceae_ngcft1
solanaceae_sha1_ngcft1
)
########################################
add_library(plugin_transfer_auto_accept MODULE
./plugin_transfer_auto_accept.cpp
./transfer_auto_accept.hpp
@ -13,25 +31,6 @@ target_compile_definitions(plugin_transfer_auto_accept PUBLIC ENTT_API_IMPORT)
target_link_libraries(plugin_transfer_auto_accept PUBLIC
solanaceae_plugin
solanaceae_util
solanaceae_object_store
solanaceae_message3
solanaceae_tox_messages # sad, for filekind
)
########################################
add_library(plugin_dice_tool MODULE
./plugin_dice_tool.cpp
./dice_tool.hpp
./dice_tool.cpp
)
set_target_properties(plugin_dice_tool PROPERTIES
C_VISIBILITY_PRESET hidden
)
target_compile_definitions(plugin_dice_tool PUBLIC ENTT_API_IMPORT)
target_link_libraries(plugin_dice_tool PUBLIC
solanaceae_plugin
solanaceae_tox_p2prng
imgui
)

View File

@ -1,241 +0,0 @@
#include "./dice_tool.hpp"
#include <solanaceae/contact/contact_store_i.hpp>
#include <solanaceae/contact/components.hpp>
#include <imgui.h>
#include <entt/container/dense_set.hpp>
#include <entt/entity/registry.hpp>
#include <entt/entity/handle.hpp>
#include <cstdint>
#include <iostream>
DiceTool::DiceTool(P2PRNGI& p2prng, ContactStore4I& cs) : _p2prng(p2prng), _cs(cs) {
p2prng.subscribe(this, P2PRNG_Event::init);
p2prng.subscribe(this, P2PRNG_Event::hmac);
p2prng.subscribe(this, P2PRNG_Event::secret);
p2prng.subscribe(this, P2PRNG_Event::done);
p2prng.subscribe(this, P2PRNG_Event::val_error);
}
DiceTool::~DiceTool(void) {
}
float DiceTool::render(float) {
if (ImGui::Begin("DiceTool")) {
// header with values for new roll
ImGui::TextUnformatted("sides:");
ImGui::SameLine();
static uint16_t g_sides {6};
ImGui::InputScalar("##sides", ImGuiDataType_U16, &g_sides);
static entt::dense_set<Contact4> peers;
if (ImGui::CollapsingHeader("peers")) {
ImGui::Indent();
// list with peers participating
for (auto it = peers.begin(); it != peers.end();) {
ImGui::PushID(entt::to_integral(*it));
if (ImGui::SmallButton("-")) {
it = peers.erase(it);
ImGui::PopID();
continue;
}
ContactHandle4 c = _cs.contactHandle(*it);
const char* str_ptr = "<unk>";
if (const auto* name_ptr = c.try_get<Contact::Components::Name>(); name_ptr != nullptr && !name_ptr->name.empty()) {
str_ptr = name_ptr->name.c_str();
}
ImGui::SameLine();
ImGui::TextUnformatted(str_ptr);
ImGui::PopID();
it++;
}
if (ImGui::Button("add")) {
ImGui::OpenPopup("peer selector");
}
if (ImGui::BeginPopup("peer selector")) {
for (const auto& [cv] : _cs.registry().view<Contact::Components::TagBig>().each()) {
ContactHandle4 c = _cs.contactHandle(cv);
if (peers.contains(c)) {
continue;
}
const char* str_ptr = "<unk>";
if (const auto* name_ptr = c.try_get<Contact::Components::Name>(); name_ptr != nullptr && !name_ptr->name.empty()) {
str_ptr = name_ptr->name.c_str();
}
if (c.all_of<Contact::Components::TagGroup, Contact::Components::ParentOf>()) {
if (ImGui::BeginMenu(str_ptr)) {
for (const Contact4 child_cv : c.get<Contact::Components::ParentOf>().subs) {
ContactHandle4 child_c = _cs.contactHandle(child_cv);
if (peers.contains(child_c)) {
continue;
}
const char* child_str_ptr = "<unk>";
if (const auto* name_ptr = child_c.try_get<Contact::Components::Name>(); name_ptr != nullptr && !name_ptr->name.empty()) {
child_str_ptr = name_ptr->name.c_str();
}
if (ImGui::MenuItem(child_str_ptr)) {
peers.emplace(child_c);
}
}
ImGui::EndMenu();
}
} else {
if (ImGui::MenuItem(str_ptr)) {
peers.emplace(c);
}
}
}
ImGui::EndPopup();
}
ImGui::SameLine();
if (ImGui::Button("clear")) {
peers.clear();
}
ImGui::Unindent();
}
if (ImGui::Button("roll")) {
//std::vector<ContactHandle4> c_vec{peers.cbegin(), peers.cend()};
std::vector<ContactHandle4> c_vec;
for (const auto cv : peers) {
c_vec.emplace_back(_cs.contactHandle(cv));
}
std::vector<uint8_t> is {'D', 'I', 'C', 'E'};
is.push_back(reinterpret_cast<uint8_t*>(&g_sides)[0]);
is.push_back(reinterpret_cast<uint8_t*>(&g_sides)[1]);
static_assert(sizeof(g_sides) == 2);
auto new_id = _p2prng.newGernationPeers(c_vec, ByteSpan{is});
//if (!new_id.empty()) {
//}
}
ImGui::SeparatorText("Rolls");
// list of past rolls and their state
for (auto it = _rolls.crbegin(); it != _rolls.crend(); it++) {
const auto& roll = *it;
std::string text{"d"};
text += std::to_string(roll.sides);
text += " [";
if (roll.state == P2PRNG::DONE) {
// dice start at 1
text += std::to_string(int(roll.final_result)+1);
} else {
text += "?";
}
text += "]";
if (roll.state == P2PRNG::INIT) {
text += " INIT";
} else if (roll.state == P2PRNG::HMAC) {
text += " HMAC ";
text += std::to_string(roll.state_number_1);
text += "/";
text += std::to_string(roll.state_number_2);
} else if (roll.state == P2PRNG::SECRET) {
text += " SECRET ";
text += std::to_string(roll.state_number_1);
text += "/";
text += std::to_string(roll.state_number_2);
}
ImGui::TextUnformatted(text.c_str());
}
}
ImGui::End();
return 10.f;
}
bool DiceTool::onEvent(const P2PRNG::Events::Init& e) {
if (e.initial_state.size != 4+2) {
return false;
}
if (e.initial_state[0] != 'D' || e.initial_state[1] != 'I' || e.initial_state[2] != 'C' || e.initial_state[3] != 'E') {
return false;
}
auto& new_roll = _rolls.emplace_back();
new_roll.id = {e.id.cbegin(), e.id.cend()};
new_roll.state = P2PRNG::State::INIT;
reinterpret_cast<uint8_t*>(&new_roll.sides)[0] = e.initial_state[4];
reinterpret_cast<uint8_t*>(&new_roll.sides)[1] = e.initial_state[5];
return true;
}
bool DiceTool::onEvent(const P2PRNG::Events::HMAC& e) {
auto roll_it = std::find_if(_rolls.begin(), _rolls.end(), [&e](const auto& a) -> bool { return ByteSpan{a.id} == e.id; });
if (roll_it == _rolls.cend()) {
return false;
}
roll_it->state = P2PRNG::State::HMAC;
roll_it->state_number_1 = e.have;
roll_it->state_number_2 = e.out_of;
return true;
}
bool DiceTool::onEvent(const P2PRNG::Events::Secret& e) {
auto roll_it = std::find_if(_rolls.begin(), _rolls.end(), [&e](const auto& a) -> bool { return ByteSpan{a.id} == e.id; });
if (roll_it == _rolls.cend()) {
return false;
}
roll_it->state = P2PRNG::State::SECRET;
roll_it->state_number_1 = e.have;
roll_it->state_number_2 = e.out_of;
return true;
}
bool DiceTool::onEvent(const P2PRNG::Events::Done& e) {
auto roll_it = std::find_if(_rolls.begin(), _rolls.end(), [&e](const auto& a) -> bool { return ByteSpan{a.id} == e.id; });
if (roll_it == _rolls.cend()) {
return false;
}
roll_it->state = P2PRNG::State::DONE;
roll_it->state_number_1 = 0;
roll_it->state_number_2 = 0;
roll_it->final_result = (e.result[0] | (e.result[1] << 8)) % roll_it->sides;
std::cout << "done die roll " << roll_it->final_result << "\n";
return true;
}
bool DiceTool::onEvent(const P2PRNG::Events::ValError& e) {
auto roll_it = std::find_if(_rolls.cbegin(), _rolls.cend(), [&e](const auto& a) -> bool { return ByteSpan{a.id} == e.id; });
if (roll_it == _rolls.cend()) {
return false;
}
return false;
}

View File

@ -1,38 +0,0 @@
#pragma once
#include <solanaceae/tox_p2prng/p2prng.hpp>
#include <solanaceae/contact/fwd.hpp>
#include <vector>
class DiceTool : public P2PRNGEventI {
P2PRNGI& _p2prng;
ContactStore4I& _cs;
struct Rolls {
std::vector<uint8_t> id;
uint16_t sides {};
P2PRNG::State state {P2PRNG::State::UNKNOWN};
uint16_t state_number_1 {};
uint16_t state_number_2 {};
uint16_t final_result{};
};
std::vector<Rolls> _rolls;
public:
DiceTool(P2PRNGI& p2prng, ContactStore4I& cs);
~DiceTool(void);
float render(float time_delta);
protected: // p2prng
bool onEvent(const P2PRNG::Events::Init&) override;
bool onEvent(const P2PRNG::Events::HMAC&) override;
bool onEvent(const P2PRNG::Events::Secret&) override;
bool onEvent(const P2PRNG::Events::Done&) override;
bool onEvent(const P2PRNG::Events::ValError&) override;
};

View File

@ -1,82 +0,0 @@
#include <solanaceae/plugin/solana_plugin_v1.h>
#include <solanaceae/contact/contact_store_i.hpp>
#include "./dice_tool.hpp"
#include <imgui.h>
#include <entt/entt.hpp>
#include <entt/fwd.hpp>
#include <memory>
#include <limits>
#include <iostream>
static std::unique_ptr<DiceTool> g_dt = nullptr;
constexpr const char* plugin_name = "DiceTool";
extern "C" {
SOLANA_PLUGIN_EXPORT const char* solana_plugin_get_name(void) {
return plugin_name;
}
SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) {
return SOLANA_PLUGIN_VERSION;
}
SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api) {
std::cout << "PLUGIN " << plugin_name << " START()\n";
if (solana_api == nullptr) {
return 1;
}
try {
auto* p2prng_i = PLUG_RESOLVE_INSTANCE(P2PRNGI);
auto* cs = PLUG_RESOLVE_INSTANCE(ContactStore4I);
// static store, could be anywhere tho
// construct with fetched dependencies
g_dt = std::make_unique<DiceTool>(*p2prng_i, *cs);
auto* imguic = PLUG_RESOLVE_INSTANCE_VERSIONED(ImGuiContext, ImGui::GetVersion());
auto* imguimemaf = PLUG_RESOLVE_INSTANCE_VERSIONED(ImGuiMemAllocFunc, ImGui::GetVersion());
auto* imguimemff = PLUG_RESOLVE_INSTANCE_VERSIONED(ImGuiMemFreeFunc, ImGui::GetVersion());
// meh
auto* imguimemud = plug_resolveInstanceOptional<void*>(solana_api, "ImGuiMemUserData", ImGui::GetVersion());
ImGui::SetCurrentContext(imguic);
ImGui::SetAllocatorFunctions(imguimemaf, imguimemff, imguimemud);
// register types
PLUG_PROVIDE_INSTANCE(DiceTool, plugin_name, g_dt.get());
} catch (const ResolveException& e) {
std::cerr << "PLUGIN " << plugin_name << " " << e.what << "\n";
return 2;
}
return 0;
}
SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void) {
std::cout << "PLUGIN " << plugin_name << " STOP()\n";
g_dt.reset();
}
SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float delta) {
(void)delta;
//g_dt->iterate();
return std::numeric_limits<float>::max();
}
SOLANA_PLUGIN_EXPORT float solana_plugin_render(float delta) {
return g_dt->render(delta);
}
} // extern C

81
plugins/plugin_ngcft1.cpp Normal file
View File

@ -0,0 +1,81 @@
#include <solanaceae/plugin/solana_plugin_v1.h>
#include <solanaceae/ngc_ext/ngcext.hpp>
#include <solanaceae/ngc_ft1/ngcft1.hpp>
#include <solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp>
#include <entt/entt.hpp>
#include <entt/fwd.hpp>
#include <memory>
#include <iostream>
static std::unique_ptr<NGCEXTEventProvider> g_ngcextep = nullptr;
// TODO: make sep plug
static std::unique_ptr<NGCFT1> g_ngcft1 = nullptr;
static std::unique_ptr<SHA1_NGCFT1> g_sha1_ngcft1 = nullptr;
constexpr const char* plugin_name = "NGCEXT";
extern "C" {
SOLANA_PLUGIN_EXPORT const char* solana_plugin_get_name(void) {
return plugin_name;
}
SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) {
return SOLANA_PLUGIN_VERSION;
}
SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api) {
std::cout << "PLUGIN " << plugin_name << " START()\n";
if (solana_api == nullptr) {
return 1;
}
try {
auto* os = PLUG_RESOLVE_INSTANCE(ObjectStore2);
auto* tox_i = PLUG_RESOLVE_INSTANCE(ToxI);
auto* tox_event_provider_i = PLUG_RESOLVE_INSTANCE(ToxEventProviderI);
auto* cr = PLUG_RESOLVE_INSTANCE_VERSIONED(Contact3Registry, "1");
auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModel);
auto* tcm = PLUG_RESOLVE_INSTANCE(ToxContactModel2);
// static store, could be anywhere tho
// construct with fetched dependencies
g_ngcextep = std::make_unique<NGCEXTEventProvider>(*tox_i, *tox_event_provider_i);
g_ngcft1 = std::make_unique<NGCFT1>(*tox_i, *tox_event_provider_i, *g_ngcextep.get());
g_sha1_ngcft1 = std::make_unique<SHA1_NGCFT1>(*os, *cr, *rmm, *g_ngcft1.get(), *tcm, *tox_event_provider_i, *g_ngcextep.get());
// register types
PLUG_PROVIDE_INSTANCE(NGCEXTEventProviderI, plugin_name, g_ngcextep.get());
PLUG_PROVIDE_INSTANCE(NGCFT1EventProviderI, plugin_name, g_ngcft1.get());
PLUG_PROVIDE_INSTANCE(NGCFT1, plugin_name, g_ngcft1.get());
PLUG_PROVIDE_INSTANCE(SHA1_NGCFT1, plugin_name, g_sha1_ngcft1.get());
} catch (const ResolveException& e) {
std::cerr << "PLUGIN " << plugin_name << " " << e.what << "\n";
return 2;
}
return 0;
}
SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void) {
std::cout << "PLUGIN " << plugin_name << " STOP()\n";
g_sha1_ngcft1.reset();
g_ngcft1.reset();
g_ngcextep.reset();
}
SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float delta) {
const float ft_interval = g_ngcft1->iterate(delta);
const float sha_interval = g_sha1_ngcft1->iterate(delta);
return std::min<float>(ft_interval, sha_interval);
}
} // extern C

View File

@ -1,8 +1,7 @@
#include <solanaceae/plugin/solana_plugin_v1.h>
#include <solanaceae/util/config_model.hpp>
#include "./transfer_auto_accept.hpp"
#include <solanaceae/util/config_model.hpp>
#include <entt/entt.hpp>
#include <entt/fwd.hpp>
@ -33,13 +32,12 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
}
try {
auto* os = PLUG_RESOLVE_INSTANCE(ObjectStore2);
auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModelI);
auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModel);
auto* conf = PLUG_RESOLVE_INSTANCE(ConfigModelI);
// static store, could be anywhere tho
// construct with fetched dependencies
g_taa = std::make_unique<TransferAutoAccept>(*os, *rmm, *conf);
g_taa = std::make_unique<TransferAutoAccept>(*rmm, *conf);
// register types
PLUG_PROVIDE_INSTANCE(TransferAutoAccept, plugin_name, g_taa.get());

View File

@ -1,18 +1,14 @@
#include "./transfer_auto_accept.hpp"
#include <solanaceae/object_store/meta_components_file.hpp>
#include <solanaceae/message3/components.hpp>
// for comp transfer tox filekind (TODO: generalize -> content system?)
#include <solanaceae/tox_messages/obj_components.hpp>
#include <solanaceae/tox_messages/components.hpp>
#include <solanaceae/util/config_model.hpp>
#include <iostream>
TransferAutoAccept::TransferAutoAccept(ObjectStore2& os, RegistryMessageModelI& rmm, ConfigModelI& conf) : _os(os), _rmm(rmm), _conf(conf) {
//_os.subscribe(this, ObjectStore_Event::object_update);
TransferAutoAccept::TransferAutoAccept(RegistryMessageModel& rmm, ConfigModelI& conf) : _rmm(rmm), _conf(conf) {
_rmm.subscribe(this, RegistryMessageModel_Event::message_construct);
_rmm.subscribe(this, RegistryMessageModel_Event::message_updated);
@ -32,94 +28,59 @@ TransferAutoAccept::TransferAutoAccept(ObjectStore2& os, RegistryMessageModelI&
void TransferAutoAccept::iterate(void) {
for (auto& it : _accept_queue) {
if (it.all_of<ObjComp::Ephemeral::File::ActionTransferAccept>()) {
if (it.all_of<Message::Components::Transfer::ActionAccept>()) {
continue; // already accepted
}
it.emplace<ObjComp::Ephemeral::File::ActionTransferAccept>(
it.emplace<Message::Components::Transfer::ActionAccept>(
// TODO: contact to entry
_conf.get_string("TransferAutoAccept", "save_path").value_or("tmp_save_dir"),
false
);
std::cout << "TAA: auto accepted transfer\n";
_os.throwEventUpdate(it);
//_rmm.throwEventUpdate(it);
_rmm.throwEventUpdate(it);
}
_accept_queue.clear();
}
void TransferAutoAccept::checkObj(ObjectHandle o) {
if (!o) {
return; // invalid object
}
if (o.all_of<ObjComp::Ephemeral::File::ActionTransferAccept>()) {
void TransferAutoAccept::checkMsg(Message3Handle h) {
if (h.all_of<Message::Components::Transfer::ActionAccept>()) {
return; // already accepted
}
if (o.all_of<ObjComp::F::TagLocalHaveAll>()) {
return; // alreay have
}
//if (!h.all_of<Message::Components::Transfer::TagReceiving, Message::Components::Transfer::TagPaused, Message::Components::Transfer::FileInfo>()) {
// TODO: tag receiving ??
if (!o.all_of</*Message::Components::Transfer::TagReceiving, */ObjComp::Ephemeral::File::TagTransferPaused>()) {
if (!h.all_of<Message::Components::Transfer::TagReceiving, Message::Components::Transfer::TagPaused, Message::Components::Transfer::FileInfo>()) {
return;
}
if (!o.any_of<ObjComp::F::SingleInfo, ObjComp::F::CollectionInfo>()) {
return; // dont know enough
}
// dont touch avatars for now
// TODO: more generic file types??
if (const auto* fk = o.try_get<ObjComp::Tox::FileKind>(); fk != nullptr && fk->kind != 0) {
if (h.all_of<Message::Components::Transfer::FileKind>() && h.get<Message::Components::Transfer::FileKind>().kind == 1) {
return;
}
uint64_t total_size {0u};
if (const auto* si = o.try_get<ObjComp::F::SingleInfo>(); si != nullptr) {
if (si->file_name.empty()) {
return; // bad file
}
total_size = si->file_size;
} else if (const auto* ci = o.try_get<ObjComp::F::CollectionInfo>(); ci != nullptr) {
if (ci->file_list.empty() || ci->file_list.front().file_name.empty()) {
return; // bad file
}
total_size = ci->total_size;
}
//const auto& file_info = h.get<Message::Components::Transfer::FileInfo>();
const auto& file_info = h.get<Message::Components::Transfer::FileInfo>();
// TODO: contact to entry
if (total_size > uint64_t(_conf.get_int("TransferAutoAccept", "autoaccept_limit").value_or(1024*1024))) {
if (file_info.total_size > uint64_t(_conf.get_int("TransferAutoAccept", "autoaccept_limit").value_or(1024*1024))) {
return; // too large
}
_accept_queue.push_back(o);
}
void TransferAutoAccept::checkMsg(Message3Handle h) {
if (!h.all_of<Message::Components::MessageFileObject>()) {
return;
if (file_info.file_list.empty() || file_info.file_list.front().file_name.empty()) {
return; // bad file
}
checkObj(h.get<Message::Components::MessageFileObject>().o);
_accept_queue.push_back(h);
}
bool TransferAutoAccept::onEvent(const Message::Events::MessageConstruct& e) {
//std::cout << "TAA: msg c\n";
checkMsg(e.e);
return false;
}
bool TransferAutoAccept::onEvent(const Message::Events::MessageUpdated& e) {
//std::cout << "TAA: msg u\n";
checkMsg(e.e);
return false;
}
bool TransferAutoAccept::onEvent(const ObjectStore::Events::ObjectUpdate&) {
// too expensive rn
//checkObj(e.e);
return false;
}

View File

@ -1,6 +1,5 @@
#pragma once
#include <solanaceae/object_store/object_store.hpp>
#include <solanaceae/message3/registry_message_model.hpp>
#include <vector>
@ -8,29 +7,25 @@
// fwd
struct ConfigModelI;
class TransferAutoAccept : public RegistryMessageModelEventI, public ObjectStoreEventI {
ObjectStore2& _os;
RegistryMessageModelI& _rmm;
class TransferAutoAccept : public RegistryMessageModelEventI {
RegistryMessageModel& _rmm;
//ContactModelI& _cm;
ConfigModelI& _conf;
std::vector<ObjectHandle> _accept_queue;
std::vector<Message3Handle> _accept_queue;
public:
TransferAutoAccept(ObjectStore2& os, RegistryMessageModelI& rmm, ConfigModelI& conf);
TransferAutoAccept(RegistryMessageModel& rmm, ConfigModelI& conf);
// TODO: iterate
void iterate(void);
protected:
void checkObj(ObjectHandle h);
void checkMsg(Message3Handle h);
protected: // mm
bool onEvent(const Message::Events::MessageConstruct& e) override;
bool onEvent(const Message::Events::MessageUpdated& e) override;
protected: // os
bool onEvent(const ObjectStore::Events::ObjectUpdate& e) override;
};