summaryrefslogtreecommitdiff
path: root/include/connection.h
blob: 9a72e6d6bbb854fe8723ec31b6c3b6c3516e1ffd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*

*/

#include "inspircd_config.h"
#include "base.h"
#include <string>
#include <map>
#include <sys/socket.h>
#include <sys/types.h>
#include <netdb.h>
#include <netinet/in.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>

#ifndef __CONNECTION_H__
#define __CONNECTION_H__

#define PT_SYN_ONLY 0
#define PT_ACK_ONLY 1
#define PT_SYN_WITH_DATA 2
#define PT_KEY_EXCHANGE 3


class packet : public classbase
{
 public:
 	long key;
 	short int id;
	short int type;
	char data[MAXBUF];

	packet();
	~packet();
};


class connection : public classbase
{
 public:
 	long key;
	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;
	time_t lastping;
	time_t signon;
	time_t idle_lastmsg;
	time_t nping;
	char internal_addr[1024];
	int internal_port;
	
	connection();
	bool CreateListener(char* host, int p);
	bool BeginLink(char* targethost, int port, char* password);
	void TerminateLink(char* targethost);
	bool SendPacket(char *message, char* host, int port, long ourkey);
	bool RecvPacket(char *message, char* host, int &prt, long &theirkey);
	bool SendSYN(char* host, int port);
	bool SendACK(char* host, int port, int reply_id);
	long GenKey();
};


#endif