Development back on the trunk!
[crack-attack.git] / enet / design.txt
blob9a88dba9f57f861f5e6e5001a18b396fe77f70f9
1 * Why ENet?
3     ENet evolved specifically as a UDP networking layer for the multiplayer 
4 first person shooter Cube. Cube necessitated low latency communcation with
5 data sent out very frequently, so TCP was an unsuitable choice due to its
6 high latency and stream orientation. UDP, however, lacks many sometimes 
7 necessary features from TCP such as reliability, sequencing, unrestricted
8 packet sizes, and connection management. So UDP by itself was not suitable
9 as a network protocol either. No suitable freely available networking 
10 libraries existed at the time of ENet's creation to fill this niche.
12     UDP and TCP could have been used together in Cube to benefit somewhat
13 from both of their features, however, the resulting combinations of protocols
14 still leaves much to be desired. TCP lacks multiple streams of communication
15 without resorting to opening many sockets and complicates delineation of 
16 packets due to its buffering behavior. UDP lacks sequencing, connection 
17 management, management of bandwidth resources, and imposes limitations on
18 the size of packets. A significant investment is required to integrate these 
19 two protocols, and the end result is worse off in features and performance 
20 than the uniform protocol presented by ENet.
22     ENet thus attempts to address these issues and provide a single, uniform
23 protocol layered over UDP to the developer with the best features of UDP and 
24 TCP as well as some useful features neither provide, with a much cleaner 
25 integration than any resulting from a mixture of UDP and TCP.
27 * Connection management
29     ENet provides a simple connection interface over which to communicate
30 with a foreign host. The liveness of the connection is actively monitored
31 by pinging the foreign host at frequent intervals, and also monitors the
32 network conditions from the local host to the foreign host such as the
33 mean round trip time and packet loss in this fashion.
35 * Sequencing
36     
37     Rather than a single byte stream that complicates the delineation 
38 of packets, ENet presents connections as multiple, properly sequenced packet
39 streams that simplify the transfer of various types of data.
41     ENet provides sequencing for all packets by assigning to each sent 
42 packet a sequence number that is incremented as packets are sent. ENet 
43 guarentees that no packet with a higher sequence number will be delivered 
44 before a packet with a lower sequence number, thus ensuring packets are 
45 delivered exactly in the order they are sent. 
47     For unreliable packets, ENet will simply discard the lower sequence 
48 number packet if a packet with a higher sequence number has already been 
49 delivered. This allows the packets to be dispatched immediately as they
50 arrive, and reduce latency of unreliable packets to an absolute minimum.
51 For reliable packets, if a higher sequence number packet arrives, but the 
52 preceding packets in the sequence have not yet arrived, ENet will stall 
53 delivery of the higher sequence number packets until its predecessors
54 have arrived.
56 * Channels
58     Since ENet will stall delivery of reliable packets to ensure proper
59 sequencing, and consequently any packets of higher sequence number whether 
60 reliable or unreliable, in the event the reliable packet's predecessors 
61 have not yet arrived, this can introduce latency into the delivery of other 
62 packets which may not need to be as strictly ordered with respect to the 
63 packet that stalled their delivery.
65     To combat this latency and reduce the ordering restrictions on packets,
66 ENet provides multiple channels of communication over a given connection.
67 Each channel is independently sequenced, and so the delivery status of
68 a packet in one channel will not stall the delivery of other packets
69 in another channel.
71 * Reliability
73     ENet provides optional reliability of packet delivery by ensuring the 
74 foreign host acknowledges receipt of all reliable packets. ENet will attempt 
75 to resend the packet up to a reasonable amount of times, if no acknowledgement
76 of the packet's receipt happens within a specified timeout. Retry timeouts
77 are progressive and become more lenient with every failed attempt to allow
78 for temporary turbulence in network conditions.
80 * Fragmentation and reassembly
82     ENet will send and deliver packets regardless of size. Large packets are
83 fragmented into many smaller packets of suitable size, and reassembled on
84 the foreign host to recover the original packet for delivery. The process
85 is entirely transparent to the developer.
87 * Aggregation
89     ENet aggregates all protocol commands, including acknowledgements and
90 packet transfer, into larger protocol packets to ensure the proper utilization
91 of the connection and to limit the opportunities for packet loss that might
92 otherwise result in further delivery latency.
94 * Adaptability
96     ENet provides an in-flight data window for reliable packets to ensure
97 connections are not overwhelmed by volumes of packets. It also provides a
98 static bandwidth allocation mechanism to ensure the total volume of packets
99 sent and received to a host don't exceed the host's capabilities. Further,
100 ENet also provides a dynamic throttle that responds to deviations from normal
101 network connections to rectify various types of network congestion by further
102 limiting the volume of packets sent.
104 * Portability
105     
106     ENet works on Windows and any other Unix or Unix-like platform providing
107 a BSD sockets interface. The library has a small and stable code base that
108 can easily be extended to support other platforms and integrates easily.
110 * Freedom
112     ENet demands no royalties and doesn't carry a viral license that would
113 restrict you in how you might use it in your programs. ENet is licensed under
114 a short-and-sweet MIT-style license, which gives you the freedom to do anything 
115 you want with it (well, almost anything).