Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | 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 
00054 class ircd_connector : public Extensible
00055 {
00056  private:
00059         sockaddr_in addr;
00060         
00063         int fd;
00064         
00067         std::string servername;
00068         
00071         std::string description;
00072         
00076         int state;
00077         
00080         bool SetHostAddress(char* host, int port);
00081 
00082 
00083  public:
00084 
00087         std::string ircdbuffer;
00088 
00089  
00094         char host[MAXBUF];
00095 
00100         int port;
00101         
00106         std::vector<std::string> routes;
00107         
00108 
00111         bool MakeOutboundConnection(char* newhost, int newport);
00112         
00115         std::string GetServerName();
00116         
00119         void SetServerName(std::string serv);
00120         
00123         int GetDescriptor();
00124         
00127         void SetDescriptor(int fd);
00128         
00131         int GetState();
00132         
00135         void SetState(int state);
00136         
00139         char* GetServerIP();
00140         
00143         std::string GetDescription();
00144         
00147         void SetDescription(std::string desc);
00148         
00154         int GetServerPort();
00155         
00158         void SetServerPort(int p);
00159         
00162         bool SetHostAndPort(char* newhost, int newport);
00163         
00167         void CloseConnection();
00168 
00169         void AddBuffer(std::string a);
00170         bool BufferIsComplete();
00171         void ClearBuffer();
00172         std::string GetBuffer();
00173 };
00174 
00175 
00178 class connection : public Extensible
00179 {
00180  public:
00183         int fd;
00184         
00187         char host[256];
00188         
00191         char ip[32];
00192         
00195         char inbuf[MAXBUF];
00196         
00199         long bytes_in;
00200 
00203         long bytes_out;
00204 
00207         long cmds_in;
00208 
00211         long cmds_out;
00212 
00215         bool haspassed;
00216 
00221         int port;
00222         
00225         int registered;
00226         
00229         short int state;
00230         
00233         time_t lastping;
00234         
00237         time_t signon;
00238         
00241         time_t idle_lastmsg;
00242         
00245         time_t nping;
00246         
00249         char internal_addr[MAXBUF];
00250         
00253         int internal_port;
00254 
00258         std::vector<ircd_connector> connectors;
00259         
00262         connection();
00263         
00266         bool CreateListener(char* host, int p);
00267         
00270         bool BeginLink(char* targethost, int port, char* password, char* servername, int myport);
00271         
00274         bool MeshCookie(char* targethost, int port, unsigned long cookie, char* servername);
00275         
00278         void TerminateLink(char* targethost);
00279         
00283         bool SendPacket(char *message, const char* host);
00284         
00289         bool RecvPacket(std::deque<std::string> &messages, char* host);
00290         
00293         ircd_connector* FindHost(std::string host);
00294         
00298         bool AddIncoming(int fd,char* targethost, int sourceport);
00299         
00302         long GenKey();
00303 };
00304 
00305 
00306 #endif
00307 

Generated on Tue Apr 26 17:11:43 2005 for InspIRCd by doxygen 1.3.3