Skip to content

Commit

Permalink
同步参数名
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowsocksRb committed Oct 11, 2019
1 parent e2373d7 commit 70921a0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 34 deletions.
27 changes: 11 additions & 16 deletions src/android.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
#include "netutils.h"
#include "utils.h"

extern char *prefix;

int
protect_socket(int fd)
{
Expand All @@ -58,23 +56,20 @@ protect_socket(int fd)
return -1;
}

// Set timeout to 1s
// Set timeout to 3s
struct timeval tv;
tv.tv_sec = 1;
tv.tv_sec = 3;
tv.tv_usec = 0;
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval));
setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval));

char path[257];
sprintf(path, "%s/protect_path", prefix);

memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);
strncpy(addr.sun_path, "protect_path", sizeof(addr.sun_path) - 1);

if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
LOGE("[android] connect() failed: %s (socket fd = %d), path: %s\n",
strerror(errno), sock, path);
LOGE("[android] connect() failed for protect_path: %s (socket fd = %d)\n",
strerror(errno), sock);
close(sock);
return -1;
}
Expand All @@ -97,9 +92,12 @@ protect_socket(int fd)
return ret;
}

extern char *stat_path;

int
send_traffic_stat(uint64_t tx, uint64_t rx)
{
if (!stat_path) return 0;
int sock;
struct sockaddr_un addr;

Expand All @@ -115,16 +113,13 @@ send_traffic_stat(uint64_t tx, uint64_t rx)
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval));
setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval));

char path[257];
sprintf(path, "%s/stat_path", prefix);

memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);
strncpy(addr.sun_path, stat_path, sizeof(addr.sun_path) - 1);

if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
LOGE("[android] connect() failed: %s (socket fd = %d), path: %s\n",
strerror(errno), sock, path);
LOGE("[android] connect() failed for stat_path: %s (socket fd = %d)\n",
strerror(errno), sock);
close(sock);
return -1;
}
Expand Down
22 changes: 7 additions & 15 deletions src/local.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,11 @@ int verbose = 0;
int keep_resolving = 1;

#ifdef ANDROID
int log_tx_rx = 0;
int vpn = 0;
uint64_t tx = 0;
uint64_t rx = 0;
ev_tstamp last = 0;
char *prefix;
char *stat_path = NULL;
#endif

#include "includeobfs.h" // I don't want to modify makefile
Expand Down Expand Up @@ -372,7 +371,6 @@ server_recv_cb(EV_P_ ev_io *w, int revents)
}
// SSR end
#ifdef ANDROID
if (log_tx_rx)
tx += buf->len;
#endif
}
Expand Down Expand Up @@ -931,13 +929,11 @@ server_send_cb(EV_P_ ev_io *w, int revents)
static void
stat_update_cb()
{
if (log_tx_rx) {
ev_tstamp now = ev_time();
if (now - last > 1.0) {
send_traffic_stat(tx, rx);
last = now;
}
}
}

#endif
Expand Down Expand Up @@ -997,7 +993,6 @@ remote_recv_cb(EV_P_ ev_io *w, int revents)

if (!remote->direct) {
#ifdef ANDROID
if (log_tx_rx)
rx += server->buf->len;
#endif
if ( r == 0 )
Expand Down Expand Up @@ -1517,7 +1512,7 @@ main(int argc, char **argv)
USE_TTY();

#ifdef ANDROID
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:L:a:n:P:xhuUvVA6"
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:L:a:n:S:huUvVA6"
"O:o:G:g:",
long_options, &option_index)) != -1)
#else
Expand Down Expand Up @@ -1625,14 +1620,11 @@ main(int argc, char **argv)
break;
#ifdef ANDROID
case 'V':
vpn = 1;
break;
case 'P':
prefix = optarg;
break;
case 'x':
log_tx_rx = 1;
break;
vpn = 1;
break;
case 'S':
stat_path = optarg;
break;
#endif
case '?':
// The option character is not recognized.
Expand Down
4 changes: 1 addition & 3 deletions src/udprelay.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ static void close_and_free_remote(EV_P_ remote_ctx_t *ctx);
static remote_ctx_t *new_remote(int fd, server_ctx_t *server_ctx);

#ifdef ANDROID
extern int log_tx_rx;
extern uint64_t tx;
extern uint64_t rx;
extern int vpn;
Expand Down Expand Up @@ -763,7 +762,7 @@ remote_recv_cb(EV_P_ ev_io *w, int revents)
memmove(buf->array, buf->array + len, buf->len);
#else
#ifdef ANDROID
if (r > 0 && log_tx_rx)
if (r > 0)
rx += r;
#endif
// Construct packet
Expand Down Expand Up @@ -1234,7 +1233,6 @@ server_recv_cb(EV_P_ ev_io *w, int revents)
}
#if !defined(MODULE_TUNNEL) && !defined(MODULE_REDIR)
#ifdef ANDROID
if (log_tx_rx)
tx += buf->len;
#endif
#endif
Expand Down

0 comments on commit 70921a0

Please sign in to comment.