mirror of
https://gitee.com/willfree/http_vpn.git
synced 2026-06-03 08:16:51 +08:00
90 lines
2.1 KiB
C++
90 lines
2.1 KiB
C++
#ifndef SOCKS_H_INCLUDED
|
|
#define SOCKS_H_INCLUDED
|
|
|
|
#include <iostream>
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
#include <netdb.h>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <unistd.h>
|
|
#include <cstring>
|
|
#include <sys/time.h>
|
|
|
|
#include "ccn_p2p/ndn_socket.h"
|
|
|
|
#define SERV_TCP_PORT 9011 /* Local listening port number */
|
|
#define MAX_SIZE 1024*7120
|
|
#define SOCKS5_VERSION 5
|
|
|
|
using namespace std;
|
|
|
|
class Socks5Server{
|
|
private:
|
|
// sockfd
|
|
int sockfd;
|
|
// sockaddr
|
|
struct sockaddr_in serv_addr;
|
|
/* Local listening port number */
|
|
int port;
|
|
// socks version
|
|
uint8_t socks_vision;
|
|
// 2 commom numbers
|
|
uint8_t ui0;
|
|
uint8_t ui5;
|
|
|
|
Ndn_socket mndn_socket ;
|
|
string listen_prefix ;
|
|
string base_listen_prefix;
|
|
unsigned int p_port_seq ;
|
|
|
|
public:
|
|
// construction function
|
|
Socks5Server(const string &server_prefix){
|
|
this->port=SERV_TCP_PORT;
|
|
this->ui0=0;
|
|
this->ui5=5;
|
|
this->socks_vision=SOCKS5_VERSION;
|
|
this->p_port_seq = 0 ;
|
|
this->listen_prefix = server_prefix ;
|
|
this->base_listen_prefix=server_prefix+"_base";
|
|
}
|
|
Socks5Server(int port , const string &server_prefix){
|
|
this->port=port;
|
|
this->ui0=0;
|
|
this->ui5=5;
|
|
this->socks_vision=SOCKS5_VERSION;
|
|
this->p_port_seq = 0 ;
|
|
this->listen_prefix = server_prefix ;
|
|
this->base_listen_prefix=server_prefix+"_base";
|
|
}
|
|
~Socks5Server(){
|
|
}
|
|
|
|
// listen to the local port
|
|
void ndn_listen_local(string prefix) ;
|
|
|
|
// waiting for the local port's connection
|
|
string ndn_accept_local(string new_prefix) ;
|
|
// a handshake for the sub-negotiation method
|
|
int ndn_negotShake(Ndn_socket &ndn_socket);
|
|
// a handshake for the connection information
|
|
// to remote server
|
|
pair<int,int> ndn_connShake(Ndn_socket &ndn_socket);
|
|
// data transmission shake
|
|
void ndn_transData(string new_prefix , string client_prefix);
|
|
|
|
// forever listenner function
|
|
void ndn_forever();
|
|
// server start
|
|
void start();
|
|
|
|
// ndn 监听线程:数据传输
|
|
static void *ndn_thread1(void *val);
|
|
static void *ndn_thread2(void *val);
|
|
};
|
|
|
|
#endif
|