checksum is now a run-time option

This commit is contained in:
eihrul 2010-05-20 16:55:27 +00:00
parent 72525fbca1
commit e49aaf7a6f
5 changed files with 44 additions and 50 deletions

View file

@ -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

View file

@ -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

1
host.c
View file

@ -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;

View file

@ -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,6 +297,7 @@ 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()
@ -319,6 +323,7 @@ typedef struct _ENetHost
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;

View file

@ -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;