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