aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--host.c2
-rw-r--r--include/enet/enet.h5
-rw-r--r--include/enet/protocol.h1
-rw-r--r--peer.c11
-rw-r--r--protocol.c29
6 files changed, 37 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 5277b2c..3383449 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+* added maximumPacketSize and maximumWaitingData fields to ENetHost to limit the amount of
+data waiting to be delivered on a peer (beware that the default maximumPacketSize is
+32MB and should be set higher if desired as should maximumWaitingData)
+
ENet 1.3.11 (December 26, 2013):
* allow an ENetHost to connect to itself
diff --git a/host.c b/host.c
index fc57f74..3be6c09 100644
--- a/host.c
+++ b/host.c
@@ -100,6 +100,8 @@ enet_host_create (const ENetAddress * address, size_t peerCount, size_t channelL
host -> connectedPeers = 0;
host -> bandwidthLimitedPeers = 0;
host -> duplicatePeers = ENET_PROTOCOL_MAXIMUM_PEER_ID;
+ host -> maximumPacketSize = ENET_HOST_DEFAULT_MAXIMUM_PACKET_SIZE;
+ host -> maximumWaitingData = ENET_HOST_DEFAULT_MAXIMUM_WAITING_DATA;
host -> compressor.context = NULL;
host -> compressor.compress = NULL;
diff --git a/include/enet/enet.h b/include/enet/enet.h
index 948f44e..a9b6dac 100644
--- a/include/enet/enet.h
+++ b/include/enet/enet.h
@@ -209,6 +209,8 @@ enum
ENET_HOST_SEND_BUFFER_SIZE = 256 * 1024,
ENET_HOST_BANDWIDTH_THROTTLE_INTERVAL = 1000,
ENET_HOST_DEFAULT_MTU = 1400,
+ ENET_HOST_DEFAULT_MAXIMUM_PACKET_SIZE = 32 * 1024 * 1024,
+ ENET_HOST_DEFAULT_MAXIMUM_WAITING_DATA = 32 * 1024 * 1024,
ENET_PEER_DEFAULT_ROUND_TRIP_TIME = 500,
ENET_PEER_DEFAULT_PACKET_THROTTLE = 32,
@@ -310,6 +312,7 @@ typedef struct _ENetPeer
enet_uint16 outgoingUnsequencedGroup;
enet_uint32 unsequencedWindow [ENET_PEER_UNSEQUENCED_WINDOW_SIZE / 32];
enet_uint32 eventData;
+ size_t totalWaitingData;
} ENetPeer;
/** An ENet packet compressor for compressing UDP packets before socket sends or receives.
@@ -384,6 +387,8 @@ typedef struct _ENetHost
size_t connectedPeers;
size_t bandwidthLimitedPeers;
size_t duplicatePeers; /**< optional number of allowed peers from duplicate IPs, defaults to ENET_PROTOCOL_MAXIMUM_PEER_ID */
+ size_t maximumPacketSize; /**< the maximum allowable packet size that may be sent or received on a peer */
+ size_t maximumWaitingData; /**< the maximum aggregate amount of buffer space a peer may use waiting for packets to be delivered */
} ENetHost;
/**
diff --git a/include/enet/protocol.h b/include/enet/protocol.h
index a7c73c6..f8c73d8 100644
--- a/include/enet/protocol.h
+++ b/include/enet/protocol.h
@@ -17,7 +17,6 @@ enum
ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT = 1,
ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255,
ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xFFF,
- ENET_PROTOCOL_MAXIMUM_PACKET_SIZE = 1024 * 1024 * 1024,
ENET_PROTOCOL_MAXIMUM_FRAGMENT_COUNT = 1024 * 1024
};
diff --git a/peer.c b/peer.c
index 2084b9b..7c6b197 100644
--- a/peer.c
+++ b/peer.c
@@ -105,7 +105,7 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
if (peer -> state != ENET_PEER_STATE_CONNECTED ||
channelID >= peer -> channelCount ||
- packet -> dataLength > ENET_PROTOCOL_MAXIMUM_PACKET_SIZE)
+ packet -> dataLength > peer -> host -> maximumPacketSize)
return -1;
fragmentLength = peer -> mtu - sizeof (ENetProtocolHeader) - sizeof (ENetProtocolSendFragment);
@@ -241,6 +241,8 @@ enet_peer_receive (ENetPeer * peer, enet_uint8 * channelID)
enet_free (incomingCommand);
+ peer -> totalWaitingData -= packet -> dataLength;
+
return packet;
}
@@ -415,6 +417,7 @@ enet_peer_reset (ENetPeer * peer)
peer -> incomingUnsequencedGroup = 0;
peer -> outgoingUnsequencedGroup = 0;
peer -> eventData = 0;
+ peer -> totalWaitingData = 0;
memset (peer -> unsequencedWindow, 0, sizeof (peer -> unsequencedWindow));
@@ -952,7 +955,11 @@ enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol * command,
}
if (packet != NULL)
- ++ packet -> referenceCount;
+ {
+ ++ packet -> referenceCount;
+
+ peer -> totalWaitingData += packet -> dataLength;
+ }
enet_list_insert (enet_list_next (currentCommand), incomingCommand);
diff --git a/protocol.c b/protocol.c
index c56d1c8..155e6ad 100644
--- a/protocol.c
+++ b/protocol.c
@@ -428,12 +428,13 @@ enet_protocol_handle_send_reliable (ENetHost * host, ENetPeer * peer, const ENet
size_t dataLength;
if (command -> header.channelID >= peer -> channelCount ||
- (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER))
+ (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER) ||
+ peer -> totalWaitingData >= host -> maximumWaitingData)
return -1;
dataLength = ENET_NET_TO_HOST_16 (command -> sendReliable.dataLength);
* currentData += dataLength;
- if (dataLength > ENET_PROTOCOL_MAXIMUM_PACKET_SIZE ||
+ if (dataLength > host -> maximumPacketSize ||
* currentData < host -> receivedData ||
* currentData > & host -> receivedData [host -> receivedDataLength])
return -1;
@@ -456,12 +457,13 @@ enet_protocol_handle_send_unsequenced (ENetHost * host, ENetPeer * peer, const E
size_t dataLength;
if (command -> header.channelID >= peer -> channelCount ||
- (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER))
+ (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER) ||
+ peer -> totalWaitingData >= host -> maximumWaitingData)
return -1;
dataLength = ENET_NET_TO_HOST_16 (command -> sendUnsequenced.dataLength);
* currentData += dataLength;
- if (dataLength > ENET_PROTOCOL_MAXIMUM_PACKET_SIZE ||
+ if (dataLength > host -> maximumPacketSize ||
* currentData < host -> receivedData ||
* currentData > & host -> receivedData [host -> receivedDataLength])
return -1;
@@ -506,12 +508,13 @@ enet_protocol_handle_send_unreliable (ENetHost * host, ENetPeer * peer, const EN
size_t dataLength;
if (command -> header.channelID >= peer -> channelCount ||
- (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER))
+ (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER) ||
+ peer -> totalWaitingData >= host -> maximumWaitingData)
return -1;
dataLength = ENET_NET_TO_HOST_16 (command -> sendUnreliable.dataLength);
* currentData += dataLength;
- if (dataLength > ENET_PROTOCOL_MAXIMUM_PACKET_SIZE ||
+ if (dataLength > host -> maximumPacketSize ||
* currentData < host -> receivedData ||
* currentData > & host -> receivedData [host -> receivedDataLength])
return -1;
@@ -541,12 +544,13 @@ enet_protocol_handle_send_fragment (ENetHost * host, ENetPeer * peer, const ENet
ENetIncomingCommand * startCommand = NULL;
if (command -> header.channelID >= peer -> channelCount ||
- (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER))
+ (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER) ||
+ peer -> totalWaitingData >= host -> maximumWaitingData)
return -1;
fragmentLength = ENET_NET_TO_HOST_16 (command -> sendFragment.dataLength);
* currentData += fragmentLength;
- if (fragmentLength > ENET_PROTOCOL_MAXIMUM_PACKET_SIZE ||
+ if (fragmentLength > host -> maximumPacketSize ||
* currentData < host -> receivedData ||
* currentData > & host -> receivedData [host -> receivedDataLength])
return -1;
@@ -569,7 +573,7 @@ enet_protocol_handle_send_fragment (ENetHost * host, ENetPeer * peer, const ENet
if (fragmentCount > ENET_PROTOCOL_MAXIMUM_FRAGMENT_COUNT ||
fragmentNumber >= fragmentCount ||
- totalLength > ENET_PROTOCOL_MAXIMUM_PACKET_SIZE ||
+ totalLength > host -> maximumPacketSize ||
fragmentOffset >= totalLength ||
fragmentLength > totalLength - fragmentOffset)
return -1;
@@ -654,12 +658,13 @@ enet_protocol_handle_send_unreliable_fragment (ENetHost * host, ENetPeer * peer,
ENetIncomingCommand * startCommand = NULL;
if (command -> header.channelID >= peer -> channelCount ||
- (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER))
+ (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER) ||
+ peer -> totalWaitingData >= host -> maximumWaitingData)
return -1;
fragmentLength = ENET_NET_TO_HOST_16 (command -> sendFragment.dataLength);
* currentData += fragmentLength;
- if (fragmentLength > ENET_PROTOCOL_MAXIMUM_PACKET_SIZE ||
+ if (fragmentLength > host -> maximumPacketSize ||
* currentData < host -> receivedData ||
* currentData > & host -> receivedData [host -> receivedDataLength])
return -1;
@@ -688,7 +693,7 @@ enet_protocol_handle_send_unreliable_fragment (ENetHost * host, ENetPeer * peer,
if (fragmentCount > ENET_PROTOCOL_MAXIMUM_FRAGMENT_COUNT ||
fragmentNumber >= fragmentCount ||
- totalLength > ENET_PROTOCOL_MAXIMUM_PACKET_SIZE ||
+ totalLength > host -> maximumPacketSize ||
fragmentOffset >= totalLength ||
fragmentLength > totalLength - fragmentOffset)
return -1;