mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-30 23:53:41 +02:00
watchtower+server: let manager Start & Stop the clients
In this commit, the `Stop` and `Start` methods are removed from the `Client` interface and instead added to the new `Manager`. Callers now only need to call the Manager to start or stop the clients instead of needing to call stop/start on each individual client.
This commit is contained in:
@@ -100,6 +100,9 @@ type Config struct {
|
||||
// required for each different commitment transaction type. The Manager acts as
|
||||
// a tower client multiplexer.
|
||||
type Manager struct {
|
||||
started sync.Once
|
||||
stopped sync.Once
|
||||
|
||||
cfg *Config
|
||||
|
||||
clients map[blob.Type]*TowerClient
|
||||
@@ -154,3 +157,38 @@ func (m *Manager) NewClient(policy wtpolicy.Policy) (*TowerClient, error) {
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
// Start starts all the clients that have been registered with the Manager.
|
||||
func (m *Manager) Start() error {
|
||||
var returnErr error
|
||||
m.started.Do(func() {
|
||||
m.clientsMu.Lock()
|
||||
defer m.clientsMu.Unlock()
|
||||
|
||||
for _, client := range m.clients {
|
||||
if err := client.start(); err != nil {
|
||||
returnErr = err
|
||||
return
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return returnErr
|
||||
}
|
||||
|
||||
// Stop stops all the clients that the Manger is managing.
|
||||
func (m *Manager) Stop() error {
|
||||
var returnErr error
|
||||
m.stopped.Do(func() {
|
||||
m.clientsMu.Lock()
|
||||
defer m.clientsMu.Unlock()
|
||||
|
||||
for _, client := range m.clients {
|
||||
if err := client.stop(); err != nil {
|
||||
returnErr = err
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return returnErr
|
||||
}
|
||||
|
Reference in New Issue
Block a user