tor: remove Onion Service upon shutdown

This commit adds a new method to call DEL_ONION when lnd is shutting
down. Tor controller will now be aware of the active serviceID and
removes the service upon shutdown.
This commit is contained in:
yyforyongyu committed 2021-10-11 13:11:53 +08:00
1 parent 0b80d4feaa
commit 90e6c70ea0
3 files changed
+67

No files matched your search

+20
View File
@@ -20,6 +20,14 @@ const (
// request.
success = 250
// invalidNumOfArguments is the Tor Control response code representing
// there being an invalid number of arguments.
invalidNumOfArguments = 512
// serviceIDNotRecognized is the Tor Control response code representing
// the specified ServiceID is not recognized.
serviceIDNotRecognized = 552
// nonceLen is the length of a nonce generated by either the controller
// or the Tor server
nonceLen = 32
@@ -100,6 +108,9 @@ type Controller struct {
// to connect to the LND node. This is required when the Tor server
// runs on another host, otherwise the service will not be reachable.
targetIPAddress string
// activeServiceID is the Onion ServiceID created by ADD_ONION.
activeServiceID string
}
// NewController returns a new Tor controller that will be able to interact with
@@ -142,6 +153,15 @@ func (c *Controller) Stop() error {
log.Info("Stopping tor controller")
// Remove the onion service.
if err := c.DelOnion(c.activeServiceID); err != nil {
log.Errorf("DEL_ONION got error: %v", err)
return err
}
// Reset service ID.
c.activeServiceID = ""
return c.conn.Close()
}