- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# ReliabilityLayer Class Reference

Datagram reliable, ordered, unordered and sequenced sends. Flow control. Message splitting, reassembly, and coalescence. More...

`#include <ReliabilityLayer.h>`

List of all members.

## Public Member Functions
| ReliabilityLayer ()
| Constructor.
| ~ReliabilityLayer ()
| Destructor.
void | Reset (bool resetVariables)
| Resets the layer for reuse.
void | SetEncryptionKey (const unsigned char *key)
void | SetSocket (SOCKET s)
SOCKET | GetSocket (void)
void | SetTimeoutTime (RakNetTime time)
RakNetTime | GetTimeoutTime (void)
bool | HandleSocketReceiveFromConnectedPlayer (const char *buffer, int length, PlayerID playerId, DataStructures::List< PluginInterface * > &messageHandlerList, int MTUSize)
int | Receive (unsigned char **data)
bool | Send (char *data, int numberOfBitsToSend, PacketPriority priority, PacketReliability reliability, unsigned char orderingChannel, bool makeDataCopy, int MTUSize, RakNetTimeNS currentTime)
void | Update (SOCKET s, PlayerID playerId, int MTUSize, RakNetTimeNS time, DataStructures::List< PluginInterface * > &messageHandlerList)
bool | IsCheater (void) const
bool | IsDeadConnection (void) const
void | KillConnection (void)
| Causes IsDeadConnection to return true.
void | SetPing (RakNetTime i)
RakNetStatisticsStruct *const | GetStatistics (void)
bool | IsDataWaiting (void)
| Are we waiting for any data to be sent out or be processed by the player?
bool | AreAcksWaiting (void)
void | ApplyNetworkSimulator (double _maxSendBPS, RakNetTime _minExtraPing, RakNetTime _extraPingVariance)
bool | IsNetworkSimulatorActive (void)
void | SetSplitMessageProgressInterval (int interval)
void | SetUnreliableTimeout (RakNetTime timeoutMS)
## Private Member Functions
unsigned | GenerateDatagram (RakNet::BitStream *output, int MTUSize, bool *reliableDataSent, RakNetTimeNS time, PlayerID playerId, DataStructures::List< PluginInterface * > &messageHandlerList)
void | SendBitStream (SOCKET s, PlayerID playerId, RakNet::BitStream *bitStream)
int | WriteToBitStreamFromInternalPacket (RakNet::BitStream *bitStream, const InternalPacket *const internalPacket)
| Parse an internalPacket and create a bitstream to represent this dataReturns number of bits used.
InternalPacket * | CreateInternalPacketFromBitStream (RakNet::BitStream *bitStream, RakNetTimeNS time)
| Parse a bitstream and create an internal packet to represent this data.
unsigned | RemovePacketFromResendListAndDeleteOlderReliableSequenced (const MessageNumberType messageNumber, RakNetTimeNS time)
| Does what the function name says.
void | SendAcknowledgementPacket (const MessageNumberType messageNumber, RakNetTimeNS time)
| Acknowledge receipt of the packet with the specified messageNumber.
bool | IsSendThrottled (int MTUSize)
| This will return true if we should not send at this time.
void | UpdateWindowFromPacketloss (RakNetTimeNS time)
| We lost a packet.
void | UpdateWindowFromAck (RakNetTimeNS time)
| Increase the window size.
int | GetBitStreamHeaderLength (const InternalPacket *const internalPacket)
| Parse an internalPacket and figure out how many header bits would be written. Returns that number.
void | GetSHA1 (unsigned char *const buffer, unsigned int nbytes, char code[SHA1_LENGTH])
| Get the SHA1 code.
bool | CheckSHA1 (char code[SHA1_LENGTH], unsigned char *const buffer, unsigned int nbytes)
| Check the SHA1 code.
void | DeleteSequencedPacketsInList (unsigned char orderingChannel, DataStructures::List< InternalPacket * > &theList, int splitPacketId=-1)
| Search the specified list for sequenced packets on the specified ordering channel, optionally skipping those with splitPacketId, and delete them.
void | DeleteSequencedPacketsInList (unsigned char orderingChannel, DataStructures::Queue< InternalPacket * > &theList)
| Search the specified list for sequenced packets with a value less than orderingIndex and delete them.
bool | IsOlderOrderedPacket (OrderingIndexType newPacketOrderingIndex, OrderingIndexType waitingForPacketOrderingIndex)
| Returns true if newPacketOrderingIndex is older than the waitingForPacketOrderingIndex.
void | SplitPacket (InternalPacket *internalPacket, int MTUSize)
| Split the passed packet into chunks under MTU_SIZE bytes (including headers) and save those new chunks.
void | InsertIntoSplitPacketList (InternalPacket *internalPacket, RakNetTimeNS time)
| Insert a packet into the split packet list.
InternalPacket * | BuildPacketFromSplitPacketList (SplitPacketIdType splitPacketId, RakNetTimeNS time)
| Take all split chunks with the specified splitPacketId and try to reconstruct a packet. If we can, allocate and return it. Otherwise return 0.
void | DeleteOldUnreliableSplitPackets (RakNetTimeNS time)
| Delete any unreliable split packets that have long since expired.
InternalPacket * | CreateInternalPacketCopy (InternalPacket *original, int dataByteOffset, int dataByteLength, RakNetTimeNS time)
DataStructures::LinkedList< InternalPacket * > * | GetOrderingListAtOrderingStream (unsigned char orderingChannel)
| Get the specified ordering list.
void | AddToOrderingList (InternalPacket *internalPacket)
| Add the internal packet to the ordering list in order based on order index.
void | InsertPacketIntoResendList (InternalPacket *internalPacket, RakNetTimeNS time, bool makeCopyOfInternalPacket, bool firstResend)
| Inserts a packet into the resend list in order.
void | FreeMemory (bool freeAllImmediately)
| Memory handling.
void | FreeThreadedMemory (void)
| Memory handling.
void | FreeThreadSafeMemory (void)
| Memory handling.
void | InitializeVariables (void)
bool | IsExpiredTime (unsigned int input, RakNetTimeNS currentTime) const
| Given the current time, is this time so old that we should consider it a timeout?
void | UpdateNextActionTime (void)
unsigned int | GetResendListDataSize (void) const
| How many elements are waiting to be resent?
void | UpdateThreadedMemory (void)
| Update all memory which is not threadsafe.
void | CalculateHistogramAckSize (void)
## Private Attributes
DataStructures::List< DataStructures::LinkedList< InternalPacket * > * > | orderingList
DataStructures::Queue< InternalPacket * > | outputQueue
DataStructures::RangeList< MessageNumberType > | acknowlegements
RakNetTimeNS | nextAckTime
int | splitMessageProgressInterval
RakNetTimeNS | unreliableTimeout
DataStructures::BPlusTree< MessageNumberType, InternalPacket *, RESEND_TREE_ORDER > | resendList
DataStructures::Queue< InternalPacket * > | resendQueue
DataStructures::Queue< InternalPacket * > | sendPacketSet [NUMBER_OF_PRIORITIES]
DataStructures::OrderedList< SplitPacketIdType, SplitPacketChannel *, SplitPacketChannelComp > | splitPacketChannelList
MessageNumberType | messageNumber
RakNetTimeNS | lastAckTime
RakNet::BitStream | updateBitStream
OrderingIndexType | waitingForOrderedPacketWriteIndex [NUMBER_OF_ORDERED_STREAMS]
OrderingIndexType | waitingForSequencedPacketWriteIndex [NUMBER_OF_ORDERED_STREAMS]
OrderingIndexType | waitingForOrderedPacketReadIndex [NUMBER_OF_ORDERED_STREAMS]
OrderingIndexType | waitingForSequencedPacketReadIndex [NUMBER_OF_ORDERED_STREAMS]
bool | deadConnection
bool | cheater
RakNetTime | ping
SplitPacketIdType | splitPacketId
RakNetTime | timeoutTime
unsigned int | blockWindowIncreaseUntilTime
RakNetStatisticsStruct | statistics
DataStructures::Queue< RakNetTimeNS > | hasReceivedPacketQueue
MessageNumberType | receivedPacketsBaseIndex
bool | resetReceivedPackets
RakNetTimeNS | lastUpdateTime
RakNetTimeNS | histogramEndTime
RakNetTimeNS | histogramStartTime
unsigned | histogramReceiveMarker
int | noPacketlossIncreaseCount
unsigned | histogramPlossCount
unsigned | histogramAckCount
double | lowBandwidth
double | highBandwidth
double | currentBandwidth
double | availableBandwidth
bool | continuousSend
DataBlockEncryptor | encryptor
unsigned | sendPacketCount
unsigned | receivePacketCount
RakNetTimeNS | ackTimeIncrement
bool | freeThreadedMemoryOnNextUpdate
| This variable is so that free memory can be called by only the update thread so we don't have to mutex things so much.
DataStructures::List< DataAndTime * > | delayList
double | maxSendBPS
RakNetTime | minExtraPing
RakNetTime | extraPingVariance
InternalPacketPool | internalPacketPool
## Classes
struct | DataAndTime

## Detailed Description

Datagram reliable, ordered, unordered and sequenced sends. Flow control. Message splitting, reassembly, and coalescence.

## Member Function Documentation

InternalPacket * ReliabilityLayer::CreateInternalPacketCopy | ( | InternalPacket * | original,
|  | int | dataByteOffset,
|  | int | dataByteLength,
|  | RakNetTimeNS | time
| ) | `[private]`

| Creates a copy of the specified internal packet with data copied from the original starting at dataByteOffset for dataByteLength bytes. Does not copy any split data parameters as that information is always generated does not have any reason to be copied

unsigned ReliabilityLayer::GenerateDatagram | ( | RakNet::BitStream * | output,
|  | int | MTUSize,
|  | bool * | reliableDataSent,
|  | RakNetTimeNS | time,
|  | PlayerID | playerId,
|  | DataStructures::List< PluginInterface * > & | messageHandlerList
| ) | `[private]`

  | Generates a datagram (coalesced packets) Parameters:
  `[out]` | output | The resulting BitStream
  `[in]` | Current | MTU size
  `[out]` | reliableDataSent | Set to true or false as a return value as to if reliable data was sent.
  `[in]` | time | Current time
  `[in]` | playerId | Who we are sending to
  `[in]` | messageHandlerList | A list of registered plugins
Returns: The number of messages sent

SOCKET ReliabilityLayer::GetSocket | ( | void |  | ) |

| Returns what was passed to SetSocket Returns: The socket

RakNetStatisticsStruct *const ReliabilityLayer::GetStatistics | ( | void |  | ) |

| Get Statistics Returns: A pointer to a static struct, filled out with current statistical information.

RakNetTime ReliabilityLayer::GetTimeoutTime | ( | void |  | ) |

  | Returns the value passed to SetTimeoutTime. or the default if it was never called Parameters:
  `[out]` | the | value passed to SetTimeoutTime

bool ReliabilityLayer::HandleSocketReceiveFromConnectedPlayer | ( | const char * | buffer,
|  | int | length,
|  | PlayerID | playerId,
|  | DataStructures::List< PluginInterface * > & | messageHandlerList,
|  | int | MTUSize
| ) |

  | Packets are read directly from the socket layer and skip the reliability layer because unconnected players do not use the reliability layer This function takes packet data after a player has been confirmed as connected. Parameters:
  `[in]` | buffer | The socket data
  `[in]` | length | The length of the socket data
  `[in]` | playerId | The player that this data is from
  `[in]` | messageHandlerList | A list of registered plugins
  `[in]` | MTUSize | maximum datagram size
  Return values:
  | true | Success
  | false | Modified packet

bool ReliabilityLayer::IsCheater | ( | void |  | ) | const

| If Read returns -1 and this returns true then a modified packetwas detected Returns: true when a modified packet is detected

bool ReliabilityLayer::IsDeadConnection | ( | void |  | ) | const

| Were you ever unable to deliver a packet despite retries? Returns: true means the connection has been lost. Otherwise not.

bool ReliabilityLayer::IsNetworkSimulatorActive | ( | void |  | ) |

| Returns if you previously called ApplyNetworkSimulator Returns: If you previously called ApplyNetworkSimulator

int ReliabilityLayer::Receive | ( | unsigned char ** | data | ) |

  | This allocates bytes and writes a user-level message to those bytes. Parameters:
  `[out]` | data | The message
Returns: Returns number of BITS put into the buffer

bool ReliabilityLayer::Send | ( | char * | data,
|  | int | numberOfBitsToSend,
|  | PacketPriority | priority,
|  | PacketReliability | reliability,
|  | unsigned char | orderingChannel,
|  | bool | makeDataCopy,
|  | int | MTUSize,
|  | RakNetTimeNS | currentTime
| ) |

  | Puts data on the send queue Parameters:
  `[in]` | data | The data to send
  `[in]` | numberOfBitsToSend | The length of data in bits
  `[in]` | priority | The priority level for the send
  `[in]` | reliability | The reliability type for the send
  `[in]` | orderingChannel | 0 to 31. Specifies what channel to use, for relational ordering and sequencing of packets.
  `[in]` | makeDataCopy | If true data will be copied. Otherwise, only a pointer will be stored.
  `[in]` | MTUSize | maximum datagram size
  `[in]` | currentTime | Current time, as per RakNet::GetTime()
Returns: True or false for success or failure.

void ReliabilityLayer::SendBitStream | ( | SOCKET | s,
|  | PlayerID | playerId,
|  | RakNet::BitStream * | bitStream
| ) | `[private]`

  | Send the contents of a bitstream to the socket Parameters:
  `[in]` | s | The socket used for sending data
  `[in]` | playerId | The address and port to send to
  `[in]` | bitStream | The data to send.

void ReliabilityLayer::SetEncryptionKey | ( | const unsigned char * | key | ) |

  | Sets the encryption key. Doing so will activate secure connections Parameters:
  `[in]` | key | Byte stream for the encryption key

void ReliabilityLayer::SetPing | ( | RakNetTime | i | ) |

  | Sets the ping, which is used by the reliability layer to determine how long to wait for resends. Mostly for flow control. Parameters:
  `[in]` | The | ping time.

void ReliabilityLayer::SetSocket | ( | SOCKET | s | ) |

  | Depreciated, from IO Completion ports Parameters:
  `[in]` | s | The socket

void ReliabilityLayer::SetTimeoutTime | ( | RakNetTime | time | ) |

  | Set the time, in MS, to use before considering ourselves disconnected after not being able to deliver a reliable packet Default time is 10,000 or 10 seconds in release and 30,000 or 30 seconds in debug. Parameters:
  `[in]` | time | Time, in MS

void ReliabilityLayer::Update | ( | SOCKET | s,
|  | PlayerID | playerId,
|  | int | MTUSize,
|  | RakNetTimeNS | time,
|  | DataStructures::List< PluginInterface * > & | messageHandlerList
| ) |

  | Call once per game cycle. Handles internal lists and actually does the send. Parameters:
  `[in]` | s | the communication end point
  `[in]` | playerId | The Unique Player Identifier who shouldhave sent some packets
  `[in]` | MTUSize | maximum datagram size
  `[in]` | time | current system time
  `[in]` | messageHandlerList | A list of registered plugins

## Member Data Documentation

DataStructures::Queue<RakNetTimeNS> ReliabilityLayer::hasReceivedPacketQueue`[private]`

| Memory-efficient receivedPackets algorithm: receivedPacketsBaseIndex is the packet number we are expecting Everything under receivedPacketsBaseIndex is a packet we already got Everything over receivedPacketsBaseIndex is stored in hasReceivedPacketQueue It stores the time to stop waiting for a particular packet number, where the packet number is receivedPacketsBaseIndex + the index into the queue If 0, we got got that packet. Otherwise, the time to give up waiting for that packet. If we get a packet number where (receivedPacketsBaseIndex-packetNumber) is less than half the range of receivedPacketsBaseIndex then it is a duplicate Otherwise, it is a duplicate packet (and ignore it).

The documentation for this class was generated from the following files:

- C:/RakNet 2.518/Include/ReliabilityLayer.h
- C:/RakNet 2.518/Source/ReliabilityLayer.cpp