design.txt 5.7 KB

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