From a49dbf1235187f0da131eecb9c52e38704d3322a Mon Sep 17 00:00:00 2001 From: Mark Pashmfouroush Date: Sat, 1 Feb 2025 15:48:36 +0000 Subject: [PATCH] misc: fix connection tests --- README.md | 5 +++-- app/app.go | 11 ++++++----- app/wg.go | 6 ++---- cmd/warp-plus/main.go | 2 ++ example_config.json | 1 + 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index dfa903519..6385a1d5e 100644 --- a/README.md +++ b/README.md @@ -32,13 +32,14 @@ FLAGS --dns STRING DNS address (default: 1.1.1.1) --gool enable gool mode (warp in warp) --cfon enable psiphon mode (must provide country as well) - --country STRING psiphon country code (valid values: [AT BE BG BR CA CH CZ DE DK EE ES FI FR GB HR HU IE IN IT JP LV NL NO PL PT RO RS SE SG SK UA US]) (default: AT) + --country STRING psiphon country code (valid values: [AT AU BE BG CA CH CZ DE DK EE ES FI FR GB HR HU IE IN IT JP LV NL NO PL PT RO RS SE SG SK US]) (default: AT) --scan enable warp scanning --rtt DURATION scanner rtt limit (default: 1s) --cache-dir STRING directory to store generated profiles - --fwmark UINT set linux firewall mark for tun mode (default: 4981) + --fwmark UINT set linux firewall mark for tun mode (requires sudo/root/CAP_NET_ADMIN) (default: 0) --reserved STRING override wireguard reserved value (format: '1,2,3') --wgconf STRING path to a normal wireguard config + --test-url STRING connectivity test url (default: http://connectivity.cloudflareclient.com/cdn-cgi/trace) -c, --config STRING path to config file --version displays version number ``` diff --git a/app/app.go b/app/app.go index c13914aeb..770c58b53 100644 --- a/app/app.go +++ b/app/app.go @@ -32,6 +32,7 @@ type WarpOptions struct { FwMark uint32 WireguardConfig string Reserved string + TestURL string } type PsiphonOptions struct { @@ -147,7 +148,7 @@ func runWireguard(ctx context.Context, l *slog.Logger, opts WarpOptions) error { } // Test wireguard connectivity - werr = usermodeTunTest(ctx, l, tnet) + werr = usermodeTunTest(ctx, l, tnet, opts.TestURL) if werr != nil { continue } @@ -216,7 +217,7 @@ func runWarp(ctx context.Context, l *slog.Logger, opts WarpOptions, endpoint str } // Test wireguard connectivity - werr = usermodeTunTest(ctx, l, tnet) + werr = usermodeTunTest(ctx, l, tnet, opts.TestURL) if werr != nil { continue } @@ -285,7 +286,7 @@ func runWarpInWarp(ctx context.Context, l *slog.Logger, opts WarpOptions, endpoi } // Test wireguard connectivity - werr = usermodeTunTest(ctx, l, tnet1) + werr = usermodeTunTest(ctx, l, tnet1, opts.TestURL) if werr != nil { continue } @@ -343,7 +344,7 @@ func runWarpInWarp(ctx context.Context, l *slog.Logger, opts WarpOptions, endpoi } // Test wireguard connectivity - if err := usermodeTunTest(ctx, l, tnet2); err != nil { + if err := usermodeTunTest(ctx, l, tnet2, opts.TestURL); err != nil { return err } @@ -405,7 +406,7 @@ func runWarpWithPsiphon(ctx context.Context, l *slog.Logger, opts WarpOptions, e } // Test wireguard connectivity - werr = usermodeTunTest(ctx, l, tnet) + werr = usermodeTunTest(ctx, l, tnet, opts.TestURL) if werr != nil { continue } diff --git a/app/wg.go b/app/wg.go index ea442b0b8..c9dc87018 100644 --- a/app/wg.go +++ b/app/wg.go @@ -17,9 +17,7 @@ import ( "github.com/bepass-org/warp-plus/wiresocks" ) -const connTestEndpoint = "http://1.1.1.1/cdn-cgi/trace" - -func usermodeTunTest(ctx context.Context, l *slog.Logger, tnet *netstack.Net) error { +func usermodeTunTest(ctx context.Context, l *slog.Logger, tnet *netstack.Net, url string) error { ctx, cancel := context.WithDeadline(ctx, time.Now().Add(5*time.Second)) defer cancel() @@ -34,7 +32,7 @@ func usermodeTunTest(ctx context.Context, l *slog.Logger, tnet *netstack.Net) er DialContext: tnet.DialContext, ResponseHeaderTimeout: 5 * time.Second, }} - resp, err := client.Head(connTestEndpoint) + resp, err := client.Head(url) if err != nil { l.Error("connection test failed") continue diff --git a/cmd/warp-plus/main.go b/cmd/warp-plus/main.go index 7b3d069de..1d99ba68e 100644 --- a/cmd/warp-plus/main.go +++ b/cmd/warp-plus/main.go @@ -47,6 +47,7 @@ func main() { fwmark = fs.UintLong("fwmark", 0x0, "set linux firewall mark for tun mode (requires sudo/root/CAP_NET_ADMIN)") reserved = fs.StringLong("reserved", "", "override wireguard reserved value (format: '1,2,3')") wgConf = fs.StringLong("wgconf", "", "path to a normal wireguard config") + testUrl = fs.StringLong("test-url", "http://connectivity.cloudflareclient.com/cdn-cgi/trace", "connectivity test url") _ = fs.String('c', "config", "", "path to config file") verFlag = fs.BoolLong("version", "displays version number") ) @@ -111,6 +112,7 @@ func main() { FwMark: uint32(*fwmark), WireguardConfig: *wgConf, Reserved: *reserved, + TestURL: *testUrl, } switch { diff --git a/example_config.json b/example_config.json index 7e3e0bf8c..ed688fea7 100644 --- a/example_config.json +++ b/example_config.json @@ -13,6 +13,7 @@ "fwmark": "0x1375", "wgconf": "", "reserved": "", + "test-url": "", "4": true, "6": true }