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 (void)
 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 Receive (unsigned char **data)
bool Send (char *data, int numberOfBitsToSend, PacketPriority priority, PacketReliability reliability, unsigned char orderingChannel, bool makeDataCopy, int MTUSize, RakNetTime currentTime)
void Update (SOCKET s, PlayerID playerId, int MTUSize, RakNetTime time, DataStructures::List< PluginInterface * > &messageHandlerList)
bool IsCheater (void) const
bool IsDeadConnection (void) const
void KillConnection (void)
 Causes IsDeadConnection to return true.
void SetPing (unsigned short i)
RakNetStatisticsStruct *const GetStatistics (void)
bool IsDataWaiting (void)
 Are we waiting for any data to be sent out or be processed by the player?
void ApplyNetworkSimulator (unsigned short _maxPacketsOnWire, unsigned short _minExtraPing, unsigned short _extraPingVariance)
bool IsNetworkSimulatorActive (void)

Private Member Functions

bool IsDatagramReady (RakNetTime time, int MTUSize)
void GenerateDatagram (RakNet::BitStream *output, int MTUSize, bool *reliableDataSent, RakNetTime 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.
InternalPacketCreateInternalPacketFromBitStream (RakNet::BitStream *bitStream, RakNetTime time)
 Parse a bitstream and create an internal packet to represent this data.
void RemovePacketFromResendQueueAndDeleteOlderReliableSequenced (const MessageNumberType messageNumber, RakNetTime time)
 Does what the function name says.
void SendAcknowledgementPacket (const MessageNumberType messageNumber, RakNetTime 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 (RakNetTime time)
 We lost a packet.
void UpdateWindowFromAck (RakNetTime 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)
 Insert a packet into the split packet list.
InternalPacketBuildPacketFromSplitPacketList (unsigned int splitPacketId, RakNetTime 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 (RakNetTime time)
 Delete any unreliable split packets that have long since expired.
InternalPacketCreateInternalPacketCopy (InternalPacket *original, int dataByteOffset, int dataByteLength, RakNetTime 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 InsertPacketIntoResendQueue (InternalPacket *internalPacket, RakNetTime 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, RakNetTime currentTime) const
 Given the current time, is this time so old that we should consider it a timeout?
unsigned int GetResendQueueDataSize (void) const
 How many elements are waiting to be resent?
void UpdateThreadedMemory (void)
 Update all memory which is not threadsafe.

Private Attributes

DataStructures::List< InternalPacket * > splitPacketList
DataStructures::List< DataStructures::LinkedList<
InternalPacket * > * > 
orderingList
DataStructures::Queue< InternalPacket * > acknowledgementQueue
DataStructures::Queue< InternalPacket * > outputQueue
DataStructures::Queue< InternalPacket * > resendQueue
DataStructures::Queue< InternalPacket * > sendPacketSet [NUMBER_OF_PRIORITIES]
MessageNumberType messageNumber
RakNetTime 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
unsigned short ping
unsigned int splitPacketId
RakNetTime timeoutTime
unsigned int blockWindowIncreaseUntilTime
RakNetStatisticsStruct statistics
DataStructures::Queue< RakNetTime > hasReceivedPacketQueue
MessageNumberType receivedPacketsBaseIndex
bool resetReceivedPackets
unsigned int windowSize
RakNetTime lastPacketLossTime
 Limit how fast the window can drop, so many fast resends doesn't drop the window to nothing immediately.
RakNetTime lastWindowDropTime
RakNetTime lastWindowIncreaseTime
DataBlockEncryptor encryptor
unsigned sendPacketCount
unsigned receivePacketCount
bool freeThreadedMemoryOnNextUpdate
 This variable is so that free memory can be called by only theupdate thread so we don't have to mutex things so much.
DataStructures::List< DataAndTime * > delayList
unsigned short maxPacketsOnWire
unsigned short minExtraPing
unsigned short 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,
RakNetTime  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

void ReliabilityLayer::GenerateDatagram RakNet::BitStream output,
int  MTUSize,
bool *  reliableDataSent,
RakNetTime  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

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
 

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 a sconnected.

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
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::IsDatagramReady RakNetTime  time,
int  MTUSize
[private]
 

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

Parameters:
[in] time The current time
Returns:
true if we can or should send a frame.

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,
RakNetTime  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 unsigned short  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,
RakNetTime  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<RakNetTime> 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).

unsigned int ReliabilityLayer::windowSize [private]
 

New windowing algorithm: For each packet containing reliable messages, assign the packet number to that message For each reliable message resent, if that packet number has not yet caused the window to drop by half, do so. For each reliable message acknowledged, if that packet number has not yet caused the window to increase by 1, do so.


The documentation for this class was generated from the following files:
Generated on Wed May 3 09:11:56 2006 for RakNet by  doxygen 1.4.6-NO