From 4fa48bfa8f400a635e16f17d76eb126b6a633513 Mon Sep 17 00:00:00 2001 From: John Brooks Date: Sat, 5 Nov 2016 22:19:13 -0600 Subject: [PATCH] cli: Add -tor-control and -connect flags --- ricochet-cli/main.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ricochet-cli/main.go b/ricochet-cli/main.go index 531007e..6ad4cd0 100644 --- a/ricochet-cli/main.go +++ b/ricochet-cli/main.go @@ -23,7 +23,10 @@ var ( backendServer string unsafeBackend bool backendMode bool + connectAuto bool configPath string = "identity.ricochet" + torAddress string + torPassword string ) func main() { @@ -41,6 +44,9 @@ func main() { flag.StringVar(&backendServer, "listen", "", "Listen on `
` for client frontend connections") flag.BoolVar(&unsafeBackend, "allow-unsafe-backend", false, "Allow a remote backend address. This is NOT RECOMMENDED and may harm your security or privacy. Do not use without a secure, trusted link") flag.BoolVar(&backendMode, "only-backend", false, "Run backend without any commandline UI") + flag.BoolVar(&connectAuto, "connect", true, "Start connecting to the network automatically") + flag.StringVar(&torAddress, "tor-control", "", "Use the tor control port at `
`, which may be 'host:port' or 'unix:/path'") + flag.StringVar(&torPassword, "tor-control-password", "", "Use `` to authenticate to the tor control port") flag.Parse() if len(flag.Args()) > 1 { flag.Usage() @@ -60,6 +66,9 @@ func main() { } else if configPath != "identity.ricochet" { fmt.Printf("Cannot use -identity with -attach, because identity is stored at the backend\n") os.Exit(1) + } else if torAddress != "" || torPassword != "" { + fmt.Printf("Cannot use -tor-control with -attach, because tor connections happen on the backend\n") + os.Exit(1) } } @@ -176,6 +185,13 @@ func startBackend() error { return err } + if torAddress != "" { + core.Network.SetControlAddress(torAddress) + } + if torPassword != "" { + core.Network.SetControlPassword(torPassword) + } + var listener net.Listener if backendServer == "" { // In-process backend, using 'InnerNet' as a fake socket @@ -209,5 +225,11 @@ func startBackend() error { } }() + if connectAuto { + go func() { + core.Network.Start() + }() + } + return nil }