watchtower: add ClientSessionFilterFn to session requests

In this commit, a new ClientSessionFilterFn parameter is added to the
DB's ListClientSession method which can be used to allow the caller to
specify a filter function for filtering sessions read from the DB.
Currently all filtering of sessions are done after the sessions have
been read from the DB, so adding this option should provide some
efficiency.
This commit is contained in:
Elle Mouton committed 2023-03-16 14:59:08 +02:00
1 parent 8a2999c789
commit 40ac82e439
5 files changed
+62 -28

No files matched your search

+7 -5
View File
@@ -418,7 +418,7 @@ func getTowerAndSessionCandidates(db DB, keyRing ECDHKeyRing,
return nil, err
}
sessions, err := db.ListClientSessions(&tower.ID, opts...)
sessions, err := db.ListClientSessions(&tower.ID, nil, opts...)
if err != nil {
return nil, err
}
@@ -470,7 +470,7 @@ func getClientSessions(db DB, keyRing ECDHKeyRing, forTower *wtdb.TowerID,
opts ...wtdb.ClientSessionListOption) (
map[wtdb.SessionID]*ClientSession, error) {
dbSessions, err := db.ListClientSessions(forTower, opts...)
dbSessions, err := db.ListClientSessions(forTower, nil, opts...)
if err != nil {
return nil, err
}
@@ -1289,7 +1289,7 @@ func (c *TowerClient) handleStaleTower(msg *staleTowerMsg) error {
// Otherwise, the tower should no longer be used for future session
// negotiations and backups.
pubKey := msg.pubKey.SerializeCompressed()
sessions, err := c.cfg.DB.ListClientSessions(&dbTower.ID)
sessions, err := c.cfg.DB.ListClientSessions(&dbTower.ID, nil)
if err != nil {
return fmt.Errorf("unable to retrieve sessions for tower %x: "+
"%v", pubKey, err)
@@ -1320,7 +1320,7 @@ func (c *TowerClient) RegisteredTowers(opts ...wtdb.ClientSessionListOption) (
if err != nil {
return nil, err
}
clientSessions, err := c.cfg.DB.ListClientSessions(nil, opts...)
clientSessions, err := c.cfg.DB.ListClientSessions(nil, nil, opts...)
if err != nil {
return nil, err
}
@@ -1361,7 +1361,9 @@ func (c *TowerClient) LookupTower(pubKey *btcec.PublicKey,
return nil, err
}
towerSessions, err := c.cfg.DB.ListClientSessions(&tower.ID, opts...)
towerSessions, err := c.cfg.DB.ListClientSessions(
&tower.ID, nil, opts...,
)
if err != nil {
return nil, err
}