forked from libswift/libswift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSocks5Connection.h
66 lines (50 loc) · 1.56 KB
/
Socks5Connection.h
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
/*
* Socks5Connection.h
*
* Created on: Jun 17, 2013
* Author: chris
*/
#ifndef SOCKS5CONNECTION_H_
#define SOCKS5CONNECTION_H_
#include "address.h"
using namespace swift;
struct UdpEncapsulationHeader {
uint16_t rsv;
unsigned char fragment;
unsigned char atyp;
Address address;
};
enum Socks5ConnectionState {
Closed = 0,
HandshakeSent = 1,
MethodSelected = 2,
UdpRequestSent = 3,
UdpAssociated = 4
};
class Socks5Connection : public Operational{
public:
Socks5Connection();
~Socks5Connection();
void open(struct event_base *evbase, Address socks5_server);
bool isOpen();
Socks5ConnectionState getCurrentState();
void setCurrentState(Socks5ConnectionState state);
Address getBindAddress();
void setBindAddress(Address address);
int tryReadHandshakeResponse(struct bufferevent *bev);
void tryUdpAssociateRequest(struct bufferevent *bev);
int tryReadUdpAssociateResponse(struct bufferevent *bev);
int unwrapDatagram(Address& addr, struct evbuffer *evb);
int prependHeader(const Address& addr, struct evbuffer *evb);
static void buffered_on_event(struct bufferevent *bev, short int what, void* cbarg);
static void buffered_on_write(struct bufferevent *bev, void *cbarg);
static void buffered_on_read(struct bufferevent *bev, void *cbarg);
int consumeUdpHeader(struct evbuffer *buff, UdpEncapsulationHeader& header);
private:
Socks5ConnectionState state;
void sendHandshake(struct bufferevent *bev);
Address bind_address;
struct bufferevent * bev;
};
typedef Socks5Connection Socks5Connection;
#endif /* SOCKS5CONNECTION_H_ */