1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
17 #include "inspircd_config.h"
21 #include <sys/types.h>
22 #include <sys/socket.h>
24 #include <netinet/in.h>
32 #ifndef __CONNECTION_H__
33 #define __CONNECTION_H__
35 #define STATE_DISCONNECTED 0
36 #define STATE_CONNECTED 1
38 #define STATE_NOAUTH_INBOUND 3
39 #define STATE_NOAUTH_OUTBOUND 4
40 #define STATE_SERVICES 5
42 std::string CreateSum();
44 /** Each connection has one or more of these
45 * each represents ONE outbound connection to another ircd
46 * so each inbound has multiple outbounds. A listening socket
47 * that accepts server type connections is represented by one
48 * class serverrec. Class serverrec will instantiate several
49 * objects of type ircd_connector to represent each established
50 * connection, inbound or outbound. So, to determine all linked
51 * servers you must walk through all the serverrecs that the
52 * core defines, and in each one iterate through until you find
53 * connection(s) relating to the server you want information on.
54 * The core and module API provide functions for this.
56 class ircd_connector : public Extensible
59 /** Sockaddr of the outbound ip and port
63 /** File descriptor of the connection
69 std::string servername;
73 std::string description;
75 /** State. STATE_NOAUTH_INBOUND, STATE_NOAUTH_OUTBOUND
76 * STATE_SYNC, STATE_DISCONNECTED, STATE_CONNECTED
80 /** PRIVATE function to set the host address and port to connect to
82 bool SetHostAddress(char* host, int port);
84 /** This string holds the ircd's version response
90 /** IRCD Buffer for input characters, holds as many lines as are
91 * pending - Note that the final line may not be complete and should
92 * only be read when there is a \n seperator.
94 std::string ircdbuffer;
97 /** When MakeOutboundConnection is called, these public members are
98 * filled with the details passed to the function, for future
103 /** When MakeOutboundConnection is called, these public members are
104 * filled with the details passed to the function, for future
109 /** Server names of servers that this server is linked to
110 * So for A->B->C, if this was the record for B it would contain A and C
111 * whilever both servers are connected to B.
113 std::vector<std::string> routes;
116 /** Create an outbound connection to a listening socket
118 bool MakeOutboundConnection(char* newhost, int newport);
120 /** Return the servername on this established connection
122 std::string GetServerName();
124 /** Set the server name of this connection
126 void SetServerName(std::string serv);
128 /** Get the file descriptor associated with this connection
132 /** Set the file descriptor for this connection
134 void SetDescriptor(int fd);
136 /** Get the state flags for this connection
140 /** Set the state flags for this connection
142 void SetState(int state);
144 /** Get the ip address (not servername) associated with this connection
148 /** Get the server description of this connection
150 std::string GetDescription();
152 /** Set the server description of this connection
154 void SetDescription(std::string desc);
156 /** Get the port number being used for this connection
157 * If the connection is outbound this will be the remote port
158 * otherwise it will be the local port, so it can always be
159 * gautanteed as open at the address given in GetServerIP().
163 /** Set the port used by this connection
165 void SetServerPort(int p);
167 /** Set both the host and the port in one operation for this connection
169 bool SetHostAndPort(char* newhost, int newport);
171 /** Close the connection by calling close() on its file descriptor
172 * This function call updates no other data.
174 void CloseConnection();
176 /** This method adds text to the ircd connection's buffer
177 * There is no limitation on how much text of what line width may
178 * be added to this buffer. It is the sending server's responsibility
179 * to ensure sent data is kept within reasonable quanities.
181 void AddBuffer(std::string a);
183 /** This method returns true if the buffer contains at least one
184 * carriage return character, e.g. one line can be read from the
185 * buffer successfully.
187 bool BufferIsComplete();
189 /** This method clears the server's buffer by setting it to an empty string.
193 /** This method retrieves the first string from the tail end of the
194 * buffer and advances the tail end of the buffer past the returned
195 * string, in a similar manner to strtok().
197 std::string GetBuffer();
199 /** This method sets the version string of the remote server
201 void SetVersionString(std::string newversion);
203 /** This method returns the version string of the remote server.
204 * If the server has no version string an empty string is returned.
206 std::string GetVersionString();
210 /** Please note: classes serverrec and userrec both inherit from class connection.
212 class connection : public Extensible
215 /** File descriptor of the connection
219 /** Hostname of connection. Not used if this is a serverrec
223 /** IP of connection.
227 /** Stats counter for bytes inbound
231 /** Stats counter for bytes outbound
235 /** Stats counter for commands inbound
239 /** Stats counter for commands outbound
243 /** True if server/user has authenticated, false if otherwise
248 * For a userrec, this is the port they connected to the network on.
249 * For a serverrec this is the current listening port of the serverrec object.
253 /** Used by userrec to indicate the registration status of the connection
257 /** Time the connection was last pinged
261 /** Time the connection was created, set in the constructor
265 /** Time that the connection last sent data, used to calculate idle time
269 /** Used by PING checks with clients
273 /** Default constructor