release: v1.05.552 release
support tcp mux Signed-off-by: Dengfeng Liu <liudf0716@gmail.com>
This commit is contained in:
12
README.md
12
README.md
@@ -16,7 +16,7 @@ the following table is detail compatible feature:
|
||||
| Feature | xfrpc | frpc |
|
||||
| ------------- | ------------- | ---------|
|
||||
| tcp | Yes | Yes |
|
||||
| tcpmux | No | Yes |
|
||||
| tcpmux | Yes | Yes |
|
||||
| http | Yes | Yes |
|
||||
| https | Yes | Yes |
|
||||
| udp | No | Yes |
|
||||
@@ -110,11 +110,8 @@ frps use latest release 0.42.0
|
||||
# frps.ini
|
||||
[common]
|
||||
bind_port = 7000
|
||||
tcp_mux = false
|
||||
```
|
||||
|
||||
**attention! cause xfrpc does not support tcp_mux yet, please disable tcp_mux otherwise xfrpc can not connect frps**
|
||||
|
||||
run frps
|
||||
|
||||
```
|
||||
@@ -179,11 +176,14 @@ QQ群 : [331230369](https://jq.qq.com/?_wv=1027&k=47QGEhL)
|
||||
|
||||
支付宝打赏
|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
微信打赏
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
|
||||
## 广告
|
||||
|
||||
|
||||
14
client.c
14
client.c
@@ -175,7 +175,6 @@ send_client_data_tail(struct proxy_client *client)
|
||||
static void
|
||||
free_proxy_client(struct proxy_client *client)
|
||||
{
|
||||
if (client->tcp_mux_ping_event) evtimer_del(client->tcp_mux_ping_event);
|
||||
if (client->local_proxy_bev) bufferevent_free(client->local_proxy_bev);
|
||||
free(client);
|
||||
}
|
||||
@@ -207,8 +206,19 @@ new_proxy_client()
|
||||
struct proxy_client *client = calloc(1, sizeof(struct proxy_client));
|
||||
assert(client);
|
||||
client->stream_id = get_next_session_id();
|
||||
client->tcp_mux_ping_id = 0;
|
||||
HASH_ADD_INT(all_pc, stream_id, client);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
void
|
||||
clear_all_proxy_client()
|
||||
{
|
||||
if (!all_pc) return;
|
||||
|
||||
struct proxy_client *client, *tmp;
|
||||
HASH_ITER(hh, all_pc, client, tmp) {
|
||||
HASH_DEL(all_pc, client);
|
||||
free_proxy_client(client);
|
||||
}
|
||||
}
|
||||
|
||||
4
client.h
4
client.h
@@ -44,8 +44,6 @@ struct proxy_client {
|
||||
struct bufferevent *local_proxy_bev; // xfrpc proxy <---> local service
|
||||
struct base_conf *bconf;
|
||||
|
||||
struct event *tcp_mux_ping_event;
|
||||
uint32_t tcp_mux_ping_id;
|
||||
uint32_t stream_id;
|
||||
int connected;
|
||||
int work_started;
|
||||
@@ -98,4 +96,6 @@ int is_ftp_proxy(const struct proxy_service *ps);
|
||||
|
||||
struct proxy_client *new_proxy_client();
|
||||
|
||||
void clear_all_proxy_client();
|
||||
|
||||
#endif //_CLIENT_H_
|
||||
|
||||
2
config.c
2
config.c
@@ -364,7 +364,7 @@ static void init_common_conf(struct common_conf *config)
|
||||
config->log_max_days = 3;
|
||||
config->heartbeat_interval = 30;
|
||||
config->heartbeat_timeout = 60;
|
||||
config->tcp_mux = 0;
|
||||
config->tcp_mux = 1;
|
||||
config->user = NULL;
|
||||
config->server_ip = NULL;
|
||||
config->is_router = 0;
|
||||
|
||||
32
control.c
32
control.c
@@ -522,10 +522,10 @@ connect_event_cb (struct bufferevent *bev, short what, void *ctx)
|
||||
c_conf->server_addr,
|
||||
c_conf->server_port,
|
||||
strerror(errno));
|
||||
free_control();
|
||||
init_main_control();
|
||||
start_base_connect();
|
||||
exit(0);
|
||||
close_main_control();
|
||||
init_main_control();
|
||||
run_control();
|
||||
} else if (what & BEV_EVENT_CONNECTED) {
|
||||
retry_times = 0;
|
||||
|
||||
@@ -538,7 +538,7 @@ static void
|
||||
keep_control_alive()
|
||||
{
|
||||
main_ctl->ticker_ping = evtimer_new(main_ctl->connect_base, hb_sender_cb, NULL);
|
||||
if ( ! main_ctl->ticker_ping) {
|
||||
if ( !main_ctl->ticker_ping) {
|
||||
debug(LOG_ERR, "Ping Ticker init failed!");
|
||||
return;
|
||||
}
|
||||
@@ -801,19 +801,34 @@ init_main_control()
|
||||
&hints,
|
||||
server_dns_cb,
|
||||
NULL);
|
||||
if (! dns_req) {
|
||||
if (!dns_req) {
|
||||
debug(LOG_ERR, "error: can not analyse the dns of [%s]", c_conf->server_addr);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
free_main_control()
|
||||
{
|
||||
SAFE_FREE(main_ctl);
|
||||
main_ctl = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
close_main_control()
|
||||
{
|
||||
assert(main_ctl);
|
||||
|
||||
if (main_ctl->ticker_ping) evtimer_del(main_ctl->ticker_ping);
|
||||
if (main_ctl->tcp_mux_ping_event) evtimer_del(main_ctl->tcp_mux_ping_event);
|
||||
|
||||
clear_all_proxy_client();
|
||||
|
||||
event_base_dispatch(main_ctl->connect_base);
|
||||
event_base_free(main_ctl->connect_base);
|
||||
evdns_base_free(main_ctl->dnsbase, 0);
|
||||
|
||||
free_main_control();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -824,11 +839,4 @@ run_control()
|
||||
keep_control_tcp_mux_alive();
|
||||
}
|
||||
|
||||
void
|
||||
free_control()
|
||||
{
|
||||
if (!main_ctl)
|
||||
return;
|
||||
|
||||
SAFE_FREE(main_ctl);
|
||||
}
|
||||
|
||||
13
control.h
13
control.h
@@ -48,15 +48,22 @@ struct control {
|
||||
};
|
||||
|
||||
void connect_eventcb(struct bufferevent *bev, short events, void *ptr);
|
||||
|
||||
void start_base_connect();
|
||||
|
||||
void init_main_control();
|
||||
|
||||
void run_control();
|
||||
|
||||
struct control *get_main_control();
|
||||
|
||||
void close_main_control();
|
||||
|
||||
void start_login_frp_server(struct event_base *base);
|
||||
|
||||
void send_login_frp_server(struct bufferevent *bev);
|
||||
|
||||
void login();
|
||||
void free_control();
|
||||
|
||||
void send_msg_frp_server(struct bufferevent *bev,
|
||||
const enum msg_type type,
|
||||
@@ -71,9 +78,9 @@ void send_enc_msg_frp_server(struct bufferevent *bev,
|
||||
uint32_t sid);
|
||||
|
||||
void control_process(struct proxy_client *client);
|
||||
|
||||
void send_new_proxy(struct proxy_service *ps);
|
||||
|
||||
struct bufferevent
|
||||
*connect_server(struct event_base *base, const char *name, const int port);
|
||||
struct bufferevent *connect_server(struct event_base *base, const char *name, const int port);
|
||||
|
||||
#endif //_CONTROL_H_
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "config.h"
|
||||
#include "tcpmux.h"
|
||||
|
||||
#define BUF_LEN 4098
|
||||
#define BUF_LEN 4096
|
||||
|
||||
// read data from local service
|
||||
void tcp_proxy_c2s_cb(struct bufferevent *bev, void *ctx)
|
||||
|
||||
63
tcpmux.c
63
tcpmux.c
@@ -91,6 +91,18 @@ tcp_mux_flag()
|
||||
return c_conf->tcp_mux;
|
||||
}
|
||||
|
||||
static void
|
||||
dump_tcp_mux_header(uint8_t *data, int len)
|
||||
{
|
||||
if (len != 12)
|
||||
return;
|
||||
|
||||
printf("tcp mux header is : \n");
|
||||
for (int i = 0; i < len; i++)
|
||||
printf("%2x", data[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
parse_tcp_mux_proto(uint8_t *data, int len, uint32_t *flag, uint32_t *type, uint32_t *stream_id, uint32_t *dlen)
|
||||
{
|
||||
@@ -105,10 +117,11 @@ parse_tcp_mux_proto(uint8_t *data, int len, uint32_t *flag, uint32_t *type, uint
|
||||
if(hdr->version == proto_version &&
|
||||
valid_tcp_mux_type(hdr->type) &&
|
||||
valid_tcp_mux_flag(htons(hdr->flags))) {
|
||||
if (hdr->type != PING && !valid_tcp_mux_sid(htonl(hdr->stream_id))) { // ??? go_away need confirm
|
||||
debug(LOG_INFO, "!!!!!!!can't find client : type [%s] flag [%s] stream_id[%d]",
|
||||
if (hdr->type == DATA && !valid_tcp_mux_sid(htonl(hdr->stream_id))) {
|
||||
debug(LOG_INFO, "!!!!!type is DATA but cant find stream_id : type [%s] flag [%s] stream_id[%d]",
|
||||
type_2_desc(hdr->type), flag_2_desc(htons(hdr->flags)), htonl(hdr->stream_id));
|
||||
return 0;
|
||||
dump_tcp_mux_header(data, len);
|
||||
exit(-1);
|
||||
}
|
||||
*type = hdr->type;
|
||||
*flag = htons(hdr->flags);
|
||||
@@ -120,34 +133,6 @@ parse_tcp_mux_proto(uint8_t *data, int len, uint32_t *flag, uint32_t *type, uint
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
parse_tcp_mux_header(uint8_t *data, int len, struct tcp_mux_header *tmux_hdr)
|
||||
{
|
||||
assert(tmux_hdr);
|
||||
struct common_conf *c_conf = get_common_config();
|
||||
if (!c_conf->tcp_mux)
|
||||
return 0;
|
||||
|
||||
if (len < sizeof(struct tcp_mux_header))
|
||||
return 0;
|
||||
|
||||
struct tcp_mux_header *hdr = (struct tcp_mux_header *)data;
|
||||
if(hdr->version == proto_version &&
|
||||
valid_tcp_mux_type(hdr->type) &&
|
||||
valid_tcp_mux_flag(htons(hdr->flags))) {
|
||||
if (hdr->type != PING && !valid_tcp_mux_sid(htonl(hdr->stream_id))) // ??? go_away need confirm
|
||||
return 0;
|
||||
tmux_hdr->type = hdr->type;
|
||||
tmux_hdr->flags = htons(hdr->flags);
|
||||
tmux_hdr->stream_id = htonl(hdr->stream_id);
|
||||
tmux_hdr->length = htonl(hdr->length);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
uint32_t
|
||||
get_next_session_id() {
|
||||
static uint32_t next_session_id = 1;
|
||||
@@ -168,6 +153,18 @@ tcp_mux_send_win_update_syn(struct bufferevent *bout, uint32_t stream_id)
|
||||
bufferevent_write(bout, (uint8_t *)&tmux_hdr, sizeof(tmux_hdr));
|
||||
}
|
||||
|
||||
void
|
||||
tcp_mux_send_win_update_ack(struct bufferevent *bout, uint32_t stream_id, uint32_t delta)
|
||||
{
|
||||
if (!tcp_mux_flag()) return;
|
||||
|
||||
struct tcp_mux_header tmux_hdr;
|
||||
memset(&tmux_hdr, 0, sizeof(tmux_hdr));
|
||||
tcp_mux_encode(WINDOW_UPDATE, ACK, stream_id, delta, &tmux_hdr);
|
||||
debug(LOG_DEBUG, "tcp mux [%d] send wind update ACK [%d]", stream_id, delta);
|
||||
bufferevent_write(bout, (uint8_t *)&tmux_hdr, sizeof(tmux_hdr));
|
||||
}
|
||||
|
||||
void
|
||||
tcp_mux_send_win_update_rst(struct bufferevent *bout, uint32_t stream_id)
|
||||
{
|
||||
@@ -200,7 +197,7 @@ tcp_mux_send_ping(struct bufferevent *bout, uint32_t ping_id)
|
||||
struct tcp_mux_header tmux_hdr;
|
||||
memset(&tmux_hdr, 0, sizeof(tmux_hdr));
|
||||
tcp_mux_encode(PING, SYN, 0, ping_id, &tmux_hdr);
|
||||
debug(LOG_DEBUG, "tcp mux send ping syn : %d", ping_id);
|
||||
//debug(LOG_DEBUG, "tcp mux send ping syn : %d", ping_id);
|
||||
bufferevent_write(bout, (uint8_t *)&tmux_hdr, sizeof(tmux_hdr));
|
||||
}
|
||||
|
||||
@@ -212,7 +209,7 @@ tcp_mux_handle_ping(struct bufferevent *bout, uint32_t ping_id)
|
||||
struct tcp_mux_header tmux_hdr;
|
||||
memset(&tmux_hdr, 0, sizeof(tmux_hdr));
|
||||
tcp_mux_encode(PING, ACK, 0, ping_id, &tmux_hdr);
|
||||
debug(LOG_DEBUG, "tcp mux send ping ack : %d", ping_id);
|
||||
//debug(LOG_DEBUG, "tcp mux send ping ack : %d", ping_id);
|
||||
bufferevent_write(bout, (uint8_t *)&tmux_hdr, sizeof(tmux_hdr));
|
||||
}
|
||||
|
||||
|
||||
2
tcpmux.h
2
tcpmux.h
@@ -50,6 +50,8 @@ struct __attribute__((__packed__)) tcp_mux_header {
|
||||
|
||||
void tcp_mux_send_win_update_syn(struct bufferevent *bout, uint32_t stream_id);
|
||||
|
||||
void tcp_mux_send_win_update_ack(struct bufferevent *bout, uint32_t stream_id, uint32_t delta);
|
||||
|
||||
void tcp_mux_send_win_update_rst(struct bufferevent *bout, uint32_t stream_id);
|
||||
|
||||
void tcp_mux_send_data(struct bufferevent *bout, uint32_t stream_id, uint32_t length);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef _VERSION_H_
|
||||
#define _VERSION_H_
|
||||
|
||||
#define VERSION "1.41.1"
|
||||
#define VERSION "1.05.552"
|
||||
#define PROTOCOL_VERESION "0.41.0"
|
||||
#define CLIENT_V 1
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
[common]
|
||||
server_addr = your_server_ip
|
||||
server_port = 7000
|
||||
token = 12345678
|
||||
|
||||
[ssh]
|
||||
type = tcp
|
||||
|
||||
Reference in New Issue
Block a user