]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - include/connection.h
Added some netsplit handling stuff (untested)
[user/henk/code/inspircd.git] / include / connection.h
index a8f7372d941e3a5b9efb97285283435154267123..3316bd6c0fd09a8f7546f4c3299edbe31aa1214a 100644 (file)
 #include <unistd.h>
 #include <errno.h>
 #include <time.h>
+#include <vector>
+#include <deque>
 
 #ifndef __CONNECTION_H__
 #define __CONNECTION_H__
 
-#define PT_SYN_ONLY 0
-#define PT_ACK_ONLY 1
-#define PT_SYN_WITH_DATA 2
+#define STATE_DISCONNECTED     0
+#define STATE_CONNECTED                1
+#define STATE_SYNC             2
+#define STATE_NOAUTH_INBOUND   3
+#define STATE_NOAUTH_OUTBOUND  4
+
+/** Each connection has one or more of these
+ * each represents ONE outbound connection to another ircd
+ * so each inbound has multiple outbounds.
+ */
+class ircd_connector : public classbase
+{
+ private:
+       /** Sockaddr of the outbound ip and port
+        */
+       sockaddr_in addr;
+       
+       /** File descriptor of the connection
+        */
+       int fd;
+       
+       /** Server name
+        */
+       std::string servername;
+       
+       /** Server 'GECOS'
+        */
+       std::string description;
+       
+       /** State. STATE_NOAUTH_INBOUND, STATE_NOAUTH_OUTBOUND
+        * STATE_SYNC, STATE_DISCONNECTED, STATE_CONNECTED
+        */
+       int state;
+       
+       bool SetHostAddress(char* host, int port);
+
+ public:
+       char host[MAXBUF];
+       int port;
+       
+       /** Server names of servers that this server is linked to
+        * So for A->B->C, if this was the record for B it would contain A and C
+        * whilever both servers are connected to B.
+        */
+       std::vector<std::string> routes;
+       
+       bool MakeOutboundConnection(char* host, int port);
+       std::string GetServerName();
+       void SetServerName(std::string serv);
+       int GetDescriptor();
+       void SetDescriptor(int fd);
+       int GetState();
+       void SetState(int state);
+       char* GetServerIP();
+       std::string GetDescription();
+       void SetDescription(std::string desc);
+       int GetServerPort();
+       bool SetHostAndPort(char* host, int port);
+       void CloseConnection();
+};
 
 
 class packet : public classbase
 {
  public:
        long key;
-       short int id;
+       int id;
        short int type;
        char data[MAXBUF];
 
@@ -50,19 +110,24 @@ class connection : public classbase
        bool haspassed;
        int port;
        int registered;
+       short int state;
        time_t lastping;
        time_t signon;
        time_t idle_lastmsg;
        time_t nping;
+       char internal_addr[1024];
+       int internal_port;
+       std::vector<ircd_connector> connectors;
        
        connection();
        bool CreateListener(char* host, int p);
-       bool BeginLink(char* targethost, int port, char* password);
+       bool BeginLink(char* targethost, int port, char* password, char* servername);
+       bool MeshCookie(char* targethost, int port, long cookie, char* servername);
        void TerminateLink(char* targethost);
-       bool SendPacket(char *message, char* host, int port);
-       bool RecvPacket(char *message, char* host, int &prt);
-       bool SendSYN(char* host, int port);
-       bool SendACK(char* host, int port, int reply_id);
+       bool SendPacket(char *message, const char* host);
+       bool RecvPacket(std::deque<std::string> &messages, char* host);
+       ircd_connector* FindHost(std::string host);
+       bool AddIncoming(int fd,char* targethost, int sourceport);
        long GenKey();
 };