From b9776e95925c3222d7adf363e69b11eb17918449 Mon Sep 17 00:00:00 2001 From: Kiritow <1362050620@qq.com> Date: Fri, 16 Jul 2021 15:19:56 +0800 Subject: [PATCH] Add Speeder support --- install.sh | 15 +++++++++++++++ tool_create.py | 35 ++++++++++++++++++++++++++++++++--- tool_generate.py | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 77 insertions(+), 5 deletions(-) diff --git a/install.sh b/install.sh index d001ef4..d5a9624 100755 --- a/install.sh +++ b/install.sh @@ -11,6 +11,12 @@ curl -vL https://github.com/wangyu-/udp2raw-tunnel/releases/download/20200818.0/ tar -xvzf udp2raw.tgz udp2raw_amd64 chmod +x udp2raw_amd64 rm udp2raw.tgz + +curl -vL https://github.com/wangyu-/UDPspeeder/releases/download/20210116.0/speederv2_binaries.tar.gz -o udpspeeder.tgz +tar -xvzf udpspeeder.tgz speederv2_amd64 +chmod +x speederv2_amd64 +rm udpspeeder.tgz + cd .. VERIFIED_HASH="a7ce38b2c30980be4e71c3af8a9c1db8183db349c699fa6f843e67add7e6cca2" @@ -21,3 +27,12 @@ then else echo "[WARN] udp2raw hash mismatch: $TEMP_HASH. Expected: $VERIFIED_HASH" fi + +VERIFIED_HASH="3cf8f6c1e9baa530170368efb8a4bfcd6e75f88c2726ecbf2a75261dd1dd9fd5" +TEMP_HASH=$(sha256sum bin/speederv2_amd64 | awk '{print $1}') +if [ "$TEMP_HASH" == "$VERIFIED_HASH" ] +then + echo "[OK] speederv2 hash match: $TEMP_HASH" +else + echo "[WARN] speederv2 hash mismatch: $TEMP_HASH. Expected: $VERIFIED_HASH" +fi diff --git a/tool_create.py b/tool_create.py index 9ddd73d..c37ef0e 100755 --- a/tool_create.py +++ b/tool_create.py @@ -45,10 +45,24 @@ if op_mode in ("s", "m"): print("A udp2raw tunnel password is required. Try again.") continue break + + is_enable_speeder = input("Enable UDP Speeder for this tunnel? [Y/n]: ").strip() + if not is_enable_speeder or is_enable_speeder.lower() in ('y', 'yes'): + speeder_ratio = input("Enter UDP Speeder Ratio (default to 20:10. Use 2:4 for gaming usage): ").strip() + speeder_info = { + "enable": True, + "port": 27100 + len(udp2raw_config["server"]), + "ratio": speeder_ratio + } + else: + speeder_info = { + "enable": False + } udp2raw_config["server"].append({ "port": udp_server_port, - "password": udp_server_password + "password": udp_server_password, + "speeder": speeder_info }) if not input("Add more udp2raw server? (Keep empty to finish)").strip(): @@ -75,12 +89,26 @@ if op_mode in ("c", "m"): continue break + is_enable_speeder = input("Enable UDP Speeder for this tunnel? [Y/n]: ").strip() + if not is_enable_speeder or is_enable_speeder.lower() in ('y', 'yes'): + speeder_ratio = input("Enter UDP Speeder Ratio (default to 20:10. Use 2:4 for gaming usage): ").strip() + speeder_info = { + "enable": True, + "port": 28100 + len(udp2raw_config["server"]), + "ratio": speeder_ratio + } + else: + speeder_info = { + "enable": False + } + udp2raw_config["client"].append({ "remote": udp_server_address, "password": udp_server_password, - "port": 28150 + len(udp2raw_config["client"]) + "port": 29100 + len(udp2raw_config["client"]), + "speeder": speeder_info }) - + if not input("Add more udp2raw client? (Keep empty to finish)").strip(): break @@ -153,6 +181,7 @@ while True: print("Saving to local config...") config = { + "version": 1, "mode": op_mode, "pubkey": wg_pubk, "prikey": wg_prik, diff --git a/tool_generate.py b/tool_generate.py index 32028d2..101516c 100644 --- a/tool_generate.py +++ b/tool_generate.py @@ -11,10 +11,16 @@ except Exception: print(traceback.format_exc()) print("[ERROR] No valid config found.") + +if "version" not in config or int(config["version"]) < 1: + print("[WARN] Legacy version of config found. This may cause issues.") + + op_mode = config["mode"] udp_clients = config["udp2raw"]["client"] udp_servers = config["udp2raw"]["server"] + print("Generating wireguard config...") with open("{}.conf".format(config["interface"]), "w", encoding='utf-8') as f: f.write('''[Interface] @@ -30,7 +36,13 @@ PublicKey = {} AllowedIPs = {} '''.format(info["pubkey"], info["allowed"])) if info["endpoint"]: - f.write("Endpoint = 127.0.0.1:{}\n".format(udp_clients[int(info["endpoint"]) - 1]["port"])) + udp_info = udp_clients[int(info["endpoint"]) - 1] + if udp_info["speeder"]["enable"]: + # WG --> Speeder + f.write("Endpoint = 127.0.0.1:{}\n".format(udp_info["speeder"]["port"])) + else: + # WG --> Tunnel + f.write("Endpoint = 127.0.0.1:{}\n".format(udp_info["port"])) if info["keepalive"]: f.write("PersistentKeepalive = {}".format(info["keepalive"])) @@ -45,10 +57,26 @@ cp {}.conf /etc/wireguard/ tmux new-session -s tunnel -d '''.format(config["interface"])) for info in udp_clients: + if info["speeder"]["enable"]: + # WG --> Speeder --> RawTunnel + speeder = info["speeder"] + f.write('''tmux new-window -t tunnel -d 'bin/speederv2_amd64 -c -l127.0.0.1:{} -r 127.0.0.1:{} -f{} --mode 0' \n'''.format(speeder["port"], info["port"], speeder["ratio"])) + f.write('''tmux new-window -t tunnel -d 'bin/udp2raw_amd64 -c -l127.0.0.1:{} -r{} -k "{}" --raw-mode faketcp -a' \n'''.format(info["port"], info["remote"], info["password"])) for info in udp_servers: - f.write('''tmux new-window -t tunnel -d 'bin/udp2raw_amd64 -s -l0.0.0.0:{} -r 127.0.0.1:{} -k "{}" --raw-mode faketcp -a' \n'''.format(info["port"], config["listen"], info["password"])) + if info["speeder"]["enable"]: + # RawTunnel --> Speeder --> WG + speeder = info["speeder"] + f.write('''tmux new-window -t tunnel -d 'bin/speederv2_amd64 -s -l127.0.0.1:{} -r 127.0.0.1:{} -f{} --mode 0' \n'''.format(speeder["port"], config["listen"], speeder["ratio"])) + f.write('''tmux new-window -t tunnel -d 'bin/udp2raw_amd64 -s -l0.0.0.0:{} -r 127.0.0.1:{} -k "{}" --raw-mode faketcp -a' \n'''.format(info["port"], speeder["port"], info["password"])) + else: + # RawTunnel --> WG + f.write('''tmux new-window -t tunnel -d 'bin/udp2raw_amd64 -s -l0.0.0.0:{} -r 127.0.0.1:{} -k "{}" --raw-mode faketcp -a' \n'''.format(info["port"], config["listen"], info["password"])) + + # Enable BBR + f.write("sysctl net.core.default_qdisc=fq\n") + f.write("sysctl net.ipv4.tcp_congestion_control=bbr\n") if op_mode in ("s", "m"): f.write("sysctl net.ipv4.ip_forward=1\n")