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
NatTypeDetection
Plugins

Use a remote server with multiple IP addresses to determine what type of NAT your router is using. More...

## Classes

class | SLNet::NatTypeDetectionClient
| Client code for NatTypeDetection. More...
class | SLNet::NatTypeDetectionServer
| Server code for NatTypeDetection. More...
struct | SLNet::NatTypeDetectionServer::NATDetectionAttempt

## Detailed Description

Use a remote server with multiple IP addresses to determine what type of NAT your router is using.

## Class Documentation

class SLNet::NatTypeDetectionClient

Client code for NatTypeDetection.

See NatTypeDetectionServer.h for algorithm To use, just connect to the server, and call DetectNAT You will get back ID_NAT_TYPE_DETECTION_RESULT with one of the enumerated values of NATTypeDetectionResult found in NATTypeDetectionCommon.h See also http://www.jenkinssoftware.com/raknet/manual/natpunchthrough.html

See Also
  NatPunchthroughClient
  NatTypeDetectionServer

Definition at line 50 of file NatTypeDetectionClient.h.

Inheritance diagram for SLNet::NatTypeDetectionClient:

### Public Member Functions

| NatTypeDetectionClient ()
virtual | ~NatTypeDetectionClient ()
void | DetectNATType (SystemAddress _serverAddress)
virtual void | Update (void)
| Update is called every time a packet is checked for .
virtual PluginReceiveResult | OnReceive (Packet *packet)
virtual void | OnClosedConnection (const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason)
virtual void | OnRakPeerShutdown (void)
| Called when RakPeer is shutdown.
virtual void | OnDetach (void)
| Called when the interface is detached.
virtual void | OnRNS2Recv (RNS2RecvStruct *recvStruct)
virtual void | DeallocRNS2RecvStruct (RNS2RecvStruct *s, const char *file, unsigned int line)
virtual RNS2RecvStruct * | AllocRNS2RecvStruct (const char *file, unsigned int line)
Public Member Functions inherited from SLNet::PluginInterface2
| PluginInterface2 ()
virtual | ~PluginInterface2 ()
virtual void | OnAttach (void)
| Called when the interface is attached.
virtual void | OnRakPeerStartup (void)
| Called when RakPeer is initialized.
virtual void | OnNewConnection (const SystemAddress &systemAddress, RakNetGUID rakNetGUID, bool isIncoming)
virtual void | OnFailedConnectionAttempt (Packet *packet, PI2_FailedConnectionAttemptReason failedConnectionAttemptReason)
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)
Public Member Functions inherited from SLNet::RNS2EventHandler
| RNS2EventHandler ()
virtual | ~RNS2EventHandler ()

### Protected Member Functions

void | Shutdown (void)
void | OnCompletion (NATTypeDetectionResult result)
bool | IsInProgress (void) const
void | OnTestPortRestricted (Packet *packet)
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

DataStructures::Queue < RNS2RecvStruct * > | bufferedPackets
SimpleMutex | bufferedPacketsMutex
RakNetSocket2 * | c2
SystemAddress | serverAddress
Protected Attributes inherited from SLNet::PluginInterface2
RakPeerInterface * | rakPeerInterface
TCPInterface * | tcpInterface

#### Constructor & Destructor Documentation

SLNet::NatTypeDetectionClient::NatTypeDetectionClient | ( |  | ) |

virtual SLNet::NatTypeDetectionClient::~NatTypeDetectionClient | ( |  | ) |

virtual

#### Member Function Documentation

virtual RNS2RecvStruct* SLNet::NatTypeDetectionClient::AllocRNS2RecvStruct | ( | const char * | file,
|  | unsigned int | line
| ) |  |

virtual

Implements SLNet::RNS2EventHandler.

virtual void SLNet::NatTypeDetectionClient::DeallocRNS2RecvStruct | ( | RNS2RecvStruct * | s,
|  | const char * | file,
|  | unsigned int | line
| ) |  |

virtual

Implements SLNet::RNS2EventHandler.

void SLNet::NatTypeDetectionClient::DetectNATType | ( | SystemAddress | _serverAddress | ) |

Send the message to the server to detect the nat type Server must be running NatTypeDetectionServer We must already be connected to the server

Parameters

  [in] | serverAddress | address of the server

bool SLNet::NatTypeDetectionClient::IsInProgress | ( | void |  | ) | const

protected

virtual void SLNet::NatTypeDetectionClient::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.

void SLNet::NatTypeDetectionClient::OnCompletion | ( | NATTypeDetectionResult | result | ) |

protected

virtual void SLNet::NatTypeDetectionClient::OnDetach | ( | void |  | ) |

virtual

Called when the interface is detached.

Reimplemented from SLNet::PluginInterface2.

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

virtual

Called when RakPeer is shutdown.

Reimplemented from SLNet::PluginInterface2.

virtual PluginReceiveResult SLNet::NatTypeDetectionClient::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.

virtual void SLNet::NatTypeDetectionClient::OnRNS2Recv | ( | RNS2RecvStruct * | recvStruct | ) |

virtual

Implements SLNet::RNS2EventHandler.

void SLNet::NatTypeDetectionClient::OnTestPortRestricted | ( | Packet * | packet | ) |

protected

void SLNet::NatTypeDetectionClient::Shutdown | ( | void |  | ) |

protected

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

virtual

Update is called every time a packet is checked for .

Reimplemented from SLNet::PluginInterface2.

#### Member Data Documentation

DataStructures::Queue<RNS2RecvStruct*> SLNet::NatTypeDetectionClient::bufferedPackets

protected

Definition at line 83 of file NatTypeDetectionClient.h.

SimpleMutex SLNet::NatTypeDetectionClient::bufferedPacketsMutex

protected

Definition at line 84 of file NatTypeDetectionClient.h.

RakNetSocket2* SLNet::NatTypeDetectionClient::c2

protected

Definition at line 86 of file NatTypeDetectionClient.h.

SystemAddress SLNet::NatTypeDetectionClient::serverAddress

protected

Definition at line 93 of file NatTypeDetectionClient.h.

class SLNet::NatTypeDetectionServer

Server code for NatTypeDetection.

Sends to a remote system on certain ports and addresses to determine what type of router, if any, that client is behind Requires that the server have 4 external IP addresses

1. Server has 1 instance of RakNet. Server has four external ip addresses S1 to S4. Five ports are used in total P1 to P5. RakNet is bound to S1P1. Sockets are bound to S1P2, S2P3, S3P4, S4P5
2. Client with one port using RakNet (C1). Another port not using anything (C2).
3. C1 connects to S1P1 for normal communication.
4. S4P5 sends to C2. If arrived, no NAT. Done. (If didn't arrive, S4P5 potentially banned, do not use again).
5. S2P3 sends to C1 (Different address, different port, to previously used port on client). If received, Full-cone nat. Done. (If didn't arrive, S2P3 potentially banned, do not use again).
6. S1P2 sends to C1 (Same address, different port, to previously used port on client). If received, address-restricted cone nat. Done.
7. Server via RakNet connection tells C1 to send to to S3P4. If address of C1 as seen by S3P4 is the same as the address of C1 as seen by S1P1 (RakNet connection), then port-restricted cone nat. Done
8. Else symmetric nat. Done.

See also http://www.jenkinssoftware.com/raknet/manual/natpunchthrough.html

See Also
  NatPunchthroughServer
  NatTypeDetectionClient

Definition at line 60 of file NatTypeDetectionServer.h.

Inheritance diagram for SLNet::NatTypeDetectionServer:

### Public Types

enum | NATDetectionState { STATE_NONE, STATE_TESTING_NONE_1, STATE_TESTING_NONE_2, STATE_TESTING_FULL_CONE_1, STATE_TESTING_FULL_CONE_2, STATE_TESTING_ADDRESS_RESTRICTED_1, STATE_TESTING_ADDRESS_RESTRICTED_2, STATE_TESTING_PORT_RESTRICTED_1, STATE_TESTING_PORT_RESTRICTED_2, STATE_DONE }

### Public Member Functions

| NatTypeDetectionServer ()
virtual | ~NatTypeDetectionServer ()
void | Startup (const char *nonRakNetIP2, const char *nonRakNetIP3, const char *nonRakNetIP4)
void | Shutdown (void)
virtual void | Update (void)
| Update is called every time a packet is checked for .
virtual PluginReceiveResult | OnReceive (Packet *packet)
virtual void | OnClosedConnection (const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason)
virtual void | OnRNS2Recv (RNS2RecvStruct *recvStruct)
virtual void | DeallocRNS2RecvStruct (RNS2RecvStruct *s, const char *file, unsigned int line)
virtual RNS2RecvStruct * | AllocRNS2RecvStruct (const char *file, unsigned int line)
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 | OnRakPeerShutdown (void)
| Called when RakPeer is shutdown.
virtual void | OnNewConnection (const SystemAddress &systemAddress, RakNetGUID rakNetGUID, bool isIncoming)
virtual void | OnFailedConnectionAttempt (Packet *packet, PI2_FailedConnectionAttemptReason failedConnectionAttemptReason)
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)
Public Member Functions inherited from SLNet::RNS2EventHandler
| RNS2EventHandler ()
virtual | ~RNS2EventHandler ()

### Protected Member Functions

void | OnDetectionRequest (Packet *packet)
unsigned int | GetDetectionAttemptIndex (const SystemAddress &sa)
unsigned int | GetDetectionAttemptIndex (RakNetGUID guid)
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

DataStructures::Queue < RNS2RecvStruct * > | bufferedPackets
SimpleMutex | bufferedPacketsMutex
DataStructures::List < NATDetectionAttempt > | natDetectionAttempts
RakNetSocket2 * | s1p2
RakNetSocket2 * | s2p3
RakNetSocket2 * | s3p4
RakNetSocket2 * | s4p5
char | s3p4Address [64]
Protected Attributes inherited from SLNet::PluginInterface2
RakPeerInterface * | rakPeerInterface
TCPInterface * | tcpInterface

#### Member Enumeration Documentation

enum SLNet::NatTypeDetectionServer::NATDetectionState

Enumerator:

  STATE_NONE |
  STATE_TESTING_NONE_1 |
  STATE_TESTING_NONE_2 |
  STATE_TESTING_FULL_CONE_1 |
  STATE_TESTING_FULL_CONE_2 |
  STATE_TESTING_ADDRESS_RESTRICTED_1 |
  STATE_TESTING_ADDRESS_RESTRICTED_2 |
  STATE_TESTING_PORT_RESTRICTED_1 |
  STATE_TESTING_PORT_RESTRICTED_2 |
  STATE_DONE |

Definition at line 96 of file NatTypeDetectionServer.h.

#### Constructor & Destructor Documentation

SLNet::NatTypeDetectionServer::NatTypeDetectionServer | ( |  | ) |

virtual SLNet::NatTypeDetectionServer::~NatTypeDetectionServer | ( |  | ) |

virtual

#### Member Function Documentation

virtual RNS2RecvStruct* SLNet::NatTypeDetectionServer::AllocRNS2RecvStruct | ( | const char * | file,
|  | unsigned int | line
| ) |  |

virtual

Implements SLNet::RNS2EventHandler.

virtual void SLNet::NatTypeDetectionServer::DeallocRNS2RecvStruct | ( | RNS2RecvStruct * | s,
|  | const char * | file,
|  | unsigned int | line
| ) |  |

virtual

Implements SLNet::RNS2EventHandler.

unsigned int SLNet::NatTypeDetectionServer::GetDetectionAttemptIndex | ( | const SystemAddress & | sa | ) |

protected

unsigned int SLNet::NatTypeDetectionServer::GetDetectionAttemptIndex | ( | RakNetGUID | guid | ) |

protected

virtual void SLNet::NatTypeDetectionServer::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.

void SLNet::NatTypeDetectionServer::OnDetectionRequest | ( | Packet * | packet | ) |

protected

virtual PluginReceiveResult SLNet::NatTypeDetectionServer::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.

virtual void SLNet::NatTypeDetectionServer::OnRNS2Recv | ( | RNS2RecvStruct * | recvStruct | ) |

virtual

Implements SLNet::RNS2EventHandler.

void SLNet::NatTypeDetectionServer::Shutdown | ( | void |  | ) |

void SLNet::NatTypeDetectionServer::Startup | ( | const char * | nonRakNetIP2,
|  | const char * | nonRakNetIP3,
|  | const char * | nonRakNetIP4
| ) |  |

Start the system, binding to 3 external IPs not already in useS

Parameters

  [in] | nonRakNetIP2 | First unused external IP
  [in] | nonRakNetIP3 | Second unused external IP
  [in] | nonRakNetIP4 | Third unused external IP

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

virtual

Update is called every time a packet is checked for .

Reimplemented from SLNet::PluginInterface2.

#### Member Data Documentation

DataStructures::Queue<RNS2RecvStruct*> SLNet::NatTypeDetectionServer::bufferedPackets

protected

Definition at line 124 of file NatTypeDetectionServer.h.

SimpleMutex SLNet::NatTypeDetectionServer::bufferedPacketsMutex

protected

Definition at line 125 of file NatTypeDetectionServer.h.

DataStructures::List<NATDetectionAttempt> SLNet::NatTypeDetectionServer::natDetectionAttempts

protected

Definition at line 128 of file NatTypeDetectionServer.h.

RakNetSocket2* SLNet::NatTypeDetectionServer::s1p2

protected

Definition at line 133 of file NatTypeDetectionServer.h.

RakNetSocket2 * SLNet::NatTypeDetectionServer::s2p3

protected

Definition at line 133 of file NatTypeDetectionServer.h.

RakNetSocket2 * SLNet::NatTypeDetectionServer::s3p4

protected

Definition at line 133 of file NatTypeDetectionServer.h.

char SLNet::NatTypeDetectionServer::s3p4Address[64]

protected

Definition at line 135 of file NatTypeDetectionServer.h.

RakNetSocket2 * SLNet::NatTypeDetectionServer::s4p5

protected

Definition at line 133 of file NatTypeDetectionServer.h.

struct SLNet::NatTypeDetectionServer::NATDetectionAttempt

Definition at line 110 of file NatTypeDetectionServer.h.

Class Members
unsigned short | c2Port |
NATDetectionState | detectionState |
RakNetGUID | guid |
TimeMS | nextStateTime |
SystemAddress | systemAddress |
TimeMS | timeBetweenAttempts |