Skip to content

Commit

Permalink
Merge branch 'release/0.4.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
lparam committed Aug 17, 2020
2 parents 9def74f + 708c103 commit 31d638d
Show file tree
Hide file tree
Showing 18 changed files with 162 additions and 136 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ tags

/Debug
/Release
.vscode
*.opensdf
*.sdf
*.suo
Expand Down
2 changes: 1 addition & 1 deletion 3rd/c-ares
2 changes: 1 addition & 1 deletion 3rd/libuv
Submodule libuv updated 362 files
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v0.4.6 (2020-8-17)
-----------
* Fix: don't use uv_write_t
* Feature: log level


v0.4.5 (2016-7-23)
-----------
* Fix: Package avalible
Expand Down
34 changes: 16 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ LIBANCILLARY = $(OBJTREE)/3rd/libancillary/libancillary.a
LIBS += $(OBJTREE)/3rd/libuv/.libs/libuv.a $(OBJTREE)/3rd/libsodium/src/libsodium/.libs/libsodium.a

ifdef MINGW32
LIBS += -lws2_32 -lpsapi -liphlpapi -luserenv
LIBS += -lws2_32 -lpsapi -liphlpapi -luserenv -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic
else
LIBS += -pthread -ldl
endif
Expand All @@ -110,8 +110,6 @@ ifdef STATIC
LDFLAGS += -Wl,-static -static -static-libgcc -s
endif

XSOCKSD=$(OBJTREE)/xSocksd
XSOCKS=$(OBJTREE)/xSocks
XTPROXY=$(OBJTREE)/xTproxy
XFORWARDER=$(OBJTREE)/xForwarder
XTUNNEL=$(OBJTREE)/xTunnel
Expand All @@ -121,13 +119,13 @@ include $(SRCTREE)/config.mk
#########################################################################

ifdef OPENWRT
all: libuv libsodium $(XSOCKS) $(XTPROXY) $(XFORWARDER) $(XTUNNEL)
all: libuv libsodium xSocks $(XTPROXY) $(XFORWARDER) $(XTUNNEL)
else
all: libuv libsodium c-ares $(XSOCKSD) $(XSOCKS) $(XTPROXY) $(XFORWARDER) $(XTUNNEL)
all: libuv libsodium c-ares xSocksd xSocks $(XTPROXY) $(XFORWARDER) $(XTUNNEL)
endif

android: libuv libsodium $(XSOCKS) $(XFORWARDER)
mingw32: libuv libsodium c-ares $(XSOCKSD).exe $(XSOCKS).exe $(XFORWARDER).exe $(XTUNNEL).exe
android: libuv libsodium xSocks $(XFORWARDER)
mingw32: libuv libsodium c-ares xSocksd xSocks $(XFORWARDER).exe $(XTUNNEL).exe

3rd/libuv/autogen.sh:
$(Q)git submodule update --init
Expand Down Expand Up @@ -210,7 +208,7 @@ lib3rd: $(LIBCORK) $(LIBIPSET)
endif

ifndef MINGW32
$(XSOCKSD): \
xSocksd: \
$(OBJTREE)/src/util.o \
$(OBJTREE)/src/logger.o \
$(OBJTREE)/src/common.o \
Expand All @@ -225,9 +223,9 @@ $(XSOCKSD): \
$(OBJTREE)/src/xSocksd_client.o \
$(OBJTREE)/src/xSocksd_remote.o \
$(OBJTREE)/src/xSocksd.o
$(LINK) $^ -o $@ $(LDFLAGS) $(OBJTREE)/3rd/c-ares/.libs/libcares.a
$(LINK) $^ -o $(OBJTREE)/$@ $(LDFLAGS) $(OBJTREE)/3rd/c-ares/.libs/libcares.a
else
$(XSOCKSD).exe: \
xSocksd: \
src/util.o \
src/logger.o \
src/common.o \
Expand All @@ -240,7 +238,7 @@ $(XSOCKSD).exe: \
src/xSocksd_client.o \
src/xSocksd_remote.o \
src/xSocksd.o
$(LINK) $^ -o $@ 3rd/c-ares/.libs/libcares.a $(LDFLAGS)
$(LINK) $^ -o $(OBJTREE)/$@.exe 3rd/c-ares/.libs/libcares.a $(LDFLAGS)
endif

XSOCKS_OBJS = \
Expand All @@ -264,12 +262,12 @@ ifdef ANDROID
endif

ifndef MINGW32
$(XSOCKS): \
xSocks: \
$(XSOCKS_OBJS) \
| lib3rd
$(LINK) $^ -o $@ $(LDFLAGS) $(LIB3RD)
$(LINK) $^ -o $(OBJTREE)/$@ $(LDFLAGS) $(LIB3RD)
else
$(XSOCKS).exe: \
xSocks: \
src/util.o \
src/logger.o \
src/common.o \
Expand All @@ -281,7 +279,7 @@ $(XSOCKS).exe: \
src/xSocks_client.o \
src/xSocks_remote.o \
src/xSocks.o
$(LINK) $^ -o $@ $(LDFLAGS)
$(LINK) $^ -o $(OBJTREE)/$@.exe $(LDFLAGS)
endif

$(XTPROXY): \
Expand Down Expand Up @@ -360,7 +358,7 @@ clean:
\( -name '*.o' -o -name '*~' \
-o -name '*.tmp' \) -print \
| xargs rm -f
@rm -f $(XSOCKSD) $(XSOCKS) $(XTPROXY) $(XFORWARDER) $(XTUNNEL)
@rm -f $(OBJTREE)/xSocksd $(OBJTREE)/xSocks $(XTPROXY) $(XFORWARDER) $(XTUNNEL)

distclean: clean
@find $(OBJTREE)/3rd/libcork $(OBJTREE)/3rd/libipset -type f \
Expand All @@ -379,8 +377,8 @@ endif

ifndef CROSS_COMPILE
install:
$(Q)$(STRIP) --strip-unneeded $(XSOCKSD) && cp $(XSOCKSD) $(INSTALL_DIR)
$(Q)$(STRIP) --strip-unneeded $(XSOCKS) && cp $(XSOCKS) $(INSTALL_DIR)
$(Q)$(STRIP) --strip-unneeded xSocksd && cp $(OBJTREE)/xSocksd $(INSTALL_DIR)
$(Q)$(STRIP) --strip-unneeded xSocks && cp $(OBJTREE)/xSocks $(INSTALL_DIR)
$(Q)$(STRIP) --strip-unneeded $(XTPROXY) && cp $(XTPROXY) $(INSTALL_DIR)
$(Q)$(STRIP) --strip-unneeded $(XFORWARDER) && cp $(XFORWARDER) $(INSTALL_DIR)
$(Q)$(STRIP) --strip-unneeded $(XTUNNEL) && cp $(XTUNNEL) $(INSTALL_DIR)
Expand Down
12 changes: 9 additions & 3 deletions src/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define LOG_MESSAGE_SIZE 256

static int _syslog = 0;
static int _level = LOG_INFO;

#ifdef _WIN32
static uv_tty_t _tty;
Expand All @@ -29,7 +30,7 @@ static uv_tty_t _ttyerr;
#endif

static const char *levels[] = {
"EMERG", "ALERT", "CRIT", "ERR", "WARN", "NOTICE", "INFO", "DEBUG"
"EMERG", "ALERT", "CRIT", "ERRO", "WARN", "NOTICE", "INFO", "DEBG"
};

#ifndef ANDROID
Expand Down Expand Up @@ -70,6 +71,10 @@ void
logger_log(uint32_t level, const char *msg, ...) {
char tmp[LOG_MESSAGE_SIZE];

if (level > _level) {
return;
}

va_list ap;
va_start(ap, msg);
vsnprintf(tmp, LOG_MESSAGE_SIZE, msg, ap);
Expand All @@ -96,7 +101,7 @@ logger_log(uint32_t level, const char *msg, ...) {
char timestr[20];
strftime(timestr, 20, "%Y/%m/%d %H:%M:%S", loctime);
char m[300] = { 0 };
sprintf(m, "%s%s [%s]\033[0m: %s\n", colors[level], timestr, levels[level], tmp);
sprintf(m, "%s %s%s\033[0m %s\n", timestr, colors[level], levels[level], tmp);
#ifdef _WIN32
log2tty(&_tty, m);
#else
Expand Down Expand Up @@ -131,7 +136,7 @@ logger_stderr(const char *msg, ...) {
}

int
logger_init(int syslog) {
logger_init(int syslog, int level) {
#ifndef _WIN32
_syslog = syslog;
#else
Expand All @@ -140,6 +145,7 @@ logger_init(int syslog) {
uv_tty_set_mode(&_tty, UV_TTY_MODE_NORMAL);
uv_tty_set_mode(&_ttyerr, UV_TTY_MODE_NORMAL);
#endif
_level = level;

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define LOG_DEBUG 7 /* debug-level messages */
#endif

int logger_init(int syslog);
int logger_init(int syslog, int level);
void logger_exit(void);
void logger_stderr(const char *msg, ...);
void logger_log(uint32_t level, const char *msg, ...);
Expand Down
5 changes: 3 additions & 2 deletions src/xForwarder.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

static int daemon_mode = 1;
static int concurrency = 0;
static int log_level = LOG_INFO;
static char *local_addr = "0.0.0.0:5533";
static char *server_addr_buf;
static char *pidfile = "/var/run/xSocks/xForwarder.pid";
Expand Down Expand Up @@ -191,9 +192,9 @@ setup_signal(uv_loop_t *loop, uv_signal_cb cb, void *data) {
static void
init(void) {
#ifdef ANDROID
logger_init(0);
logger_init(0, log_level);
#else
logger_init(daemon_mode);
logger_init(daemon_mode, log_level);
#endif

setvbuf(stdout, NULL, _IONBF, 0);
Expand Down
6 changes: 3 additions & 3 deletions src/xSocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

static int daemon_mode = 1;
static int concurrency = 0;
static int log_level = LOG_INFO;
static char *local_addr = "0.0.0.0:1080";
static char *server_addr_buf;
static char *pidfile = "/var/run/xSocks/xSocks.pid";
Expand Down Expand Up @@ -193,7 +194,6 @@ signal_cb(uv_signal_t *handle, int signum) {
uv_close((uv_handle_t *)&ctx->tcp, NULL);
udprelay_close(ctx);
}

}
if (signum == SIGTERM) {
logger_log(LOG_INFO, "Received SIGTERM, scheduling shutdown...");
Expand All @@ -220,9 +220,9 @@ setup_signal(uv_loop_t *loop, uv_signal_cb cb, void *data) {
static void
init(void) {
#ifdef ANDROID
logger_init(0);
logger_init(0, log_level);
#else
logger_init(daemon_mode);
logger_init(daemon_mode, log_level);
#endif

setvbuf(stdout, NULL, _IONBF, 0);
Expand Down
6 changes: 2 additions & 4 deletions src/xSocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ struct client_context {
uv_tcp_t tcp;
uv_udp_t udp;
} handle;
uv_write_t write_req;
struct sockaddr addr;
struct remote_context *remote;
uint8_t buf[MAX_PACKET_SIZE];
Expand All @@ -36,7 +35,6 @@ struct remote_context {
uv_tcp_t tcp;
uv_udp_t udp;
} handle;
uv_write_t write_req;
uv_timer_t *timer;
uv_connect_t connect_req;
struct sockaddr addr;
Expand All @@ -47,15 +45,15 @@ struct remote_context {

struct client_context * new_client();
void close_client(struct client_context *client);
void receive_from_client(struct client_context *client);
int receive_from_client(struct client_context *client);
void forward_to_client(struct client_context *client, uint8_t *buf, int buflen);
void client_accept_cb(uv_stream_t *server, int status);
void request_ack(struct client_context *client, enum s5_rep rep);

struct remote_context * new_remote(uint16_t timeout, struct sockaddr *addr);
void close_remote(struct remote_context *remote);
void connect_to_remote(struct remote_context *remote);
void receive_from_remote(struct remote_context *remote);
int receive_from_remote(struct remote_context *remote);
void forward_to_remote(struct remote_context *remote, uint8_t *buf, int buflen);
void reset_timer(struct remote_context *remote);

Expand Down
Loading

0 comments on commit 31d638d

Please sign in to comment.