ircproxy  The Ultimate Cyborg

Server Class Reference

#include <Server.h>

List of all members.


Detailed Description

An IRC server.

This class represents an IRC server.

Definition at line 34 of file Server.h.


Public Types

typedef std::vector< unsigned
short > 
ports_type
 The type of the list with ports.

Public Member Functions

 Server (Network &network, std::string const &hostname, unsigned short port, struct in_addr vhost)
 Construct a Server object with DNS name hostname and default listen port default_port.
 Server (void)
 Construct an uninitialized object for the given network.
 Server (Server const &server)
 Copy constructor.
std::string const & hostname (void) const
 The resolvable name of the server that one can connect to (as passed to the constructor).
unsigned short next_port (void) const
 Return the next port we will try to connect to.
void set_next_port (unsigned short next_port)
 Set the next port to connect to.
unsigned short random_port (void) const
 Returns one of the ports of the server that one can connect to.
unsigned short port (void) const
 Returns the port we last tried to connect to.
struct in_addr & vhost (void)
 Returns a reference to the vhost of this server.
struct in_addr vhost (void) const
 Returns the vhost that should be used for this server.
ports_type const & ports (void) const
 A const reference to the list with known port numbers of this server.
Network const & network (void) const
 Return the corresponding network.
Networknetwork (void)
 Return the corresponding network.
void set_network (Network *network)
 Set the final network. Called from Identity::detected_network.
ServerVersion const & version (void) const
 The server version object.
ServerVersionversion (void)
 The server version object.
bool find_port (unsigned short port) const
 Return true if port port is known.
bool add_port (unsigned short port)
 Add port port (duplicates are ignored). Return true when it was a new port.
bool delete_port (unsigned short port)
 Delete port port. Return true when the port was found.
void set_port (unsigned short port)
 Make port the port returned by port().
bool set_irc_name (std::string const &irc_name)
 Set the IRC name of this server. Returns true when not set before.
std::string const & get_irc_name (void) const
 IRC name of the server as set with set_irc_name.
timeval const & last_connection_event (void) const
 Last we attempted to connect to this server.
void attempting_to_connect (void)
 Called when a connect attempt to the server is being made.
void connection_lost (void)
 Called when we disconnected from this server.
void serialize (PersistXML &xml)
 Serialize object to XML.

Private Attributes

std::string M_hostname
 The resolvable name of the server, or IP number if there is no hostname available.
std::string M_irc_name
 The IRC name of the server, as received by the proxy during connect.
ports_type M_ports
 Client listen ports that we successfully connected to in the past.
unsigned short M_default_port
 The last port that was successfully connected to.
unsigned short M_next_port
 The next port that we will try to connect to.
unsigned short M_port
 The port that we try to connect to.
struct in_addr M_vhost
 Vhost to use to connect to server.
NetworkM_network
 Reference to the corresponding network.
timeval M_last_connection_event
 Last time we disconnected or tried to connect to this server.
ServerVersion M_version
 Information about the server version.

Static Private Attributes

static timeval S_last_connection_event_init = { 0, 0 }
 Initial value for M_last_connection_event.

Member Typedef Documentation

typedef std::vector<unsigned short> Server::ports_type

The type of the list with ports.

Definition at line 36 of file Server.h.


Constructor & Destructor Documentation

Server::Server ( Network network,
std::string const &  hostname,
unsigned short  port,
struct in_addr  vhost 
) [inline]

Construct a Server object with DNS name hostname and default listen port default_port.

Definition at line 61 of file Server.h.

References debug::channels::dc::objects.

00061                                                                                                  :
00062       M_hostname(hostname), M_default_port(port), M_next_port(port), M_port(0), M_vhost(vhost),
00063       M_network(&network), M_last_connection_event(S_last_connection_event_init)
00064       {
00065         Dout(dc::objects, "Constructing Server(" << network << ", \"" << hostname << "\", " << port << ", " << vhost << ")");
00066       }

Server::Server ( void   )  [inline]

Construct an uninitialized object for the given network.

Definition at line 69 of file Server.h.

References M_vhost, and debug::channels::dc::objects.

00069                : M_next_port(0), M_network(NULL)
00070       {
00071         Dout(dc::objects, "Constructing Server()");
00072         std::memset(&M_vhost, 0, sizeof(struct in_addr));
00073       }

Server::Server ( Server const &  server  )  [inline]

Copy constructor.

Definition at line 76 of file Server.h.

References debug::channels::dc::objects.

00076                                :
00077       M_hostname(server.M_hostname),
00078       M_irc_name(server.M_irc_name),
00079       M_ports(server.M_ports),
00080       M_default_port(server.M_default_port),
00081       M_next_port(server.M_next_port),
00082       M_port(server.M_port),
00083       M_vhost(server.M_vhost),
00084       M_network(server.M_network),
00085       M_last_connection_event(server.M_last_connection_event)
00086       { Dout(dc::objects, "Copy-constructing Server from " << server); }


Member Function Documentation

std::string const& Server::hostname ( void   )  const [inline]

The resolvable name of the server that one can connect to (as passed to the constructor).

Definition at line 89 of file Server.h.

References M_hostname.

Referenced by operator<<().

00089 { return M_hostname; }

unsigned short Server::next_port ( void   )  const [inline]

Return the next port we will try to connect to.

Definition at line 92 of file Server.h.

References M_next_port.

00092 { return M_next_port; }

void Server::set_next_port ( unsigned short  next_port  )  [inline]

Set the next port to connect to.

Definition at line 95 of file Server.h.

References M_next_port.

00095 { M_next_port = next_port; }

unsigned short Server::random_port ( void   )  const

Returns one of the ports of the server that one can connect to.

Definition at line 45 of file Server.cc.

References M_default_port, and M_ports.

Referenced by attempting_to_connect(), and serialize().

00046 {
00047   static uint64_t seed = (uint64_t)timerRequest.get_now().tv_sec << 32 + timerRequest.get_now().tv_usec;
00048   static boost::rand48 urng(seed);
00049   if (M_ports.empty())
00050     return M_default_port;
00051   boost::uniform_smallint<int> rd(0, M_ports.size() - 1);
00052   return M_ports[rd(urng)];
00053 }

unsigned short Server::port ( void   )  const [inline]

Returns the port we last tried to connect to.

Definition at line 101 of file Server.h.

References M_port.

00101 { return M_port; }

struct in_addr& Server::vhost ( void   )  [inline, read]

Returns a reference to the vhost of this server.

Definition at line 104 of file Server.h.

References M_vhost.

00104 { return M_vhost; }

struct in_addr Server::vhost ( void   )  const [inline, read]

Returns the vhost that should be used for this server.

Definition at line 107 of file Server.h.

References M_vhost.

00107 { return M_vhost; }

ports_type const& Server::ports ( void   )  const [inline]

A const reference to the list with known port numbers of this server.

Definition at line 110 of file Server.h.

References M_ports.

Referenced by operator<<().

00110 { return M_ports; }

Network const& Server::network ( void   )  const [inline]

Return the corresponding network.

Definition at line 113 of file Server.h.

References M_network.

00113 { return *M_network; }

Network& Server::network ( void   )  [inline]

Return the corresponding network.

Definition at line 116 of file Server.h.

References M_network.

00116 { return *M_network; }

void Server::set_network ( Network network  )  [inline]

Set the final network. Called from Identity::detected_network.

Definition at line 119 of file Server.h.

References M_network.

00119 { M_network = network; }

ServerVersion const& Server::version ( void   )  const [inline]

The server version object.

Definition at line 122 of file Server.h.

References M_version.

00122 { return M_version; }

ServerVersion& Server::version ( void   )  [inline]

The server version object.

Definition at line 125 of file Server.h.

References M_version.

00125 { return M_version; }

bool Server::find_port ( unsigned short  port  )  const [inline]

Return true if port port is known.

Definition at line 128 of file Server.h.

References M_ports.

Referenced by add_port().

00129   {
00130     ports_type::const_iterator iter = std::find(M_ports.begin(), M_ports.end(), port);
00131     return iter != M_ports.end(); 
00132   }

bool Server::add_port ( unsigned short  port  )  [inline]

Add port port (duplicates are ignored). Return true when it was a new port.

Definition at line 135 of file Server.h.

References find_port(), and M_ports.

00136     {
00137       bool new_port = !this->find_port(port);
00138       if (new_port)
00139         M_ports.push_back(port);
00140       return new_port;
00141     }

bool Server::delete_port ( unsigned short  port  )  [inline]

Delete port port. Return true when the port was found.

Definition at line 144 of file Server.h.

References M_ports.

Referenced by set_port().

00145     {
00146       ports_type::iterator iter = std::find(M_ports.begin(), M_ports.end(), port);
00147       bool found = iter != M_ports.end();
00148       if (found)
00149         M_ports.erase(iter);
00150       return found;
00151     }

void Server::set_port ( unsigned short  port  )  [inline]

Make port the port returned by port().

Definition at line 154 of file Server.h.

References delete_port(), and M_ports.

00155     {
00156       delete_port(port);
00157       M_ports.insert(M_ports.begin(), port);
00158     }

bool Server::set_irc_name ( std::string const &  irc_name  )  [inline]

Set the IRC name of this server. Returns true when not set before.

Definition at line 161 of file Server.h.

References M_irc_name.

00162     {
00163       bool empty = M_irc_name.empty();
00164       M_irc_name = irc_name;
00165       return empty;
00166     }

std::string const& Server::get_irc_name ( void   )  const [inline]

IRC name of the server as set with set_irc_name.

Definition at line 169 of file Server.h.

References M_irc_name.

Referenced by operator<<().

00169 { return M_irc_name; }

timeval const& Server::last_connection_event ( void   )  const [inline]

Last we attempted to connect to this server.

Definition at line 172 of file Server.h.

References M_last_connection_event.

Referenced by operator<<().

00172 { return M_last_connection_event; }

void Server::attempting_to_connect ( void   )  [inline]

Called when a connect attempt to the server is being made.

Definition at line 175 of file Server.h.

References M_last_connection_event, M_next_port, M_port, and random_port().

00176       {
00177         M_port = M_next_port;
00178         M_next_port = random_port();
00179         M_last_connection_event = timerRequest.get_now();
00180       }

void Server::connection_lost ( void   )  [inline]

Called when we disconnected from this server.

Definition at line 183 of file Server.h.

References M_last_connection_event.

00183 { M_last_connection_event = timerRequest.get_now(); }

void Server::serialize ( PersistXML xml  ) 

Serialize object to XML.

Definition at line 31 of file Server.cc.

References PersistXML::load, M_default_port, M_hostname, M_irc_name, M_last_connection_event, M_next_port, M_ports, M_version, PersistXML::openmode(), random_port(), and PersistXML::serialize().

00032 {
00033   xml.serialize("M_hostname", M_hostname);
00034   xml.serialize("M_irc_name", M_irc_name);
00035   xml.serialize("M_ports", M_ports);
00036   xml.serialize("M_default_port", M_default_port);
00037   xml.serialize("M_last_connection_event.tv_sec", M_last_connection_event.tv_sec);
00038   xml.serialize("M_last_connection_event.tv_usec", M_last_connection_event.tv_usec);
00039   xml.serialize("M_version", M_version);
00040 
00041   if (xml.openmode() == PersistXML::load)
00042     M_next_port = random_port();
00043 }


Member Data Documentation

std::string Server::M_hostname [private]

The resolvable name of the server, or IP number if there is no hostname available.

Definition at line 40 of file Server.h.

Referenced by hostname(), and serialize().

std::string Server::M_irc_name [private]

The IRC name of the server, as received by the proxy during connect.

Definition at line 43 of file Server.h.

Referenced by get_irc_name(), serialize(), and set_irc_name().

Client listen ports that we successfully connected to in the past.

Definition at line 45 of file Server.h.

Referenced by add_port(), delete_port(), find_port(), ports(), random_port(), serialize(), and set_port().

unsigned short Server::M_default_port [private]

The last port that was successfully connected to.

Definition at line 46 of file Server.h.

Referenced by random_port(), and serialize().

unsigned short Server::M_next_port [private]

The next port that we will try to connect to.

Definition at line 47 of file Server.h.

Referenced by attempting_to_connect(), next_port(), serialize(), and set_next_port().

unsigned short Server::M_port [private]

The port that we try to connect to.

Definition at line 48 of file Server.h.

Referenced by attempting_to_connect(), and port().

struct in_addr Server::M_vhost [read, private]

Vhost to use to connect to server.

Definition at line 50 of file Server.h.

Referenced by Server(), and vhost().

Reference to the corresponding network.

Definition at line 52 of file Server.h.

Referenced by network(), and set_network().

Last time we disconnected or tried to connect to this server.

Definition at line 53 of file Server.h.

Referenced by attempting_to_connect(), connection_lost(), last_connection_event(), and serialize().

timeval Server::S_last_connection_event_init = { 0, 0 } [static, private]

Initial value for M_last_connection_event.

Definition at line 55 of file Server.h.

Information about the server version.

Definition at line 57 of file Server.h.

Referenced by serialize(), and version().


The documentation for this class was generated from the following files:

Copyright © 2005-2007 Carlo Wood.  All rights reserved.