diff --git a/README.md b/README.md index 20aef8c..3f77fca 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,8 @@ windscribe-proxy -list-proxies | auth-secret | String | client auth secret (default `952b4412f002315aa50751032fcaab03`) | | bind-address | String | HTTP proxy listen address (default `127.0.0.1:28080`) | | cafile | String | use custom CA certificate bundle file | +| fake-sni | String | fake SNI to use to contact windscribe servers (default "com") | +| force-cold-init | - | force cold init | | list-locations | - | list available locations and exit | | list-proxies | - | output proxy list and exit | | location | String | desired proxy location. Default: best location | diff --git a/main.go b/main.go index 25d48bf..ab57307 100644 --- a/main.go +++ b/main.go @@ -62,6 +62,7 @@ type CLIArgs struct { password string tfacode string fakeSNI string + forceColdInit bool } func parse_args() CLIArgs { @@ -90,6 +91,7 @@ func parse_args() CLIArgs { flag.StringVar(&args.password, "password", "", "password for login") flag.StringVar(&args.tfacode, "2fa", "", "2FA code for login") flag.StringVar(&args.fakeSNI, "fake-sni", "com", "fake SNI to use to contact windscribe servers") + flag.BoolVar(&args.forceColdInit, "force-cold-init", false, "force cold init") flag.Parse() if args.listLocations && args.listProxies { arg_fail("list-locations and list-proxies flags are mutually exclusive") @@ -191,10 +193,15 @@ func run() int { wndc.State.Settings.ClientAuthSecret = args.clientAuthSecret wndc.Mux.Unlock() - // Try ressurect state - state, err := loadState(args.stateFile) + // Try to resurrect state + state, err := maybeLoadState(args.forceColdInit, args.stateFile) if err != nil { - mainLogger.Warning("Failed to load client state: %v. It is OK for a first run. Performing cold init...", err) + switch err { + case errColdInitForced: + mainLogger.Info("Cold init forced.") + default: + mainLogger.Warning("Failed to load client state: %v. It is OK for a first run. Performing cold init...", err) + } err = coldInit(wndc, args.username, args.password, args.tfacode, args.timeout) if err != nil { mainLogger.Critical("Cold init failed: %v", err) @@ -345,6 +352,14 @@ func pickServer(serverList wndclient.ServerList, location string) string { return candidates[rnd.Intn(len(candidates))] } +var errColdInitForced = errors.New("cold init forced!") +func maybeLoadState(forceColdInit bool, filename string) (*wndclient.WndClientState, error) { + if forceColdInit { + return nil, errColdInitForced + } + return loadState(filename) +} + func loadState(filename string) (*wndclient.WndClientState, error) { file, err := os.Open(filename) if err != nil {