5 #include "inspircd_config.h"
9 #include <sys/socket.h>
10 #include <sys/types.h>
12 #include <netinet/in.h>
19 #ifndef __CONNECTION_H__
20 #define __CONNECTION_H__
22 #define STATE_DISCONNECTED 0
23 #define STATE_CONNECTED 1
25 #define STATE_NOAUTH_INBOUND 3
26 #define STATE_NOAUTH_OUTBOUND 4
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.
32 class ircd_connector : public classbase
35 /** Sockaddr of the outbound ip and port
39 /** File descriptor of the connection
45 std::string servername;
49 std::string description;
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.
55 std::vector<std::string> routes;
57 /** State. STATE_NOAUTH_INBOUND, STATE_NOAUTH_OUTBOUND
58 * STATE_SYNC, STATE_DISCONNECTED, STATE_CONNECTED
62 bool SetHostAddress(char* host, int port);
69 bool MakeOutboundConnection(char* host, int port);
70 std::string GetServerName();
71 void SetServerName(std::string serv);
73 void SetDescriptor(int fd);
75 void SetState(int state);
77 std::string GetDescription();
78 void SetDescription(std::string desc);
80 bool SetHostAndPort(char* host, int port);
84 class packet : public classbase
97 class connection : public classbase
101 int fd; // file descriptor
102 char host[256]; // hostname
103 long ip; // ipv4 address
104 char inbuf[MAXBUF]; // recvQ
117 char internal_addr[1024];
119 std::vector<ircd_connector> connectors;
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);