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

connection.h

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
00006  *                       E-mail:
00007  *                <brain@chatspike.net>
00008  *                <Craig@chatspike.net>
00009  *     
00010  * Written by Craig Edwards, Craig McLure, and others.
00011  * This program is free but copyrighted software; see
00012  *            the file COPYING for details.
00013  *
00014  * ---------------------------------------------------
00015  */
00016 
00017 #include "inspircd_config.h"
00018 #include "base.h"
00019 #include <string>
00020 #include <map>
00021 #include <sys/types.h>
00022 #include <sys/socket.h>
00023 #include <netdb.h>
00024 #include <netinet/in.h>
00025 #include <unistd.h>
00026 #include <errno.h>
00027 #include <time.h>
00028 #include <vector>
00029 #include <deque>
00030 #include <sstream>
00031 
00032 #ifndef __CONNECTION_H__
00033 #define __CONNECTION_H__
00034 
00035 #define STATE_DISCONNECTED      0
00036 #define STATE_CONNECTED         1
00037 #define STATE_SYNC              2
00038 #define STATE_NOAUTH_INBOUND    3
00039 #define STATE_NOAUTH_OUTBOUND   4
00040 #define STATE_SERVICES          5
00041 
00042 std::string CreateSum();
00043 
00056 class ircd_connector : public Extensible
00057 {
00058  private:
00061         sockaddr_in addr;
00062         
00065         int fd;
00066         
00069         std::string servername;
00070         
00073         std::string description;
00074         
00078         char state;
00079         
00082         bool SetHostAddress(char* host, int port);
00083 
00086         std::string version;
00087 
00088  public:
00089 
00094         std::string ircdbuffer;
00095 
00096  
00101         char host[MAXBUF];
00102 
00107         int port;
00108         
00113         std::vector<std::string> routes;
00114         
00115 
00118         bool MakeOutboundConnection(char* newhost, int newport);
00119         
00122         std::string GetServerName();
00123         
00126         void SetServerName(std::string serv);
00127         
00130         int GetDescriptor();
00131         
00134         void SetDescriptor(int fd);
00135         
00138         int GetState();
00139         
00142         void SetState(int state);
00143         
00146         char* GetServerIP();
00147         
00150         std::string GetDescription();
00151         
00154         void SetDescription(std::string desc);
00155         
00161         int GetServerPort();
00162         
00165         void SetServerPort(int p);
00166         
00169         bool SetHostAndPort(char* newhost, int newport);
00170         
00174         void CloseConnection();
00175 
00181         void AddBuffer(std::string a);
00182 
00187         bool BufferIsComplete();
00188 
00191         void ClearBuffer();
00192 
00197         std::string GetBuffer();
00198 
00201         void SetVersionString(std::string newversion);
00202 
00206         std::string GetVersionString();
00207 };
00208 
00209 
00212 class connection : public Extensible
00213 {
00214  public:
00217         int fd;
00218         
00221         char host[160];
00222         
00225         char ip[16];
00226         
00229         long bytes_in;
00230 
00233         long bytes_out;
00234 
00237         long cmds_in;
00238 
00241         long cmds_out;
00242 
00245         bool haspassed;
00246 
00251         int port;
00252         
00255         char registered;
00256         
00259         time_t lastping;
00260         
00263         time_t signon;
00264         
00267         time_t idle_lastmsg;
00268         
00271         time_t nping;
00272         
00276         std::vector<ircd_connector> connectors;
00277         
00280         connection();
00281         
00284         bool CreateListener(char* host, int p);
00285         
00288         bool BeginLink(char* targethost, int port, char* password, char* servername, int myport);
00289         
00292         bool MeshCookie(char* targethost, int port, unsigned long cookie, char* servername);
00293         
00296         void TerminateLink(char* targethost);
00297         
00301         bool SendPacket(char *message, const char* host);
00302         
00307         bool RecvPacket(std::deque<std::string> &messages, char* host, std::deque<std::string> &sums);
00308         
00311         ircd_connector* FindHost(std::string host);
00312         
00316         bool AddIncoming(int fd,char* targethost, int sourceport);
00317         
00318 };
00319 
00320 
00321 #endif

Generated on Sun May 15 17:02:05 2005 for InspIRCd by doxygen 1.3.3