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