]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/connection.h
Fixes for nonblocking socket issues
[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 '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  
66         bool MakeOutboundConnection(char* host, int port);
67         std::string GetServerName();
68         void SetServerName(std::string serv);
69         int GetDescriptor();
70         void SetDescriptor(int fd);
71         int GetState();
72         void SetState(int state);
73 };
74
75
76 class packet : public classbase
77 {
78  public:
79         long key;
80         int id;
81         short int type;
82         char data[MAXBUF];
83
84         packet();
85         ~packet();
86 };
87
88
89 class connection : public classbase
90 {
91  public:
92         long key;
93         int fd;                 // file descriptor
94         char host[256];         // hostname
95         long ip;                // ipv4 address
96         char inbuf[MAXBUF];     // recvQ
97         long bytes_in;
98         long bytes_out;
99         long cmds_in;
100         long cmds_out;
101         bool haspassed;
102         int port;
103         int registered;
104         short int state;
105         time_t lastping;
106         time_t signon;
107         time_t idle_lastmsg;
108         time_t nping;
109         char internal_addr[1024];
110         int internal_port;
111         std::vector<ircd_connector> connectors;
112         
113         connection();
114         bool CreateListener(char* host, int p);
115         bool BeginLink(char* targethost, int port, char* password, char* servername);
116         void TerminateLink(char* targethost);
117         bool SendPacket(char *message, const char* host);
118         bool RecvPacket(std::deque<std::string> &messages, char* host);
119         ircd_connector* FindHost(std::string host);
120         bool AddIncoming(int fd,char* targethost);
121         long GenKey();
122 };
123
124
125 #endif
126