Sfoglia il codice sorgente

added per-peer configurable ping interval and timeouts
1.3.4 release prep

lsalzman 13 anni fa
parent
commit
ea8faf3579
9 ha cambiato i file con 68 aggiunte e 9 eliminazioni
  1. 5 0
      ChangeLog
  2. 1 1
      Makefile.am
  3. 1 1
      configure.ac
  4. 4 0
      docs/install.dox
  5. 1 1
      docs/license.dox
  6. 1 1
      docs/mainpage.dox
  7. 7 1
      include/enet/enet.h
  8. 44 0
      peer.c
  9. 4 4
      protocol.c

+ 5 - 0
ChangeLog

@@ -1,3 +1,8 @@
+ENet 1.3.4 (May 29, 2012):
+* added enet_peer_ping_interval() for configuring per-peer ping intervals
+* added enet_peer_timeout() for configuring per-peer timeouts
+* added protocol packet size limits
+
 ENet 1.3.3 (June 28, 2011):
 ENet 1.3.3 (June 28, 2011):
 
 
 * fixed bug with simultaneous disconnects not dispatching events
 * fixed bug with simultaneous disconnects not dispatching events

+ 1 - 1
Makefile.am

@@ -16,7 +16,7 @@ enetinclude_HEADERS = \
 lib_LTLIBRARIES = libenet.la
 lib_LTLIBRARIES = libenet.la
 libenet_la_SOURCES = callbacks.c compress.c host.c list.c packet.c peer.c protocol.c unix.c win32.c
 libenet_la_SOURCES = callbacks.c compress.c host.c list.c packet.c peer.c protocol.c unix.c win32.c
 # see info '(libtool) Updating version info' before making a release
 # see info '(libtool) Updating version info' before making a release
-libenet_la_LDFLAGS = $(AM_LDFLAGS) -version-info 1:3:0
+libenet_la_LDFLAGS = $(AM_LDFLAGS) -version-info 2:0:0
 INCLUDES = -I$(top_srcdir)/include
 INCLUDES = -I$(top_srcdir)/include
 
 
 ACLOCAL_AMFLAGS = -Im4
 ACLOCAL_AMFLAGS = -Im4

+ 1 - 1
configure.ac

@@ -1,4 +1,4 @@
-AC_INIT([libenet], [1.3.3])
+AC_INIT([libenet], [1.3.4])
 AC_CONFIG_SRCDIR([include/enet/enet.h])
 AC_CONFIG_SRCDIR([include/enet/enet.h])
 AM_INIT_AUTOMAKE([foreign])
 AM_INIT_AUTOMAKE([foreign])
 
 

+ 4 - 0
docs/install.dox

@@ -27,6 +27,10 @@ is linked in.
 
 
 @section Windows Microsoft Windows
 @section Windows Microsoft Windows
 
 
+You may simply use the included "enet.lib" or "enet64.lib" static libraries. 
+However, if you wish to build the library yourself, then the following
+instructions apply:
+
 There is an included MSVC 6 project (enet.dsp) which you may use to
 There is an included MSVC 6 project (enet.dsp) which you may use to
 build a suitable library file. Alternatively, you may simply drag all 
 build a suitable library file. Alternatively, you may simply drag all 
 the ENet source files into your main project.
 the ENet source files into your main project.

+ 1 - 1
docs/license.dox

@@ -1,7 +1,7 @@
 /**
 /**
  @page License License
  @page License License
  
  
-Copyright (c) 2002-2011 Lee Salzman
+Copyright (c) 2002-2012 Lee Salzman
 
 
 Permission is hereby granted, free of charge, to any person obtaining
 Permission is hereby granted, free of charge, to any person obtaining
 a copy of this software and associated documentation files (the
 a copy of this software and associated documentation files (the

+ 1 - 1
docs/mainpage.dox

@@ -36,7 +36,7 @@ portable, and easily embeddable.
 You can retrieve the source to ENet by downloading it in either .tar.gz form
 You can retrieve the source to ENet by downloading it in either .tar.gz form
 or accessing the github distribution directly.
 or accessing the github distribution directly.
 
 
-The most recent stable release (1.3.3) can be downloaded <a href="http://enet.bespin.org/download/enet-1.3.3.tar.gz">here</a>. 
+The most recent stable release (1.3.4) can be downloaded <a href="http://enet.bespin.org/download/enet-1.3.4.tar.gz">here</a>. 
 The last release that is protocol compatible with the 1.2 series or earlier (1.2.5) can be downloaded <a href="http://enet.bespin.org/download/enet-1.2.5.tar.gz">here</a> 
 The last release that is protocol compatible with the 1.2 series or earlier (1.2.5) can be downloaded <a href="http://enet.bespin.org/download/enet-1.2.5.tar.gz">here</a> 
 
 
 You can find the most recent ENet source at <a href="https://github.com/lsalzman/enet">the github repository</a>.
 You can find the most recent ENet source at <a href="https://github.com/lsalzman/enet">the github repository</a>.

+ 7 - 1
include/enet/enet.h

@@ -25,7 +25,7 @@ extern "C"
 
 
 #define ENET_VERSION_MAJOR 1
 #define ENET_VERSION_MAJOR 1
 #define ENET_VERSION_MINOR 3
 #define ENET_VERSION_MINOR 3
-#define ENET_VERSION_PATCH 3
+#define ENET_VERSION_PATCH 4
 #define ENET_VERSION_CREATE(major, minor, patch) (((major)<<16) | ((minor)<<8) | (patch))
 #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)
 #define ENET_VERSION ENET_VERSION_CREATE(ENET_VERSION_MAJOR, ENET_VERSION_MINOR, ENET_VERSION_PATCH)
 
 
@@ -269,6 +269,10 @@ typedef struct _ENetPeer
    enet_uint32   packetThrottleAcceleration;
    enet_uint32   packetThrottleAcceleration;
    enet_uint32   packetThrottleDeceleration;
    enet_uint32   packetThrottleDeceleration;
    enet_uint32   packetThrottleInterval;
    enet_uint32   packetThrottleInterval;
+   enet_uint32   pingInterval;
+   enet_uint32   timeoutLimit;
+   enet_uint32   timeoutMinimum;
+   enet_uint32   timeoutMaximum;
    enet_uint32   lastRoundTripTime;
    enet_uint32   lastRoundTripTime;
    enet_uint32   lowestRoundTripTime;
    enet_uint32   lowestRoundTripTime;
    enet_uint32   lastRoundTripTimeVariance;
    enet_uint32   lastRoundTripTimeVariance;
@@ -517,6 +521,8 @@ extern   void       enet_host_bandwidth_throttle (ENetHost *);
 ENET_API int                 enet_peer_send (ENetPeer *, enet_uint8, ENetPacket *);
 ENET_API int                 enet_peer_send (ENetPeer *, enet_uint8, ENetPacket *);
 ENET_API ENetPacket *        enet_peer_receive (ENetPeer *, enet_uint8 * channelID);
 ENET_API ENetPacket *        enet_peer_receive (ENetPeer *, enet_uint8 * channelID);
 ENET_API void                enet_peer_ping (ENetPeer *);
 ENET_API void                enet_peer_ping (ENetPeer *);
+ENET_API void                enet_peer_ping_interval (ENetPeer *, enet_uint32);
+ENET_API void                enet_peer_timeout (ENetPeer *, enet_uint32, enet_uint32, enet_uint32);
 ENET_API void                enet_peer_reset (ENetPeer *);
 ENET_API void                enet_peer_reset (ENetPeer *);
 ENET_API void                enet_peer_disconnect (ENetPeer *, enet_uint32);
 ENET_API void                enet_peer_disconnect (ENetPeer *, enet_uint32);
 ENET_API void                enet_peer_disconnect_now (ENetPeer *, enet_uint32);
 ENET_API void                enet_peer_disconnect_now (ENetPeer *, enet_uint32);

+ 44 - 0
peer.c

@@ -372,6 +372,10 @@ enet_peer_reset (ENetPeer * peer)
     peer -> packetThrottleAcceleration = ENET_PEER_PACKET_THROTTLE_ACCELERATION;
     peer -> packetThrottleAcceleration = ENET_PEER_PACKET_THROTTLE_ACCELERATION;
     peer -> packetThrottleDeceleration = ENET_PEER_PACKET_THROTTLE_DECELERATION;
     peer -> packetThrottleDeceleration = ENET_PEER_PACKET_THROTTLE_DECELERATION;
     peer -> packetThrottleInterval = ENET_PEER_PACKET_THROTTLE_INTERVAL;
     peer -> packetThrottleInterval = ENET_PEER_PACKET_THROTTLE_INTERVAL;
+    peer -> pingInterval = ENET_PEER_PING_INTERVAL;
+    peer -> timeoutLimit = ENET_PEER_TIMEOUT_LIMIT;
+    peer -> timeoutMinimum = ENET_PEER_TIMEOUT_MINIMUM;
+    peer -> timeoutMaximum = ENET_PEER_TIMEOUT_MAXIMUM;
     peer -> lastRoundTripTime = ENET_PEER_DEFAULT_ROUND_TRIP_TIME;
     peer -> lastRoundTripTime = ENET_PEER_DEFAULT_ROUND_TRIP_TIME;
     peer -> lowestRoundTripTime = ENET_PEER_DEFAULT_ROUND_TRIP_TIME;
     peer -> lowestRoundTripTime = ENET_PEER_DEFAULT_ROUND_TRIP_TIME;
     peer -> lastRoundTripTimeVariance = 0;
     peer -> lastRoundTripTimeVariance = 0;
@@ -412,6 +416,46 @@ enet_peer_ping (ENetPeer * peer)
     enet_peer_queue_outgoing_command (peer, & command, NULL, 0, 0);
     enet_peer_queue_outgoing_command (peer, & command, NULL, 0, 0);
 }
 }
 
 
+/** Sets the interval at which pings will be sent to a peer. 
+    
+    Pings are used both to monitor the liveness of the connection and also to dynamically
+    adjust the throttle during periods of low traffic so that the throttle has reasonable
+    responsiveness during traffic spikes.
+
+    @param peer the peer to adjust
+    @param pingInterval the interval at which to send pings; defaults to ENET_PEER_PING_INTERVAL if 0
+*/
+void
+enet_peer_ping_interval (ENetPeer * peer, enet_uint32 pingInterval)
+{
+    peer -> pingInterval = pingInterval ? pingInterval : ENET_PEER_PING_INTERVAL;
+}
+
+/** Sets the timeout parameters for a peer.
+
+    The timeout parameter control how and when a peer will timeout from a failure to acknowledge
+    reliable traffic. Timeout values use an exponential backoff mechanism, where if a reliable
+    packet is not acknowledge within some multiple of the average RTT plus a variance tolerance, 
+    the timeout will be doubled until it reaches a set limit. If the timeout is thus at this
+    limit and reliable packets have been sent but not acknowledged within a certain minimum time 
+    period, the peer will be disconnected. Alternatively, if reliable packets have been sent
+    but not acknowledged for a certain maximum time period, the peer will be disconnected regardless
+    of the current timeout limit value.
+    
+    @param peer the peer to adjust
+    @param timeoutLimit the timeout limit; defaults to ENET_PEER_TIMEOUT_LIMIT if 0
+    @param timeoutMinimum the timeout minimum; defaults to ENET_PEER_TIMEOUT_MINIMUM if 0
+    @param timeoutMaximum the timeout maximum; defaults to ENET_PEER_TIMEOUT_MAXIMUM if 0
+*/
+
+void
+enet_peer_timeout (ENetPeer * peer, enet_uint32 timeoutLimit, enet_uint32 timeoutMinimum, enet_uint32 timeoutMaximum)
+{
+    peer -> timeoutLimit = timeoutLimit ? timeoutLimit : ENET_PEER_TIMEOUT_LIMIT;
+    peer -> timeoutMinimum = timeoutMinimum ? timeoutMinimum : ENET_PEER_TIMEOUT_MINIMUM;
+    peer -> timeoutMaximum = timeoutMaximum ? timeoutMaximum : ENET_PEER_TIMEOUT_MAXIMUM;
+}
+
 /** Force an immediate disconnection from a peer.
 /** Force an immediate disconnection from a peer.
     @param peer peer to disconnect
     @param peer peer to disconnect
     @param data data describing the disconnection
     @param data data describing the disconnection

+ 4 - 4
protocol.c

@@ -1375,9 +1375,9 @@ enet_protocol_check_timeouts (ENetHost * host, ENetPeer * peer, ENetEvent * even
          peer -> earliestTimeout = outgoingCommand -> sentTime;
          peer -> earliestTimeout = outgoingCommand -> sentTime;
 
 
        if (peer -> earliestTimeout != 0 &&
        if (peer -> earliestTimeout != 0 &&
-             (ENET_TIME_DIFFERENCE (host -> serviceTime, peer -> earliestTimeout) >= ENET_PEER_TIMEOUT_MAXIMUM ||
+             (ENET_TIME_DIFFERENCE (host -> serviceTime, peer -> earliestTimeout) >= peer -> timeoutMaximum ||
                (outgoingCommand -> roundTripTimeout >= outgoingCommand -> roundTripTimeoutLimit &&
                (outgoingCommand -> roundTripTimeout >= outgoingCommand -> roundTripTimeoutLimit &&
-                 ENET_TIME_DIFFERENCE (host -> serviceTime, peer -> earliestTimeout) >= ENET_PEER_TIMEOUT_MINIMUM)))
+                 ENET_TIME_DIFFERENCE (host -> serviceTime, peer -> earliestTimeout) >= peer -> timeoutMinimum)))
        {
        {
           enet_protocol_notify_disconnect (host, peer, event);
           enet_protocol_notify_disconnect (host, peer, event);
 
 
@@ -1486,7 +1486,7 @@ enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer)
        if (outgoingCommand -> roundTripTimeout == 0)
        if (outgoingCommand -> roundTripTimeout == 0)
        {
        {
           outgoingCommand -> roundTripTimeout = peer -> roundTripTime + 4 * peer -> roundTripTimeVariance;
           outgoingCommand -> roundTripTimeout = peer -> roundTripTime + 4 * peer -> roundTripTimeVariance;
-          outgoingCommand -> roundTripTimeoutLimit = ENET_PEER_TIMEOUT_LIMIT * outgoingCommand -> roundTripTimeout;
+          outgoingCommand -> roundTripTimeoutLimit = peer -> timeoutLimit * outgoingCommand -> roundTripTimeout;
        }
        }
 
 
        if (enet_list_empty (& peer -> sentReliableCommands))
        if (enet_list_empty (& peer -> sentReliableCommands))
@@ -1572,7 +1572,7 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch
         if ((enet_list_empty (& currentPeer -> outgoingReliableCommands) ||
         if ((enet_list_empty (& currentPeer -> outgoingReliableCommands) ||
               enet_protocol_send_reliable_outgoing_commands (host, currentPeer)) &&
               enet_protocol_send_reliable_outgoing_commands (host, currentPeer)) &&
             enet_list_empty (& currentPeer -> sentReliableCommands) &&
             enet_list_empty (& currentPeer -> sentReliableCommands) &&
-            ENET_TIME_DIFFERENCE (host -> serviceTime, currentPeer -> lastReceiveTime) >= ENET_PEER_PING_INTERVAL &&
+            ENET_TIME_DIFFERENCE (host -> serviceTime, currentPeer -> lastReceiveTime) >= currentPeer -> pingInterval &&
             currentPeer -> mtu - host -> packetSize >= sizeof (ENetProtocolPing))
             currentPeer -> mtu - host -> packetSize >= sizeof (ENetProtocolPing))
         { 
         { 
             enet_peer_ping (currentPeer);
             enet_peer_ping (currentPeer);