summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoreihrul <eihrul>2010-05-20 16:55:27 +0000
committereihrul <eihrul>2010-05-20 16:55:27 +0000
commite49aaf7a6fe63937e56f2efaebad3f37574fd93f (patch)
tree28e11eb3d8c633f81fa81f1019131b898c21b995
parent72525fbca19d4a643ae1e0547947d4d6fa32f4b4 (diff)
downloadenet-e49aaf7a6fe63937e56f2efaebad3f37574fd93f.tar.gz
enet-e49aaf7a6fe63937e56f2efaebad3f37574fd93f.zip
checksum is now a run-time option
-rw-r--r--ChangeLog4
-rw-r--r--configure.ac11
-rw-r--r--host.c1
-rw-r--r--include/enet/enet.h57
-rw-r--r--protocol.c21
5 files changed, 44 insertions, 50 deletions
diff --git a/ChangeLog b/ChangeLog
index 1117b2f..16524b5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
-ENet 1.2.2 (May 13, 2010):
+ENet 1.2.2 (May 20, 2010):
+* checksum functionality is now enabled by setting a checksum callback
+inside ENetHost instead of compile time option
* added totalSentData, totalSentPackets, totalReceivedData, and
totalReceivedPackets counters inside ENetHost for getting usage
statistics
diff --git a/configure.ac b/configure.ac
index c55c9fe..06a7526 100644
--- a/configure.ac
+++ b/configure.ac
@@ -24,17 +24,6 @@ AC_CHECK_TYPE(socklen_t, [AC_DEFINE(HAS_SOCKLEN_T)], ,
AC_EGREP_HEADER(MSG_MAXIOVLEN, /usr/include/sys/socket.h, AC_DEFINE(ENET_BUFFER_MAXIMUM, [MSG_MAXIOVLEN]))
AC_EGREP_HEADER(MSG_MAXIOVLEN, socket.h, AC_DEFINE(ENET_BUFFER_MAXIMUM, [MSG_MAXIOVLEN]))
-AC_MSG_CHECKING(whether to use CRC32)
-AC_ARG_ENABLE(crc32,
- [ --enable-crc32 enable CRC32 packet verification ],
- [if test "$enableval" = yes; then
- AC_MSG_RESULT(yes)
- AC_DEFINE(USE_CRC32)
- else
- AC_MSG_RESULT(no)
- fi],
- [AC_MSG_RESULT(no)])
-
AC_CONFIG_FILES([Makefile
libenet.pc])
AC_OUTPUT
diff --git a/host.c b/host.c
index 67accd9..447c7ac 100644
--- a/host.c
+++ b/host.c
@@ -75,6 +75,7 @@ enet_host_create (const ENetAddress * address, size_t peerCount, enet_uint32 inc
host -> peerCount = peerCount;
host -> commandCount = 0;
host -> bufferCount = 0;
+ host -> checksum = NULL;
host -> receivedAddress.host = ENET_HOST_ANY;
host -> receivedAddress.port = 0;
host -> receivedDataLength = 0;
diff --git a/include/enet/enet.h b/include/enet/enet.h
index 7d4ac33..2aa61f1 100644
--- a/include/enet/enet.h
+++ b/include/enet/enet.h
@@ -284,6 +284,9 @@ typedef struct _ENetPeer
enet_uint32 disconnectData;
} ENetPeer;
+/** Callback that computes the checksum of the data held in buffers [0..bufferCount-1] */
+typedef enet_uint32 (ENET_CALLBACK * ENetChecksumCallback) (const ENetBuffer * buffers, size_t bufferCount);
+
/** An ENet host for communicating with peers.
*
* No fields should be modified.
@@ -294,38 +297,40 @@ typedef struct _ENetPeer
@sa enet_host_service()
@sa enet_host_flush()
@sa enet_host_broadcast()
+ @sa enet_host_checksum()
@sa enet_host_channel_limit()
@sa enet_host_bandwidth_limit()
@sa enet_host_bandwidth_throttle()
*/
typedef struct _ENetHost
{
- ENetSocket socket;
- ENetAddress address; /**< Internet address of the host */
- enet_uint32 incomingBandwidth; /**< downstream bandwidth of the host */
- enet_uint32 outgoingBandwidth; /**< upstream bandwidth of the host */
- enet_uint32 bandwidthThrottleEpoch;
- enet_uint32 mtu;
- int recalculateBandwidthLimits;
- ENetPeer * peers; /**< array of peers allocated for this host */
- size_t peerCount; /**< number of peers allocated for this host */
- size_t channelLimit; /**< maximum number of channels allowed for connected peers */
- enet_uint32 serviceTime;
- ENetList dispatchQueue;
- int continueSending;
- size_t packetSize;
- enet_uint16 headerFlags;
- ENetProtocol commands [ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS];
- size_t commandCount;
- ENetBuffer buffers [ENET_BUFFER_MAXIMUM];
- size_t bufferCount;
- ENetAddress receivedAddress;
- enet_uint8 receivedData [ENET_PROTOCOL_MAXIMUM_MTU];
- size_t receivedDataLength;
- enet_uint32 totalSentData; /**< total data sent, user should reset to 0 as needed to prevent overflow */
- enet_uint32 totalSentPackets; /**< total UDP packets sent, user should reset to 0 as needed to prevent overflow */
- enet_uint32 totalReceivedData; /**< total data received, user should reset to 0 as needed to prevent overflow */
- enet_uint32 totalReceivedPackets; /**< total UDP packets received, user should reset to 0 as needed to prevent overflow */
+ ENetSocket socket;
+ ENetAddress address; /**< Internet address of the host */
+ enet_uint32 incomingBandwidth; /**< downstream bandwidth of the host */
+ enet_uint32 outgoingBandwidth; /**< upstream bandwidth of the host */
+ enet_uint32 bandwidthThrottleEpoch;
+ enet_uint32 mtu;
+ int recalculateBandwidthLimits;
+ ENetPeer * peers; /**< array of peers allocated for this host */
+ size_t peerCount; /**< number of peers allocated for this host */
+ size_t channelLimit; /**< maximum number of channels allowed for connected peers */
+ enet_uint32 serviceTime;
+ ENetList dispatchQueue;
+ int continueSending;
+ size_t packetSize;
+ enet_uint16 headerFlags;
+ ENetProtocol commands [ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS];
+ size_t commandCount;
+ ENetBuffer buffers [ENET_BUFFER_MAXIMUM];
+ size_t bufferCount;
+ ENetChecksumCallback checksum;
+ ENetAddress receivedAddress;
+ enet_uint8 receivedData [ENET_PROTOCOL_MAXIMUM_MTU];
+ size_t receivedDataLength;
+ enet_uint32 totalSentData; /**< total data sent, user should reset to 0 as needed to prevent overflow */
+ enet_uint32 totalSentPackets; /**< total UDP packets sent, user should reset to 0 as needed to prevent overflow */
+ enet_uint32 totalReceivedData; /**< total data received, user should reset to 0 as needed to prevent overflow */
+ enet_uint32 totalReceivedPackets; /**< total UDP packets received, user should reset to 0 as needed to prevent overflow */
} ENetHost;
/**
diff --git a/protocol.c b/protocol.c
index 21460b1..4150a2a 100644
--- a/protocol.c
+++ b/protocol.c
@@ -245,9 +245,9 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
ENetPeer * currentPeer;
ENetProtocol verifyCommand;
-#ifdef USE_CRC32
+ if (host -> checksum != NULL)
{
- enet_uint32 crc = header -> checksum;
+ enet_uint32 checksum = header -> checksum;
ENetBuffer buffer;
command -> header.reliableSequenceNumber = ENET_HOST_TO_NET_16 (command -> header.reliableSequenceNumber);
@@ -257,12 +257,11 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
buffer.data = host -> receivedData;
buffer.dataLength = host -> receivedDataLength;
- if (enet_crc32 (& buffer, 1) != crc)
+ if (host -> checksum (& buffer, 1) != checksum)
return NULL;
command -> header.reliableSequenceNumber = ENET_NET_TO_HOST_16 (command -> header.reliableSequenceNumber);
}
-#endif
channelCount = ENET_NET_TO_HOST_32 (command -> connect.channelCount);
@@ -834,9 +833,9 @@ enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event)
peer -> address.host != ENET_HOST_BROADCAST))
return 0;
-#ifdef USE_CRC32
+ if (host -> checksum != NULL)
{
- enet_uint32 crc = header -> checksum;
+ enet_uint32 checksum = header -> checksum;
ENetBuffer buffer;
header -> checksum = peer -> sessionID;
@@ -844,13 +843,12 @@ enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event)
buffer.data = host -> receivedData;
buffer.dataLength = host -> receivedDataLength;
- if (enet_crc32 (& buffer, 1) != crc)
+ if (host -> checksum (& buffer, 1) != checksum)
return 0;
}
-#else
+ else
if (header -> checksum != peer -> sessionID)
return 0;
-#endif
peer -> address.host = host -> receivedAddress.host;
peer -> address.port = host -> receivedAddress.port;
@@ -1415,9 +1413,8 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch
else
host -> buffers -> dataLength = (size_t) & ((ENetProtocolHeader *) 0) -> sentTime;
-#ifdef USE_CRC32
- header.checksum = enet_crc32 (host -> buffers, host -> bufferCount);
-#endif
+ if (host -> checksum != NULL)
+ header.checksum = host -> checksum (host -> buffers, host -> bufferCount);
currentPeer -> lastSendTime = host -> serviceTime;