Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
33ed5a8
add noise support
paulocoutinhox Jul 20, 2025
c8ee51a
add noise support
paulocoutinhox Jul 20, 2025
014189c
add noise support
paulocoutinhox Jul 20, 2025
0032be1
Merge branch 'main' of github.com:bitchatz/bitchatz-cpp into noise-su…
paulocoutinhox Jul 20, 2025
640dc74
add linux build support in ci
paulocoutinhox Jul 21, 2025
5d0b6b9
add linux build support in ci
paulocoutinhox Jul 21, 2025
618c8e9
add noise support
paulocoutinhox Jul 21, 2025
e551ed6
add noise support
paulocoutinhox Jul 21, 2025
9c01314
add noise support
paulocoutinhox Jul 21, 2025
a36f0e0
add noise support
paulocoutinhox Jul 21, 2025
a56529c
code refactor
paulocoutinhox Jul 22, 2025
a03fd0e
code refactor
paulocoutinhox Jul 22, 2025
0e09087
code refactor
paulocoutinhox Jul 23, 2025
58f4188
code refactor
paulocoutinhox Jul 23, 2025
4f2390f
code refactor
paulocoutinhox Jul 23, 2025
ef72b4a
code refactor
paulocoutinhox Jul 23, 2025
bfa8963
code refactor
paulocoutinhox Jul 23, 2025
2a41167
code refactor
paulocoutinhox Jul 23, 2025
317ccd7
code refactor
paulocoutinhox Jul 23, 2025
83fcb50
code refactor
paulocoutinhox Jul 23, 2025
4520753
code refactor
paulocoutinhox Jul 23, 2025
18aad66
code refactor
paulocoutinhox Jul 23, 2025
55ffb9c
code refactor
paulocoutinhox Jul 23, 2025
e947698
code refactor
paulocoutinhox Jul 23, 2025
3cfa803
code refactor
paulocoutinhox Jul 24, 2025
dce2184
code refactor
paulocoutinhox Jul 24, 2025
bf76bcf
code refactor
paulocoutinhox Jul 25, 2025
417a523
code refactor
paulocoutinhox Jul 25, 2025
54549c3
code refactor
paulocoutinhox Jul 25, 2025
b9b659b
code refactor
paulocoutinhox Jul 25, 2025
46a42af
code refactor
paulocoutinhox Jul 25, 2025
d6266e5
code refactor
paulocoutinhox Jul 26, 2025
2d8df56
code refactor
paulocoutinhox Jul 26, 2025
c83e0e7
code refactor
paulocoutinhox Jul 26, 2025
3542dbd
code refactor
paulocoutinhox Jul 26, 2025
f6cfff1
code refactor
paulocoutinhox Jul 26, 2025
98cc4a6
code refactor
paulocoutinhox Jul 26, 2025
1cf094a
code refactor
paulocoutinhox Jul 26, 2025
c21c5dd
code refactor
paulocoutinhox Jul 26, 2025
f6143cf
code refactor
paulocoutinhox Jul 26, 2025
446d5f2
code refactor
paulocoutinhox Jul 26, 2025
0c5046b
code refactor
paulocoutinhox Jul 26, 2025
4e30cee
code refactor
paulocoutinhox Jul 26, 2025
2993154
code refactor
paulocoutinhox Jul 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
29 changes: 22 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ jobs:
- {
name: "macOS",
os: macos-latest,
artifact: "macos"
artifact: "macos"
}
- {
name: "Linux",
os: ubuntu-latest,
artifact: "linux"
}

steps:
Expand All @@ -32,7 +37,13 @@ jobs:
- name: Install Ninja
uses: seanmiddleditch/gha-setup-ninja@master
with:
version: "1.10.0"
version: "1.13.1"

- name: Install Linux Dependencies
if: matrix.config.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libssl-dev libbluetooth-dev

- name: Verify
run: |
Expand All @@ -41,14 +52,18 @@ jobs:

- name: Build
run: |
mkdir -p build
cd build
cmake ..
cmake --build .
rm -rf build
cmake -B build . -G Ninja -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON -DENABLE_ASAN=OFF -DBUILD_EXECUTABLE=OFF
cmake --build build
cd build && ctest --output-on-failure --verbose

- name: Package
run: |
cd build && cpack -G ZIP

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.config.artifact }}
path: build/bin
path: build/*.zip
retention-days: 30
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ poetry.lock
/*.log
/peers_keys.txt
/temp
/data
196 changes: 134 additions & 62 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
cmake_minimum_required(VERSION 3.20)
project(bitchat)

# General settings
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Testing option
option(ENABLE_ASAN "Enable Address Sanitizer" OFF)
option(ENABLE_TESTS "Enable Tests" OFF)
option(BUILD_EXECUTABLE "Build The Main Executable" ON)

# UI type option
set(BITCHAT_GUI "CONSOLE" CACHE STRING "UI Type: CONSOLE or DUMMY")
set_property(CACHE BITCHAT_GUI PROPERTY STRINGS "CONSOLE" "DUMMY")

if(ENABLE_TESTS)
enable_testing()
endif()

# Set output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
Expand All @@ -13,14 +27,14 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# Include CPM for dependency management
include(cmake/CPM.cmake)

# Library options
set(BUILD_SHARED_LIBS OFF)
set(BUILD_STATIC_LIBS ON)
# Include custom functions
include(cmake/functions.cmake)

# Include noise-c configuration
include(cmake/noise-c.cmake)

# LZ4 options
set(LZ4_BUILD_CLI OFF)
set(LZ4_BUILD_LEGACY_LZ4C OFF)
set(LZ4_BUNDLED_MODE OFF)
# Include lz4 configuration
include(cmake/lz4.cmake)

# Platform-specific settings
if(APPLE)
Expand All @@ -39,94 +53,152 @@ elseif(UNIX AND NOT APPLE)
endif()

# Add dependencies via CPM
CPMAddPackage(
NAME uuid
GITHUB_REPOSITORY rkg82/uuid-v4
GIT_TAG dd2f75c027d033586e9eb62b484748cb4bfc515d
)

CPMAddPackage(
NAME spdlog
GITHUB_REPOSITORY gabime/spdlog
VERSION 1.15.3
)

CPMAddPackage(
NAME lz4
GITHUB_REPOSITORY lz4/lz4
VERSION 1.10.0
SOURCE_SUBDIR "build/cmake"
)
CPMAddPackage("gh:nlohmann/json@3.12.0")

# Add Google Test only if tests are enabled
if(ENABLE_TESTS)
CPMAddPackage("gh:google/googletest@1.17.0")
endif()

# Find OpenSSL
find_package(OpenSSL REQUIRED)

# Include directories
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
# Common libraries
set(COMMON_LIBRARIES
spdlog::spdlog
nlohmann_json::nlohmann_json
noise-c
lz4
OpenSSL::SSL
OpenSSL::Crypto
)

# Source files
set(SOURCES
main.cpp
src/bitchat/protocol/packet_utils.cpp
src/bitchat/compression/compression_manager.cpp
src/bitchat/crypto/crypto_manager.cpp
src/bitchat/protocol/packet_serializer.cpp
src/bitchat/core/bitchat_manager.cpp
set(COMMON_SOURCES
${CMAKE_SOURCE_DIR}/src/bitchat/core/bitchat_data.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/core/bitchat_manager.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/helpers/compression_helper.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/helpers/datetime_helper.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/helpers/noise_helper.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/helpers/protocol_helper.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/helpers/string_helper.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/identity/identity_models.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/noise/noise_hybrid_key_exchange.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/noise/noise_post_quantum_key_exchange.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/noise/noise_protocol.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/noise/noise_protocol_migration.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/noise/noise_pq_handshake_pattern.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/noise/noise_security_error.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/noise/noise_session_default.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/protocol/message_padding.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/protocol/packet_serializer.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/protocol/packet.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/runners/bluetooth_announce_runner.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/runners/cleanup_runner.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/services/crypto_service.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/services/identity_service.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/services/message_service.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/services/network_service.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/services/noise_service.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/ui/dummy_ui.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/ui/console_ui.cpp
)

set(SOURCES ${COMMON_SOURCES})

if(BUILD_EXECUTABLE)
set(SOURCES ${SOURCES} src/main.cpp)
endif()

# Platform-specific source files
if(PLATFORM_APPLE)
set(SOURCES ${SOURCES} src/platforms/apple/bluetooth.mm src/platforms/apple/bluetooth_bridge.mm)
set(SOURCES ${SOURCES}
src/platforms/apple/bluetooth_factory.mm
src/platforms/apple/bluetooth.mm
src/platforms/apple/bluetooth_bridge.mm
)

set_source_files_properties(src/platforms/apple/bluetooth.mm PROPERTIES COMPILE_FLAGS "-x objective-c++")
set_source_files_properties(src/platforms/apple/bluetooth_bridge.mm PROPERTIES COMPILE_FLAGS "-x objective-c++")
set_source_files_properties(src/platforms/apple/bluetooth_factory.mm PROPERTIES COMPILE_FLAGS "-x objective-c++")
elseif(PLATFORM_LINUX)
set(SOURCES ${SOURCES} src/platforms/linux/bluetooth.cpp src/platforms/linux/bluetooth_factory.cpp)
set(SOURCES ${SOURCES}
src/platforms/linux/bluetooth.cpp
src/platforms/linux/bluetooth_factory.cpp
)
endif()

# Create executable
add_executable(bitchat ${SOURCES})
# Create executable only if BUILD_EXECUTABLE is enabled
if(BUILD_EXECUTABLE)
add_executable(bitchat ${SOURCES})

# Link libraries
target_link_libraries(bitchat
spdlog::spdlog
OpenSSL::SSL
OpenSSL::Crypto
lz4_static
)
# Include directories
target_include_directories(bitchat PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/vendor
)

# Add UI macro
target_compile_definitions(bitchat PRIVATE BITCHAT_GUI_${BITCHAT_GUI})

# Link libraries
target_link_libraries(bitchat ${COMMON_LIBRARIES})
endif()

# Platform-specific linking
if(PLATFORM_APPLE)
target_link_libraries(bitchat
${FRAMEWORK_COREBLUETOOTH}
${FRAMEWORK_FOUNDATION}
${FRAMEWORK_IOKIT}
${FRAMEWORK_COREFOUNDATION}
)
elseif(PLATFORM_LINUX)
target_link_libraries(bitchat ${BLUEZ_LIBRARIES})
target_include_directories(bitchat PRIVATE ${BLUEZ_INCLUDE_DIRS})
if(BUILD_EXECUTABLE)
if(PLATFORM_APPLE)
target_link_libraries(bitchat
${FRAMEWORK_COREBLUETOOTH}
${FRAMEWORK_FOUNDATION}
${FRAMEWORK_IOKIT}
${FRAMEWORK_COREFOUNDATION}
)
elseif(PLATFORM_LINUX)
target_link_libraries(bitchat ${BLUEZ_LIBRARIES})
target_include_directories(bitchat PRIVATE ${BLUEZ_INCLUDE_DIRS})
endif()
endif()

# Apply compiler flags to main executable
if(BUILD_EXECUTABLE)
apply_compiler_flags(bitchat)

# AddressSanitizer option
if(ENABLE_ASAN)
message(STATUS "Building with AddressSanitizer enabled")
set(ASAN_FLAGS -fsanitize=address -fno-omit-frame-pointer)
target_compile_options(bitchat PRIVATE ${ASAN_FLAGS})
target_link_options(bitchat PRIVATE -fsanitize=address)
endif()
endif()

# Compiler-specific flags
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(bitchat PRIVATE -Wall -Wextra -Wpedantic)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_compile_options(bitchat PRIVATE -Wall -Wextra -Wpedantic)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(bitchat PRIVATE /W4)
if(ENABLE_TESTS)
add_subdirectory(tests)
endif()

# Install target
install(TARGETS bitchat
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
if(BUILD_EXECUTABLE)
install(TARGETS bitchat
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
endif()

# Print configuration info
message(STATUS "Platform: ${CMAKE_SYSTEM_NAME}")
message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Testing enabled: ${ENABLE_TESTS}")
message(STATUS "Building executable: ${BUILD_EXECUTABLE}")

# CPack configuration
include(cmake/cpack.cmake)
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

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 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.

For more information, please refer to <https://unlicense.org>
26 changes: 23 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: help format windows-format clean build run run-windows
.PHONY: help format windows-format clean build run run-windows test package
.DEFAULT_GOAL := help

help:
Expand All @@ -10,12 +10,16 @@ help:
@echo "- clean"
@echo ""
@echo "- build"
@echo "- build-dev"
@echo "- run"
@echo "- run-windows"
@echo "- run-leaks"
@echo "- test"
@echo "- package"
@echo ""

format:
find src/ include/ \( -name "*.cpp" -o -name "*.hpp" -o -name "*.cc" -o -name "*.cxx" -o -name "*.c" -o -name "*.h" -o -name "*.m" -o -name "*.mm" \) -exec clang-format -style=file -i {} +
find src/ include/ tests/ \( -name "*.cpp" -o -name "*.hpp" -o -name "*.cc" -o -name "*.cxx" -o -name "*.c" -o -name "*.h" -o -name "*.m" -o -name "*.mm" \) -exec clang-format -style=file -i {} +

windows-format:
powershell -Command "Get-ChildItem -Path src,include -Recurse -Include *.cpp,*.hpp,*.cc,*.cxx,*.c,*.h,*.m,*.mm | ForEach-Object { clang-format -style=file -i $$_.FullName }"
Expand All @@ -27,11 +31,27 @@ clean:
build:
rm -rf build
cmake -B build . -G Ninja
cmake --build build
cmake --build build

build-dev:
rm -rf build
cmake -B build . -G Ninja -DCMAKE_BUILD_TYPE=Debug -DENABLE_ASAN=ON
cmake --build build

run:
./build/bin/bitchat

run-windows:
powershell -Command ".\build\bin\bitchat.exe"

run-leaks:
leaks -atExit -- ./build/bin/bitchat

test:
rm -rf build
cmake -B build . -G Ninja -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON -DENABLE_ASAN=ON -DBUILD_EXECUTABLE=OFF
cmake --build build
cd build && ctest --output-on-failure --verbose

package: build
cd build && cpack
Loading
Loading