2003-01-26 23:53:03 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2003-02-02 16:43:53 +00:00
|
|
|
#include "inspircd_config.h"
|
2003-01-26 23:53:03 +00:00
|
|
|
#include "base.h"
|
|
|
|
#include <string>
|
2003-07-22 21:56:38 +00:00
|
|
|
#include <map>
|
2003-02-02 16:43:53 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <time.h>
|
2004-04-11 18:00:44 +00:00
|
|
|
#include <vector>
|
2003-02-02 16:43:53 +00:00
|
|
|
|
|
|
|
#ifndef __CONNECTION_H__
|
|
|
|
#define __CONNECTION_H__
|
|
|
|
|
2004-04-14 17:15:07 +00:00
|
|
|
#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 outbound connection
|
|
|
|
*/
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
/** Server name
|
|
|
|
*/
|
|
|
|
std::string servername;
|
|
|
|
|
|
|
|
/** 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;
|
|
|
|
|
|
|
|
/** State. STATE_NOAUTH_INBOUND, STATE_NOAUTH_OUTBOUND
|
|
|
|
* STATE_SYNC, STATE_DISCONNECTED, STATE_CONNECTED
|
|
|
|
*/
|
|
|
|
int state;
|
|
|
|
|
|
|
|
bool SetHostAddress(char* host, int port);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
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);
|
|
|
|
};
|
2003-02-02 16:43:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
class packet : public classbase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
long key;
|
2004-04-11 16:38:53 +00:00
|
|
|
int id;
|
2003-02-02 16:43:53 +00:00
|
|
|
short int type;
|
|
|
|
char data[MAXBUF];
|
|
|
|
|
|
|
|
packet();
|
|
|
|
~packet();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-01-26 23:53:03 +00:00
|
|
|
class connection : public classbase
|
|
|
|
{
|
|
|
|
public:
|
2003-02-02 16:43:53 +00:00
|
|
|
long key;
|
2003-01-26 23:53:03 +00:00
|
|
|
int fd; // file descriptor
|
|
|
|
char host[256]; // hostname
|
|
|
|
long ip; // ipv4 address
|
|
|
|
char inbuf[MAXBUF]; // recvQ
|
|
|
|
long bytes_in;
|
|
|
|
long bytes_out;
|
|
|
|
long cmds_in;
|
|
|
|
long cmds_out;
|
|
|
|
bool haspassed;
|
|
|
|
int port;
|
|
|
|
int registered;
|
2004-04-11 16:38:53 +00:00
|
|
|
short int state;
|
2003-01-26 23:53:03 +00:00
|
|
|
time_t lastping;
|
|
|
|
time_t signon;
|
|
|
|
time_t idle_lastmsg;
|
|
|
|
time_t nping;
|
2004-04-01 20:21:06 +00:00
|
|
|
char internal_addr[1024];
|
2004-04-10 14:10:51 +00:00
|
|
|
int internal_port;
|
2004-04-14 17:15:07 +00:00
|
|
|
std::vector<ircd_connector> connectors;
|
2003-02-02 16:43:53 +00:00
|
|
|
|
|
|
|
connection();
|
2003-02-07 21:15:27 +00:00
|
|
|
bool CreateListener(char* host, int p);
|
2004-04-14 17:15:07 +00:00
|
|
|
bool BeginLink(char* targethost, int port, char* password, char* servername);
|
2003-02-02 16:43:53 +00:00
|
|
|
void TerminateLink(char* targethost);
|
2004-04-14 17:15:07 +00:00
|
|
|
bool SendPacket(char *message, char* host);
|
2004-04-14 18:58:25 +00:00
|
|
|
bool RecvPacket(string_list &messages, char* host);
|
2004-04-14 17:15:07 +00:00
|
|
|
ircd_connector* FindHost(std::string host);
|
|
|
|
bool AddIncoming(int fd,char* targethost);
|
2003-02-02 16:43:53 +00:00
|
|
|
long GenKey();
|
2003-01-26 23:53:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|