diff options
author | eihrul <eihrul> | 2010-06-09 21:16:23 +0000 |
---|---|---|
committer | eihrul <eihrul> | 2010-06-09 21:16:23 +0000 |
commit | 572636062e61ad66cc2b4d232394d9de0645baf2 (patch) | |
tree | 1307f92de016aaf9fc32179eff193a820d49c2b6 /include | |
parent | 2d985dba913f815302b8fb86c9ff0956f3c2f1a3 (diff) | |
download | enet-572636062e61ad66cc2b4d232394d9de0645baf2.tar.gz enet-572636062e61ad66cc2b4d232394d9de0645baf2.zip |
1.3.0 import
Diffstat (limited to 'include')
-rw-r--r-- | include/enet/callbacks.h | 2 | ||||
-rw-r--r-- | include/enet/enet.h | 51 | ||||
-rw-r--r-- | include/enet/protocol.h | 23 |
3 files changed, 55 insertions, 21 deletions
diff --git a/include/enet/callbacks.h b/include/enet/callbacks.h index b488ac7..340a4a9 100644 --- a/include/enet/callbacks.h +++ b/include/enet/callbacks.h @@ -11,7 +11,6 @@ typedef struct _ENetCallbacks { void * (ENET_CALLBACK * malloc) (size_t size); void (ENET_CALLBACK * free) (void * memory); - int (ENET_CALLBACK * rand) (void); void (ENET_CALLBACK * no_memory) (void); } ENetCallbacks; @@ -21,7 +20,6 @@ typedef struct _ENetCallbacks */ extern void * enet_malloc (size_t); extern void enet_free (void *); -extern int enet_rand (void); /** @} */ diff --git a/include/enet/enet.h b/include/enet/enet.h index 17a34e7..425e753 100644 --- a/include/enet/enet.h +++ b/include/enet/enet.h @@ -24,8 +24,8 @@ extern "C" #include "enet/callbacks.h" #define ENET_VERSION_MAJOR 1 -#define ENET_VERSION_MINOR 2 -#define ENET_VERSION_PATCH 2 +#define ENET_VERSION_MINOR 3 +#define ENET_VERSION_PATCH 0 #define ENET_VERSION_CREATE(major, minor, patch) (((major)<<16) | ((minor)<<8) | (patch)) #define ENET_VERSION ENET_VERSION_CREATE(ENET_VERSION_MAJOR, ENET_VERSION_MINOR, ENET_VERSION_PATCH) @@ -233,7 +233,9 @@ typedef struct _ENetPeer struct _ENetHost * host; enet_uint16 outgoingPeerID; enet_uint16 incomingPeerID; - enet_uint32 sessionID; + enet_uint32 connectID; + enet_uint8 outgoingSessionID; + enet_uint8 incomingSessionID; ENetAddress address; /**< Internet address of the peer */ void * data; /**< Application private data, may be freely modified */ ENetPeerState state; @@ -267,7 +269,7 @@ typedef struct _ENetPeer enet_uint32 highestRoundTripTimeVariance; enet_uint32 roundTripTime; /**< mean round trip time (RTT), in milliseconds, between sending a reliable packet and receiving its acknowledgement */ enet_uint32 roundTripTimeVariance; - enet_uint16 mtu; + enet_uint32 mtu; enet_uint32 windowSize; enet_uint32 reliableDataInTransit; enet_uint16 outgoingReliableSequenceNumber; @@ -281,15 +283,29 @@ typedef struct _ENetPeer enet_uint16 incomingUnsequencedGroup; enet_uint16 outgoingUnsequencedGroup; enet_uint32 unsequencedWindow [ENET_PEER_UNSEQUENCED_WINDOW_SIZE / 32]; - enet_uint32 disconnectData; + enet_uint32 eventData; } ENetPeer; +/** An ENet packet compressor for compressing UDP packets before socket sends or receives. + */ +typedef struct _ENetCompressor +{ + /**< Context data for the compressor. Must be non-NULL. */ + void * context; + /**< Compresses from inBuffers[0..inBufferCount-1], containing inLimit bytes, to outData, outputting at most outLimit bytes. Should return 0 on failure. */ + size_t (ENET_CALLBACK * compress) (void * context, const ENetBuffer * inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 * outData, size_t outLimit); + /**< Decompresses from inData, containing inLimit bytes, to outData, outputting at most outLimit bytes. Should return 0 on failure. */ + size_t (ENET_CALLBACK * decompress) (void * context, const enet_uint8 * inData, size_t inLimit, enet_uint8 * outData, size_t outLimit); + /**< Destroys the context when compression is disabled or the host is destroyed. May be NULL. */ + void (ENET_CALLBACK * destroy) (void * context); +} ENetCompressor; + /** 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. + * No fields should be modified unless otherwise stated. @sa enet_host_create() @sa enet_host_destroy() @@ -297,7 +313,8 @@ typedef enet_uint32 (ENET_CALLBACK * ENetChecksumCallback) (const ENetBuffer * b @sa enet_host_service() @sa enet_host_flush() @sa enet_host_broadcast() - @sa enet_host_checksum() + @sa enet_host_compress() + @sa enet_host_compress_with_range_coder() @sa enet_host_channel_limit() @sa enet_host_bandwidth_limit() @sa enet_host_bandwidth_throttle() @@ -310,6 +327,7 @@ typedef struct _ENetHost enet_uint32 outgoingBandwidth; /**< upstream bandwidth of the host */ enet_uint32 bandwidthThrottleEpoch; enet_uint32 mtu; + enet_uint32 randomSeed; int recalculateBandwidthLimits; ENetPeer * peers; /**< array of peers allocated for this host */ size_t peerCount; /**< number of peers allocated for this host */ @@ -323,9 +341,11 @@ typedef struct _ENetHost size_t commandCount; ENetBuffer buffers [ENET_BUFFER_MAXIMUM]; size_t bufferCount; - ENetChecksumCallback checksum; + ENetChecksumCallback checksum; /**< callback the user can set to enable packet checksums for this host */ + ENetCompressor compressor; + enet_uint8 packetData [2][ENET_PROTOCOL_MAXIMUM_MTU]; ENetAddress receivedAddress; - enet_uint8 receivedData [ENET_PROTOCOL_MAXIMUM_MTU]; + enet_uint8 * receivedData; 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 */ @@ -475,13 +495,15 @@ ENET_API void enet_packet_destroy (ENetPacket *); ENET_API int enet_packet_resize (ENetPacket *, size_t); extern enet_uint32 enet_crc32 (const ENetBuffer *, size_t); -ENET_API ENetHost * enet_host_create (const ENetAddress *, size_t, enet_uint32, enet_uint32); +ENET_API ENetHost * enet_host_create (const ENetAddress *, size_t, size_t, enet_uint32, enet_uint32); ENET_API void enet_host_destroy (ENetHost *); -ENET_API ENetPeer * enet_host_connect (ENetHost *, const ENetAddress *, size_t); +ENET_API ENetPeer * enet_host_connect (ENetHost *, const ENetAddress *, size_t, enet_uint32); ENET_API int enet_host_check_events (ENetHost *, ENetEvent *); ENET_API int enet_host_service (ENetHost *, ENetEvent *, enet_uint32); ENET_API void enet_host_flush (ENetHost *); ENET_API void enet_host_broadcast (ENetHost *, enet_uint8, ENetPacket *); +ENET_API void enet_host_compress (ENetHost *, const ENetCompressor *); +ENET_API int enet_host_compress_with_range_coder (ENetHost * host); 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 *); @@ -503,6 +525,11 @@ extern ENetAcknowledgement * enet_peer_queue_acknowledgement (ENetPeer *, const extern void enet_peer_dispatch_incoming_unreliable_commands (ENetPeer *, ENetChannel *); extern void enet_peer_dispatch_incoming_reliable_commands (ENetPeer *, ENetChannel *); +ENET_API void * enet_range_coder_create (void); +ENET_API void enet_range_coder_destroy (void *); +ENET_API size_t enet_range_coder_compress (void *, const ENetBuffer *, size_t, size_t, enet_uint8 *, size_t); +ENET_API size_t enet_range_coder_decompress (void *, const enet_uint8 *, size_t, enet_uint8 *, size_t); + extern size_t enet_protocol_command_size (enet_uint8); #ifdef __cplusplus diff --git a/include/enet/protocol.h b/include/enet/protocol.h index 4e61cad..19f7e45 100644 --- a/include/enet/protocol.h +++ b/include/enet/protocol.h @@ -16,7 +16,7 @@ enum ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE = 32768, ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT = 1, ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255, - ENET_PROTOCOL_MAXIMUM_PEER_ID = 0x7FFF + ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xFFF }; typedef enum _ENetProtocolCommand @@ -43,8 +43,12 @@ typedef enum _ENetProtocolFlag ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE = (1 << 7), ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED = (1 << 6), - ENET_PROTOCOL_HEADER_FLAG_SENT_TIME = (1 << 15), - ENET_PROTOCOL_HEADER_FLAG_MASK = 0x8000 + ENET_PROTOCOL_HEADER_FLAG_COMPRESSED = (1 << 14), + ENET_PROTOCOL_HEADER_FLAG_SENT_TIME = (1 << 15), + ENET_PROTOCOL_HEADER_FLAG_MASK = ENET_PROTOCOL_HEADER_FLAG_COMPRESSED | ENET_PROTOCOL_HEADER_FLAG_SENT_TIME, + + ENET_PROTOCOL_HEADER_SESSION_MASK = (3 << 12), + ENET_PROTOCOL_HEADER_SESSION_SHIFT = 12 } ENetProtocolFlag; #ifdef _MSC_VER_ @@ -58,7 +62,6 @@ typedef enum _ENetProtocolFlag typedef struct _ENetProtocolHeader { - enet_uint32 checksum; enet_uint16 peerID; enet_uint16 sentTime; } ENET_PACKED ENetProtocolHeader; @@ -81,7 +84,9 @@ typedef struct _ENetProtocolConnect { ENetProtocolCommandHeader header; enet_uint16 outgoingPeerID; - enet_uint16 mtu; + enet_uint8 incomingSessionID; + enet_uint8 outgoingSessionID; + enet_uint32 mtu; enet_uint32 windowSize; enet_uint32 channelCount; enet_uint32 incomingBandwidth; @@ -89,14 +94,17 @@ typedef struct _ENetProtocolConnect enet_uint32 packetThrottleInterval; enet_uint32 packetThrottleAcceleration; enet_uint32 packetThrottleDeceleration; - enet_uint32 sessionID; + enet_uint32 connectID; + enet_uint32 data; } ENET_PACKED ENetProtocolConnect; typedef struct _ENetProtocolVerifyConnect { ENetProtocolCommandHeader header; enet_uint16 outgoingPeerID; - enet_uint16 mtu; + enet_uint8 incomingSessionID; + enet_uint8 outgoingSessionID; + enet_uint32 mtu; enet_uint32 windowSize; enet_uint32 channelCount; enet_uint32 incomingBandwidth; @@ -104,6 +112,7 @@ typedef struct _ENetProtocolVerifyConnect enet_uint32 packetThrottleInterval; enet_uint32 packetThrottleAcceleration; enet_uint32 packetThrottleDeceleration; + enet_uint32 connectID; } ENET_PACKED ENetProtocolVerifyConnect; typedef struct _ENetProtocolBandwidthLimit |