Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

ircd_connector Class Reference

Each connection has one or more of these each represents ONE outbound connection to another ircd so each inbound has multiple outbounds. More...

#include <connection.h>

Inheritance diagram for ircd_connector:

Inheritance graph
[legend]
Collaboration diagram for ircd_connector:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ircd_connector ()
 Constructor clears the sendq and initialises the fd to -1.

bool MakeOutboundConnection (char *newhost, int newport)
 Create an outbound connection to a listening socket.

std::string GetServerName ()
 Return the servername on this established connection.

void SetServerName (std::string serv)
 Set the server name of this connection.

int GetDescriptor ()
 Get the file descriptor associated with this connection.

void SetDescriptor (int fd)
 Set the file descriptor for this connection.

int GetState ()
 Get the state flags for this connection.

void SetState (int state)
 Set the state flags for this connection.

char * GetServerIP ()
 Get the ip address (not servername) associated with this connection.

std::string GetDescription ()
 Get the server description of this connection.

void SetDescription (std::string desc)
 Set the server description of this connection.

int GetServerPort ()
 Get the port number being used for this connection If the connection is outbound this will be the remote port otherwise it will be the local port, so it can always be gautanteed as open at the address given in GetServerIP().

void SetServerPort (int p)
 Set the port used by this connection.

bool SetHostAndPort (char *newhost, int newport)
 Set both the host and the port in one operation for this connection.

void CloseConnection ()
 Close the connection by calling close() on its file descriptor This function call updates no other data.

bool AddBuffer (std::string a)
 This method adds text to the ircd connection's buffer.

bool BufferIsComplete ()
 This method returns true if the buffer contains at least one carriage return character, e.g.

void ClearBuffer ()
 This method clears the server's buffer by setting it to an empty string.

std::string GetBuffer ()
 This method retrieves the first string from the tail end of the buffer and advances the tail end of the buffer past the returned string, in a similar manner to strtok().

void SetVersionString (std::string newversion)
 This method sets the version string of the remote server.

std::string GetVersionString ()
 This method returns the version string of the remote server.

bool AddWriteBuf (std::string data)
 Adds data to the connection's sendQ to be flushed later.

bool FlushWriteBuf ()
 Flushes as much of the data from the buffer as possible, and advances the queue pointer to what is left.

void SetWriteError (std::string error)
 Sets the error string for this connection.

std::string GetWriteError ()
 Gets the error string for this connection.

bool HasBufferedOutput ()
 Returns true if there is data to be written that hasn't been sent yet.

bool CheckPing ()
 Checks if the connection replied to its last ping, and if it did sends another and returns true, if not, returns false.

void ResetPing ()
 Resets the ping counter.


Public Attributes

std::string ircdbuffer
 IRCD Buffer for input characters, holds as many lines as are pending - Note that the final line may not be complete and should only be read when there is a
seperator.

char host [MAXBUF]
 When MakeOutboundConnection is called, these public members are filled with the details passed to the function, for future reference.

int port
 When MakeOutboundConnection is called, these public members are filled with the details passed to the function, for future reference.

std::vector< std::string > routes
 Server names of servers that this server is linked to So for A->B->C, if this was the record for B it would contain A and C whilever both servers are connected to B.


Private Member Functions

bool SetHostAddress (char *host, int port)
 PRIVATE function to set the host address and port to connect to.


Private Attributes

sockaddr_in addr
 Sockaddr of the outbound ip and port.

int fd
 File descriptor of the connection.

std::string servername
 Server name.

std::string description
 Server 'GECOS'.

char state
 State.

std::string version
 This string holds the ircd's version response.

std::string sendq
 SendQ of the outbound connector, does not have a limit.

std::string WriteError
 Write error of connection.

time_t nextping
 Time this connection was last pinged.

bool replied
 Did this connection reply to its last ping?


Detailed Description

Each connection has one or more of these each represents ONE outbound connection to another ircd so each inbound has multiple outbounds.

A listening socket that accepts server type connections is represented by one class serverrec. Class serverrec will instantiate several objects of type ircd_connector to represent each established connection, inbound or outbound. So, to determine all linked servers you must walk through all the serverrecs that the core defines, and in each one iterate through until you find connection(s) relating to the server you want information on. The core and module API provide functions for this.

Definition at line 56 of file connection.h.


Constructor & Destructor Documentation

ircd_connector::ircd_connector  ) 
 

Constructor clears the sendq and initialises the fd to -1.


Member Function Documentation

bool ircd_connector::AddBuffer std::string  a  ) 
 

This method adds text to the ircd connection's buffer.

Parameters:
a The text to add to the buffer up to a maximum size of 1MB
This buffer's maximum size is one megabyte, the method returning false if the buffer is full.

Returns:
True on success, false if the buffer is full or the connection is down

bool ircd_connector::AddWriteBuf std::string  data  ) 
 

Adds data to the connection's sendQ to be flushed later.

Parameters:
data The data to add to the write buffer
Fails if there is an error pending on the connection.

Returns:
True on success, false if the connection is down or the buffer is full

Referenced by serverrec::SendPacket().

bool ircd_connector::BufferIsComplete  ) 
 

This method returns true if the buffer contains at least one carriage return character, e.g.

one line can be read from the buffer successfully.

Returns:
True if there is at least one complete line waiting to be processed

bool ircd_connector::CheckPing  ) 
 

Checks if the connection replied to its last ping, and if it did sends another and returns true, if not, returns false.

Returns:
True if the server is still replying to pings

void ircd_connector::ClearBuffer  ) 
 

This method clears the server's buffer by setting it to an empty string.

void ircd_connector::CloseConnection  ) 
 

Close the connection by calling close() on its file descriptor This function call updates no other data.

Referenced by serverrec::SendPacket().

bool ircd_connector::FlushWriteBuf  ) 
 

Flushes as much of the data from the buffer as possible, and advances the queue pointer to what is left.

Returns:
True if the flush succeeded, false if the connection is down

Referenced by serverrec::SendPacket().

std::string ircd_connector::GetBuffer  ) 
 

This method retrieves the first string from the tail end of the buffer and advances the tail end of the buffer past the returned string, in a similar manner to strtok().

Returns:
The first line of the buffer up to a carriage return

std::string ircd_connector::GetDescription  ) 
 

Get the server description of this connection.

Returns:
The description (GECOS) of this connection

int ircd_connector::GetDescriptor  ) 
 

Get the file descriptor associated with this connection.

Returns:
The file descriptor associated with this connection

char* ircd_connector::GetServerIP  ) 
 

Get the ip address (not servername) associated with this connection.

Returns:
The connections IP address in dotted decimal form

std::string ircd_connector::GetServerName  ) 
 

Return the servername on this established connection.

Referenced by serverrec::SendPacket().

int ircd_connector::GetServerPort  ) 
 

Get the port number being used for this connection If the connection is outbound this will be the remote port otherwise it will be the local port, so it can always be gautanteed as open at the address given in GetServerIP().

Returns:
The port number of this connection

int ircd_connector::GetState  ) 
 

Get the state flags for this connection.

Returns:
The state flags associated with this connection

Referenced by serverrec::SendPacket().

std::string ircd_connector::GetVersionString  ) 
 

This method returns the version string of the remote server.

If the server has no version string an empty string is returned.

Returns:
The version text of this connection

std::string ircd_connector::GetWriteError  ) 
 

Gets the error string for this connection.

Returns:
The last error to occur or an empty string

Referenced by serverrec::SendPacket().

bool ircd_connector::HasBufferedOutput  ) 
 

Returns true if there is data to be written that hasn't been sent yet.

Returns:
True if the buffer is not empty

bool ircd_connector::MakeOutboundConnection char *  newhost,
int  newport
 

Create an outbound connection to a listening socket.

Referenced by serverrec::BeginLink(), and serverrec::MeshCookie().

void ircd_connector::ResetPing  ) 
 

Resets the ping counter.

void ircd_connector::SetDescription std::string  desc  ) 
 

Set the server description of this connection.

Parameters:
desc The description (GECOS) of this connection to be set

void ircd_connector::SetDescriptor int  fd  ) 
 

Set the file descriptor for this connection.

Parameters:
fd The file descriptor to associate with the connection

Referenced by serverrec::AddIncoming().

bool ircd_connector::SetHostAddress char *  host,
int  port
[private]
 

PRIVATE function to set the host address and port to connect to.

bool ircd_connector::SetHostAndPort char *  newhost,
int  newport
 

Set both the host and the port in one operation for this connection.

Parameters:
newhost The hostname to set for this connection
newport The port number to set for this connection
Returns:
True on success, false on failure

Referenced by serverrec::AddIncoming(), serverrec::BeginLink(), and serverrec::MeshCookie().

void ircd_connector::SetServerName std::string  serv  ) 
 

Set the server name of this connection.

Parameters:
serv The server name to set

Referenced by serverrec::AddIncoming(), serverrec::BeginLink(), and serverrec::MeshCookie().

void ircd_connector::SetServerPort int  p  ) 
 

Set the port used by this connection.

Parameters:
p The port number to set for this connection

void ircd_connector::SetState int  state  ) 
 

Set the state flags for this connection.

Parameters:
state The state flags to set for this connection

Referenced by serverrec::AddIncoming(), serverrec::BeginLink(), serverrec::MeshCookie(), and serverrec::SendPacket().

void ircd_connector::SetVersionString std::string  newversion  ) 
 

This method sets the version string of the remote server.

Parameters:
newversion The version string to set

void ircd_connector::SetWriteError std::string  error  ) 
 

Sets the error string for this connection.

Parameters:
error The error string to set


Member Data Documentation

sockaddr_in ircd_connector::addr [private]
 

Sockaddr of the outbound ip and port.

Definition at line 61 of file connection.h.

std::string ircd_connector::description [private]
 

Server 'GECOS'.

Definition at line 73 of file connection.h.

int ircd_connector::fd [private]
 

File descriptor of the connection.

Definition at line 65 of file connection.h.

char ircd_connector::host[MAXBUF]
 

When MakeOutboundConnection is called, these public members are filled with the details passed to the function, for future reference.

Definition at line 117 of file connection.h.

std::string ircd_connector::ircdbuffer
 

IRCD Buffer for input characters, holds as many lines as are pending - Note that the final line may not be complete and should only be read when there is a
seperator.

Definition at line 110 of file connection.h.

time_t ircd_connector::nextping [private]
 

Time this connection was last pinged.

Definition at line 98 of file connection.h.

int ircd_connector::port
 

When MakeOutboundConnection is called, these public members are filled with the details passed to the function, for future reference.

Definition at line 123 of file connection.h.

bool ircd_connector::replied [private]
 

Did this connection reply to its last ping?

Definition at line 102 of file connection.h.

std::vector<std::string> ircd_connector::routes
 

Server names of servers that this server is linked to So for A->B->C, if this was the record for B it would contain A and C whilever both servers are connected to B.

Definition at line 129 of file connection.h.

std::string ircd_connector::sendq [private]
 

SendQ of the outbound connector, does not have a limit.

Definition at line 90 of file connection.h.

std::string ircd_connector::servername [private]
 

Server name.

Definition at line 69 of file connection.h.

char ircd_connector::state [private]
 

State.

STATE_NOAUTH_INBOUND, STATE_NOAUTH_OUTBOUND STATE_SYNC, STATE_DISCONNECTED, STATE_CONNECTED

Definition at line 78 of file connection.h.

std::string ircd_connector::version [private]
 

This string holds the ircd's version response.

Definition at line 86 of file connection.h.

std::string ircd_connector::WriteError [private]
 

Write error of connection.

Definition at line 94 of file connection.h.


The documentation for this class was generated from the following file:
Generated on Mon May 30 05:17:18 2005 for InspIRCd by doxygen 1.3.3