ionflux.org | Impressum

Ionflux::Tools::TCPAuthServer Class Reference
[Network interface]

Authenticated TCP server. More...

#include <TCPAuthServer.hpp>

Inheritance diagram for Ionflux::Tools::TCPAuthServer:

Inheritance graph
[legend]
Collaboration diagram for Ionflux::Tools::TCPAuthServer:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TCPAuthServer ()
 Constructor.
 TCPAuthServer (const std::string &initAuthFileName)
 Constructor.
virtual ~TCPAuthServer ()
 Destructor.
virtual void onMessage (TCPRemotePeer &peer)
 Event handler for received messages.
virtual void onInvalidMessage (TCPRemotePeer &peer)
 Event handler for invalid messages.
virtual void broadcast (const std::string &bytes)
 Broadcast bytes.
virtual void setAuth (Auth *newAuth)
 Set authentication facility.
virtual void setAuthFileName (const std::string &newAuthFileName)
 Set authentication file name.
virtual void setCurrentMsgID (unsigned int newCurrentMsgID)
 Set current Message ID.
virtual AuthgetAuth ()
 Get authentication facility.
virtual std::string getAuthFileName ()
 Get authentication file name.
virtual unsigned int getCurrentMsgID ()
 Get current Message ID.

Static Public Attributes

static const std::string MAGIC_WORD = "IFTA"
 Magic word.
static const unsigned int AUTH_VERSION = 0x000001L
 Protocol version.
static const unsigned int AUTH_VERSION_UPPER = 0x000001L
 Protocol version (upper boundary).
static const unsigned int AUTH_VERSION_LOWER = 0x000001L
 Protocol version (lower boundary).
static const int MSGID_HELLO = 101
 Message type ID: HELLO.
static const int MSGID_WELCOME = 201
 Message type ID: WELCOME.
static const int MSGID_AUTH = 102
 Message type ID: AUTH.
static const int MSGID_AUTH_OK = 202
 Message type ID: AUTH_OK.
static const int MSGID_AUTH_FAILED = 401
 Message type ID: AUTH_FAILED.
static const int PS_WAIT_HELLO = 1
 Protocol state: Wait for HELLO.
static const int PS_WAIT_AUTH = 2
 Protocol state: Wait for AUTH.
static const int PS_AUTH_OK = 3
 Protocol state: Authentication succeeded.

Protected Member Functions

virtual void onConnect (TCPRemotePeer &client)
 Event handler for new connections.
virtual void onAuthMessage (TCPRemotePeer &peer)
 Event handler for authenticated messages.
virtual void onAuthOK (TCPRemotePeer &peer)
 Event handler for successful authentication.
virtual void onAuthFailed (TCPRemotePeer &peer)
 Event handler for failed authentication.

Protected Attributes

Authauth
 Authentication facility.
std::string authFileName
 Authentication file name.
unsigned int currentMsgID
 Current Message ID.
MTRand * randomizer
 Randomizer.

Detailed Description

Authenticated TCP server.

A Message based TCP server supporting a simple client authentication protocol.

To define your own protocol on top of an authenticated connection, override the TCPAuthServer::onAuthMessage() function. The TCPAuthServer will handle all the rest for you. If you want to define additional protocol states for your own protocol, the associated values must be of the form TCPAuthServer::PS_AUTH_OK + n, where n is a positive integer.

See misc/ifta.txt for a specification of the authentication protocol.


Constructor & Destructor Documentation

Ionflux::Tools::TCPAuthServer::TCPAuthServer  ) 
 

Constructor.

Construct new TCPAuthServer object.

Ionflux::Tools::TCPAuthServer::TCPAuthServer const std::string &  initAuthFileName  ) 
 

Constructor.

Construct new TCPAuthServer object.

Parameters:
initAuthFileName Authentication file name.

Ionflux::Tools::TCPAuthServer::~TCPAuthServer  )  [virtual]
 

Destructor.

Destruct TCPAuthServer object.


Member Function Documentation

void Ionflux::Tools::TCPAuthServer::broadcast const std::string &  bytes  )  [virtual]
 

Broadcast bytes.

Sends the specified byte string to all connected peers.

Parameters:
bytes The bytes to broadcast.

Reimplemented from Ionflux::Tools::TCPMessageServer.

Auth * Ionflux::Tools::TCPAuthServer::getAuth  )  [virtual]
 

Get authentication facility.

Returns:
Pointer to the authentication facility used by this server.

std::string Ionflux::Tools::TCPAuthServer::getAuthFileName  )  [virtual]
 

Get authentication file name.

Returns:
Name of the authentication file, or an empty string if the authentication file is not set.

unsigned int Ionflux::Tools::TCPAuthServer::getCurrentMsgID  )  [virtual]
 

Get current Message ID.

Returns:
Current message ID.

void Ionflux::Tools::TCPAuthServer::onAuthFailed TCPRemotePeer peer  )  [protected, virtual]
 

Event handler for failed authentication.

This is called when authentication with a peer has failed.

Note:
Override this to implement your own authentication failure handling.
Parameters:
peer The peer which caused the event.

void Ionflux::Tools::TCPAuthServer::onAuthMessage TCPRemotePeer peer  )  [protected, virtual]
 

Event handler for authenticated messages.

This is called whenever a message is received from an authenticated peer. The received message will be available from TCPRemotePeer::getMessage().

Note:
Override this to implement your own authenticated message handling.
Parameters:
peer The peer which caused the event.

void Ionflux::Tools::TCPAuthServer::onAuthOK TCPRemotePeer peer  )  [protected, virtual]
 

Event handler for successful authentication.

This is called when authentication with a peer has succeeded.

Note:
Override this to implement your own authentication success handling.
Parameters:
peer The peer which caused the event.

void Ionflux::Tools::TCPAuthServer::onConnect TCPRemotePeer client  )  [protected, virtual]
 

Event handler for new connections.

This is called by the main loop whenever a new client connects.

Note:
Override this to implement your own connection handling.
Parameters:
client The client which caused the event.

Reimplemented from Ionflux::Tools::TCPMessageServer.

void Ionflux::Tools::TCPAuthServer::onInvalidMessage TCPRemotePeer peer  )  [virtual]
 

Event handler for invalid messages.

This is called whenever an invalid message is received from a peer.

Note:
Override this to implement your own invalid message handling.
Parameters:
peer The peer which caused the event.

Reimplemented from Ionflux::Tools::TCPMessageServer.

void Ionflux::Tools::TCPAuthServer::onMessage TCPRemotePeer peer  )  [virtual]
 

Event handler for received messages.

This is called whenever a valid message is received from a peer. The received message will be available from TCPRemotePeer::getMessage().

Note:
Override this to implement your own message handling.
Parameters:
peer The peer which caused the event.

Reimplemented from Ionflux::Tools::TCPMessageServer.

void Ionflux::Tools::TCPAuthServer::setAuth Auth newAuth  )  [virtual]
 

Set authentication facility.

Set new value of authentication facility.

Parameters:
newAuth New value of authentication facility.

void Ionflux::Tools::TCPAuthServer::setAuthFileName const std::string &  newAuthFileName  )  [virtual]
 

Set authentication file name.

Set new value of authentication file name.

Parameters:
newAuthFileName New value of authentication file name.

void Ionflux::Tools::TCPAuthServer::setCurrentMsgID unsigned int  newCurrentMsgID  )  [virtual]
 

Set current Message ID.

Set new value of current Message ID.

Parameters:
newCurrentMsgID New value of current Message ID.


Member Data Documentation

Auth* Ionflux::Tools::TCPAuthServer::auth [protected]
 

Authentication facility.

const unsigned int Ionflux::Tools::TCPAuthServer::AUTH_VERSION = 0x000001L [static]
 

Protocol version.

const unsigned int Ionflux::Tools::TCPAuthServer::AUTH_VERSION_LOWER = 0x000001L [static]
 

Protocol version (lower boundary).

const unsigned int Ionflux::Tools::TCPAuthServer::AUTH_VERSION_UPPER = 0x000001L [static]
 

Protocol version (upper boundary).

std::string Ionflux::Tools::TCPAuthServer::authFileName [protected]
 

Authentication file name.

unsigned int Ionflux::Tools::TCPAuthServer::currentMsgID [protected]
 

Current Message ID.

const std::string Ionflux::Tools::TCPAuthServer::MAGIC_WORD = "IFTA" [static]
 

Magic word.

const int Ionflux::Tools::TCPAuthServer::MSGID_AUTH = 102 [static]
 

Message type ID: AUTH.

const int Ionflux::Tools::TCPAuthServer::MSGID_AUTH_FAILED = 401 [static]
 

Message type ID: AUTH_FAILED.

const int Ionflux::Tools::TCPAuthServer::MSGID_AUTH_OK = 202 [static]
 

Message type ID: AUTH_OK.

const int Ionflux::Tools::TCPAuthServer::MSGID_HELLO = 101 [static]
 

Message type ID: HELLO.

const int Ionflux::Tools::TCPAuthServer::MSGID_WELCOME = 201 [static]
 

Message type ID: WELCOME.

const int Ionflux::Tools::TCPAuthServer::PS_AUTH_OK = 3 [static]
 

Protocol state: Authentication succeeded.

const int Ionflux::Tools::TCPAuthServer::PS_WAIT_AUTH = 2 [static]
 

Protocol state: Wait for AUTH.

const int Ionflux::Tools::TCPAuthServer::PS_WAIT_HELLO = 1 [static]
 

Protocol state: Wait for HELLO.

MTRand* Ionflux::Tools::TCPAuthServer::randomizer [protected]
 

Randomizer.


The documentation for this class was generated from the following files:
Generated on Tue Mar 14 21:10:39 2006 for Ionflux Tools Class Library (iftools) by  doxygen 1.4.6