Skip to content

Commit

Permalink
remove encryption support from core library (#59)
Browse files Browse the repository at this point in the history
remove encryption support from the core library
  • Loading branch information
nathhB authored Jul 16, 2024
1 parent ac94054 commit 32b1b62
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 2,721 deletions.
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,14 @@ If you want to discuss the library or need help, join the [nbnet's discord serve

- Connection management
- Sending/Receiving both reliable ordered and unreliable ordered messages
- Sending/Receiving messages larger than the MTU (using nbnet's message fragmentation)
- Sending/Receiving messages larger than the MTU through nbnet's message fragmentation system
- Bit-level serialization (for bandwidth optimization): integers (signed and unsigned), floats, booleans, and byte arrays
- Network conditions simulation: ping, jitter, packet loss, packet duplication, and out-of-order packets)
- Network statistics: ping, bandwidth (upload and download) and packet loss
- Web (WebRTC) support (both natively and through WASM using [emscripten](https://emscripten.org/docs/introducing_emscripten/about_emscripten.html))
- Encrypted and authenticated packets

## Thanks

nbnet encryption and packet authentication use the following open-source libraries:

- [tiny-ECDH](https://github.com/kokke/tiny-ECDH-c)
- [tiny-AES](https://github.com/kokke/tiny-AES-c)
- [poly1305-donna](https://github.com/floodyberry/poly1305-donna)

the native WebRTC driver relies on:

- [libdatachannel](https://github.com/paullouisageneau/libdatachannel)
Expand Down Expand Up @@ -85,7 +78,7 @@ A driver is a set of function definitions that live outside the nbnet header and
nbnet comes with three ready-to-use drivers:

- UDP: works with a single UDP socket, designed for desktop games
- WebRTC (WASM): works with a single unreliable/unordered data channel, implemented in JS using emscripten API
- WebRTC (WASM): works with a single unreliable/unordered data channel, implemented in JS using the emscripten API
- WebRTC (Native): works the same way as the WASM WebRTC driver but can be natively compiled

## How to use
Expand Down
7 changes: 1 addition & 6 deletions examples/echo/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,10 @@ int main(int argc, char *argv[])
#endif // __EMSCRIPTEN__

// Initialize the client
#ifdef NBN_ENCRYPTION
bool enable_encryption = true;
#else
bool enable_encryption = false;
#endif

// Start the client with a protocol name (must be the same than the one used by the server)
// the server host and port and with packet encryption on or off
if (NBN_GameClient_StartEx(ECHO_PROTOCOL_NAME, "127.0.0.1", ECHO_EXAMPLE_PORT, enable_encryption, NULL, 0) < 0)
if (NBN_GameClient_StartEx(ECHO_PROTOCOL_NAME, "127.0.0.1", ECHO_EXAMPLE_PORT, NULL, 0) < 0)
{
Log(LOG_ERROR, "Failed to start client");

Expand Down
8 changes: 1 addition & 7 deletions examples/echo/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,8 @@ int main(int argc, const char **argv)
NBN_UDP_Register(); // Register the UDP driver
#endif

#ifdef NBN_ENCRYPTION
bool enable_encryption = true;
#else
bool enable_encryption = false;
#endif

// Start the server with a protocol name, a port, and with packet encryption on or off
if (NBN_GameServer_StartEx(ECHO_PROTOCOL_NAME, ECHO_EXAMPLE_PORT, enable_encryption) < 0)
if (NBN_GameServer_StartEx(ECHO_PROTOCOL_NAME, ECHO_EXAMPLE_PORT) < 0)
{
Log(LOG_ERROR, "Failed to start the server");

Expand Down
2 changes: 0 additions & 2 deletions examples/echo_bytes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ add_compile_options(-Wall -Wextra -Wpedantic)
target_compile_definitions(echo_bytes_client PUBLIC NBN_DEBUG)
target_compile_definitions(echo_bytes_server PUBLIC NBN_DEBUG)

option(ENCRYPTION_ENABLED OFF)

if(WIN32)
target_link_libraries(echo_bytes_client wsock32 ws2_32)
target_link_libraries(echo_bytes_server wsock32 ws2_32)
Expand Down
2 changes: 1 addition & 1 deletion examples/echo_bytes/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int main(void)
NBN_UDP_Register(); // Register the UDP driver
#endif // __EMSCRIPTEN__

// Start the server with a protocol name, a port, and with packet encryption on or off
// Start the server with a protocol name and a port
if (NBN_GameServer_Start(ECHO_PROTOCOL_NAME, ECHO_EXAMPLE_PORT) < 0)
{
Log(LOG_ERROR, "Failed to start the server");
Expand Down
9 changes: 0 additions & 9 deletions examples/raylib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ target_compile_definitions(raylib_client PUBLIC NBN_DEBUG)
target_compile_definitions(raylib_server PUBLIC NBN_DEBUG)
target_compile_definitions(raylib_server PUBLIC NBN_RAYLIB_SERVER)

if (ENCRYPTION_ENABLED)
message("Encryption enabled")

target_compile_definitions(raylib_client PUBLIC EXAMPLE_ENCRYPTION)
target_compile_definitions(raylib_server PUBLIC EXAMPLE_ENCRYPTION)
endif(ENCRYPTION_ENABLED)

unset(ENCRYPTION_ENABLED)

# compile with C WebRTC driver
if (WEBRTC_C_DRIVER)
# can't compile WebRTC native driver with emscripten
Expand Down
9 changes: 2 additions & 7 deletions examples/raylib/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,15 +517,10 @@ int main(int argc, char *argv[])
#endif // __EMSCRIPTEN__

// Initialize the client with a protocol name (must be the same than the one used by the server), the server ip address and port
#ifdef EXAMPLE_ENCRYPTION
bool enable_encryption = true;
#else
bool enable_encryption = false;
#endif

// Start the client with a protocol name (must be the same than the one used by the server)
// the server host and port and with packet encryption on or off
if (NBN_GameClient_StartEx(RAYLIB_EXAMPLE_PROTOCOL_NAME, "127.0.0.1", RAYLIB_EXAMPLE_PORT, enable_encryption, NULL, 0) < 0)
// the server host and port
if (NBN_GameClient_StartEx(RAYLIB_EXAMPLE_PROTOCOL_NAME, "127.0.0.1", RAYLIB_EXAMPLE_PORT, NULL, 0) < 0)
{
TraceLog(LOG_WARNING, "Game client failed to start. Exit");

Expand Down
10 changes: 2 additions & 8 deletions examples/raylib/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,8 @@ int main(int argc, char *argv[])

#endif // __EMSCRIPTEN__

#ifdef EXAMPLE_ENCRYPTION
bool enable_encryption = true;
#else
bool enable_encryption = false;
#endif

// Start the server with a protocol name, a port, and with packet encryption on or off
if (NBN_GameServer_StartEx(RAYLIB_EXAMPLE_PROTOCOL_NAME, RAYLIB_EXAMPLE_PORT, enable_encryption) < 0)
// Start the server with a protocol name and a port
if (NBN_GameServer_StartEx(RAYLIB_EXAMPLE_PROTOCOL_NAME, RAYLIB_EXAMPLE_PORT) < 0)
{
TraceLog(LOG_ERROR, "Game server failed to start. Exit");

Expand Down
1 change: 0 additions & 1 deletion examples/rpc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ add_compile_options(-Wall -Wextra -Wpedantic)
target_compile_definitions(rpc_client PUBLIC NBN_DEBUG)
target_compile_definitions(rpc_server PUBLIC NBN_DEBUG)

option(ENCRYPTION_ENABLED OFF)
option(WEBRTC_DRIVER_C OFF)

if(WIN32)
Expand Down
7 changes: 1 addition & 6 deletions examples/rpc/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,8 @@ int main(int argc, char *argv[])
#endif // __EMSCRIPTEN__

// Initialize the client with a protocol name (must be the same than the one used by the server), the server ip address and port
#ifdef NBN_ENCRYPTION
bool enable_encryption = true;
#else
bool enable_encryption = false;
#endif

if (NBN_GameClient_StartEx(RPC_PROTOCOL_NAME, "127.0.0.1", RPC_EXAMPLE_PORT, enable_encryption, NULL, 0) < 0)
if (NBN_GameClient_StartEx(RPC_PROTOCOL_NAME, "127.0.0.1", RPC_EXAMPLE_PORT, NULL, 0) < 0)
{
Log(LOG_ERROR, "Failed to start client");

Expand Down
8 changes: 1 addition & 7 deletions examples/rpc/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,7 @@ int main(void)
NBN_UDP_Register(); // Register the UDP driver
#endif // __EMSCRIPTEN__

#ifdef NBN_ENCRYPTION
bool enable_encryption = true;
#else
bool enable_encryption = false;
#endif

if (NBN_GameServer_StartEx(RPC_PROTOCOL_NAME, RPC_EXAMPLE_PORT, enable_encryption) < 0)
if (NBN_GameServer_StartEx(RPC_PROTOCOL_NAME, RPC_EXAMPLE_PORT) < 0)
{
Log(LOG_ERROR, "Failed to start the server");

Expand Down
Loading

0 comments on commit 32b1b62

Please sign in to comment.