|
|
@ -253,7 +253,6 @@ delayed_connect_cb(EV_P_ ev_timer *watcher, int revents) |
|
|
|
server_t *server = cork_container_of(watcher, server_t, |
|
|
|
delayed_connect_watcher); |
|
|
|
|
|
|
|
server->stage = STAGE_WAIT; |
|
|
|
server_recv_cb(EV_A_ & server->recv_ctx->io, revents); |
|
|
|
} |
|
|
|
|
|
|
@ -266,13 +265,15 @@ server_recv_cb(EV_P_ ev_io *w, int revents) |
|
|
|
buffer_t *buf; |
|
|
|
ssize_t r; |
|
|
|
|
|
|
|
ev_timer_stop(EV_A_ & server->delayed_connect_watcher); |
|
|
|
|
|
|
|
if (remote == NULL) { |
|
|
|
buf = server->buf; |
|
|
|
} else { |
|
|
|
buf = remote->buf; |
|
|
|
} |
|
|
|
|
|
|
|
if (server->stage != STAGE_WAIT) { |
|
|
|
if (revents != EV_TIMER) { |
|
|
|
r = recv(server->fd, buf->data + buf->len, BUF_SIZE - buf->len, 0); |
|
|
|
|
|
|
|
if (r == 0) { |
|
|
@ -294,8 +295,6 @@ server_recv_cb(EV_P_ ev_io *w, int revents) |
|
|
|
} |
|
|
|
} |
|
|
|
buf->len += r; |
|
|
|
} else { |
|
|
|
server->stage = STAGE_STREAM; |
|
|
|
} |
|
|
|
|
|
|
|
while (1) { |
|
|
@ -307,8 +306,6 @@ server_recv_cb(EV_P_ ev_io *w, int revents) |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
ev_timer_stop(EV_A_ & server->delayed_connect_watcher); |
|
|
|
|
|
|
|
// insert shadowsocks header |
|
|
|
if (!remote->direct) { |
|
|
|
#ifdef __ANDROID__ |
|
|
@ -498,7 +495,9 @@ server_recv_cb(EV_P_ ev_io *w, int revents) |
|
|
|
|
|
|
|
buf->len = 0; |
|
|
|
return; |
|
|
|
} else if (server->stage == STAGE_HANDSHAKE || server->stage == STAGE_PARSE) { |
|
|
|
} else if (server->stage == STAGE_HANDSHAKE || |
|
|
|
server->stage == STAGE_PARSE || |
|
|
|
server->stage == STAGE_SNI) { |
|
|
|
struct socks5_request *request = (struct socks5_request *)buf->data; |
|
|
|
size_t request_len = sizeof(struct socks5_request); |
|
|
|
struct sockaddr_in sock_addr; |
|
|
@ -568,9 +567,9 @@ server_recv_cb(EV_P_ ev_io *w, int revents) |
|
|
|
// Wait until client closes the connection |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
server->stage = STAGE_PARSE; |
|
|
|
server->stage = STAGE_PARSE; |
|
|
|
} |
|
|
|
|
|
|
|
char host[257], ip[INET6_ADDRSTRLEN], port[16]; |
|
|
|
|
|
|
@ -650,7 +649,9 @@ server_recv_cb(EV_P_ ev_io *w, int revents) |
|
|
|
else if (dst_port == tls_protocol->default_port) |
|
|
|
ret = tls_protocol->parse_packet(buf->data + 3 + abuf->len, |
|
|
|
buf->len - 3 - abuf->len, &hostname); |
|
|
|
if (ret == -1 && buf->len < BUF_SIZE) { |
|
|
|
if (ret == -1 && buf->len < BUF_SIZE && server->stage != STAGE_SNI) { |
|
|
|
server->stage = STAGE_SNI; |
|
|
|
ev_timer_start(EV_A_ & server->delayed_connect_watcher); |
|
|
|
return; |
|
|
|
} else if (ret > 0) { |
|
|
|
sni_detected = 1; |
|
|
@ -683,13 +684,16 @@ server_recv_cb(EV_P_ ev_io *w, int revents) |
|
|
|
&& !(vpn && strcmp(port, "53") == 0) |
|
|
|
#endif |
|
|
|
) { |
|
|
|
int host_match = acl_match_host(host); |
|
|
|
int bypass = 0; |
|
|
|
int resolved = 0; |
|
|
|
struct sockaddr_storage storage; |
|
|
|
memset(&storage, 0, sizeof(struct sockaddr_storage)); |
|
|
|
int err; |
|
|
|
|
|
|
|
int host_match = 0; |
|
|
|
if (sni_detected || atyp == 3) |
|
|
|
host_match = acl_match_host(host); |
|
|
|
|
|
|
|
if (host_match > 0) |
|
|
|
bypass = 1; // bypass hostnames in black list |
|
|
|
else if (host_match < 0) |
|
|
@ -786,7 +790,6 @@ server_recv_cb(EV_P_ ev_io *w, int revents) |
|
|
|
remote->server = server; |
|
|
|
|
|
|
|
if (buf->len > 0 || sni_detected) { |
|
|
|
server->stage = STAGE_STREAM; |
|
|
|
continue; |
|
|
|
} else { |
|
|
|
ev_timer_start(EV_A_ & server->delayed_connect_watcher); |
|
|
|