Browse Source

2.4.5 roll-up

Checksum-related fixes.
Matt Coburn 5 years ago
parent
commit
0fecf60442
3 changed files with 11 additions and 10 deletions
  1. 1 1
      ENet-CSharp.nuspec
  2. 1 1
      Source/Managed/ENet.cs
  3. 9 8
      Source/Native/enet.h

+ 1 - 1
ENet-CSharp.nuspec

@@ -2,7 +2,7 @@
 <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
   <metadata>
     <id>ENet-CSharp</id>
-    <version>2.4.4</version>
+    <version>2.4.5</version>
     <title>ENet-CSharp</title>
     <authors>Matt Coburn</authors>
     <owners>coburn64</owners>

+ 1 - 1
Source/Managed/ENet.cs

@@ -1128,7 +1128,7 @@ namespace ENet
 		public const uint timeoutLimit = 32;
 		public const uint timeoutMinimum = 5000;
 		public const uint timeoutMaximum = 30000;
-		public const uint version = (2 << 16) | (4 << 8) | (4);
+		public const uint version = (2 << 16) | (4 << 8) | (5);
 
 		public static uint Time
 		{

+ 9 - 8
Source/Native/enet.h

@@ -32,7 +32,7 @@
 
 #define ENET_VERSION_MAJOR 2
 #define ENET_VERSION_MINOR 4
-#define ENET_VERSION_PATCH 4
+#define ENET_VERSION_PATCH 5
 #define ENET_VERSION_CREATE(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch))
 #define ENET_VERSION_GET_MAJOR(version) (((version) >> 16) & 0xFF)
 #define ENET_VERSION_GET_MINOR(version) (((version) >> 8) & 0xFF)
@@ -1253,6 +1253,7 @@ uint32_t enet_time_get(void) {
 
 =======================================================================
 */
+typedef uint64_t enet_checksum;
 
 static const uint64_t crcTable[256] = {
 	UINT64_C(0x0000000000000000), UINT64_C(0x7ad870c830358979),
@@ -2433,7 +2434,7 @@ static int enet_protocol_handle_incoming_commands(ENetHost* host, ENetEvent* eve
 	headerSize = (flags & ENET_PROTOCOL_HEADER_FLAG_SENT_TIME ? sizeof(ENetProtocolHeader) : (size_t) & ((ENetProtocolHeader*)0)->sentTime);
 
 	if (host->checksumCallback != NULL)
-		headerSize += sizeof(uint64_t);
+		headerSize += sizeof(enet_checksum);
 
 	if (peerID == ENET_PROTOCOL_MAXIMUM_PEER_ID) {
 		peer = NULL;
@@ -2449,8 +2450,8 @@ static int enet_protocol_handle_incoming_commands(ENetHost* host, ENetEvent* eve
 	}
 
 	if (host->checksumCallback != NULL) {
-		uint64_t* checksum = (uint64_t*)&host->receivedData[headerSize - sizeof(uint64_t)];
-		uint64_t desiredChecksum = *checksum;
+		enet_checksum* checksum = (enet_checksum*)&host->receivedData[headerSize - sizeof(enet_checksum)];
+		enet_checksum desiredChecksum = *checksum;
 		ENetBuffer buffer;
 		*checksum = peer != NULL ? peer->connectID : 0;
 		buffer.data = host->receivedData;
@@ -2905,7 +2906,7 @@ static int enet_protocol_check_outgoing_commands(ENetHost* host, ENetPeer* peer)
 }
 
 static int enet_protocol_send_outgoing_commands(ENetHost* host, ENetEvent* event, int checkForTimeouts) {
-	uint8_t headerData[sizeof(ENetProtocolHeader) + sizeof(uint32_t)];
+	uint8_t headerData[sizeof(ENetProtocolHeader) + sizeof(enet_checksum)];
 	ENetProtocolHeader* header = (ENetProtocolHeader*)headerData;
 	ENetPeer* currentPeer;
 	int sentLength;
@@ -2955,9 +2956,9 @@ static int enet_protocol_send_outgoing_commands(ENetHost* host, ENetEvent* event
 			header->peerID = ENET_HOST_TO_NET_16(currentPeer->outgoingPeerID | host->headerFlags);
 
 			if (host->checksumCallback != NULL) {
-				uint64_t* checksum = (uint64_t*)&headerData[host->buffers->dataLength];
+				enet_checksum* checksum = (enet_checksum*)&headerData[host->buffers->dataLength];
 				*checksum = currentPeer->outgoingPeerID < ENET_PROTOCOL_MAXIMUM_PEER_ID ? currentPeer->connectID : 0;
-				host->buffers->dataLength += sizeof(uint64_t);
+				host->buffers->dataLength += sizeof(enet_checksum);
 				*checksum = host->checksumCallback(host->buffers, host->bufferCount);
 			}
 
@@ -3158,7 +3159,7 @@ int enet_peer_send(ENetPeer* peer, uint8_t channelID, ENetPacket* packet) {
 	fragmentLength = peer->mtu - sizeof(ENetProtocolHeader) - sizeof(ENetProtocolSendFragment);
 
 	if (peer->host->checksumCallback != NULL)
-		fragmentLength -= sizeof(uint64_t);
+		fragmentLength -= sizeof(enet_checksum);
 
 	if (packet->dataLength > fragmentLength) {
 		uint32_t fragmentCount = (packet->dataLength + fragmentLength - 1) / fragmentLength, fragmentNumber, fragmentOffset;