SLikeNet 0.1.3

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

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes
Router2
Plugins

Part of the NAT punchthrough solution, allowing you to connect to systems by routing through a shared connection. More...

## Classes

class | SLNet::Router2
| Class interface for the Router2 system. More...
struct | SLNet::Router2::ConnectionRequestSystem
struct | SLNet::Router2::ConnnectRequest
struct | SLNet::Router2::ForwardedConnection
struct | SLNet::Router2::MiniPunchRequest

## Detailed Description

Part of the NAT punchthrough solution, allowing you to connect to systems by routing through a shared connection.

Router2 routes datagrams between two systems that are not directly connected by using the bandwidth of a third system, to which the other two systems were connected It is of benefit when a fully connected mesh topology is desired, but could not be completely established due to routers and/or firewalls As the system address of a remote system will be the system address of the intermediary, it is necessary to use the RakNetGUID object to refer to systems, including with other plugins

## Class Documentation

class SLNet::Router2

Class interface for the Router2 system.

Definition at line 59 of file Router2.h.

Inheritance diagram for SLNet::Router2:

### Public Types

enum | Router2RequestStates { R2RS_REQUEST_STATE_QUERY_FORWARDING, REQUEST_STATE_REQUEST_FORWARDING }

### Public Member Functions

| Router2 ()
virtual | ~Router2 ()
void | SetSocketFamily (unsigned short _socketFamily)
void | EstablishRouting (RakNetGUID endpointGuid)
| Query all connected systems to connect through them to a third system. System will return ID_ROUTER_2_FORWARDING_NO_PATH if unable to connect. Else you will get ID_ROUTER_2_FORWARDING_ESTABLISHED.
void | SetMaximumForwardingRequests (int max)
void | SetDebugInterface (Router2DebugInterface *_debugInterface)
| For testing and debugging.
Router2DebugInterface * | GetDebugInterface (void) const
| Get the pointer passed to SetDebugInterface()
virtual PluginReceiveResult | OnReceive (Packet *packet)
virtual void | Update (void)
| Update is called every time a packet is checked for .
virtual void | OnClosedConnection (const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason)
virtual void | OnFailedConnectionAttempt (Packet *packet, PI2_FailedConnectionAttemptReason failedConnectionAttemptReason)
virtual void | OnRakPeerShutdown (void)
| Called when RakPeer is shutdown.
unsigned int | GetConnectionRequestIndex (RakNetGUID endpointGuid)
Public Member Functions inherited from SLNet::PluginInterface2
| PluginInterface2 ()
virtual | ~PluginInterface2 ()
virtual void | OnAttach (void)
| Called when the interface is attached.
virtual void | OnDetach (void)
| Called when the interface is detached.
virtual void | OnRakPeerStartup (void)
| Called when RakPeer is initialized.
virtual void | OnNewConnection (const SystemAddress &systemAddress, RakNetGUID rakNetGUID, bool isIncoming)
virtual bool | UsesReliabilityLayer (void) const
virtual void | OnDirectSocketSend (const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress)
virtual void | OnDirectSocketReceive (const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress)
virtual void | OnReliabilityLayerNotification (const char *errorMessage, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress, bool isError)
virtual void | OnInternalPacket (InternalPacket *internalPacket, unsigned frameNumber, SystemAddress remoteSystemAddress, SLNet::TimeMS time, int isSend)
virtual void | OnAck (unsigned int messageNumber, SystemAddress remoteSystemAddress, SLNet::TimeMS time)
virtual void | OnPushBackPacket (const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress)
RakPeerInterface * | GetRakPeerInterface (void) const
RakNetGUID | GetMyGUIDUnified (void) const
void | SetRakPeerInterface (RakPeerInterface *ptr)
void | SetTCPInterface (TCPInterface *ptr)

### Protected Member Functions

bool | UpdateForwarding (ConnnectRequest *connectionRequest)
void | RemoveConnectionRequest (unsigned int connectionRequestIndex)
void | RequestForwarding (ConnnectRequest *connectionRequest)
void | OnQueryForwarding (Packet *packet)
void | OnQueryForwardingReply (Packet *packet)
void | OnRequestForwarding (Packet *packet)
void | OnRerouted (Packet *packet)
void | OnMiniPunchReply (Packet *packet)
void | OnMiniPunchReplyBounce (Packet *packet)
bool | OnForwardingSuccess (Packet *packet)
int | GetLargestPingAmongConnectedSystems (void) const
void | ReturnToUser (MessageID messageId, RakNetGUID endpointGuid, const SystemAddress &systemAddress, bool wasGeneratedLocally)
bool | ConnectInternal (RakNetGUID endpointGuid, bool returnConnectionLostOnFailure)
void | ClearConnectionRequests (void)
void | ClearMinipunches (void)
void | ClearForwardedConnections (void)
void | ClearAll (void)
int | ReturnFailureOnCannotForward (RakNetGUID sourceGuid, RakNetGUID endpointGuid)
void | SendFailureOnCannotForward (RakNetGUID sourceGuid, RakNetGUID endpointGuid)
void | SendForwardingSuccess (MessageID messageId, RakNetGUID sourceGuid, RakNetGUID endpointGuid, unsigned short sourceToDstPort)
void | SendOOBFromRakNetPort (OutOfBandIdentifiers oob, BitStream *extraData, SystemAddress sa)
void | SendOOBFromSpecifiedSocket (OutOfBandIdentifiers oob, SystemAddress sa, __UDPSOCKET__ socket)
void | SendOOBMessages (MiniPunchRequest *mpr)
Protected Member Functions inherited from SLNet::PluginInterface2
void | SendUnified (const SLNet::BitStream *bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast)
void | SendUnified (const char *data, const int length, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast)
bool | SendListUnified (const char **data, const int *lengths, const int numParameters, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast)
Packet * | AllocatePacketUnified (unsigned dataSize)
void | PushBackPacketUnified (Packet *packet, bool pushAtHead)
void | DeallocPacketUnified (Packet *packet)

### Protected Attributes

UDPForwarder * | udpForwarder
int | maximumForwardingRequests
SimpleMutex | connectionRequestsMutex
SimpleMutex | miniPunchesInProgressMutex
SimpleMutex | forwardedConnectionListMutex
DataStructures::List < ConnnectRequest * > | connectionRequests
DataStructures::List < MiniPunchRequest > | miniPunchesInProgress
DataStructures::List < ForwardedConnection > | forwardedConnectionList
Router2DebugInterface * | debugInterface
unsigned short | socketFamily
Protected Attributes inherited from SLNet::PluginInterface2
RakPeerInterface * | rakPeerInterface
TCPInterface * | tcpInterface

#### Member Enumeration Documentation

enum SLNet::Router2::Router2RequestStates

Enumerator:

  R2RS_REQUEST_STATE_QUERY_FORWARDING |
  REQUEST_STATE_REQUEST_FORWARDING |

Definition at line 112 of file Router2.h.

#### Constructor & Destructor Documentation

SLNet::Router2::Router2 | ( |  | ) |

virtual SLNet::Router2::~Router2 | ( |  | ) |

virtual

#### Member Function Documentation

void SLNet::Router2::ClearAll | ( | void |  | ) |

protected

void SLNet::Router2::ClearConnectionRequests | ( | void |  | ) |

protected

void SLNet::Router2::ClearForwardedConnections | ( | void |  | ) |

protected

void SLNet::Router2::ClearMinipunches | ( | void |  | ) |

protected

bool SLNet::Router2::ConnectInternal | ( | RakNetGUID | endpointGuid,
|  | bool | returnConnectionLostOnFailure
| ) |  |

protected

void SLNet::Router2::EstablishRouting | ( | RakNetGUID | endpointGuid | ) |

Query all connected systems to connect through them to a third system. System will return ID_ROUTER_2_FORWARDING_NO_PATH if unable to connect. Else you will get ID_ROUTER_2_FORWARDING_ESTABLISHED.

On ID_ROUTER_2_FORWARDING_ESTABLISHED, EstablishRouting as follows:

SLNet::BitStream bs(packet->data, packet->length, false); bs.IgnoreBytes(sizeof(MessageID)); RakNetGUID endpointGuid; bs.Read(endpointGuid); unsigned short sourceToDestPort; bs.Read(sourceToDestPort); char ipAddressString[32]; packet->systemAddress.ToString(false, ipAddressString); rakPeerInterface->EstablishRouting(ipAddressString, sourceToDestPort, 0,0);

Note
  The SystemAddress for a connection should not be used - always use RakNetGuid as the address can change at any time. When the address changes, you will get ID_ROUTER_2_REROUTED

unsigned int SLNet::Router2::GetConnectionRequestIndex | ( | RakNetGUID | endpointGuid | ) |

Router2DebugInterface* SLNet::Router2::GetDebugInterface | ( | void |  | ) | const

Get the pointer passed to SetDebugInterface()

int SLNet::Router2::GetLargestPingAmongConnectedSystems | ( | void |  | ) | const

protected

virtual void SLNet::Router2::OnClosedConnection | ( | const SystemAddress & | systemAddress,
|  | RakNetGUID | rakNetGUID,
|  | PI2_LostConnectionReason | lostConnectionReason
| ) |  |

virtual

Called when a connection is dropped because the user called RakPeer::CloseConnection() for a particular system

Parameters

  [in] | systemAddress | The system whose connection was closed
  [in] | rakNetGuid | The guid of the specified system
  [in] | lostConnectionReason | How the connection was closed: manually, connection lost, or notification of disconnection

Reimplemented from SLNet::PluginInterface2.

virtual void SLNet::Router2::OnFailedConnectionAttempt | ( | Packet * | packet,
|  | PI2_FailedConnectionAttemptReason | failedConnectionAttemptReason
| ) |  |

virtual

Called when a connection attempt fails

Parameters

  [in] | packet | Packet to be returned to the user
  [in] | failedConnectionReason | Why the connection failed

Reimplemented from SLNet::PluginInterface2.

bool SLNet::Router2::OnForwardingSuccess | ( | Packet * | packet | ) |

protected

void SLNet::Router2::OnMiniPunchReply | ( | Packet * | packet | ) |

protected

void SLNet::Router2::OnMiniPunchReplyBounce | ( | Packet * | packet | ) |

protected

void SLNet::Router2::OnQueryForwarding | ( | Packet * | packet | ) |

protected

void SLNet::Router2::OnQueryForwardingReply | ( | Packet * | packet | ) |

protected

virtual void SLNet::Router2::OnRakPeerShutdown | ( | void |  | ) |

virtual

Called when RakPeer is shutdown.

Reimplemented from SLNet::PluginInterface2.

virtual PluginReceiveResult SLNet::Router2::OnReceive | ( | Packet * | packet | ) |

virtual

OnReceive is called for every packet.

Parameters

  [in] | packet | the packet that is being returned to the user

Returns
  True to allow the game and other plugins to get this message, false to absorb it

Reimplemented from SLNet::PluginInterface2.

void SLNet::Router2::OnRequestForwarding | ( | Packet * | packet | ) |

protected

void SLNet::Router2::OnRerouted | ( | Packet * | packet | ) |

protected

void SLNet::Router2::RemoveConnectionRequest | ( | unsigned int | connectionRequestIndex | ) |

protected

void SLNet::Router2::RequestForwarding | ( | ConnnectRequest * | connectionRequest | ) |

protected

int SLNet::Router2::ReturnFailureOnCannotForward | ( | RakNetGUID | sourceGuid,
|  | RakNetGUID | endpointGuid
| ) |  |

protected

void SLNet::Router2::ReturnToUser | ( | MessageID | messageId,
|  | RakNetGUID | endpointGuid,
|  | const SystemAddress & | systemAddress,
|  | bool | wasGeneratedLocally
| ) |  |

protected

void SLNet::Router2::SendFailureOnCannotForward | ( | RakNetGUID | sourceGuid,
|  | RakNetGUID | endpointGuid
| ) |  |

protected

void SLNet::Router2::SendForwardingSuccess | ( | MessageID | messageId,
|  | RakNetGUID | sourceGuid,
|  | RakNetGUID | endpointGuid,
|  | unsigned short | sourceToDstPort
| ) |  |

protected

void SLNet::Router2::SendOOBFromRakNetPort | ( | OutOfBandIdentifiers | oob,
|  | BitStream * | extraData,
|  | SystemAddress | sa
| ) |  |

protected

void SLNet::Router2::SendOOBFromSpecifiedSocket | ( | OutOfBandIdentifiers | oob,
|  | SystemAddress | sa,
|  | __UDPSOCKET__ | socket
| ) |  |

protected

void SLNet::Router2::SendOOBMessages | ( | MiniPunchRequest * | mpr | ) |

protected

void SLNet::Router2::SetDebugInterface | ( | Router2DebugInterface * | _debugInterface | ) |

For testing and debugging.

void SLNet::Router2::SetMaximumForwardingRequests | ( | int | max | ) |

Set the maximum number of bidirectional connections this system will support Defaults to 0

void SLNet::Router2::SetSocketFamily | ( | unsigned short | _socketFamily | ) |

Sets the socket family to use, either IPV4 or IPV6

Parameters

  [in] | socketFamily | For IPV4, use AF_INET (default). For IPV6, use AF_INET6. To autoselect, use AF_UNSPEC.

virtual void SLNet::Router2::Update | ( | void |  | ) |

virtual

Update is called every time a packet is checked for .

Reimplemented from SLNet::PluginInterface2.

bool SLNet::Router2::UpdateForwarding | ( | ConnnectRequest * | connectionRequest | ) |

protected

#### Member Data Documentation

DataStructures::List<ConnnectRequest*> SLNet::Router2::connectionRequests

protected

Definition at line 184 of file Router2.h.

SimpleMutex SLNet::Router2::connectionRequestsMutex

protected

Definition at line 183 of file Router2.h.

Router2DebugInterface* SLNet::Router2::debugInterface

protected

Definition at line 200 of file Router2.h.

DataStructures::List<ForwardedConnection> SLNet::Router2::forwardedConnectionList

protected

Definition at line 187 of file Router2.h.

SimpleMutex SLNet::Router2::forwardedConnectionListMutex

protected

Definition at line 183 of file Router2.h.

int SLNet::Router2::maximumForwardingRequests

protected

Definition at line 182 of file Router2.h.

DataStructures::List<MiniPunchRequest> SLNet::Router2::miniPunchesInProgress

protected

Definition at line 185 of file Router2.h.

SimpleMutex SLNet::Router2::miniPunchesInProgressMutex

protected

Definition at line 183 of file Router2.h.

unsigned short SLNet::Router2::socketFamily

protected

Definition at line 201 of file Router2.h.

UDPForwarder* SLNet::Router2::udpForwarder

protected

Definition at line 181 of file Router2.h.

struct SLNet::Router2::ConnectionRequestSystem

Definition at line 118 of file Router2.h.

Class Members
RakNetGUID | guid |
int | pingToEndpoint |
unsigned short | usedForwardingEntries |

struct SLNet::Router2::ConnnectRequest

Definition at line 125 of file Router2.h.

### Public Member Functions

| ConnnectRequest ()
| ~ConnnectRequest ()
unsigned int | GetGuidIndex (RakNetGUID guid)

### Public Attributes

DataStructures::List < ConnectionRequestSystem > | connectionRequestSystems
SimpleMutex | connectionRequestSystemsMutex
Router2RequestStates | requestState
SLNet::TimeMS | pingTimeout
RakNetGUID | endpointGuid
RakNetGUID | lastRequestedForwardingSystem
bool | returnConnectionLostOnFailure

#### Constructor & Destructor Documentation

SLNet::Router2::ConnnectRequest::ConnnectRequest | ( |  | ) |

SLNet::Router2::ConnnectRequest::~ConnnectRequest | ( |  | ) |

#### Member Function Documentation

unsigned int SLNet::Router2::ConnnectRequest::GetGuidIndex | ( | RakNetGUID | guid | ) |

#### Member Data Documentation

DataStructures::List<ConnectionRequestSystem> SLNet::Router2::ConnnectRequest::connectionRequestSystems

Definition at line 130 of file Router2.h.

SimpleMutex SLNet::Router2::ConnnectRequest::connectionRequestSystemsMutex

Definition at line 131 of file Router2.h.

RakNetGUID SLNet::Router2::ConnnectRequest::endpointGuid

Definition at line 134 of file Router2.h.

RakNetGUID SLNet::Router2::ConnnectRequest::lastRequestedForwardingSystem

Definition at line 135 of file Router2.h.

SLNet::TimeMS SLNet::Router2::ConnnectRequest::pingTimeout

Definition at line 133 of file Router2.h.

Router2RequestStates SLNet::Router2::ConnnectRequest::requestState

Definition at line 132 of file Router2.h.

bool SLNet::Router2::ConnnectRequest::returnConnectionLostOnFailure

Definition at line 136 of file Router2.h.

struct SLNet::Router2::ForwardedConnection

Definition at line 156 of file Router2.h.

Class Members
RakNetGUID | endpointGuid |
SystemAddress | intermediaryAddress |
RakNetGUID | intermediaryGuid |
bool | returnConnectionLostOnFailure |
bool | weInitiatedForwarding |

struct SLNet::Router2::MiniPunchRequest

Definition at line 142 of file Router2.h.

Class Members
SystemAddress | endpointAddress |
RakNetGUID | endpointGuid |
unsigned short | forwardingPort |
__UDPSOCKET__ | forwardingSocket |
bool | gotReplyFromEndpoint |
bool | gotReplyFromSource |
TimeMS | nextAction |
SystemAddress | sourceAddress |
RakNetGUID | sourceGuid |
TimeMS | timeout |