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