Skip to content

Commit

Permalink
refactor: refactor tcp mux
Browse files Browse the repository at this point in the history
Signed-off-by: DengfengLiu <[email protected]>
  • Loading branch information
apcoin authored and liudf0716 committed Nov 13, 2022
1 parent 855f602 commit c53693b
Show file tree
Hide file tree
Showing 8 changed files with 749 additions and 131 deletions.
18 changes: 13 additions & 5 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ xfrp_proxy_event_cb(struct bufferevent *bev, short what, void *ctx)
debug(LOG_DEBUG, "xfrpc proxy close connect server [%s:%d] stream_id %d: %s",
client->ps->local_ip, client->ps->local_port,
client->stream_id, strerror(errno));
tcp_mux_send_win_update_fin(client->ctl_bev, client->stream_id);
client->stream_state = LOCAL_CLOSE;
tmux_stream_close(client->ctl_bev, &client->stream);
} else if (what & BEV_EVENT_CONNECTED) {
debug(LOG_DEBUG, "client [%d] connected", client->stream_id);
//client->stream_state = ESTABLISHED;
//client->stream.state = ESTABLISHED;
if (client->data_tail_size > 0) {
debug(LOG_DEBUG, "send client data ...");
send_client_data_tail(client);
Expand Down Expand Up @@ -178,6 +177,7 @@ send_client_data_tail(struct proxy_client *client)
static void
free_proxy_client(struct proxy_client *client)
{
debug(LOG_DEBUG, "free client %d", client->stream_id);
if (client->local_proxy_bev) bufferevent_free(client->local_proxy_bev);
free(client);
}
Expand All @@ -195,6 +195,15 @@ del_proxy_client(struct proxy_client *client)
free_proxy_client(client);
}

void
del_proxy_client_by_stream_id(uint32_t sid)
{
del_stream(sid);

struct proxy_client *pc = get_proxy_client(sid);
del_proxy_client(pc);
}

struct proxy_client *
get_proxy_client(uint32_t sid)
{
Expand All @@ -209,8 +218,7 @@ new_proxy_client()
struct proxy_client *client = calloc(1, sizeof(struct proxy_client));
assert(client);
client->stream_id = get_next_session_id();
client->send_window = 200*1024;
client->stream_state = INIT;
init_tmux_stream(&client->stream, client->stream_id, INIT);
HASH_ADD_INT(all_pc, stream_id, client);

return client;
Expand Down
7 changes: 4 additions & 3 deletions client.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ struct proxy_client {
struct bufferevent *ctl_bev; // xfrpc proxy <---> frps
struct bufferevent *local_proxy_bev; // xfrpc proxy <---> local service
struct base_conf *bconf;

struct tmux_stream stream;

uint32_t stream_id;
uint32_t send_window;
enum tcp_mux_state stream_state;
int connected;
int work_started;
struct proxy_service *ps;
Expand Down Expand Up @@ -91,6 +90,8 @@ void start_xfrp_tunnel(struct proxy_client *client);

void del_proxy_client(struct proxy_client *client);

void del_proxy_client_by_stream_id(uint32_t sid);

struct proxy_client *get_proxy_client(uint32_t sid);

int send_client_data_tail(struct proxy_client *client);
Expand Down
5 changes: 0 additions & 5 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,22 +239,17 @@ proxy_service_handler(void *user, const char *sect, const char *nm, const char *
ps->remote_data_port = atoi(value);
} else if (MATCH_NAME("http_user")) {
ps->http_user = strdup(value);
assert(ps->http_user);
} else if (MATCH_NAME("http_pwd")) {
ps->http_pwd = strdup(value);
assert(ps->http_pwd);
} else if (MATCH_NAME("subdomain")) {
ps->subdomain = strdup(value);
assert(ps->http_pwd);
} else if (MATCH_NAME("custom_domains")) {
ps->custom_domains = strdup(value);
assert(ps->custom_domains);
} else if (MATCH_NAME("locations")) {
ps->locations = strdup(value);
assert(ps->locations);
} else if (MATCH_NAME("host_header_rewrite")) {
ps->host_header_rewrite = strdup(value);
assert(ps->host_header_rewrite);
} else if (MATCH_NAME("use_encryption")) {
ps->use_encryption = TO_BOOL(value);
} else if (MATCH_NAME("use_compression")) {
Expand Down
Loading

0 comments on commit c53693b

Please sign in to comment.