# ReliabilityLayer Class Reference

`#include <ReliabilityLayer.h>`

List of all members.

## Public Member Functions

| ReliabilityLayer ()
| ~ReliabilityLayer ()
void | Reset (void)
void | SetEncryptionKey (const unsigned char *key)
void | SetSocket (SOCKET s)
SOCKET | GetSocket (void)
bool | HandleSocketReceiveFromConnectedPlayer (char *buffer, int length)
int | Receive (char **data)
bool | Send (RakNet::BitStream *bitStream, PacketPriority priority, PacketReliability reliability, unsigned char orderingChannel, bool makeDataCopy, int MTUSize)
void | Update (SOCKET s, PlayerID playerId, int MTUSize, unsigned long time)
bool | IsCheater (void) const
bool | IsDeadConnection (void) const
void | SetLostPacketResendDelay (unsigned long i)
RakNetStatisticsStruct *const | GetStatistics (void)

## Private Types

enum | { sendQueueSystemPriority_MUTEX, sendQueueHighPriority_MUTEX, sendQueueMediumPriority_MUTEX, sendQueueLowPriority_MUTEX, packetNumber_MUTEX, waitingForOrderedPacketWriteIndex_MUTEX, waitingForSequencedPacketWriteIndex_MUTEX, NUMBER_OF_RELIABILITY_LAYER_MUTEXES }

## Private Member Functions

bool | IsFrameReady (unsigned long time)
void | GenerateFrame (RakNet::BitStream *output, int MTUSize, bool *reliableDataSent, unsigned long time)
void | SendBitStream (SOCKET s, PlayerID playerId, RakNet::BitStream *bitStream)
int | WriteToBitStreamFromInternalPacket (RakNet::BitStream *bitStream, const InternalPacket *const internalPacket)
InternalPacket * | CreateInternalPacketFromBitStream (RakNet::BitStream *bitStream, unsigned long time)
void | RemovePacketFromResendQueueAndDeleteOlderReliableSequenced (PacketNumberType packetNumber)
void | SendAcknowledgementPacket (PacketNumberType packetNumber, unsigned long time)
bool | IsSendThrottled (void)
void | UpdatePacketloss (unsigned long time)
int | GetBitStreamHeaderLength (const InternalPacket *const internalPacket)
void | GetSHA1 (unsigned char *const buffer, unsigned long nbytes, char code[SHA1_LENGTH])
bool | CheckSHA1 (char code[SHA1_LENGTH], unsigned char *const buffer, unsigned long nbytes)
void | DeleteSequencedPacketsInList (unsigned char orderingChannel, BasicDataStructures::List< InternalPacket * > &theList, int splitPacketId=-1)
void | DeleteSequencedPacketsInList (unsigned char orderingChannel, BasicDataStructures::Queue< InternalPacket * > &theList)
bool | IsOlderOrderedPacket (unsigned char newPacketOrderingIndex, unsigned char waitingForPacketOrderingIndex)
void | SplitPacketAndDeleteOriginal (InternalPacket *internalPacket, int MTUSize)
void | InsertIntoSplitPacketList (InternalPacket *internalPacket)
InternalPacket * | BuildPacketFromSplitPacketList (unsigned long splitPacketId, unsigned long time)
void | DeleteOldUnreliableSplitPackets (unsigned long time)
InternalPacket * | CreateInternalPacketCopy (InternalPacket *original, int dataByteOffset, int dataByteLength, unsigned long time)
BasicDataStructures::LinkedList< InternalPacket * > * | GetOrderingListAtOrderingStream (unsigned char orderingChannel)
void | AddToOrderingList (InternalPacket *internalPacket)
void | InsertPacketIntoResendQueue (InternalPacket *internalPacket, unsigned long time)
void | FreeMemory (bool freeAllImmediately)
void | FreeThreadedMemory (void)
void | FreeThreadSafeMemory (void)
void | InitializeVariables (void)

## Private Attributes

SimpleMutex | reliabilityLayerMutexes [NUMBER_OF_RELIABILITY_LAYER_MUTEXES]
BasicDataStructures::List< InternalPacket * > | splitPacketList
BasicDataStructures::List< BasicDataStructures::LinkedList< InternalPacket * > * > | orderingList
BasicDataStructures::Queue< InternalPacket * > | acknowledgementQueue
BasicDataStructures::Queue< InternalPacket * > | outputQueue
BasicDataStructures::Queue< InternalPacket * > | sendQueue [NUMBER_OF_PRIORITIES]
BasicDataStructures::Queue< InternalPacket * > | resendQueue
PacketNumberType | packetNumber
unsigned long | lastAckTime
RakNet::BitStream | updateBitStream
unsigned char | waitingForOrderedPacketWriteIndex [NUMBER_OF_ORDERED_STREAMS]
unsigned char | waitingForSequencedPacketWriteIndex [NUMBER_OF_ORDERED_STREAMS]
unsigned char | waitingForOrderedPacketReadIndex [NUMBER_OF_ORDERED_STREAMS]
unsigned char | waitingForSequencedPacketReadIndex [NUMBER_OF_ORDERED_STREAMS]
bool | deadConnection
bool | cheater
unsigned long | lostPacketResendDelay
unsigned long | splitPacketId
unsigned long | receivedPackets [RECEIVED_PACKET_LOG_LENGTH]
unsigned long | blockWindowIncreaseUntilTime
RakNetStatisticsStruct | statistics
int | windowSize
int | lossyWindowSize
unsigned long | lastWindowIncreaseSizeTime
DataBlockEncryptor | encryptor
bool | freeThreadedMemoryOnNextUpdate

## Detailed Description

This class provide reliable communication services.

## Member Enumeration Documentation

anonymous enum`[private]`

Enumeration values:

  sendQueueSystemPriority_MUTEX |
  sendQueueHighPriority_MUTEX |
  sendQueueMediumPriority_MUTEX |
  sendQueueLowPriority_MUTEX |
  packetNumber_MUTEX |
  waitingForOrderedPacketWriteIndex_MUTEX |
  waitingForSequencedPacketWriteIndex_MUTEX |
  NUMBER_OF_RELIABILITY_LAYER_MUTEXES |

## Constructor & Destructor Documentation

ReliabilityLayer::ReliabilityLayer | ( |  | ) |

| Default Constructor

ReliabilityLayer::~ReliabilityLayer | ( |  | ) |

| Destructor

## Member Function Documentation

void ReliabilityLayer::AddToOrderingList | ( | InternalPacket * | internalPacket | ) | `[private]`

InternalPacket * ReliabilityLayer::BuildPacketFromSplitPacketList | ( | unsigned long | splitPacketId,
|  | unsigned long | time
| ) | `[private]`

bool ReliabilityLayer::CheckSHA1 | ( | char | code[SHA1_LENGTH],
|  | unsigned char *const | buffer,
|  | unsigned long | nbytes
| ) | `[private]`

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

InternalPacket * ReliabilityLayer::CreateInternalPacketFromBitStream | ( | RakNet::BitStream * | bitStream,
|  | unsigned long | time
| ) | `[private]`

void ReliabilityLayer::DeleteOldUnreliableSplitPackets | ( | unsigned long | time | ) | `[private]`

void ReliabilityLayer::DeleteSequencedPacketsInList | ( | unsigned char | orderingChannel,
|  | BasicDataStructures::Queue< InternalPacket * > & | theList
| ) | `[private]`

void ReliabilityLayer::DeleteSequencedPacketsInList | ( | unsigned char | orderingChannel,
|  | BasicDataStructures::List< InternalPacket * > & | theList,
|  | int | splitPacketId = `-1`
| ) | `[private]`

void ReliabilityLayer::FreeMemory | ( | bool | freeAllImmediately | ) | `[private]`

void ReliabilityLayer::FreeThreadedMemory | ( | void |  | ) | `[private]`

void ReliabilityLayer::FreeThreadSafeMemory | ( | void |  | ) | `[private]`

void ReliabilityLayer::GenerateFrame | ( | RakNet::BitStream * | output,
|  | int | MTUSize,
|  | bool * | reliableDataSent,
|  | unsigned long | time
| ) | `[private]`

Generates a frame (coalesced packets)

Parameters:

  | output | The resulting BitStream
  | MTUSize |
  | reliableDataSent | True if we have to sent a reliable data
  | time | Delay to send the packet or deadline

Todo:
  Check for time paramter

int ReliabilityLayer::GetBitStreamHeaderLength | ( | const InternalPacket *const | internalPacket | ) | `[private]`

BasicDataStructures::LinkedList< InternalPacket * > * ReliabilityLayer::GetOrderingListAtOrderingStream | ( | unsigned char | orderingChannel | ) | `[private]`

void ReliabilityLayer::GetSHA1 | ( | unsigned char *const | buffer,
|  | unsigned long | nbytes,
|  | char | code[SHA1_LENGTH]
| ) | `[private]`

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

Get the socket held by the reliability layer Callable from multiple threads

Returns:
  Retrieve the socket so that every body can used it

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

Get Statistics

Returns:
  The object containing all stats

bool ReliabilityLayer::HandleSocketReceiveFromConnectedPlayer | ( | char * | buffer,
|  | int | length
| ) |

Must be called by the same thread as update 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. The game should not use that data directly because some data is used internally, such as packet acknowledgement and split packets

Parameters:

  | buffer | Store up to length byte from the incomming data
  | length | The size of buffer

Returns:
  false on modified packets

void ReliabilityLayer::InitializeVariables | ( | void |  | ) | `[private]`

void ReliabilityLayer::InsertIntoSplitPacketList | ( | InternalPacket * | internalPacket | ) | `[private]`

void ReliabilityLayer::InsertPacketIntoResendQueue | ( | InternalPacket * | internalPacket,
|  | unsigned long | time
| ) | `[private]`

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

If Read returns -1 and this returns true then a modified packet was 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 if the connection no more responds

bool ReliabilityLayer::IsFrameReady | ( | unsigned long | time | ) | `[private]`

Returns true if we can or should send a frame. False if we should not

Parameters:

  | time | The time to wait before sending a frame

Returns:
  true if we can or should send a frame.

bool ReliabilityLayer::IsOlderOrderedPacket | ( | unsigned char | newPacketOrderingIndex,
|  | unsigned char | waitingForPacketOrderingIndex
| ) | `[private]`

bool ReliabilityLayer::IsSendThrottled | ( | void |  | ) | `[private]`

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

This gets an end-user packet already parsed out.

Parameters:

  | data | The game data

Returns:
  Returns number of BITS put into the buffer

Note:
  Callable from multiple threads

void ReliabilityLayer::RemovePacketFromResendQueueAndDeleteOlderReliableSequenced | ( | PacketNumberType | packetNumber | ) | `[private]`

void ReliabilityLayer::Reset | ( | void |  | ) |

| Resets the layer for reuse. Callable from multiple threads

bool ReliabilityLayer::Send | ( | RakNet::BitStream * | bitStream,
|  | PacketPriority | priority,
|  | PacketReliability | reliability,
|  | unsigned char | orderingChannel,
|  | bool | makeDataCopy,
|  | int | MTUSize
| ) |

Puts data on the send queue

Parameters:

  | bitStream | contains the data to send
  | priority | is what priority to send the data at
  | reliability | is what reliability to use
  | orderingChannel | is from 0 to 31 and specifies what stream to use
  | makeDataCopy | if true bitStream will keep an internal copy of the packet.
  | MTUSize |

Note:
  Callable from multiple threads

Todo:
  Document MTUSize parameter

void ReliabilityLayer::SendAcknowledgementPacket | ( | PacketNumberType | packetNumber,
|  | unsigned long | time
| ) | `[private]`

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

Writes a bitstream to the socket

Parameters:

  | s | The socket used for sending data
  | playerId | The target of the communication
  | bitStream | The data to send.

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

Sets up encryption Callable from multiple threads

Parameters:

  | key | the key used for encryption

void ReliabilityLayer::SetLostPacketResendDelay | ( | unsigned long | i | ) |

How long to wait between packet resends

Parameters:

  | i | time to wait before resending a packet

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

Assign a socket for the reliability layer to use for writing Callable from multiple threads

Parameters:

  | s | The socket to use for communication

void ReliabilityLayer::SplitPacketAndDeleteOriginal | ( | InternalPacket * | internalPacket,
|  | int | MTUSize
| ) | `[private]`

void ReliabilityLayer::Update | ( | SOCKET | s,
|  | PlayerID | playerId,
|  | int | MTUSize,
|  | unsigned long | time
| ) |

Run this once per game cycle. Handles internal lists and actually does the send Must be called by the same thread as HandleSocketReceiveFromConnectedPlayer

Parameters:

  | s | the communication end point
  | playerId | The Unique Player Identifier who should have sent some packets
  | MTUSize |
  | time |

Todo:
  Document MTUSize and time parameter

void ReliabilityLayer::UpdatePacketloss | ( | unsigned long | time | ) | `[private]`

int ReliabilityLayer::WriteToBitStreamFromInternalPacket | ( | RakNet::BitStream * | bitStream,
|  | const InternalPacket *const | internalPacket
| ) | `[private]`

| Parse an internalPacket and create a bitstream to represent this data Returns number of bits used

## Member Data Documentation

BasicDataStructures::Queue<InternalPacket*> ReliabilityLayer::acknowledgementQueue `[private]`

unsigned long ReliabilityLayer::blockWindowIncreaseUntilTime `[private]`

bool ReliabilityLayer::cheater `[private]`

bool ReliabilityLayer::deadConnection `[private]`

DataBlockEncryptor ReliabilityLayer::encryptor `[private]`

bool ReliabilityLayer::freeThreadedMemoryOnNextUpdate `[private]`

| 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

unsigned long ReliabilityLayer::lastAckTime `[private]`

unsigned long ReliabilityLayer::lastWindowIncreaseSizeTime `[private]`

int ReliabilityLayer::lossyWindowSize `[private]`

unsigned long ReliabilityLayer::lostPacketResendDelay `[private]`

BasicDataStructures::List<BasicDataStructures::LinkedList<InternalPacket*>*> ReliabilityLayer::orderingList `[private]`

BasicDataStructures::Queue<InternalPacket*> ReliabilityLayer::outputQueue `[private]`

PacketNumberType ReliabilityLayer::packetNumber `[private]`

unsigned long ReliabilityLayer::receivedPackets[RECEIVED_PACKET_LOG_LENGTH]`[private]`

SimpleMutex ReliabilityLayer::reliabilityLayerMutexes[NUMBER_OF_RELIABILITY_LAYER_MUTEXES]`[private]`

BasicDataStructures::Queue<InternalPacket*> ReliabilityLayer::resendQueue `[private]`

BasicDataStructures::Queue<InternalPacket*> ReliabilityLayer::sendQueue[NUMBER_OF_PRIORITIES]`[private]`

unsigned long ReliabilityLayer::splitPacketId `[private]`

BasicDataStructures::List<InternalPacket*> ReliabilityLayer::splitPacketList `[private]`

RakNetStatisticsStruct ReliabilityLayer::statistics `[private]`

RakNet::BitStream ReliabilityLayer::updateBitStream `[private]`

unsigned char ReliabilityLayer::waitingForOrderedPacketReadIndex[NUMBER_OF_ORDERED_STREAMS]`[private]`

unsigned char ReliabilityLayer::waitingForOrderedPacketWriteIndex[NUMBER_OF_ORDERED_STREAMS]`[private]`

unsigned char ReliabilityLayer::waitingForSequencedPacketReadIndex[NUMBER_OF_ORDERED_STREAMS]`[private]`

unsigned char ReliabilityLayer::waitingForSequencedPacketWriteIndex[NUMBER_OF_ORDERED_STREAMS]`[private]`

int ReliabilityLayer::windowSize `[private]`

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

- Projects/raknet/include/raknet/ReliabilityLayer.h
- Projects/raknet/Source/ReliabilityLayer.cpp