mirror of
https://github.com/novatiq/packages.git
synced 2026-04-30 07:28:39 +01:00
kcptun: bump to v20190809, merge config and service scripts
This commit updates: - bump version to v20190809 - fix PKG_LICENSE_FILES - rename package names to kcptun-server, kcptun-client - refactor Makefile - merge config and service scripts - add more config options to support all features - add additional options: gogc, syslog, user - add README.md Reference: - package shadowsocks-libev Signed-off-by: Chao Liu <expiron18@gmail.com>
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
config kcptun
|
||||
option local_port 12948 # this port should be your service port
|
||||
option remote_ip 'your vps ip'
|
||||
option remote_port 29900
|
||||
option mode 'fast'
|
||||
option nocomp 1
|
||||
option sndwnd 128
|
||||
option rcvwnd 512
|
||||
option disabled 1 # set 0 to enable it
|
||||
@@ -1,56 +0,0 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2019 Dengfeng Liu
|
||||
|
||||
START=99
|
||||
|
||||
USE_PROCD=1
|
||||
NAME=kcptun-c
|
||||
PROG=/usr/bin/${NAME}
|
||||
|
||||
validate_section_kcptun()
|
||||
{
|
||||
uci_load_validate "${NAME}" kcptun "$1" "$2" \
|
||||
'local_port:port' \
|
||||
'remote_ip:string' \
|
||||
'remote_port:port' \
|
||||
'mode:string' \
|
||||
'nocomp:bool' \
|
||||
'sndwnd:uinteger' \
|
||||
'rcvwnd:uinteger' \
|
||||
'disabled:bool'
|
||||
}
|
||||
|
||||
kcptun_instance()
|
||||
{
|
||||
[ "$2" = 0 ] || {
|
||||
echo "validation failed"
|
||||
return 1
|
||||
}
|
||||
|
||||
[ "${disabled}" = "1" ] && return 1
|
||||
|
||||
[ "${local_port}" -gt 0 ] && [ "${local_port}" -lt 65536 ] || return 1
|
||||
|
||||
[ "${remote_port}" -gt 0 ] && [ "${remote_port}" -lt 65536 ] || return 1
|
||||
|
||||
[ -n "${remote_ip}" ] || {
|
||||
return 1
|
||||
}
|
||||
|
||||
procd_open_instance
|
||||
procd_set_param command "${PROG}"
|
||||
procd_append_param command --localaddr ":${local_port}"
|
||||
procd_append_param command --remoteaddr "${remote_ip}:${remote_port}"
|
||||
[ -n "${mode}" ] && procd_append_param command --mode "${mode}"
|
||||
[ "${nocomp}" -eq 1 ] && procd_append_param command --nocomp
|
||||
[ "${sndwnd}" -gt 0 ] && procd_append_param command --sndwnd "${sndwnd}"
|
||||
[ "${rcvwnd}" -gt 0 ] && procd_append_param command --rcvwnd "${rcvwnd}"
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
start_service()
|
||||
{
|
||||
config_load "${NAME}"
|
||||
config_foreach validate_section_kcptun kcptun kcptun_instance
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
config kcptun
|
||||
option local_port 29900
|
||||
option target_ip '127.0.0.1'
|
||||
option target_port 12948 # this port should be your service port
|
||||
option mode 'fast'
|
||||
option nocomp 1
|
||||
option sndwnd 1024
|
||||
option rcvwnd 1024
|
||||
option disabled 1 # set 0 to enable it
|
||||
@@ -1,56 +0,0 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2019 Dengfeng Liu
|
||||
|
||||
START=99
|
||||
|
||||
USE_PROCD=1
|
||||
NAME=kcptun-s
|
||||
PROG=/usr/bin/${NAME}
|
||||
|
||||
validate_section_kcptun()
|
||||
{
|
||||
uci_load_validate "${NAME}" kcptun "$1" "$2" \
|
||||
'local_port:port' \
|
||||
'target_ip:string' \
|
||||
'target_port:port' \
|
||||
'mode:string' \
|
||||
'nocomp:bool' \
|
||||
'sndwnd:uinteger' \
|
||||
'rcvwnd:uinteger' \
|
||||
'disabled:bool'
|
||||
}
|
||||
|
||||
kcptun_instance()
|
||||
{
|
||||
[ "$2" = 0 ] || {
|
||||
echo "validation failed"
|
||||
return 1
|
||||
}
|
||||
|
||||
[ "${disabled}" = "1" ] && return 1
|
||||
|
||||
[ "${local_port}" -gt 0 ] && [ "${local_port}" -lt 65536 ] || return 1
|
||||
|
||||
[ "${target_port}" -gt 0 ] && [ "${target_port}" -lt 65536 ] || return 1
|
||||
|
||||
[ -n "${target_ip}" ] || {
|
||||
return 1
|
||||
}
|
||||
|
||||
procd_open_instance
|
||||
procd_set_param command "${PROG}"
|
||||
procd_append_param command --listen ":${local_port}"
|
||||
procd_append_param command --target "${target_ip}:${target_port}"
|
||||
[ -n "${mode}" ] && procd_append_param command --mode "${mode}"
|
||||
[ "${nocomp}" -eq 1 ] && procd_append_param command --nocomp
|
||||
[ "${sndwnd}" -gt 0 ] && procd_append_param command --sndwnd "${sndwnd}"
|
||||
[ "${rcvwnd}" -gt 0 ] && procd_append_param command --rcvwnd "${rcvwnd}"
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
start_service()
|
||||
{
|
||||
config_load "${NAME}"
|
||||
config_foreach validate_section_kcptun kcptun kcptun_instance
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
config server
|
||||
option disabled 1
|
||||
option listen 29900
|
||||
option target '127.0.0.1'
|
||||
option target_port 12948
|
||||
option crypt 'aes'
|
||||
option key 'secret'
|
||||
option mode 'fast'
|
||||
option datashard 10
|
||||
option parityshard 3
|
||||
option dscp 46
|
||||
option nocomp 1
|
||||
option snmplog '/var/log/snmp.log'
|
||||
option snmpperiod 60
|
||||
option pprof 1
|
||||
option quiet 1
|
||||
option syslog 1
|
||||
option user nobody
|
||||
|
||||
config client
|
||||
option disabled 1
|
||||
option bind_address '0.0.0.0'
|
||||
option local_port 12948
|
||||
option server 'vps'
|
||||
option server_port 29900
|
||||
option crypt 'aes'
|
||||
option key 'secret'
|
||||
option mode 'fast'
|
||||
option conn 1
|
||||
option autoexpire 0
|
||||
option scavengettl 600
|
||||
option mtu 1350
|
||||
option sndwnd 128
|
||||
option rcvwnd 512
|
||||
option nocomp 1
|
||||
option sockbuf 4194304
|
||||
option smuxbuf 4194304
|
||||
option keepalive 10
|
||||
option quiet 1
|
||||
option gogc 20
|
||||
option user nobody
|
||||
@@ -0,0 +1,170 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
#
|
||||
# Copyright (C) 2019 Chao Liu <expiron18@gmail.com>
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v3.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
USE_PROCD=1
|
||||
START=99
|
||||
|
||||
confdir=/var/etc/kcptun
|
||||
bindir=/usr/bin
|
||||
|
||||
mkjson_server_conf() {
|
||||
[ "$disabled" = 0 ] || return 1
|
||||
[ -n "$listen" ] || return 1
|
||||
[ -n "$target" ] || return 1
|
||||
[ -n "$target_port" ] || return 1
|
||||
json_add_string listen ":$listen"
|
||||
json_add_string target "$target:$target_port"
|
||||
json_add_boolean pprof "$pprof"
|
||||
}
|
||||
|
||||
mkjson_client_conf() {
|
||||
[ "$disabled" = 0 ] || return 1
|
||||
[ -n "$local_port" ] || return 1
|
||||
[ -n "$server" ] || return 1
|
||||
[ -n "$server_port" ] || return 1
|
||||
json_add_string localaddr "$bind_address:$local_port"
|
||||
json_add_string remoteaddr "$server:$server_port"
|
||||
[ -z "$conn" ] || json_add_int conn "$conn"
|
||||
[ -z "$autoexpire" ] || json_add_int autoexpire "$autoexpire"
|
||||
[ -z "$scavengettl" ] || json_add_int scavengettl "$scavengettl"
|
||||
}
|
||||
|
||||
kcptun() {
|
||||
local cfg="$1"
|
||||
local cfgtype="$2"
|
||||
local bin="$bindir/kcptun-$cfgtype"
|
||||
local confjson="$confdir/$cfgtype.$cfg.json"
|
||||
|
||||
[ -x "$bin" ] || return
|
||||
eval "$("validate_${cfgtype}_section" "$cfg" validate_mklocal)"
|
||||
"validate_${cfgtype}_section" "$cfg" || return
|
||||
[ "$disabled" = 0 ] || return
|
||||
|
||||
json_init
|
||||
mkjson_${cfgtype}_conf || return
|
||||
[ -z "$crypt" ] || json_add_string crypt "$crypt"
|
||||
[ -z "$key" ] || json_add_string key "$key"
|
||||
[ -z "$mode" ] || json_add_string mode "$mode"
|
||||
[ -z "$mtu" ] || json_add_int mtu "$mtu"
|
||||
[ -z "$sndwnd" ] || json_add_int sndwnd "$sndwnd"
|
||||
[ -z "$rcvwnd" ] || json_add_int rcvwnd "$rcvwnd"
|
||||
[ -z "$datashard" ] || json_add_int datashard "$datashard"
|
||||
[ -z "$parityshard" ] || json_add_int parityshard "$parityshard"
|
||||
[ -z "$dscp" ] || json_add_int dscp "$dscp"
|
||||
json_add_boolean nocomp "$nocomp"
|
||||
[ -z "$sockbuf" ] || json_add_int sockbuf "$sockbuf"
|
||||
[ -z "$smuxbuf" ] || json_add_int smuxbuf "$smuxbuf"
|
||||
[ -z "$keepalive" ] || json_add_int keepalive "$keepalive"
|
||||
[ -z "$snmplog" ] || json_add_string snmplog "$snmplog"
|
||||
[ -z "$snmpperiod" ] || json_add_int snmpperiod "$snmpperiod"
|
||||
json_add_boolean quiet "$quiet"
|
||||
json_dump -i > "$confjson"
|
||||
|
||||
procd_open_instance "$cfgtype.$cfg"
|
||||
procd_set_param command "$bin" -c "$confjson"
|
||||
[ -z "$gogc" ] || procd_set_param env GOGC="$gogc"
|
||||
[ -z "$syslog" ] || procd_set_param stderr 1
|
||||
[ -z "$user" ] || procd_set_param user "$user"
|
||||
procd_set_param file "$confjson"
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
start_service() {
|
||||
local cfgtype
|
||||
|
||||
mkdir -p "$confdir"
|
||||
config_load kcptun
|
||||
for cfgtype in server client; do
|
||||
config_foreach kcptun "$cfgtype" "$cfgtype"
|
||||
done
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
rm -rf "$confdir"
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_interface_trigger wan
|
||||
procd_add_reload_trigger kcptun
|
||||
procd_open_validate
|
||||
validate_server_section
|
||||
validate_client_section
|
||||
procd_close_validate
|
||||
}
|
||||
|
||||
validate_mklocal() {
|
||||
local tuple opts
|
||||
|
||||
shift 2
|
||||
for tuple in "$@"; do
|
||||
opts="${tuple%%:*} $opts"
|
||||
done
|
||||
[ -z "$opts" ] || echo "local $opts"
|
||||
}
|
||||
|
||||
validate() {
|
||||
uci_validate_section kcptun "$@"
|
||||
}
|
||||
|
||||
validate_common_options() {
|
||||
local cfgtype="$1"; shift
|
||||
local cfg="$1"; shift
|
||||
local func="$1"; shift
|
||||
local crypt_methods='"aes", "aes-128", "aes-192", "salsa20", "blowfish", "twofish", "cast5", "3des", "tea", "xtea", "xor", "sm4", "none"'
|
||||
local mode_profiles='"fast3", "fast2", "fast", "normal", "manual"'
|
||||
|
||||
"${func:-validate}" "$cfgtype" "$cfg" "$@" \
|
||||
'disabled:bool:0' \
|
||||
'key:string' \
|
||||
"crypt:or($crypt_methods)" \
|
||||
"mode:or($mode_profiles)" \
|
||||
'mtu:uinteger' \
|
||||
'sndwnd:uinteger' \
|
||||
'rcvwnd:uinteger' \
|
||||
'datashard:uinteger' \
|
||||
'parityshard:uinteger' \
|
||||
'dscp:uinteger' \
|
||||
'nocomp:bool' \
|
||||
'sockbuf:uinteger' \
|
||||
'smuxbuf:uinteger' \
|
||||
'keepalive:uinteger' \
|
||||
'snmplog:string' \
|
||||
'snmpperiod:uinteger' \
|
||||
'quiet:bool' \
|
||||
'gogc:uinteger' \
|
||||
'syslog:bool:1' \
|
||||
'user:string:nobody'
|
||||
}
|
||||
|
||||
validate_server_options() {
|
||||
validate_common_options server "$@" \
|
||||
'listen:port' \
|
||||
'target:host' \
|
||||
'target_port:port' \
|
||||
'pprof:bool'
|
||||
}
|
||||
|
||||
validate_client_options() {
|
||||
validate_common_options client "$@" \
|
||||
'bind_address:ipaddr' \
|
||||
'local_port:port' \
|
||||
'server:host' \
|
||||
'server_port:port' \
|
||||
'conn:uinteger' \
|
||||
'autoexpire:uinteger' \
|
||||
'scavengettl:uinteger'
|
||||
}
|
||||
|
||||
validate_server_section() {
|
||||
validate_server_options "$1" "$2"
|
||||
}
|
||||
|
||||
validate_client_section() {
|
||||
validate_client_options "$1" "$2"
|
||||
}
|
||||
Reference in New Issue
Block a user