Skip to content

Commit

Permalink
add hysteria
Browse files Browse the repository at this point in the history
misc
  • Loading branch information
twnesss committed Jun 21, 2024
1 parent 36b3507 commit 6725e28
Show file tree
Hide file tree
Showing 7 changed files with 242 additions and 190 deletions.
22 changes: 22 additions & 0 deletions box/hysteria/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
server: your.domain.net:443
auth: some_password
tls:
sni: your.domain.net
# insecure: false
# pinSHA256: BA:88:45:17:A1...
# ca: custom_ca.crt
bandwidth:
up: 20 mbps
down: 100 mbps

lazy: true

socks5:
listen: 127.0.0.1:1080
http:
listen: 127.0.0.1:7080

tcpTProxy:
listen: :9898
udpTProxy:
listen: :9898
241 changes: 92 additions & 149 deletions box/scripts/box.iptables

Large diffs are not rendered by default.

86 changes: 69 additions & 17 deletions box/scripts/box.service
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ box_check_bin() {
exit 1
fi
case "${bin_name}" in
clash) version_output=$("${bin_path}" -v) >/dev/null 2>&1 || return 1 ;;
*) version_output=$("${bin_path}" version) >/dev/null 2>&1 || return 1 ;;
clash) version_output=$("${bin_path}" -v) >/dev/null 2>&1 || return 1;;
*) version_output=$("${bin_path}" version) >/dev/null 2>&1 || return 1;;
esac
log Info "${version_output}"
}
Expand All @@ -138,17 +138,17 @@ box_create_tun() {
prepare_singbox() {
# Check configuration file
if ! [ -f "${sing_config}" ]; then
log Error "configuration file ${sing_config} not found"
log Error "Configuration file ${sing_config} not found"
exit 1
else
log Info "config ${sing_config}"
log Info "Config ${sing_config} found"
fi

# Check yq
yq="yq"
if ! command -v yq &>/dev/null; then
if [ ! -e "${box_dir}/bin/yq" ]; then
log Debug "yq file not found, start to download from github"
log Debug "yq file not found, starting download from GitHub"
${scripts_dir}/box.tool upyq
fi
yq="${box_dir}/bin/yq"
Expand All @@ -165,8 +165,23 @@ prepare_singbox() {
# Check if "type" is "tun" in configuration
if ! busybox grep -q '"type": "tun"' "${sing_config}"; then
# Add "tun" configuration if missing
${yq} '.inbounds += [{"type": "tun","tag": "tun-in","interface_name": "utun","inet4_address": "172.19.0.1/30","inet6_address": "fdfe:dcba:9876::1/126","mtu": 9000,"stack": "system","auto_route": true,"strict_route": false,"inet4_route_exclude_address": ["192.168.0.0/16"],"inet6_route_exclude_address": ["fc00::/7"],"sniff": true,"sniff_override_destination": false,"include_android_user": [0,10],"include_package": [],"exclude_package": []}]' -i --output-format=json "${sing_config}"
log Debug "[Tun] configuration has been added to ${sing_config}"
${yq} '.inbounds += [{
"type": "tun",
"tag": "tun-in",
"interface_name": "utun",
"address": ["172.18.0.1/30","fdfe:dcba:9876::1/126"],
"mtu": 9000,
"stack": "system",
"auto_route": true,
"strict_route": false,
"route_exclude_address": ["192.168.0.0/16","fc00::/7"],
"sniff": true,
"sniff_override_destination": false,
"include_android_user": [0,10],
"include_package": [],
"exclude_package": []
}]' -i --output-format=json "${sing_config}"
log Debug "[Tun] configuration added to ${sing_config}"
fi
else
# Set auto_route to false for non-"tun" network_mode
Expand All @@ -177,15 +192,24 @@ prepare_singbox() {
# Check if "type" is "tproxy" in configuration
if ! busybox grep -q '"type": "tproxy"' "${sing_config}"; then
# Add "tproxy" configuration if missing
${yq} '.inbounds += [{"type": "tproxy", "tag": "tproxy-in", "listen": "::", "listen_port": '"${tproxy_port}"', "sniff": true, "sniff_override_destination": false}]' -i --output-format=json "${sing_config}"
log Debug "[Tproxy] configuration has been added to ${sing_config}"
${yq} '.inbounds += [{
"type": "tproxy",
"tag": "tproxy-in",
"listen": "::",
"listen_port": '"${tproxy_port}"',
"sniff": true,
"sniff_override_destination": false
}]' -i --output-format=json "${sing_config}"
log Debug "[Tproxy] configuration added to ${sing_config}"
fi

# Sync tproxy port sing-box
# del tun
${yq} 'del(.inbounds[] | select(.type == "tun"))' -i --output-format=json "${sing_config}"

# Sync tproxy port in sing-box configuration
for file in "${box_dir}/sing-box/"*.json; do
tproxy=$(sed -n 's/.*"type": "\(tproxy\)".*/\1/p' "${file}")
if [ -n "${tproxy}" ]; then
${yq} -o=json "(.inbounds[]? | select(.type == \"tproxy\") | .listen_port) = ${tproxy_port}" -i --output-format=json "${file}"
if busybox grep -q '"type": "tproxy"' "${file}"; then
${yq} '(.inbounds[] | select(.type == "tproxy") | .listen_port) = '"${tproxy_port}" -i --output-format=json "${file}"
fi
done
fi
Expand All @@ -202,13 +226,27 @@ prepare_singbox() {
if [[ "${network_mode}" == @(mixed|enhance|redirect) ]]; then
if ! busybox grep -q '"type": "redirect"' "${sing_config}"; then
# Add "redirect" configuration if missing
${yq} '.inbounds += [{"type": "redirect","tag": "redirect-in","listen": "::","listen_port": '"${redir_port}"',"sniff": true,"sniff_override_destination": false}]' -i --output-format=json "${sing_config}"
log Debug "[Redirect] configuration has been added to ${sing_config}"
${yq} '.inbounds += [{
"type": "redirect",
"tag": "redirect-in",
"listen": "::",
"listen_port": '"${redir_port}"',
"sniff": true,
"sniff_override_destination": false
}]' -i --output-format=json "${sing_config}"
log Debug "[Redirect] configuration added to ${sing_config}"
fi

# Sync redir_port port in sing-box configuration
for file in "${box_dir}/sing-box/"*.json; do
if busybox grep -q '"type": "redirect"' "${file}"; then
${yq} '(.inbounds[] | select(.type == "redirect") | .listen_port) = '"${redir_port}" -i --output-format=json "${file}"
fi
done
fi
else
log Error "$(<"${box_run}/${bin_name}.log")"
log Error "configuration failed. Please check the ${box_run}/${bin_name}.log file."
log Error "Configuration failed. Please check the ${box_run}/${bin_name}.log file."
exit 1
fi
}
Expand Down Expand Up @@ -317,6 +355,20 @@ box_run_bin() {
# Use ulimit to limit the memory usage of a process to 200MB
# ulimit -v 200000 # Set the virtual memory limit in KB
case "${bin_name}" in
hysteria)
# sync port
sed -i -e "/tcpTProxy:/,/listen:/s/listen: :.*/listen: :${tproxy_port}/" "${box_dir}/${bin_name}/config.yaml"
sed -i -e "/udpTProxy:/,/listen:/s/listen: :.*/listen: :${tproxy_port}/" "${box_dir}/${bin_name}/config.yaml"

# set network_mode variable value to "tproxy"
if [[ "${network_mode}" != "tproxy" ]]; then
sed -i 's/\(network_mode=\)\"[^\"]*\"/\1"tproxy"/g' ${settings}
fi
nohup busybox setuidgid ${box_user_group} ${bin_path} -c ${box_dir}/${bin_name}/config.yaml > "${bin_log}" 2>&1 &
PID=$!
echo -n $PID > "${box_pid}"
sleep 1
;;
sing-box)
prepare_singbox
if ${bin_path} check -D "${box_dir}/${bin_name}" -C "${box_dir}/${bin_name}" > "${box_run}/${bin_name}.log" 2>&1; then
Expand Down Expand Up @@ -553,7 +605,7 @@ start_box() {

# Checks if bin_name is defined
case "${bin_name}" in
clash|xray|sing-box|v2fly)
clash|xray|sing-box|v2fly|hysteria)
log Info "Good day"
[ "${bin_name}" = "clash" ] && {
xclash || exit 1
Expand Down
57 changes: 45 additions & 12 deletions box/scripts/box.tool
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ upfile() {
# Restart the binary, after stopping and running again
restart_box() {
"${scripts_dir}/box.service" restart
# PIDS=("clash" "xray" "sing-box" "v2fly")
# PIDS=("clash" "xray" "sing-box" "v2fly" "hysteria")
PIDS=(${bin_name})
PID=""
i=0
Expand Down Expand Up @@ -98,6 +98,9 @@ check() {
log Error "$(<"${box_run}/${bin_name}_report.log")" >&2
fi
;;
hysteria)
true
;;
*)
log Error "<${bin_name}> unknown binary."
exit 1
Expand Down Expand Up @@ -145,7 +148,7 @@ reload() {
return 1
fi
;;
"xray"|"v2fly")
"xray"|"v2fly"|"hysteria")
if [ -f "${box_pid}" ]; then
if kill -0 "$(<"${box_pid}" 2>/dev/null)"; then
restart_box
Expand Down Expand Up @@ -315,7 +318,7 @@ upsubs() {
return 0
fi
;;
"xray"|"v2fly"|"sing-box")
"xray"|"v2fly"|"sing-box"|"hysteria")
log Warning "${bin_name} does not support subscriptions.."
return 1
;;
Expand Down Expand Up @@ -396,7 +399,10 @@ upkernel() {
download_link="https://github.com/$(if [ "${bin_name}" = "xray" ]; then echo "XTLS/Xray-core/releases"; else echo "v2fly/v2ray-core/releases"; fi)"
log Debug "Downloading ${download_link}/download/${latest_version}/${download_file}"
upfile "${box_dir}/${file_kernel}.zip" "${download_link}/download/${latest_version}/${download_file}" && xkernel
;;
;;
"hysteria")
true
;;
*)
log Error "<${bin_name}> unknown binary."
exit 1
Expand Down Expand Up @@ -471,6 +477,9 @@ xkernel() {
fi
rm -rf "${bin_dir}/update"
;;
"hysteria")
true
;;
*)
log Error "<${bin_name}> unknown binary."
exit 1
Expand Down Expand Up @@ -672,16 +681,40 @@ touch -n > $path_webroot
fi
}

bond1() {
su -mm -c "cmd wifi force-low-latency-mode enabled"
su -mm -c "sysctl -w net.ipv4.tcp_low_latency=1"
su -mm -c "ip link set dev wlan0 txqueuelen 4000"
bond0() {
# Menonaktifkan mode low latency untuk TCP
sysctl -w net.ipv4.tcp_low_latency=0 >/dev/null 2>&1
log Debug "tcp low latency: 0"

# Mengatur panjang antrian transmisi (txqueuelen) menjadi 3000 untuk semua interface wireless (wlan*)
for dev in /sys/class/net/wlan*; do ip link set dev $(basename $dev) txqueuelen 3000; done
log Debug "wlan* txqueuelen: 3000"

# Mengatur panjang antrian transmisi (txqueuelen) menjadi 1000 untuk semua interface rmnet_data*
for txqueuelen in /sys/class/net/rmnet_data*; do txqueuelen_name=$(basename $txqueuelen); ip link set dev $txqueuelen_name txqueuelen 1000; done
log Debug "rmnet_data* txqueuelen: 1000"

# Mengatur MTU (Maximum Transmission Unit) menjadi 1500 untuk semua interface rmnet_data*
for mtu in /sys/class/net/rmnet_data*; do mtu_name=$(basename $mtu); ip link set dev $mtu_name mtu 1500; done
log Debug "rmnet_data* mtu: 1500"
}

bond0() {
su -mm -c "cmd wifi force-low-latency-mode disabled"
su -mm -c "sysctl -w net.ipv4.tcp_low_latency=0"
su -mm -c "ip link set dev wlan0 txqueuelen 3000"
bond1() {
# Mengaktifkan mode low latency untuk TCP
sysctl -w net.ipv4.tcp_low_latency=1 >/dev/null 2>&1
log Debug "tcp low latency: 1"

# Mengatur panjang antrian transmisi (txqueuelen) menjadi 4000 untuk semua interface wireless (wlan*)
for dev in /sys/class/net/wlan*; do ip link set dev $(basename $dev) txqueuelen 4000; done
log Debug "wlan* txqueuelen: 4000"

# Mengatur panjang antrian transmisi (txqueuelen) menjadi 2000 untuk semua interface rmnet_data*
for txqueuelen in /sys/class/net/rmnet_data*; do txqueuelen_name=$(basename $txqueuelen); ip link set dev $txqueuelen_name txqueuelen 2000; done
log Debug "rmnet_data* txqueuelen: 2000"

# Mengatur MTU (Maximum Transmission Unit) menjadi 9000 untuk semua interface rmnet_data*
for mtu in /sys/class/net/rmnet_data*; do mtu_name=$(basename $mtu); ip link set dev $mtu_name mtu 9000; done
log Debug "rmnet_data* mtu: 9000"
}

case "$1" in
Expand Down
16 changes: 8 additions & 8 deletions box/settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ port_detect="false"
ipv6="false"

# list of available kernel binaries
bin_list=( "clash" "sing-box" "xray" "v2fly" )
bin_list=( "clash" "sing-box" "xray" "v2fly" "hysteria" )

# for run and download premium or mihomo
# put kernel premium and mihomo into /data/adb/box/bin directory
Expand Down Expand Up @@ -49,9 +49,9 @@ packages_list=()
# The gid in the list will be bypassed or proxied according to the proxy_mode configuration, and the gid can be arbitrarily specified by the busybox setuidgid command
gid_list=()

# Display AP info by typing "ifconfig" in terminal
# Display AP info by typing "su -c ifconfig" in terminal "swlan+" "wlan+" "rndis+"
ap_list=( "ap+" "wlan+" "rndis+" "swlan+" )
# Ignore AP in the out list
# Ignore AP in the out list, doesn't work in fake-ip mode
ignore_out_list=()

# Set cgroup to limit memory usage
Expand Down Expand Up @@ -119,11 +119,11 @@ blue="\033[1;34m"

# eg: notify $title $content
notify() {
# using Xposed edge app toast
am start -a android.intent.action.VIEW -n com.jozein.xedgepro/.ui.ActivityPerformAction --ei __0 111 --es __1 "$2" >/dev/null 2>&1
# using system notification
# su -lp "2000" -c "cmd notification post -S messaging --conversation '$1' --message '$1':'$2' 'Tag' '$(echo $RANDOM)' " >/dev/null 2>&1
# using Xposed edge app toast
am start -a android.intent.action.VIEW -n com.jozein.xedgepro/.ui.ActivityPerformAction --ei __0 111 --es __1 "$2" >/dev/null 2>&1

# using system notification
# su -lp "2000" -c "cmd notification post -S messaging --conversation '$1' --message '$1':'$2' 'Tag' '$(echo $RANDOM)' " >/dev/null 2>&1
}

log() {
Expand Down
8 changes: 5 additions & 3 deletions customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ chmod ugo+x $MODPATH/uninstall.sh
chmod ugo+x /data/adb/box/scripts/*

ui_print "-----------------------------------------------------------"
ui_print "- Do you want to download Kernel(xray clash v2fly sing-box) and GeoX(geosite geoip mmdb)? size: ±100MB."
ui_print "- Do you want to download Kernel(xray hysteria clash v2fly sing-box) and GeoX(geosite geoip mmdb)? size: ±100MB."
ui_print "- Make sure you have a good internet connection."
ui_print "- [ Vol UP(+): Yes ]"
ui_print "- [ Vol DOWN(-): No ]"
Expand All @@ -104,7 +104,7 @@ while true ; do
done

if [ "${backup_box}" = "true" ]; then
ui_print "- Restore configuration xray, clash, sing-box, and v2fly"
ui_print "- Restore configuration xray, hysteria, clash, sing-box, and v2fly"
restore_config() {
config_dir="$1"
if [ -d "${temp_dir}/${config_dir}" ]; then
Expand All @@ -116,6 +116,7 @@ if [ "${backup_box}" = "true" ]; then
restore_config "xray"
restore_config "v2fly"
restore_config "sing-box"
restore_config "hysteria"

restore_kernel() {
kernel_name="$1"
Expand All @@ -130,6 +131,7 @@ if [ "${backup_box}" = "true" ]; then
restore_kernel "xray"
restore_kernel "sing-box"
restore_kernel "v2fly"
restore_kernel "hysteria"
restore_kernel "xclash/mihomo"
restore_kernel "xclash/premium"

Expand All @@ -138,7 +140,7 @@ if [ "${backup_box}" = "true" ]; then
fi

if [ -z "$(find /data/adb/box/bin -type f)" ]; then
sed -Ei 's/^description=(\[.*][[:space:]]*)?/description=[ 😱 Module installed but you need to download Kernel(xray clash v2fly sing-box) and GeoX(geosite geoip mmdb) manually ] /g' $MODPATH/module.prop
sed -Ei 's/^description=(\[.*][[:space:]]*)?/description=[ 😱 Module installed but you need to download Kernel(xray hysteria clash v2fly sing-box) and GeoX(geosite geoip mmdb) manually ] /g' $MODPATH/module.prop
fi

if [ "$KSU" = "true" ]; then
Expand Down
2 changes: 1 addition & 1 deletion module.prop
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ name=Box for Magisk/KernelSU
version=v1.5.0
versionCode=20240326
author=t@amarin
description=use sing-box, clash, v2ray, and xray for tunnel proxy on android device
description=use sing-box, clash, v2ray, hysteria and xray for tunnel proxy on android device
updateJson=https://github.com/taamarin/box_for_magisk/raw/master/update.json

1 comment on commit 6725e28

@LIghtJUNction
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good

Please sign in to comment.