Skip to content

Commit

Permalink
enable TCP_NODELAY from config file (#1757)
Browse files Browse the repository at this point in the history
* Fix #1739

Refine #1739

* enable TCP_NODELAY from config file
  • Loading branch information
wangxufire authored and madeye committed Oct 30, 2017
1 parent 54c7190 commit 44027da
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -93,3 +93,6 @@ doc/*.html
*.tar.gz
*.tgz
#

# Visual Studio Code
.vscode/*
12 changes: 11 additions & 1 deletion README.md
Expand Up @@ -184,7 +184,7 @@ Supported distributions:

If you are using CentOS 7, you need to install these prequirement to build from source code:

```bash
```bash
yum install epel-release -y
yum install gcc gettext autoconf libtool automake make pcre-devel asciidoc xmlto c-ares-devel libev-devel libsodium-devel mbedtls-devel -y
```
Expand Down Expand Up @@ -381,9 +381,13 @@ you may refer to the man pages of the applications, respectively.
for local port forwarding,
only available in tunnel mode
[-6] Resovle hostname to IPv6 address first.
[-d <addr>] setup name servers for internal DNS resolver,
only available in server mode
[--reuse-port] Enable port reuse.
[--fast-open] enable TCP fast open,
only available in local and server mode,
with Linux kernel > 3.7.0
Expand All @@ -394,6 +398,12 @@ you may refer to the man pages of the applications, respectively.
[--manager-address <addr>] UNIX domain socket address
only available in server and manager mode
[--mtu <MTU>] MTU of your network interface.
[--mptcp] Enable Multipath TCP on MPTCP Kernel.
[--no-delay] Enable TCP_NODELAY.
[--executable <path>] path to the executable of ss-server
only available in manager mode
Expand Down
2 changes: 1 addition & 1 deletion completions/bash/ss-local
@@ -1,7 +1,7 @@
_ss_local()
{
local cur prev opts ciphers
opts='-s -p -l -k -m -a -f -t -c -n -i -b -u -U -v -h --reuse-port --fast-open --acl --mtu --mptcp --key --plugin --plugin-opts --help'
opts='-s -p -l -k -m -a -f -t -c -n -i -b -u -U -v -h --reuse-port --fast-open --acl --mtu --mptcp --no-delay --key --plugin --plugin-opts --help'
ciphers='rc4-md5 aes-128-gcm aes-192-gcm aes-256-gcm aes-128-cfb aes-192-cfb aes-256-cfb aes-128-ctr aes-192-ctr aes-256-ctr camellia-128-cfb camellia-192-cfb camellia-256-cfb bf-cfb chacha20-ietf-poly1305 salsa20 chacha20 chacha20-ietf'
cur=${COMP_WORDS[COMP_CWORD]}
prev="${COMP_WORDS[COMP_CWORD-1]}"
Expand Down
2 changes: 1 addition & 1 deletion completions/bash/ss-server
@@ -1,7 +1,7 @@
_ss_server()
{
local cur prev opts ciphers
opts='-s -p -l -k -m -a -f -t -c -n -i -b -u -U -6 -d -v -h --reuse-port --fast-open --acl --manager-address --mtu --mptcp --key --plugin --plugin-opts --help'
opts='-s -p -l -k -m -a -f -t -c -n -i -b -u -U -6 -d -v -h --reuse-port --fast-open --acl --manager-address --mtu --mptcp --no-delay --key --plugin --plugin-opts --help'
ciphers='rc4-md5 aes-128-gcm aes-192-gcm aes-256-gcm aes-128-cfb aes-192-cfb aes-256-cfb aes-128-ctr aes-192-ctr aes-256-ctr camellia-128-cfb camellia-192-cfb camellia-256-cfb bf-cfb chacha20-ietf-poly1305 salsa20 chacha20 chacha20-ietf'
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
Expand Down
1 change: 1 addition & 0 deletions completions/zsh/_ss-local
Expand Up @@ -24,6 +24,7 @@ _arguments "-h::" \
"--acl:acl file:_files" \
"--mtu::" \
"--mptcp::" \
"--no-delay::" \
"--key:key in base64:" \
"--plugin:plugin name:" \
"--plugin-opts:plugin options:" \
Expand Down
1 change: 1 addition & 0 deletions completions/zsh/_ss-redir
Expand Up @@ -23,6 +23,7 @@ _arguments "-h::" \
"--acl:acl file:_files" \
"--mtu::" \
"--mptcp::" \
"--no-delay::" \
"--key:key in base64:" \
"--plugin:plugin name:" \
"--plugin-opts:plugin options:" \
Expand Down
1 change: 1 addition & 0 deletions completions/zsh/_ss-server
Expand Up @@ -27,6 +27,7 @@ _arguments "-h::" \
"--acl:acl file:_files" \
"--mtu::" \
"--mptcp::" \
"--no-delay::" \
"--key:key in base64:" \
"--plugin:plugin name:" \
"--plugin-opts:plugin options:" \
Expand Down
1 change: 1 addition & 0 deletions doc/shadowsocks-libev.asciidoc
Expand Up @@ -179,6 +179,7 @@ The config file equivalent of command line options is listed as example below.
| -a nobody | "user": "nobody"
| --fast-open | "fast_open": true
| --reuse-port | "reuse_port": true
| --no-delay | "no_delay": true
| --plugin "obfs-server" | "plugin": "obfs-server"
| --plugin-opts "obfs=http" | "plugin_opts": "obfs=http"
| -6 | "ipv6_first": true
Expand Down
5 changes: 5 additions & 0 deletions src/jconf.c
Expand Up @@ -326,6 +326,11 @@ read_jconf(const char *file)
"invalid config file: option 'use_syslog' must be a boolean");
use_syslog = value->u.boolean;
#endif
} else if (strcmp(name, "no_delay") == 0) {
check_json_value_type(
value, json_boolean,
"invalid config file: option 'no_delay' must be a boolean");
conf.no_delay = value->u.boolean;
}
}
} else {
Expand Down
1 change: 1 addition & 0 deletions src/jconf.h
Expand Up @@ -86,6 +86,7 @@ typedef struct {
int mtu;
int mptcp;
int ipv6_first;
int no_delay;
} jconf_t;

jconf_t *read_jconf(const char *file);
Expand Down
7 changes: 7 additions & 0 deletions src/local.c
Expand Up @@ -1493,6 +1493,9 @@ main(int argc, char **argv)
if (mptcp == 0) {
mptcp = conf->mptcp;
}
if (no_delay == 0) {
no_delay = conf->no_delay;
}
#ifdef HAVE_SETRLIMIT
if (nofile == 0) {
nofile = conf->nofile;
Expand Down Expand Up @@ -1563,6 +1566,10 @@ main(int argc, char **argv)
#endif
}

if (no_delay) {
LOGI("enable TCP no-delay");
}

if (ipv6first) {
LOGI("resolving hostname to IPv6 address first");
}
Expand Down
7 changes: 7 additions & 0 deletions src/redir.c
Expand Up @@ -1071,6 +1071,9 @@ main(int argc, char **argv)
if (mptcp == 0) {
mptcp = conf->mptcp;
}
if (no_delay == 0) {
no_delay = conf->no_delay;
}
if (reuse_port == 0) {
reuse_port = conf->reuse_port;
}
Expand Down Expand Up @@ -1150,6 +1153,10 @@ main(int argc, char **argv)
daemonize(pid_path);
}

if (no_delay) {
LOGI("enable TCP no-delay");
}

if (ipv6first) {
LOGI("resolving hostname to IPv6 address first");
}
Expand Down
7 changes: 7 additions & 0 deletions src/server.c
Expand Up @@ -1679,6 +1679,9 @@ main(int argc, char **argv)
if (mptcp == 0) {
mptcp = conf->mptcp;
}
if (no_delay == 0) {
no_delay = conf->no_delay;
}
if (reuse_port == 0) {
reuse_port = conf->reuse_port;
}
Expand Down Expand Up @@ -1771,6 +1774,10 @@ main(int argc, char **argv)
LOGI("TCP relay disabled");
}

if (no_delay) {
LOGI("enable TCP no-delay");
}

// ignore SIGPIPE
signal(SIGPIPE, SIG_IGN);
signal(SIGABRT, SIG_IGN);
Expand Down
3 changes: 3 additions & 0 deletions src/tunnel.c
Expand Up @@ -974,6 +974,9 @@ main(int argc, char **argv)
if (mptcp == 0) {
mptcp = conf->mptcp;
}
if (no_delay == 0) {
no_delay = conf->no_delay;
}
if (reuse_port == 0) {
reuse_port = conf->reuse_port;
}
Expand Down

0 comments on commit 44027da

Please sign in to comment.