Skip to content

Commit 050f5f5

Browse files
authored
Higher level network refactor (#33)
* Cleanup on ProtocolPacket, merge FluxPacket with ProtocolPacket * Renaming COUNTID -> COUNTER * add ClientStatus class, add timeout handling in ClientSideNetUdp * IpAddress: add todo for hostname * Socket: add setDontFragment() * Socket: add retrieveCurrentAdapterMTU() and getAdaptersInfo() * SocketUdp: add retrieveAdapterMTUForDestination() * Socket: fix "_win32" instead of "_WIN32" * server: add NetCommand, add NetMTUCommand in order to retrieve MTU via custom path discovery * deps/.gitignore: add wsl/ folder * add linux version for retrieveCurrentAdapterMTU() and getAdaptersInfo() * Socket: add missing include, fix bad construct * ClientSideNetUdp::sendTo: fix missing id usage * socket: try fix mac * try fixing mac * Packet: add ERR_TRANSMIT, cleaning extra namespaces * move net::Error class to a new file * add Compressor class, add CompressorLZ4 * add CompressorLZ4HC, refactor PacketLZ4/PacketLZ4HC with Compressor, TODO: remove throw * Packet: onSend() now return a bool to indicate an error * move C_compressor.hpp out of network/ * move CompressorLZ4/HC class in new file * Drop the PacketBZ2, add CompressorBZ2 class * Packet: made _g_data, _g_readPos and _g_valid private * Packet: rename _g_sendPos -> _g_transmitPos, _g_lastData -> _g_transmitCache, _g_lastDataValidity -> _g_transmitCacheValid * Packet: onReceive() use std::span * Packet: remove buffer argument on onSend() * Packet: remove _defaultReserveSize static variable * Client: use deque, add pushForcedFrontPacket() * Identity: add default values * PacketLZ4 : add missing argument * add PacketDefragmentation class, move threadReception/threadTransmission from ClientSideNetUdp to .cpp file * move PacketDefragmentation to C_protocol * ClientList: general cleaning, clean namespaces * ClientList: use fge::AccessLock * ClientList: add PacketDefragmentation class for every client * ServerSideNetUdp: move out of template threadReception and threadTransmission * ProtocolPacket: add isFragmented() method * ServerNetFluxUdp::process: support defragmentation * Server: fix missing refClient set * apply commits to clientServerLifeSimulator_004/server/main.cpp * TransmissionPacket: add enable_shared_from_this, add fragment() method * PacketDefragmentation: correctly move code to correct file, use vector instead of map, add fragmentation to ServerSideNetUdp * merging TransmissionPacket class to ProtocolPacket class * Client: add mtu * add do not fragment flag on ProtocolPacket * CMakeLists.txt: add OpenSSL package and link to it * add DTLS handshake, still WIP, add new connect command * ClientStatus: use a time_point for the timeout * Client: add getLastPacketElapsedTime() / getLastPacketLatency(), add _mtuFinalizedFlag * NetCommand: add CommandQueue, complete NetConnectCommand (still WIP) * ClientList: Data: use CommandQueue, add _mtuFutur * Server: continue to work on client/server communication * Server: handle MTU_DISCOVERED state, set cipher list, key/certificate * add CryptGenerateKeyAndCertificate() * Fix client/server examples * fix server handling end of crypt handshake * modify the way the timeout is handled in NetCommand, also did a cleaning pass * encryption from server, decryption from client, now working WIP * fix examples * ProtocolPacket: add haveCorrectHeader() and unmarkForEncryption() * encryption from client to server * ServerSideNetUdp::threadReception: now handle packet encryption as it now have identity/client association * move crypt function to own files * correctly destroy cryptinfo * ClientStatus: remove USER_HANDLED state, add isInEncryptedState() method * Protocol: remove FGE_NET_HEADER_LOCAL_REORDERED_FLAG, add FGE_NET_HEADER_COMPRESSED_FLAG * ProtocolPacket: add compress() and decompress() * ProtocolPacket: fix some bits mask issues * Compressor: reorder some code * Client: pushPacket: use isInEncryptedState() method * NetConnectCommand: fix broken promise * Add compression/decompression, client is still not compressing WIP * enable compression on client * remove LIFESIM_CLIENT_PORT and use FGE_ANYPORT * rename NET_INTERNAL_ID_FRAGMENTED_PACKET, add NET_INTERNAL_ID_RETURN_PACKET * Add code for the return packet * Identity: add toString() helper * made return packet usable by adding handling of the packet in server/client * clientServerLifeSimulator_004: modify examples by adding the return packet internally * ProtocolPacket: add lastReorderedCounter used on reordered packet * Scene: pack() now reset client stat * update clientServerLifeSimulator_004 * async connect * add NET_INTERNAL_ID_DISCONNECT, for clean disconnection handling (client only in this commit) * removing skey * add custom versioning string during handshake * Add server disconnection notice to client * add _onTransmitReturnPacket event * Client: add status check helper, disallow packets when disconnected, add disconnect() helper * NetConnectCommand: add timeout on WAITING_SERVER_FINAL_MTU * Fixing, allow sending packet when disconnected client * increase FGE_NET_MTU_TIMEOUT_MS to 500ms * NetCommand: make sure to steal unique_ptr owner on onReceive() if packet is for the command * ClientSideNetUdp: add option to set return packet rate * don't throw in disconnect() * fix iteration in processClients() * rework FluxProcessResults: this fix a packets process lag * ChainedArguments: remove newChain(), simplify a bit the way rules must be implemented * Add RStringRange and RStringMustEqual helper * add fge_debug.hpp with macro FGE_DEBUG_PRINT * NetCommand: handling of the timeout is now global * add the PacketCache class, in order to retransmit packets that wasn't received by the client WIP * AccessLock: add DataLockPair alias helper for std::pair * Client: avoid data race for getPacketCache() * NetCommand: fix missing setCurrentPacketCounter * fix PacketCache, add debug print * fixing server, make sure PacketCache work * add constructor for Label * Label: add default constructor * mute unused variables in release mode * add FGE_NET_PACKET_CACHE_DELAY_FACTOR, add the ability to set maximum size of packet reorder - also add macro to help user compute a "perfect" size * TransmitPacketPtr now use a unique_ptr as it doesn't make sense anymore to have it shared * fix MTU discovery when low MTU * fix packet defragmentation, remove extra debugging code
1 parent 1f55d8d commit 050f5f5

Some content is hidden

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

43 files changed

+6005
-2059
lines changed

CMakeLists.txt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ else()
2121
endif()
2222
endif()
2323

24+
#Find the OpenSSL package
25+
find_package(OpenSSL REQUIRED)
26+
2427
#Add a LZ4 fix for missing INTERFACE_INCLUDE_DIRECTORIES property
2528
get_target_property(VAR_PROPERTY_CHECK LZ4::lz4_static INTERFACE_INCLUDE_DIRECTORIES)
2629

@@ -246,6 +249,8 @@ target_sources(${FGE_SERVER_LIB_NAME} PRIVATE
246249
sources/C_tilelayer.cpp
247250
sources/C_timer.cpp
248251
sources/C_quad.cpp
252+
sources/C_compressorBZ2.cpp
253+
sources/C_compressorLZ4.cpp
249254
sources/fge_endian.cpp)
250255

251256
target_sources(${FGE_SERVER_LIB_NAME} PRIVATE
@@ -275,14 +280,15 @@ target_sources(${FGE_SERVER_LIB_NAME} PRIVATE
275280

276281
target_sources(${FGE_SERVER_LIB_NAME} PRIVATE
277282
sources/network/C_client.cpp
283+
sources/network/C_error.cpp
278284
sources/network/C_clientList.cpp
279285
sources/network/C_ipAddress.cpp
280286
sources/network/C_networkType.cpp
281287
sources/network/C_packet.cpp
282-
sources/network/C_packetBZ2.cpp
283288
sources/network/C_packetLZ4.cpp
284289
sources/network/C_server.cpp
285290
sources/network/C_socket.cpp
291+
sources/network/C_netCommand.cpp
286292
sources/network/C_protocol.cpp)
287293

288294
target_sources(${FGE_SERVER_LIB_NAME} PRIVATE
@@ -302,6 +308,8 @@ target_sources(${FGE_SERVER_LIB_NAME} PRIVATE
302308
sources/manager/timer_manager.cpp
303309
sources/manager/task_manager.cpp)
304310

311+
target_sources(${FGE_SERVER_LIB_NAME} PRIVATE sources/private/fge_crypt.cpp)
312+
305313
#######################
306314

307315
target_sources(${FGE_LIB_NAME} PUBLIC FILE_SET publicHeaders TYPE HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/includes FILES ${FGE_INCLUDES_PUBLIC})
@@ -358,6 +366,8 @@ target_sources(${FGE_LIB_NAME} PRIVATE
358366
sources/C_tilelayer.cpp
359367
sources/C_timer.cpp
360368
sources/C_quad.cpp
369+
sources/C_compressorBZ2.cpp
370+
sources/C_compressorLZ4.cpp
361371
sources/fge_endian.cpp)
362372

363373
target_sources(${FGE_LIB_NAME} PRIVATE
@@ -387,14 +397,15 @@ target_sources(${FGE_LIB_NAME} PRIVATE
387397

388398
target_sources(${FGE_LIB_NAME} PRIVATE
389399
sources/network/C_client.cpp
400+
sources/network/C_error.cpp
390401
sources/network/C_clientList.cpp
391402
sources/network/C_ipAddress.cpp
392403
sources/network/C_networkType.cpp
393404
sources/network/C_packet.cpp
394-
sources/network/C_packetBZ2.cpp
395405
sources/network/C_packetLZ4.cpp
396406
sources/network/C_server.cpp
397407
sources/network/C_socket.cpp
408+
sources/network/C_netCommand.cpp
398409
sources/network/C_protocol.cpp)
399410

400411
target_sources(${FGE_LIB_NAME} PRIVATE
@@ -416,11 +427,12 @@ target_sources(${FGE_LIB_NAME} PRIVATE
416427
sources/manager/task_manager.cpp)
417428

418429
target_sources(${FGE_LIB_NAME} PRIVATE sources/private/spirv_reflect.cpp)
430+
target_sources(${FGE_LIB_NAME} PRIVATE sources/private/fge_crypt.cpp)
419431

420432
#Linking library
421433
if(WIN32)
422-
target_link_libraries(${FGE_LIB_NAME} PUBLIC user32 ws2_32 winmm)
423-
target_link_libraries(${FGE_SERVER_LIB_NAME} PUBLIC user32 ws2_32 winmm)
434+
target_link_libraries(${FGE_LIB_NAME} PUBLIC user32 ws2_32 winmm iphlpapi)
435+
target_link_libraries(${FGE_SERVER_LIB_NAME} PUBLIC user32 ws2_32 winmm iphlpapi)
424436
endif()
425437

426438
target_link_libraries(${FGE_LIB_NAME} PRIVATE glslang::glslang-default-resource-limits glslang::SPIRV glslang::glslang)
@@ -431,6 +443,7 @@ target_link_libraries(${FGE_LIB_NAME} PRIVATE fmt::fmt-header-only)
431443
target_link_libraries(${FGE_LIB_NAME} PRIVATE Freetype::Freetype)
432444
target_link_libraries(${FGE_LIB_NAME} PRIVATE re2::re2)
433445
target_link_libraries(${FGE_LIB_NAME} PUBLIC glm::glm-header-only volk::volk_headers GPUOpen::VulkanMemoryAllocator Vulkan::Headers)
446+
target_link_libraries(${FGE_LIB_NAME} PRIVATE OpenSSL::SSL OpenSSL::Crypto)
434447

435448
target_link_libraries(${FGE_SERVER_LIB_NAME} PRIVATE glslang::glslang-default-resource-limits glslang::SPIRV glslang::glslang)
436449
target_link_libraries(${FGE_SERVER_LIB_NAME} PUBLIC SDL2::SDL2 SDL2_image::SDL2_image)
@@ -440,6 +453,7 @@ target_link_libraries(${FGE_SERVER_LIB_NAME} PRIVATE fmt::fmt-header-only)
440453
target_link_libraries(${FGE_SERVER_LIB_NAME} PRIVATE Freetype::Freetype)
441454
target_link_libraries(${FGE_SERVER_LIB_NAME} PRIVATE re2::re2)
442455
target_link_libraries(${FGE_SERVER_LIB_NAME} PUBLIC glm::glm-header-only volk::volk_headers GPUOpen::VulkanMemoryAllocator Vulkan::Headers)
456+
target_link_libraries(${FGE_SERVER_LIB_NAME} PRIVATE OpenSSL::SSL OpenSSL::Crypto)
443457

444458
#Install
445459
include(GNUInstallDirs)

deps/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/x32/
66
/msvc/
77
/clang/
8+
/wsl/
89
/build*/
910

1011
/.idea/

0 commit comments

Comments
 (0)