]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/connection.h
954cc919bd7838995ffa942795098af5e369b796
[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         /** Server names of servers that this server is linked to
52          * So for A->B->C, if this was the record for B it would contain A and C
53          * whilever both servers are connected to B.
54          */
55         std::vector<std::string> routes;
56         
57         /** State. STATE_NOAUTH_INBOUND, STATE_NOAUTH_OUTBOUND
58          * STATE_SYNC, STATE_DISCONNECTED, STATE_CONNECTED
59          */
60         int state;
61         
62         bool SetHostAddress(char* host, int port);
63
64  public:
65         char host[MAXBUF];
66         int port;
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         bool SetHostAndPort(char* host, int port);
81 };
82
83
84 class packet : public classbase
85 {
86  public:
87         long key;
88         int id;
89         short int type;
90         char data[MAXBUF];
91
92         packet();
93         ~packet();
94 };
95
96
97 class connection : public classbase
98 {
99  public:
100         long key;
101         int fd;                 // file descriptor
102         char host[256];         // hostname
103         long ip;                // ipv4 address
104         char inbuf[MAXBUF];     // recvQ
105         long bytes_in;
106         long bytes_out;
107         long cmds_in;
108         long cmds_out;
109         bool haspassed;
110         int port;
111         int registered;
112         short int state;
113         time_t lastping;
114         time_t signon;
115         time_t idle_lastmsg;
116         time_t nping;
117         char internal_addr[1024];
118         int internal_port;
119         std::vector<ircd_connector> connectors;
120         
121         connection();
122         bool CreateListener(char* host, int p);
123         bool BeginLink(char* targethost, int port, char* password, char* servername);
124         bool MeshCookie(char* targethost, int port, long cookie, char* servername);
125         void TerminateLink(char* targethost);
126         bool SendPacket(char *message, const char* host);
127         bool RecvPacket(std::deque<std::string> &messages, char* host);
128         ircd_connector* FindHost(std::string host);
129         bool AddIncoming(int fd,char* targethost, int sourceport);
130         long GenKey();
131 };
132
133
134 #endif
135