Skip to content

Commit

Permalink
misc: fix connection tests
Browse files Browse the repository at this point in the history
  • Loading branch information
markpash committed Feb 1, 2025
1 parent e2d1274 commit a49dbf1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
11 changes: 6 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type WarpOptions struct {
FwMark uint32
WireguardConfig string
Reserved string
TestURL string
}

type PsiphonOptions struct {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 2 additions & 4 deletions app/wg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cmd/warp-plus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
Expand Down Expand Up @@ -111,6 +112,7 @@ func main() {
FwMark: uint32(*fwmark),
WireguardConfig: *wgConf,
Reserved: *reserved,
TestURL: *testUrl,
}

switch {
Expand Down
1 change: 1 addition & 0 deletions example_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"fwmark": "0x1375",
"wgconf": "",
"reserved": "",
"test-url": "",
"4": true,
"6": true
}

0 comments on commit a49dbf1

Please sign in to comment.