Skip to content

Commit

Permalink
clean: clean unused function
Browse files Browse the repository at this point in the history
Signed-off-by: Dengfeng Liu <[email protected]>
  • Loading branch information
liudf0716 committed Nov 14, 2022
1 parent c53693b commit 3396100
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 252 deletions.
1 change: 0 additions & 1 deletion control.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,6 @@ connect_event_cb (struct bufferevent *bev, short what, void *ctx)
c_conf->server_addr,
c_conf->server_port,
strerror(errno));
assert(0);
reset_session_id();
clear_main_control();
run_control();
Expand Down
252 changes: 1 addition & 251 deletions tcpmux.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,71 +44,6 @@ static struct tmux_stream *all_stream;
static uint32_t ring_buffer_read(struct bufferevent *bev, struct ring_buffer *ring, uint32_t len);
static uint32_t ring_buffer_write(struct bufferevent *bev, struct ring_buffer *ring, uint32_t len);

static struct tcp_mux_type_desc type_desc[] = {
{DATA, "data"},
{WINDOW_UPDATE, "window update"},
{PING, "ping"},
{GO_AWAY, "go away"},
};

static struct tcp_mux_flag_desc flag_desc[] = {
{ZERO, "zero"},
{SYN, "syn"},
{ACK, "ack"},
{FIN, "fin"},
{RST, "rst"},
};

static const char *
type_2_desc(enum tcp_mux_type type)
{
for(int i = 0; i < sizeof(type_desc)/sizeof(struct tcp_mux_type_desc); i++){
if (type == type_desc[i].type)
return type_desc[i].desc;
}

return "unkown_type";
}

static const char *
flag_2_desc(enum tcp_mux_flag flag)
{
for(int i = 0; i < sizeof(flag_desc)/sizeof(struct tcp_mux_flag_desc); i++){
if (flag == flag_desc[i].flag)
return flag_desc[i].desc;
}

return "unkown_flag";
}

static int
valid_tcp_mux_flag(uint16_t flag)
{
for(int i = 0; i < sizeof(flag_desc)/sizeof(struct tcp_mux_flag_desc); i++){
if (flag == flag_desc[i].flag)
return 1;
}
return 0;
}

static int
valid_tcp_mux_type(uint8_t type)
{
if (type >= DATA && type <= GO_AWAY)
return 1;

return 0;
}

static int
valid_tcp_mux_sid(uint32_t sid)
{
if (sid == 1)
return 1;

return get_proxy_client(sid)?1:0;
}

void
add_stream(struct tmux_stream *stream)
{
Expand Down Expand Up @@ -189,45 +124,6 @@ tcp_mux_flag()
return c_conf->tcp_mux;
}

static void
dump_tcp_mux_header(uint8_t *data, int len)
{
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)
{
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 == 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));
dump_tcp_mux_header(data, len);
exit(-1);
}
*type = hdr->type;
*flag = htons(hdr->flags);
*stream_id = htonl(hdr->stream_id);
*dlen = htonl(hdr->length);
return 1;
}

return 0;
}


void
reset_session_id() {
g_session_id = 1;
Expand Down Expand Up @@ -711,150 +607,4 @@ tmux_stream_close(struct bufferevent *bout, struct tmux_stream *stream)
}
}

static void
deprecated_handle_tcp_mux_frps_msg(uint8_t *buf, int ilen, void (*fn)(uint8_t *, int, void *))
{
static uint32_t l_stream_id = 0;
static uint32_t l_dlen = 0;
static uint32_t l_type = 0;
static uint32_t l_flag = 0;
static int8_t only_data = 0;
uint8_t *data = buf;
while (ilen > 0) {
uint32_t type = 0, stream_id = 0, dlen = 0, flag = 0;
uint32_t is_tmux;
if (only_data) {
is_tmux = 0;
only_data = 0;
} else {
is_tmux = parse_tcp_mux_proto(data, ilen, &flag, &type, &stream_id, &dlen);
}
if (!is_tmux) {
struct proxy_client *pc = get_proxy_client(l_stream_id);
debug(LOG_DEBUG, "receive only %s data : l_stream_id %d l_type %s l_flag %s l_dlen %d ilen %d",
!pc?"main control ":"worker ",
l_stream_id, type_2_desc(l_type),
flag_2_desc(l_flag), l_dlen, ilen);
assert(ilen);
if (ilen == 12)
dump_tcp_mux_header(data, ilen);

if (!pc || (pc && !pc->local_proxy_bev)) {
assert(ilen >= l_dlen);
assert(l_dlen > 0);
fn(data, l_dlen, pc);
data += l_dlen;
ilen -= l_dlen;
l_dlen = 0;
continue;
}

if (pc->stream.state != ESTABLISHED) {
debug(LOG_INFO, "client [%d] state is [%d]", pc->stream_id, pc->stream.state);
break;
}

if ( ilen >= l_dlen) {
assert(pc->local_proxy_bev);
bufferevent_write(pc->local_proxy_bev, data, l_dlen);
data += l_dlen;
ilen -= l_dlen;
l_dlen = 0;
} else {
assert(pc->local_proxy_bev);
bufferevent_write(pc->local_proxy_bev, data, ilen);
l_dlen -= ilen;
ilen = 0;
}

continue;
}

struct proxy_client *pc = get_proxy_client(stream_id);
debug(LOG_DEBUG, "[%s] receive tcp mux type [%s] flag [%s] stream_id [%d] dlen [%d] ilen [%d]",
pc?"worker":"main control",
type_2_desc(type), flag_2_desc(flag), stream_id, dlen, ilen);
data += sizeof(struct tcp_mux_header);
ilen -= sizeof(struct tcp_mux_header);
l_stream_id = stream_id;
l_type = type;
l_flag = flag;
l_dlen = type==PING?0:dlen;
assert(ilen >= 0);

switch(type) {
case DATA:
{
if (ilen == 0) {
only_data = 1;
break;
}

if (!pc || (pc && !pc->local_proxy_bev)) {
assert(ilen >= dlen);
fn(data, dlen, pc);
data += dlen;
ilen -= dlen;
l_dlen = 0;
continue;
}

if (pc->stream.state != ESTABLISHED) {
debug(LOG_INFO, "client [%d] state is [%d]", pc->stream_id, pc->stream.state);
break;
}

if (ilen >= dlen){
assert(pc->local_proxy_bev);
bufferevent_write(pc->local_proxy_bev, data, dlen);
data += dlen;
ilen -= dlen;
l_dlen = 0;
} else {
assert(pc->local_proxy_bev);
bufferevent_write(pc->local_proxy_bev, data, ilen);
l_dlen -= ilen;
ilen = 0;
}
break;
}
case PING:
{
struct bufferevent *bout = get_main_control()->connect_bev;
uint32_t seq = dlen;
assert(bout);
if (flag == SYN)
tcp_mux_handle_ping(bout, seq);
break;
}
case WINDOW_UPDATE:
{
switch(flag) {
case RST:
case FIN:
del_proxy_client(pc);
break;
case ZERO:
case ACK:
if (!pc)
break;

if (dlen > 0) {
pc->stream.send_window += dlen;
bufferevent_enable(pc->local_proxy_bev, EV_READ|EV_WRITE);
}
pc->stream.state = ESTABLISHED;
break;
default:
debug(LOG_INFO, "window update no need process : flag %2x %s dlen %d stream_id %d",
flag, flag_2_desc(flag), dlen, stream_id);
}

break;
}
default:
debug(LOG_INFO, "no need unhandle tcp mux msg : type %s flag %s stream_id %d dlen %d ilen %d",
type_2_desc(type), flag_2_desc(flag), stream_id, dlen, ilen);
}
}
}

0 comments on commit 3396100

Please sign in to comment.