5 #include "inspircd_config.h"
9 #include <sys/socket.h>
10 #include <sys/types.h>
12 #include <netinet/in.h>
18 #ifndef __CONNECTION_H__
19 #define __CONNECTION_H__
21 #define STATE_DISCONNECTED 0
22 #define STATE_CONNECTED 1
24 #define STATE_NOAUTH_INBOUND 3
25 #define STATE_NOAUTH_OUTBOUND 4
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.
31 class ircd_connector : public classbase
34 /** Sockaddr of the outbound ip and port
38 /** File descriptor of the outbound connection
44 std::string servername;
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.
50 std::vector<std::string> routes;
52 /** State. STATE_NOAUTH_INBOUND, STATE_NOAUTH_OUTBOUND
53 * STATE_SYNC, STATE_DISCONNECTED, STATE_CONNECTED
57 bool SetHostAddress(char* host, int port);
61 bool MakeOutboundConnection(char* host, int port);
62 std::string GetServerName();
63 void SetServerName(std::string serv);
65 void SetDescriptor(int fd);
67 void SetState(int state);
71 class packet : public classbase
84 class connection : public classbase
88 int fd; // file descriptor
89 char host[256]; // hostname
90 long ip; // ipv4 address
91 char inbuf[MAXBUF]; // recvQ
104 char internal_addr[1024];
106 std::vector<ircd_connector> connectors;
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);