]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/connection.h
1550d470438e2d9ef4674d3923e7b2935b023e3b
[user/henk/code/inspircd.git] / include / connection.h
1 /*
2
3 */
4
5 #include "inspircd_config.h"
6 #include "base.h"
7 #include <string>
8 #include <map>
9 #include <sys/socket.h>
10 #include <sys/types.h>
11 #include <netdb.h>
12 #include <netinet/in.h>
13 #include <unistd.h>
14 #include <errno.h>
15 #include <time.h>
16 #include <vector>
17 #include <deque>
18
19 #ifndef __CONNECTION_H__
20 #define __CONNECTION_H__
21
22 #define STATE_DISCONNECTED      0
23 #define STATE_CONNECTED         1
24 #define STATE_SYNC              2
25 #define STATE_NOAUTH_INBOUND    3
26 #define STATE_NOAUTH_OUTBOUND   4
27
28 /** Each connection has one or more of these
29  * each represents ONE outbound connection to another ircd
30  * so each inbound has multiple outbounds.
31  */
32 class ircd_connector : public classbase
33 {
34  private:
35         /** Sockaddr of the outbound ip and port
36          */
37         sockaddr_in addr;
38         
39         /** File descriptor of the connection
40          */
41         int fd;
42         
43         /** Server name
44          */
45         std::string servername;
46         
47         /** Server 'GECOS'
48          */
49         std::string description;
50         
51         /** State. STATE_NOAUTH_INBOUND, STATE_NOAUTH_OUTBOUND
52          * STATE_SYNC, STATE_DISCONNECTED, STATE_CONNECTED
53          */
54         int state;
55         
56         bool SetHostAddress(char* host, int port);
57
58  public:
59         char host[MAXBUF];
60         int port;
61         
62         /** Server names of servers that this server is linked to
63          * So for A->B->C, if this was the record for B it would contain A and C
64          * whilever both servers are connected to B.
65          */
66         std::vector<std::string> routes;
67         
68  
69         bool MakeOutboundConnection(char* host, int port);
70         std::string GetServerName();
71         void SetServerName(std::string serv);
72         int GetDescriptor();
73         void SetDescriptor(int fd);
74         int GetState();
75         void SetState(int state);
76         char* GetServerIP();
77         std::string GetDescription();
78         void SetDescription(std::string desc);
79         int GetServerPort();
80         void SetServerPort(int p);
81         bool SetHostAndPort(char* host, int port);
82         void CloseConnection();
83 };
84
85
86 class packet : public classbase
87 {
88  public:
89         long key;
90         int id;
91         short int type;
92         char data[MAXBUF];
93
94         packet();
95         ~packet();
96 };
97
98
99 class connection : public classbase
100 {
101  public:
102         long key;
103         int fd;                 // file descriptor
104         char host[256];         // hostname
105         long ip;                // ipv4 address
106         char inbuf[MAXBUF];     // recvQ
107         long bytes_in;
108         long bytes_out;
109         long cmds_in;
110         long cmds_out;
111         bool haspassed;
112         int port;
113         int registered;
114         short int state;
115         time_t lastping;
116         time_t signon;
117         time_t idle_lastmsg;
118         time_t nping;
119         char internal_addr[1024];
120         int internal_port;
121         std::vector<ircd_connector> connectors;
122         
123         connection();
124         bool CreateListener(char* host, int p);
125         bool BeginLink(char* targethost, int port, char* password, char* servername, int myport);
126         bool MeshCookie(char* targethost, int port, long cookie, char* servername);
127         void TerminateLink(char* targethost);
128         bool SendPacket(char *message, const char* host);
129         bool RecvPacket(std::deque<std::string> &messages, char* host);
130         ircd_connector* FindHost(std::string host);
131         bool AddIncoming(int fd,char* targethost, int sourceport);
132         long GenKey();
133 };
134
135
136 #endif
137