InternalPacket.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. /// \file
  11. /// \brief \b [Internal] A class which stores a user message, and all information associated with sending and receiving that message.
  12. ///
  13. #ifndef __INTERNAL_PACKET_H
  14. #define __INTERNAL_PACKET_H
  15. #include "PacketPriority.h"
  16. #include "RakNetTypes.h"
  17. #include "RakMemoryOverride.h"
  18. #include "RakNetDefines.h"
  19. #include "NativeTypes.h"
  20. #include "RakNetDefines.h"
  21. #if USE_SLIDING_WINDOW_CONGESTION_CONTROL!=1
  22. #include "CCRakNetUDT.h"
  23. #else
  24. #include "CCRakNetSlidingWindow.h"
  25. #endif
  26. namespace RakNet {
  27. typedef uint16_t SplitPacketIdType;
  28. typedef uint32_t SplitPacketIndexType;
  29. /// This is the counter used for holding packet numbers, so we can detect duplicate packets. It should be large enough that if the variables
  30. /// Internally assumed to be 4 bytes, but written as 3 bytes in ReliabilityLayer::WriteToBitStreamFromInternalPacket
  31. typedef uint24_t MessageNumberType;
  32. /// This is the counter used for holding ordered packet numbers, so we can detect out-of-order packets. It should be large enough that if the variables
  33. /// were to wrap, the newly wrapped values would no longer be in use. Warning: Too large of a value wastes bandwidth!
  34. typedef MessageNumberType OrderingIndexType;
  35. typedef RakNet::TimeUS RemoteSystemTimeType;
  36. struct InternalPacketFixedSizeTransmissionHeader
  37. {
  38. /// A unique numerical identifier given to this user message. Used to identify reliable messages on the network
  39. MessageNumberType reliableMessageNumber;
  40. ///The ID used as identification for ordering messages. Also included in sequenced messages
  41. OrderingIndexType orderingIndex;
  42. // Used only with sequenced messages
  43. OrderingIndexType sequencingIndex;
  44. ///What ordering channel this packet is on, if the reliability type uses ordering channels
  45. unsigned char orderingChannel;
  46. ///The ID of the split packet, if we have split packets. This is the maximum number of split messages we can send simultaneously per connection.
  47. SplitPacketIdType splitPacketId;
  48. ///If this is a split packet, the index into the array of subsplit packets
  49. SplitPacketIndexType splitPacketIndex;
  50. ///The size of the array of subsplit packets
  51. SplitPacketIndexType splitPacketCount;;
  52. ///How many bits long the data is
  53. BitSize_t dataBitLength;
  54. ///What type of reliability algorithm to use with this packet
  55. PacketReliability reliability;
  56. // Not endian safe
  57. // unsigned char priority : 3;
  58. // unsigned char reliability : 5;
  59. };
  60. /// Used in InternalPacket when pointing to sharedDataBlock, rather than allocating itself
  61. struct InternalPacketRefCountedData
  62. {
  63. unsigned char *sharedDataBlock;
  64. unsigned int refCount;
  65. };
  66. /// Holds a user message, and related information
  67. /// Don't use a constructor or destructor, due to the memory pool I am using
  68. struct InternalPacket : public InternalPacketFixedSizeTransmissionHeader
  69. {
  70. /// Identifies the order in which this number was sent. Used locally
  71. MessageNumberType messageInternalOrder;
  72. /// Has this message number been assigned yet? We don't assign until the message is actually sent.
  73. /// This fixes a bug where pre-determining message numbers and then sending a message on a different channel creates a huge gap.
  74. /// This causes performance problems and causes those messages to timeout.
  75. bool messageNumberAssigned;
  76. /// Was this packet number used this update to track windowing drops or increases? Each packet number is only used once per update.
  77. // bool allowWindowUpdate;
  78. ///When this packet was created
  79. RakNet::TimeUS creationTime;
  80. ///The resendNext time to take action on this packet
  81. RakNet::TimeUS nextActionTime;
  82. // For debugging
  83. RakNet::TimeUS retransmissionTime;
  84. // Size of the header when encoded into a bitstream
  85. BitSize_t headerLength;
  86. /// Buffer is a pointer to the actual data, assuming this packet has data at all
  87. unsigned char *data;
  88. /// How to alloc and delete the data member
  89. enum AllocationScheme
  90. {
  91. /// Data is allocated using rakMalloc. Just free it
  92. NORMAL,
  93. /// data points to a larger block of data, where the larger block is reference counted. internalPacketRefCountedData is used in this case
  94. REF_COUNTED,
  95. /// If allocation scheme is STACK, data points to stackData and should not be deallocated
  96. /// This is only used when sending. Received packets are deallocated in RakPeer
  97. STACK
  98. } allocationScheme;
  99. InternalPacketRefCountedData *refCountedData;
  100. /// How many attempts we made at sending this message
  101. unsigned char timesSent;
  102. /// The priority level of this packet
  103. PacketPriority priority;
  104. /// If the reliability type requires a receipt, then return this number with it
  105. uint32_t sendReceiptSerial;
  106. // Used for the resend queue
  107. // Linked list implementation so I can remove from the list via a pointer, without finding it in the list
  108. InternalPacket *resendPrev, *resendNext,*unreliablePrev,*unreliableNext;
  109. unsigned char stackData[128];
  110. };
  111. } // namespace RakNet
  112. #endif
粤ICP备19079148号