From 32fbe37ab4d0f654fc4625bda018d157e0987ab2 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Mon, 13 Jul 2020 19:35:57 +0200 Subject: Reorganize ENet pactches. --- thirdparty/enet/enet/enet.h | 35 +++++----- thirdparty/enet/enet/godot.h | 8 +++ thirdparty/enet/enet/godot_ext.h | 18 +++++ thirdparty/enet/patches/dtls_support.patch | 13 ---- thirdparty/enet/patches/godot.patch | 98 +++++++++++++++++++++++++++ thirdparty/enet/patches/ipv6_support.patch | 105 ----------------------------- 6 files changed, 143 insertions(+), 134 deletions(-) create mode 100644 thirdparty/enet/enet/godot_ext.h delete mode 100644 thirdparty/enet/patches/dtls_support.patch create mode 100644 thirdparty/enet/patches/godot.patch delete mode 100644 thirdparty/enet/patches/ipv6_support.patch diff --git a/thirdparty/enet/enet/enet.h b/thirdparty/enet/enet/enet.h index d3b3b54b9d..24d36647d9 100644 --- a/thirdparty/enet/enet/enet.h +++ b/thirdparty/enet/enet/enet.h @@ -13,7 +13,16 @@ extern "C" #include #include +// -- Godot start -- +#if 0 +#ifdef _WIN32 +#include "enet/win32.h" +#else +#include "enet/unix.h" +#endif +#endif #include "enet/godot.h" +// -- Godot end -- #include "enet/types.h" #include "enet/protocol.h" @@ -69,6 +78,7 @@ typedef enum _ENetSocketShutdown ENET_SOCKET_SHUTDOWN_READ_WRITE = 2 } ENetSocketShutdown; +#define ENET_HOST_ANY 0 #define ENET_HOST_BROADCAST 0xFFFFFFFFU #define ENET_PORT_ANY 0 @@ -82,13 +92,15 @@ typedef enum _ENetSocketShutdown * but not for enet_host_create. Once a server responds to a broadcast, the * address is updated from ENET_HOST_BROADCAST to the server's actual IP address. */ +// -- Godot start -- +#if 0 typedef struct _ENetAddress { - uint8_t host[16]; + enet_uint32 host; enet_uint16 port; - uint8_t wildcard; } ENetAddress; -#define enet_host_equal(host_a, host_b) (memcmp(&host_a, &host_b,16) == 0) +#endif +// -- Godot end -- /** * Packet flag bit constants. @@ -535,16 +547,6 @@ ENET_API int enet_address_set_host_ip (ENetAddress * address, const char * hostN */ ENET_API int enet_address_set_host (ENetAddress * address, const char * hostName); -/** Sets the host field in the address parameter from ip struct. - @param address destination to store resolved address - @param ip the ip struct to read from - @param size the size of the ip struct. - @retval 0 on success - @retval != 0 on failure - @returns the address of the given ip in address on success. -*/ -ENET_API void enet_address_set_ip(ENetAddress * address, const uint8_t * ip, size_t size); - /** Gives the printable form of the IP address specified in the address parameter. @param address address printed @param hostName destination for name, must not be NULL @@ -585,9 +587,6 @@ ENET_API void enet_host_channel_limit (ENetHost *, size_t); ENET_API void enet_host_bandwidth_limit (ENetHost *, enet_uint32, enet_uint32); extern void enet_host_bandwidth_throttle (ENetHost *); extern enet_uint32 enet_host_random_seed (void); -ENET_API void enet_host_dtls_server_setup (ENetHost *, void *, void *); -ENET_API void enet_host_dtls_client_setup (ENetHost *, void *, uint8_t, const char *); -ENET_API void enet_host_refuse_new_connections (ENetHost *, int); ENET_API int enet_peer_send (ENetPeer *, enet_uint8, ENetPacket *); ENET_API ENetPacket * enet_peer_receive (ENetPeer *, enet_uint8 * channelID); @@ -617,6 +616,10 @@ ENET_API size_t enet_range_coder_decompress (void *, const enet_uint8 *, size_t, extern size_t enet_protocol_command_size (enet_uint8); +// -- Godot start -- +#include "enet/godot_ext.h" +// -- Godot end -- + #ifdef __cplusplus } #endif diff --git a/thirdparty/enet/enet/godot.h b/thirdparty/enet/enet/godot.h index 4f25ea9c7b..296b92763d 100644 --- a/thirdparty/enet/enet/godot.h +++ b/thirdparty/enet/enet/godot.h @@ -69,4 +69,12 @@ typedef struct typedef void ENetSocketSet; +typedef struct _ENetAddress +{ + uint8_t host[16]; + uint16_t port; + uint8_t wildcard; +} ENetAddress; +#define enet_host_equal(host_a, host_b) (memcmp(&host_a, &host_b,16) == 0) + #endif /* __ENET_GODOT_H__ */ diff --git a/thirdparty/enet/enet/godot_ext.h b/thirdparty/enet/enet/godot_ext.h new file mode 100644 index 0000000000..84a23b1c85 --- /dev/null +++ b/thirdparty/enet/enet/godot_ext.h @@ -0,0 +1,18 @@ +#ifndef __ENET_GODOT_EXT_H__ +#define __ENET_GODOT_EXT_H__ + +/** Sets the host field in the address parameter from ip struct. + @param address destination to store resolved address + @param ip the ip struct to read from + @param size the size of the ip struct. + @retval 0 on success + @retval != 0 on failure + @returns the address of the given ip in address on success. +*/ +ENET_API void enet_address_set_ip(ENetAddress * address, const uint8_t * ip, size_t size); + +ENET_API void enet_host_dtls_server_setup (ENetHost *, void *, void *); +ENET_API void enet_host_dtls_client_setup (ENetHost *, void *, uint8_t, const char *); +ENET_API void enet_host_refuse_new_connections (ENetHost *, int); + +#endif // __ENET_GODOT_EXT_H__ diff --git a/thirdparty/enet/patches/dtls_support.patch b/thirdparty/enet/patches/dtls_support.patch deleted file mode 100644 index ce3480a858..0000000000 --- a/thirdparty/enet/patches/dtls_support.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/thirdparty/enet/enet/enet.h b/thirdparty/enet/enet/enet.h -index 966e3a465d..ac7552adb2 100644 ---- a/thirdparty/enet/enet/enet.h -+++ b/thirdparty/enet/enet/enet.h -@@ -578,6 +578,8 @@ ENET_API void enet_host_channel_limit (ENetHost *, size_t); - ENET_API void enet_host_bandwidth_limit (ENetHost *, enet_uint32, enet_uint32); - extern void enet_host_bandwidth_throttle (ENetHost *); - extern enet_uint32 enet_host_random_seed (void); -+ENET_API void enet_host_dtls_server_setup (ENetHost *, void *, void *); -+ENET_API void enet_host_dtls_client_setup (ENetHost *, void *, uint8_t, const char *); - - ENET_API int enet_peer_send (ENetPeer *, enet_uint8, ENetPacket *); - ENET_API ENetPacket * enet_peer_receive (ENetPeer *, enet_uint8 * channelID); diff --git a/thirdparty/enet/patches/godot.patch b/thirdparty/enet/patches/godot.patch new file mode 100644 index 0000000000..c8b4a5225d --- /dev/null +++ b/thirdparty/enet/patches/godot.patch @@ -0,0 +1,98 @@ +diff --git a/thirdparty/enet/enet/enet.h b/thirdparty/enet/enet/enet.h +index 54d91b5603..24d36647d9 100644 +--- a/thirdparty/enet/enet/enet.h ++++ b/thirdparty/enet/enet/enet.h +@@ -10,13 +10,19 @@ extern "C" + { + #endif + ++#include + #include + ++// -- Godot start -- ++#if 0 + #ifdef _WIN32 + #include "enet/win32.h" + #else + #include "enet/unix.h" + #endif ++#endif ++#include "enet/godot.h" ++// -- Godot end -- + + #include "enet/types.h" + #include "enet/protocol.h" +@@ -86,11 +92,15 @@ typedef enum _ENetSocketShutdown + * but not for enet_host_create. Once a server responds to a broadcast, the + * address is updated from ENET_HOST_BROADCAST to the server's actual IP address. + */ ++// -- Godot start -- ++#if 0 + typedef struct _ENetAddress + { + enet_uint32 host; + enet_uint16 port; + } ENetAddress; ++#endif ++// -- Godot end -- + + /** + * Packet flag bit constants. +@@ -606,6 +616,10 @@ ENET_API size_t enet_range_coder_decompress (void *, const enet_uint8 *, size_t, + + extern size_t enet_protocol_command_size (enet_uint8); + ++// -- Godot start -- ++#include "enet/godot_ext.h" ++// -- Godot end -- ++ + #ifdef __cplusplus + } + #endif +diff --git a/thirdparty/enet/host.c b/thirdparty/enet/host.c +index 3be6c0922c..fc4da4ca67 100644 +--- a/thirdparty/enet/host.c ++++ b/thirdparty/enet/host.c +@@ -87,7 +87,7 @@ enet_host_create (const ENetAddress * address, size_t peerCount, size_t channelL + host -> commandCount = 0; + host -> bufferCount = 0; + host -> checksum = NULL; +- host -> receivedAddress.host = ENET_HOST_ANY; ++ memset(host -> receivedAddress.host, 0, 16); + host -> receivedAddress.port = 0; + host -> receivedData = NULL; + host -> receivedDataLength = 0; +diff --git a/thirdparty/enet/protocol.c b/thirdparty/enet/protocol.c +index 0a60253173..fefc0e6f0a 100644 +--- a/thirdparty/enet/protocol.c ++++ b/thirdparty/enet/protocol.c +@@ -307,7 +307,7 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet + } + else + if (currentPeer -> state != ENET_PEER_STATE_CONNECTING && +- currentPeer -> address.host == host -> receivedAddress.host) ++ enet_host_equal(currentPeer -> address.host, host -> receivedAddress.host)) + { + if (currentPeer -> address.port == host -> receivedAddress.port && + currentPeer -> connectID == command -> connect.connectID) +@@ -1027,9 +1027,8 @@ enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event) + + if (peer -> state == ENET_PEER_STATE_DISCONNECTED || + peer -> state == ENET_PEER_STATE_ZOMBIE || +- ((host -> receivedAddress.host != peer -> address.host || +- host -> receivedAddress.port != peer -> address.port) && +- peer -> address.host != ENET_HOST_BROADCAST) || ++ (!enet_host_equal(host -> receivedAddress.host, peer -> address.host) || ++ host -> receivedAddress.port != peer -> address.port) || + (peer -> outgoingPeerID < ENET_PROTOCOL_MAXIMUM_PEER_ID && + sessionID != peer -> incomingSessionID)) + return 0; +@@ -1071,7 +1070,7 @@ enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event) + + if (peer != NULL) + { +- peer -> address.host = host -> receivedAddress.host; ++ enet_address_set_ip(&(peer -> address), host -> receivedAddress.host, 16); + peer -> address.port = host -> receivedAddress.port; + peer -> incomingDataTotal += host -> receivedDataLength; + } diff --git a/thirdparty/enet/patches/ipv6_support.patch b/thirdparty/enet/patches/ipv6_support.patch deleted file mode 100644 index 1f79863645..0000000000 --- a/thirdparty/enet/patches/ipv6_support.patch +++ /dev/null @@ -1,105 +0,0 @@ -diff --git a/thirdparty/enet/enet/enet.h b/thirdparty/enet/enet/enet.h -index 650b199ee5..246cbb0a62 100644 ---- a/thirdparty/enet/enet/enet.h -+++ b/thirdparty/enet/enet/enet.h -@@ -10,13 +10,10 @@ extern "C" - { - #endif - -+#include - #include - --#ifdef _WIN32 --#include "enet/win32.h" --#else --#include "enet/unix.h" --#endif -+#include "enet/godot.h" - - #include "enet/types.h" - #include "enet/protocol.h" -@@ -72,7 +69,6 @@ typedef enum _ENetSocketShutdown - ENET_SOCKET_SHUTDOWN_READ_WRITE = 2 - } ENetSocketShutdown; - --#define ENET_HOST_ANY 0 - #define ENET_HOST_BROADCAST 0xFFFFFFFFU - #define ENET_PORT_ANY 0 - -@@ -88,9 +84,11 @@ typedef enum _ENetSocketShutdown - */ - typedef struct _ENetAddress - { -- enet_uint32 host; -+ uint8_t host[16]; - enet_uint16 port; -+ uint8_t wildcard; - } ENetAddress; -+#define enet_host_equal(host_a, host_b) (memcmp(&host_a, &host_b,16) == 0) - - /** - * Packet flag bit constants. -@@ -519,6 +517,16 @@ ENET_API int enet_socketset_select (ENetSocket, ENetSocketSet *, ENetSock - */ - ENET_API int enet_address_set_host (ENetAddress * address, const char * hostName); - -+/** Sets the host field in the address parameter from ip struct. -+ @param address destination to store resolved address -+ @param ip the ip struct to read from -+ @param size the size of the ip struct. -+ @retval 0 on success -+ @retval != 0 on failure -+ @returns the address of the given ip in address on success. -+*/ -+ENET_API void enet_address_set_ip(ENetAddress * address, const uint8_t * ip, size_t size); -+ - /** Gives the printable form of the IP address specified in the address parameter. - @param address address printed - @param hostName destination for name, must not be NULL -diff --git a/thirdparty/enet/host.c b/thirdparty/enet/host.c -index 3be6c0922c..fc4da4ca67 100644 ---- a/thirdparty/enet/host.c -+++ b/thirdparty/enet/host.c -@@ -87,7 +87,7 @@ enet_host_create (const ENetAddress * address, size_t peerCount, size_t channelL - host -> commandCount = 0; - host -> bufferCount = 0; - host -> checksum = NULL; -- host -> receivedAddress.host = ENET_HOST_ANY; -+ memset(host -> receivedAddress.host, 0, 16); - host -> receivedAddress.port = 0; - host -> receivedData = NULL; - host -> receivedDataLength = 0; -diff --git a/thirdparty/enet/protocol.c b/thirdparty/enet/protocol.c -index 29d648732d..ab26886de4 100644 ---- a/thirdparty/enet/protocol.c -+++ b/thirdparty/enet/protocol.c -@@ -298,7 +298,7 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet - } - else - if (currentPeer -> state != ENET_PEER_STATE_CONNECTING && -- currentPeer -> address.host == host -> receivedAddress.host) -+ enet_host_equal(currentPeer -> address.host, host -> receivedAddress.host)) - { - if (currentPeer -> address.port == host -> receivedAddress.port && - currentPeer -> connectID == command -> connect.connectID) -@@ -1010,9 +1010,8 @@ enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event) - - if (peer -> state == ENET_PEER_STATE_DISCONNECTED || - peer -> state == ENET_PEER_STATE_ZOMBIE || -- ((host -> receivedAddress.host != peer -> address.host || -- host -> receivedAddress.port != peer -> address.port) && -- peer -> address.host != ENET_HOST_BROADCAST) || -+ (!enet_host_equal(host -> receivedAddress.host, peer -> address.host) || -+ host -> receivedAddress.port != peer -> address.port) || - (peer -> outgoingPeerID < ENET_PROTOCOL_MAXIMUM_PEER_ID && - sessionID != peer -> incomingSessionID)) - return 0; -@@ -1054,7 +1053,7 @@ enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event) - - if (peer != NULL) - { -- peer -> address.host = host -> receivedAddress.host; -+ enet_address_set_ip(&(peer -> address), host -> receivedAddress.host, 16); - peer -> address.port = host -> receivedAddress.port; - peer -> incomingDataTotal += host -> receivedDataLength; - } -- cgit v1.2.3