ReplicaNet and RNLobby  1
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
BaseTransportServer Class Reference

A server base class that handles encrypted messages to and from a transport. More...

#include <BaseTransportServer.h>

Inheritance diagram for BaseTransportServer:
Inheritance graph
[legend]
Collaboration diagram for BaseTransportServer:
Collaboration graph
[legend]

Classes

struct  Entry
 

Public Member Functions

void SetEncryptionKey (const void *data, const int length)
 
virtual bool StartWithTransport (Transport *transport, const bool allowDelete=true, const bool isListen=true)
 
virtual bool Stop (void)
 
size_t GetNumConnections (void) const
 Returns the number of active connections.
 
size_t GetNumTotalSessions (void) const
 Returns the total number of connections.
 
bool SetAsDisconnecting (Transport *transport)
 This will put the connection into a list pending disconnection after a timeout period.
 
- Public Member Functions inherited from ThreadClass
 ThreadClass ()
 
virtual ~ThreadClass ()
 
void Sleep (int milliseconds)
 
- Public Member Functions inherited from MutexClass
 MutexClass ()
 
virtual ~MutexClass ()
 
void Lock (void)
 
void UnLock (void)
 
- Public Member Functions inherited from Thread
 Thread ()
 
virtual ~Thread ()
 
void Begin (ThreadClass *threaded_class)
 
void Terminate (void)
 
bool GetTerminated (void)
 
bool GetEverTerminated (void)
 
bool GetIsRunning (void) const
 
void SetPreferredProcessor (int processor=kReplicaNetPreferredProcessorOSChoice)
 
int GetPreferredProcessor (void)
 

Static Public Member Functions

static SysTimeType FloatTime (void)
 
- Static Public Member Functions inherited from Thread
static int CallThreadEntry (ThreadClass *thread_class)
 
static int GetCurrentProcessorNumber (void)
 
static size_t GetNumAllocated (void)
 
static size_t GetNumActive (void)
 

Protected Member Functions

virtual bool CallbackParseValidMessage (Transport *transport, DynamicMessageHelper &message, const size_t length)
 
virtual bool PackageAndSendData (Transport *transport, const DynamicMessageHelper &message)
 The class mutex is locked during the context of this function.
 
virtual bool CallbackParsePacketData (Transport *transport, void *data, size_t &length, DynamicMessageHelper &result, Entry &entry)
 
virtual void CallbackAccepted (Transport *transport)
 Called when the server accepts a connection or when a non-listen class instance connection gets a first valid reply from the server.
 
virtual void CallbackDisconnected (Transport *transport)
 Called when the transport is disconnected. This is also called if there is a problem trying to connect. It is therefore possible for a non-listen class instance to receive this callback without a corresponding CallbackAccepted()
 
virtual void CallbackDataReceived (DynamicMessageHelper &message)
 
virtual void CallbackDataSend (DynamicMessageHelper &message)
 
virtual void CallbackQueryReplyTime (const float seconds)
 
virtual bool CallbackPoll (void)
 
virtual void CallbackTidy (void)
 
int ThreadEntry (void)
 
void GenerateNewNonce (void)
 
int GetConnectionNOnce (Transport *transport=0, const Entry *entry=0)
 Gets the connection's NOnce with respect to a Transport.
 
int CalculateConnectionNOnce (Transport *transport)
 
const EntryFindEntry (Transport *transport)
 
- Protected Member Functions inherited from ThreadClass
void DoQuitNow (const int returnCode)
 
void CheckQuit (void)
 

Protected Attributes

TransportmTransport
 
bool mAllowDelete
 
int mNOnce
 
std::map< Transport *, EntrymConnected
 
bool mIsListen
 
bool mClientGotAPacket
 
bool mClientIsStable
 
Entry mClientEntry
 
size_t mNumConnections
 
size_t mNumTotalConnections
 

Additional Inherited Members

- Public Types inherited from MutexClass
enum  { kNoOwnerThread = -1 }
 
- Static Protected Member Functions inherited from ThreadClass
static size_t GetNumAllocated (void)
 

Detailed Description

A server base class that handles encrypted messages to and from a transport.

Member Function Documentation

virtual void CallbackDataReceived ( DynamicMessageHelper message)
inlineprotectedvirtual

This callback may be used to alter data after it has been received and before the data received is processed.

Parameters
messageThe data held in a DynamicMessageHelper class.
virtual void CallbackDataSend ( DynamicMessageHelper message)
inlineprotectedvirtual

This callback may be used to alter any data in a reply, just before it gets sent by the socket.

Parameters
messageThe data held in a DynamicMessageHelper class.
virtual bool CallbackParsePacketData ( Transport transport,
void *  data,
size_t &  length,
DynamicMessageHelper result,
Entry entry 
)
protectedvirtual

The class mutex is locked during the context of this function. The default operation is to decrypt the packet and then set result.SetGuardSize() with the size of the data and then call CallbackParseValidMessage(). This will cause a MessageHepler::Exception() exception to be thrown and may be caught by the user parser routines or will be caught by this server class.

Parameters
resultThe resultant data after decrypting and length will be updated with the new packet length.
virtual bool CallbackParseValidMessage ( Transport transport,
DynamicMessageHelper message,
const size_t  length 
)
inlineprotectedvirtual

Called from the scope of the thread but without the class mutex being locked. If a MessageHelper::Exception() is caught by this server class the connection will be terminated.

Reimplemented in UserClient, AdvertiseClient, and StatClient.

virtual bool CallbackPoll ( void  )
inlineprotectedvirtual

Called from the scope of the thread but without the class mutex being locked. This can be called with or without a valid mTransport

Reimplemented in UserClient, AdvertiseClient, and StatClient.

virtual void CallbackQueryReplyTime ( const float  seconds)
inlineprotectedvirtual

This callback reports how long a query and reply took starting from when packet data was received until the packet data is sent.

Parameters
secondsThe time in seconds.
virtual void CallbackTidy ( void  )
inlineprotectedvirtual

This callback may be used to tidy allocation of objects when the thread terminates. The class mutex is locked when executing this callback.

Reimplemented in UserClient, AdvertiseClient, and StatClient.

void SetEncryptionKey ( const void *  data,
const int  length 
)

Sets the encryption key to be used by all queries for this server. The same key must be used with any other RNLobby::BaseTransportServer querying this server.

Parameters
dataThe data to use as a seed for the key. This can be NULL to use the default key.
lengthThe length of the data to use for creating the key.
virtual bool StartWithTransport ( Transport transport,
const bool  allowDelete = true,
const bool  isListen = true 
)
virtual

Starts the thread. If this function is overridden then this base implementation must also be called.

Parameters
transportThe transport to poll for this class.
allowDeleteWhen true this class is responsible for deleting the socket.
isListenWhen true this class will listen for connections on the
Returns
Success returns true, failure returns false.
virtual bool Stop ( void  )
virtual

Stops the thread. If this function is overridden then this base implementation must also be called. This will not generate CallbackDisconnected() events for any existing connections.

Returns
Success returns true, failure returns false.

Reimplemented in UserClient.

int ThreadEntry ( void  )
protectedvirtual

The thread starts executing from here.

Implements ThreadClass.