Skip to content

Commit 30f4fb1

Browse files
Merge pull request #8 from bitchatz/noise-support
noise support very early stage but i added a lot of other things
2 parents 9e4ccc2 + 2993154 commit 30f4fb1

File tree

326 files changed

+71502
-2127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

326 files changed

+71502
-2127
lines changed

.github/workflows/build.yml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ jobs:
1818
- {
1919
name: "macOS",
2020
os: macos-latest,
21-
artifact: "macos"
21+
artifact: "macos"
22+
}
23+
- {
24+
name: "Linux",
25+
os: ubuntu-latest,
26+
artifact: "linux"
2227
}
2328

2429
steps:
@@ -32,7 +37,13 @@ jobs:
3237
- name: Install Ninja
3338
uses: seanmiddleditch/gha-setup-ninja@master
3439
with:
35-
version: "1.10.0"
40+
version: "1.13.1"
41+
42+
- name: Install Linux Dependencies
43+
if: matrix.config.os == 'ubuntu-latest'
44+
run: |
45+
sudo apt-get update
46+
sudo apt-get install -y pkg-config libssl-dev libbluetooth-dev
3647
3748
- name: Verify
3849
run: |
@@ -41,14 +52,18 @@ jobs:
4152
4253
- name: Build
4354
run: |
44-
mkdir -p build
45-
cd build
46-
cmake ..
47-
cmake --build .
55+
rm -rf build
56+
cmake -B build . -G Ninja -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON -DENABLE_ASAN=OFF -DBUILD_EXECUTABLE=OFF
57+
cmake --build build
58+
cd build && ctest --output-on-failure --verbose
59+
60+
- name: Package
61+
run: |
62+
cd build && cpack -G ZIP
4863
4964
- name: Upload artifact
5065
uses: actions/upload-artifact@v4
5166
with:
5267
name: ${{ matrix.config.artifact }}
53-
path: build/bin
68+
path: build/*.zip
5469
retention-days: 30

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ poetry.lock
5252
/*.log
5353
/peers_keys.txt
5454
/temp
55+
/data

CMakeLists.txt

Lines changed: 134 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
cmake_minimum_required(VERSION 3.20)
22
project(bitchat)
33

4+
# General settings
45
set(CMAKE_CXX_STANDARD 20)
56
set(CMAKE_CXX_STANDARD_REQUIRED ON)
67
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
78

9+
# Testing option
10+
option(ENABLE_ASAN "Enable Address Sanitizer" OFF)
11+
option(ENABLE_TESTS "Enable Tests" OFF)
12+
option(BUILD_EXECUTABLE "Build The Main Executable" ON)
13+
14+
# UI type option
15+
set(BITCHAT_GUI "CONSOLE" CACHE STRING "UI Type: CONSOLE or DUMMY")
16+
set_property(CACHE BITCHAT_GUI PROPERTY STRINGS "CONSOLE" "DUMMY")
17+
18+
if(ENABLE_TESTS)
19+
enable_testing()
20+
endif()
21+
822
# Set output directories
923
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
1024
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
@@ -13,14 +27,14 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
1327
# Include CPM for dependency management
1428
include(cmake/CPM.cmake)
1529

16-
# Library options
17-
set(BUILD_SHARED_LIBS OFF)
18-
set(BUILD_STATIC_LIBS ON)
30+
# Include custom functions
31+
include(cmake/functions.cmake)
32+
33+
# Include noise-c configuration
34+
include(cmake/noise-c.cmake)
1935

20-
# LZ4 options
21-
set(LZ4_BUILD_CLI OFF)
22-
set(LZ4_BUILD_LEGACY_LZ4C OFF)
23-
set(LZ4_BUNDLED_MODE OFF)
36+
# Include lz4 configuration
37+
include(cmake/lz4.cmake)
2438

2539
# Platform-specific settings
2640
if(APPLE)
@@ -39,94 +53,152 @@ elseif(UNIX AND NOT APPLE)
3953
endif()
4054

4155
# Add dependencies via CPM
42-
CPMAddPackage(
43-
NAME uuid
44-
GITHUB_REPOSITORY rkg82/uuid-v4
45-
GIT_TAG dd2f75c027d033586e9eb62b484748cb4bfc515d
46-
)
47-
4856
CPMAddPackage(
4957
NAME spdlog
5058
GITHUB_REPOSITORY gabime/spdlog
5159
VERSION 1.15.3
5260
)
5361

54-
CPMAddPackage(
55-
NAME lz4
56-
GITHUB_REPOSITORY lz4/lz4
57-
VERSION 1.10.0
58-
SOURCE_SUBDIR "build/cmake"
59-
)
62+
CPMAddPackage("gh:nlohmann/json@3.12.0")
63+
64+
# Add Google Test only if tests are enabled
65+
if(ENABLE_TESTS)
66+
CPMAddPackage("gh:google/googletest@1.17.0")
67+
endif()
6068

6169
# Find OpenSSL
6270
find_package(OpenSSL REQUIRED)
6371

64-
# Include directories
65-
include_directories(
66-
${CMAKE_CURRENT_SOURCE_DIR}/include
72+
# Common libraries
73+
set(COMMON_LIBRARIES
74+
spdlog::spdlog
75+
nlohmann_json::nlohmann_json
76+
noise-c
77+
lz4
78+
OpenSSL::SSL
79+
OpenSSL::Crypto
6780
)
6881

6982
# Source files
70-
set(SOURCES
71-
main.cpp
72-
src/bitchat/protocol/packet_utils.cpp
73-
src/bitchat/compression/compression_manager.cpp
74-
src/bitchat/crypto/crypto_manager.cpp
75-
src/bitchat/protocol/packet_serializer.cpp
76-
src/bitchat/core/bitchat_manager.cpp
83+
set(COMMON_SOURCES
84+
${CMAKE_SOURCE_DIR}/src/bitchat/core/bitchat_data.cpp
85+
${CMAKE_SOURCE_DIR}/src/bitchat/core/bitchat_manager.cpp
86+
${CMAKE_SOURCE_DIR}/src/bitchat/helpers/compression_helper.cpp
87+
${CMAKE_SOURCE_DIR}/src/bitchat/helpers/datetime_helper.cpp
88+
${CMAKE_SOURCE_DIR}/src/bitchat/helpers/noise_helper.cpp
89+
${CMAKE_SOURCE_DIR}/src/bitchat/helpers/protocol_helper.cpp
90+
${CMAKE_SOURCE_DIR}/src/bitchat/helpers/string_helper.cpp
91+
${CMAKE_SOURCE_DIR}/src/bitchat/identity/identity_models.cpp
92+
${CMAKE_SOURCE_DIR}/src/bitchat/noise/noise_hybrid_key_exchange.cpp
93+
${CMAKE_SOURCE_DIR}/src/bitchat/noise/noise_post_quantum_key_exchange.cpp
94+
${CMAKE_SOURCE_DIR}/src/bitchat/noise/noise_protocol.cpp
95+
${CMAKE_SOURCE_DIR}/src/bitchat/noise/noise_protocol_migration.cpp
96+
${CMAKE_SOURCE_DIR}/src/bitchat/noise/noise_pq_handshake_pattern.cpp
97+
${CMAKE_SOURCE_DIR}/src/bitchat/noise/noise_security_error.cpp
98+
${CMAKE_SOURCE_DIR}/src/bitchat/noise/noise_session_default.cpp
99+
${CMAKE_SOURCE_DIR}/src/bitchat/protocol/message_padding.cpp
100+
${CMAKE_SOURCE_DIR}/src/bitchat/protocol/packet_serializer.cpp
101+
${CMAKE_SOURCE_DIR}/src/bitchat/protocol/packet.cpp
102+
${CMAKE_SOURCE_DIR}/src/bitchat/runners/bluetooth_announce_runner.cpp
103+
${CMAKE_SOURCE_DIR}/src/bitchat/runners/cleanup_runner.cpp
104+
${CMAKE_SOURCE_DIR}/src/bitchat/services/crypto_service.cpp
105+
${CMAKE_SOURCE_DIR}/src/bitchat/services/identity_service.cpp
106+
${CMAKE_SOURCE_DIR}/src/bitchat/services/message_service.cpp
107+
${CMAKE_SOURCE_DIR}/src/bitchat/services/network_service.cpp
108+
${CMAKE_SOURCE_DIR}/src/bitchat/services/noise_service.cpp
109+
${CMAKE_SOURCE_DIR}/src/bitchat/ui/dummy_ui.cpp
110+
${CMAKE_SOURCE_DIR}/src/bitchat/ui/console_ui.cpp
77111
)
78112

113+
set(SOURCES ${COMMON_SOURCES})
114+
115+
if(BUILD_EXECUTABLE)
116+
set(SOURCES ${SOURCES} src/main.cpp)
117+
endif()
118+
79119
# Platform-specific source files
80120
if(PLATFORM_APPLE)
81-
set(SOURCES ${SOURCES} src/platforms/apple/bluetooth.mm src/platforms/apple/bluetooth_bridge.mm)
121+
set(SOURCES ${SOURCES}
122+
src/platforms/apple/bluetooth_factory.mm
123+
src/platforms/apple/bluetooth.mm
124+
src/platforms/apple/bluetooth_bridge.mm
125+
)
126+
82127
set_source_files_properties(src/platforms/apple/bluetooth.mm PROPERTIES COMPILE_FLAGS "-x objective-c++")
83128
set_source_files_properties(src/platforms/apple/bluetooth_bridge.mm PROPERTIES COMPILE_FLAGS "-x objective-c++")
129+
set_source_files_properties(src/platforms/apple/bluetooth_factory.mm PROPERTIES COMPILE_FLAGS "-x objective-c++")
84130
elseif(PLATFORM_LINUX)
85-
set(SOURCES ${SOURCES} src/platforms/linux/bluetooth.cpp src/platforms/linux/bluetooth_factory.cpp)
131+
set(SOURCES ${SOURCES}
132+
src/platforms/linux/bluetooth.cpp
133+
src/platforms/linux/bluetooth_factory.cpp
134+
)
86135
endif()
87136

88-
# Create executable
89-
add_executable(bitchat ${SOURCES})
137+
# Create executable only if BUILD_EXECUTABLE is enabled
138+
if(BUILD_EXECUTABLE)
139+
add_executable(bitchat ${SOURCES})
90140

91-
# Link libraries
92-
target_link_libraries(bitchat
93-
spdlog::spdlog
94-
OpenSSL::SSL
95-
OpenSSL::Crypto
96-
lz4_static
97-
)
141+
# Include directories
142+
target_include_directories(bitchat PRIVATE
143+
${CMAKE_CURRENT_SOURCE_DIR}/include
144+
${CMAKE_CURRENT_SOURCE_DIR}/vendor
145+
)
146+
147+
# Add UI macro
148+
target_compile_definitions(bitchat PRIVATE BITCHAT_GUI_${BITCHAT_GUI})
149+
150+
# Link libraries
151+
target_link_libraries(bitchat ${COMMON_LIBRARIES})
152+
endif()
98153

99154
# Platform-specific linking
100-
if(PLATFORM_APPLE)
101-
target_link_libraries(bitchat
102-
${FRAMEWORK_COREBLUETOOTH}
103-
${FRAMEWORK_FOUNDATION}
104-
${FRAMEWORK_IOKIT}
105-
${FRAMEWORK_COREFOUNDATION}
106-
)
107-
elseif(PLATFORM_LINUX)
108-
target_link_libraries(bitchat ${BLUEZ_LIBRARIES})
109-
target_include_directories(bitchat PRIVATE ${BLUEZ_INCLUDE_DIRS})
155+
if(BUILD_EXECUTABLE)
156+
if(PLATFORM_APPLE)
157+
target_link_libraries(bitchat
158+
${FRAMEWORK_COREBLUETOOTH}
159+
${FRAMEWORK_FOUNDATION}
160+
${FRAMEWORK_IOKIT}
161+
${FRAMEWORK_COREFOUNDATION}
162+
)
163+
elseif(PLATFORM_LINUX)
164+
target_link_libraries(bitchat ${BLUEZ_LIBRARIES})
165+
target_include_directories(bitchat PRIVATE ${BLUEZ_INCLUDE_DIRS})
166+
endif()
167+
endif()
168+
169+
# Apply compiler flags to main executable
170+
if(BUILD_EXECUTABLE)
171+
apply_compiler_flags(bitchat)
172+
173+
# AddressSanitizer option
174+
if(ENABLE_ASAN)
175+
message(STATUS "Building with AddressSanitizer enabled")
176+
set(ASAN_FLAGS -fsanitize=address -fno-omit-frame-pointer)
177+
target_compile_options(bitchat PRIVATE ${ASAN_FLAGS})
178+
target_link_options(bitchat PRIVATE -fsanitize=address)
179+
endif()
110180
endif()
111181

112-
# Compiler-specific flags
113-
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
114-
target_compile_options(bitchat PRIVATE -Wall -Wextra -Wpedantic)
115-
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
116-
target_compile_options(bitchat PRIVATE -Wall -Wextra -Wpedantic)
117-
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
118-
target_compile_options(bitchat PRIVATE /W4)
182+
if(ENABLE_TESTS)
183+
add_subdirectory(tests)
119184
endif()
120185

121186
# Install target
122-
install(TARGETS bitchat
123-
RUNTIME DESTINATION bin
124-
LIBRARY DESTINATION lib
125-
ARCHIVE DESTINATION lib
126-
)
187+
if(BUILD_EXECUTABLE)
188+
install(TARGETS bitchat
189+
RUNTIME DESTINATION bin
190+
LIBRARY DESTINATION lib
191+
ARCHIVE DESTINATION lib
192+
)
193+
endif()
127194

128195
# Print configuration info
129196
message(STATUS "Platform: ${CMAKE_SYSTEM_NAME}")
130197
message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID}")
131198
message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
132199
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
200+
message(STATUS "Testing enabled: ${ENABLE_TESTS}")
201+
message(STATUS "Building executable: ${BUILD_EXECUTABLE}")
202+
203+
# CPack configuration
204+
include(cmake/cpack.cmake)

LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <https://unlicense.org>

Makefile

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: help format windows-format clean build run run-windows
1+
.PHONY: help format windows-format clean build run run-windows test package
22
.DEFAULT_GOAL := help
33

44
help:
@@ -10,12 +10,16 @@ help:
1010
@echo "- clean"
1111
@echo ""
1212
@echo "- build"
13+
@echo "- build-dev"
1314
@echo "- run"
1415
@echo "- run-windows"
16+
@echo "- run-leaks"
17+
@echo "- test"
18+
@echo "- package"
1519
@echo ""
1620

1721
format:
18-
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 {} +
22+
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 {} +
1923

2024
windows-format:
2125
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 }"
@@ -27,11 +31,27 @@ clean:
2731
build:
2832
rm -rf build
2933
cmake -B build . -G Ninja
30-
cmake --build build
34+
cmake --build build
35+
36+
build-dev:
37+
rm -rf build
38+
cmake -B build . -G Ninja -DCMAKE_BUILD_TYPE=Debug -DENABLE_ASAN=ON
39+
cmake --build build
3140

3241
run:
3342
./build/bin/bitchat
3443

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

47+
run-leaks:
48+
leaks -atExit -- ./build/bin/bitchat
49+
50+
test:
51+
rm -rf build
52+
cmake -B build . -G Ninja -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON -DENABLE_ASAN=ON -DBUILD_EXECUTABLE=OFF
53+
cmake --build build
54+
cd build && ctest --output-on-failure --verbose
55+
56+
package: build
57+
cd build && cpack

0 commit comments

Comments
 (0)