From 94389db18e0ba4b0d0008d1d242e5a4dc2c2d850 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Wed, 6 Nov 2019 11:26:54 -0800 Subject: [PATCH 1/2] Expose Reboot --- connectivity/acn.go | 3 +++ connectivity/torProvider.go | 10 +++++++++- go.mod | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/connectivity/acn.go b/connectivity/acn.go index f6b67b4..12efcbc 100644 --- a/connectivity/acn.go +++ b/connectivity/acn.go @@ -28,6 +28,9 @@ type ACN interface { // Sets the calback function to be called when ACN status changes SetStatusCallback(callback func(int, string)) + // Restarts the underlying connection + Reboot() + // Open takes a hostname and returns a net.conn to the derived endpoint // Open allows a client to resolve various hostnames to connections // The supported types are onions address are: diff --git a/connectivity/torProvider.go b/connectivity/torProvider.go index 473efb7..85f723b 100644 --- a/connectivity/torProvider.go +++ b/connectivity/torProvider.go @@ -121,7 +121,7 @@ func (tp *torProvider) Listen(identity PrivateKey, port int) (ListenService, err case ed25519.PrivateKey: privkey = pk gpubk := pk.Public() - switch pubk := gpubk.(type) { + switch pubk := gpubk.(type) {git case ed25519.PublicKey: onion = utils.GetTorV3Hostname(pubk) } @@ -155,6 +155,10 @@ func (tp *torProvider) Listen(identity PrivateKey, port int) (ListenService, err return ols, nil } +func (tp *torProvider) Reboot() { + tp.restart() +} + func (tp *torProvider) Open(hostname string) (net.Conn, string, error) { tp.lock.Lock() @@ -285,6 +289,9 @@ func (tp *torProvider) monitorRestart() { } } lastBootstrapProgress = prog + + tp. + case <-tp.breakChan: return } @@ -324,6 +331,7 @@ func createFromExisting(controlport *control.Conn, datadir string) *tor.Tor { StopProcessOnClose: false, GeoIPCreatedFile: "", GeoIPv6CreatedFile: "", + } t.Control.DebugWriter = t.DebugWriter diff --git a/go.mod b/go.mod index 382f90e..7fcefae 100644 --- a/go.mod +++ b/go.mod @@ -9,3 +9,5 @@ require ( golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3 // indirect golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect ) + +go 1.13 -- 2.25.1 From c3451dd0684eddc5ca3200bf53671a7ac4be5087 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Wed, 6 Nov 2019 11:29:44 -0800 Subject: [PATCH 2/2] Expose Restart --- connectivity/acn.go | 4 ++-- connectivity/localProvider.go | 4 ++++ connectivity/torProvider.go | 17 ++++++++--------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/connectivity/acn.go b/connectivity/acn.go index 12efcbc..b6b1d06 100644 --- a/connectivity/acn.go +++ b/connectivity/acn.go @@ -28,8 +28,8 @@ type ACN interface { // Sets the calback function to be called when ACN status changes SetStatusCallback(callback func(int, string)) - // Restarts the underlying connection - Reboot() + // Restart the underlying connection + Restart() // Open takes a hostname and returns a net.conn to the derived endpoint // Open allows a client to resolve various hostnames to connections diff --git a/connectivity/localProvider.go b/connectivity/localProvider.go index be8dc48..96440fb 100644 --- a/connectivity/localProvider.go +++ b/connectivity/localProvider.go @@ -38,6 +38,10 @@ func (lp *localProvider) SetStatusCallback(callback func(int, string)) { // nop } +func (lp *localProvider) Restart() { + // noop +} + // WaitTillBootstrapped Blocks until underlying network is bootstrapped func (lp *localProvider) WaitTillBootstrapped() { } diff --git a/connectivity/torProvider.go b/connectivity/torProvider.go index 85f723b..07fde26 100644 --- a/connectivity/torProvider.go +++ b/connectivity/torProvider.go @@ -121,7 +121,7 @@ func (tp *torProvider) Listen(identity PrivateKey, port int) (ListenService, err case ed25519.PrivateKey: privkey = pk gpubk := pk.Public() - switch pubk := gpubk.(type) {git + switch pubk := gpubk.(type) { case ed25519.PublicKey: onion = utils.GetTorV3Hostname(pubk) } @@ -155,10 +155,6 @@ func (tp *torProvider) Listen(identity PrivateKey, port int) (ListenService, err return ols, nil } -func (tp *torProvider) Reboot() { - tp.restart() -} - func (tp *torProvider) Open(hostname string) (net.Conn, string, error) { tp.lock.Lock() @@ -178,6 +174,13 @@ func (tp *torProvider) Open(hostname string) (net.Conn, string, error) { return conn, resolvedHostname, err } +func (tp *torProvider) Restart() { + if tp.statusCallback != nil { + tp.statusCallback(0, "rebooting") + } + tp.restart() +} + func (tp *torProvider) Close() { for _, child := range tp.childListeners { child.Close() @@ -289,9 +292,6 @@ func (tp *torProvider) monitorRestart() { } } lastBootstrapProgress = prog - - tp. - case <-tp.breakChan: return } @@ -331,7 +331,6 @@ func createFromExisting(controlport *control.Conn, datadir string) *tor.Tor { StopProcessOnClose: false, GeoIPCreatedFile: "", GeoIPv6CreatedFile: "", - } t.Control.DebugWriter = t.DebugWriter -- 2.25.1