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:
5 files changed
+62
-28
No files matched your search
@@ -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
|
||||
}
|
||||
|
||||
@@ -60,7 +60,8 @@ type DB interface {
|
||||
// ListClientSessions returns the set of all client sessions known to
|
||||
// the db. An optional tower ID can be used to filter out any client
|
||||
// sessions in the response that do not correspond to this tower.
|
||||
ListClientSessions(*wtdb.TowerID, ...wtdb.ClientSessionListOption) (
|
||||
ListClientSessions(*wtdb.TowerID, wtdb.ClientSessionFilterFn,
|
||||
...wtdb.ClientSessionListOption) (
|
||||
map[wtdb.SessionID]*wtdb.ClientSession, error)
|
||||
|
||||
// FetchSessionCommittedUpdates retrieves the current set of un-acked
|
||||
|
||||
Reference in new issue
Block a user