-
Notifications
You must be signed in to change notification settings - Fork 11
/
server.h
85 lines (53 loc) · 1.67 KB
/
server.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// Created by itsuy on 2020/4/4.
//
#ifndef LIGHTSOCKS_SERVER_H
#define LIGHTSOCKS_SERVER_H
#include <iostream>
#include "lib/base64/base64.h"
#ifdef _WIN32
#include "event2/event.h"
#include "event2/bufferevent.h"
#include "event2/buffer.h"
#include "event2/listener.h"
#else
#include <event2/event.h>
#include <event2/bufferevent.h>
#include <event2/buffer.h>
#include <event2/listener.h>
#endif
#ifdef _WIN32
#include <WinSock2.h>
#pragma comment(lib, "ws2_32.lib")
#else
#include <csignal>
#endif
#include "spdlog/spdlog.h"
using std::string;
struct Socks5ctx {
bufferevent *self; //这个self是客户端
bufferevent *partner; //这个是远程客户端
int request_port;
std::string request_ip;
};
class server {
public:
static void setConfig(unsigned short listen_port, string password);
public:
static void local_event_cb(bufferevent *bev, short what, void *ctx);
static void local_read_cb(bufferevent *bev, void *arg);
// static void local_write_cb(bufferevent *bev, void *arg);
static void remote_event_cb(bufferevent *bev, short what, void *ctx);
static void remote_read_cb(bufferevent *bev, void *arg);
// static void remote_write_cb(bufferevent *bev, void *arg);
// static void close_on_finished_write_cb(struct bufferevent *bev, void *ctx);
static void listen_cb(evconnlistener *ev, evutil_socket_t s, sockaddr *sin, int sin_len, void *arg);
static void dns_cb(int errcode, evutil_addrinfo *addr, void *ctx);
static void run();
static void clear();
public:
static event_base *base_loop;
static evdns_base *base_dns_loop;
static unsigned short listen_port;
};
#endif //LIGHTSOCKS_SERVER_H