wtclient+lnrpc: move Policy to Manager

This commit is contained in:
Elle Mouton
2023-05-16 14:15:09 +02:00
parent 4e51bf3a3f
commit ab2f781b4a
3 changed files with 31 additions and 11 deletions

View File

@@ -95,9 +95,6 @@ type RegisteredTower struct {
// Client is the primary interface used by the daemon to control a client's
// lifecycle and backup revoked states.
type Client interface {
// Policy returns the active client policy configuration.
Policy() wtpolicy.Policy
// RegisterChannel persistently initializes any channel-dependent
// parameters within the client. This should be called during link
// startup to ensure that the client is able to support the link during
@@ -1620,8 +1617,8 @@ func (c *TowerClient) getStats() ClientStats {
return c.stats.getStatsCopy()
}
// Policy returns the active client policy configuration.
func (c *TowerClient) Policy() wtpolicy.Policy {
// policy returns the active client policy configuration.
func (c *TowerClient) policy() wtpolicy.Policy {
return c.cfg.Policy
}

View File

@@ -38,6 +38,9 @@ type TowerClientManager interface {
// Stats returns the in-memory statistics of the client since startup.
Stats() ClientStats
// Policy returns the active client policy configuration.
Policy(blob.Type) (wtpolicy.Policy, error)
// RegisteredTowers retrieves the list of watchtowers registered with
// the client. It returns a set of registered towers per client policy
// type.
@@ -353,7 +356,7 @@ func (m *Manager) RegisteredTowers(opts ...wtdb.ClientSessionListOption) (
return nil, err
}
resp[client.Policy().BlobType] = towers
resp[client.policy().BlobType] = towers
}
return resp, nil
@@ -379,8 +382,23 @@ func (m *Manager) LookupTower(key *btcec.PublicKey,
return nil, err
}
resp[client.Policy().BlobType] = tower
resp[client.policy().BlobType] = tower
}
return resp, nil
}
// Policy returns the active client policy configuration for the client using
// the given blob type.
func (m *Manager) Policy(blobType blob.Type) (wtpolicy.Policy, error) {
m.clientsMu.Lock()
defer m.clientsMu.Unlock()
var policy wtpolicy.Policy
client, ok := m.clients[blobType]
if !ok {
return policy, fmt.Errorf("no client for the given blob type")
}
return client.policy(), nil
}