watchtower: make use of the new AddressIterator
This commit upgrades the wtclient package to make use of the new `AddressIterator`. It does so by first creating new `Tower` and `ClientSession` types. The new `Tower` type has an `AddressIterator` instead of a list of addresses. The `ClientSession` type contains a `Tower`.
This commit is contained in:
13 files changed
+274
-184
No files matched your search
@@ -429,7 +429,7 @@ func (c *ClientDB) RemoveTower(pubKey *btcec.PublicKey, addr net.Addr) error {
|
||||
}
|
||||
|
||||
towerSessions, err := listTowerSessions(
|
||||
towerID, sessions, towers, towersToSessionsIndex,
|
||||
towerID, sessions, towersToSessionsIndex,
|
||||
WithPerCommittedUpdate(perCommittedUpdate),
|
||||
)
|
||||
if err != nil {
|
||||
@@ -766,7 +766,7 @@ func (c *ClientDB) ListClientSessions(id *TowerID,
|
||||
// known to the db.
|
||||
if id == nil {
|
||||
clientSessions, err = listClientAllSessions(
|
||||
sessions, towers, opts...,
|
||||
sessions, opts...,
|
||||
)
|
||||
return err
|
||||
}
|
||||
@@ -778,7 +778,7 @@ func (c *ClientDB) ListClientSessions(id *TowerID,
|
||||
}
|
||||
|
||||
clientSessions, err = listTowerSessions(
|
||||
*id, sessions, towers, towerToSessionIndex, opts...,
|
||||
*id, sessions, towerToSessionIndex, opts...,
|
||||
)
|
||||
return err
|
||||
}, func() {
|
||||
@@ -792,7 +792,7 @@ func (c *ClientDB) ListClientSessions(id *TowerID,
|
||||
}
|
||||
|
||||
// listClientAllSessions returns the set of all client sessions known to the db.
|
||||
func listClientAllSessions(sessions, towers kvdb.RBucket,
|
||||
func listClientAllSessions(sessions kvdb.RBucket,
|
||||
opts ...ClientSessionListOption) (map[SessionID]*ClientSession, error) {
|
||||
|
||||
clientSessions := make(map[SessionID]*ClientSession)
|
||||
@@ -801,7 +801,7 @@ func listClientAllSessions(sessions, towers kvdb.RBucket,
|
||||
// the CommittedUpdates and AckedUpdates on startup to resume
|
||||
// committed updates and compute the highest known commit height
|
||||
// for each channel.
|
||||
session, err := getClientSession(sessions, towers, k, opts...)
|
||||
session, err := getClientSession(sessions, k, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -819,7 +819,7 @@ func listClientAllSessions(sessions, towers kvdb.RBucket,
|
||||
|
||||
// listTowerSessions returns the set of all client sessions known to the db
|
||||
// that are associated with the given tower id.
|
||||
func listTowerSessions(id TowerID, sessionsBkt, towersBkt,
|
||||
func listTowerSessions(id TowerID, sessionsBkt,
|
||||
towerToSessionIndex kvdb.RBucket, opts ...ClientSessionListOption) (
|
||||
map[SessionID]*ClientSession, error) {
|
||||
|
||||
@@ -834,9 +834,7 @@ func listTowerSessions(id TowerID, sessionsBkt, towersBkt,
|
||||
// the CommittedUpdates and AckedUpdates on startup to resume
|
||||
// committed updates and compute the highest known commit height
|
||||
// for each channel.
|
||||
session, err := getClientSession(
|
||||
sessionsBkt, towersBkt, k, opts...,
|
||||
)
|
||||
session, err := getClientSession(sessionsBkt, k, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1248,7 +1246,7 @@ func WithPerCommittedUpdate(cb PerCommittedUpdateCB) ClientSessionListOption {
|
||||
// getClientSession loads the full ClientSession associated with the serialized
|
||||
// session id. This method populates the CommittedUpdates, AckUpdates and Tower
|
||||
// in addition to the ClientSession's body.
|
||||
func getClientSession(sessions, towers kvdb.RBucket, idBytes []byte,
|
||||
func getClientSession(sessions kvdb.RBucket, idBytes []byte,
|
||||
opts ...ClientSessionListOption) (*ClientSession, error) {
|
||||
|
||||
cfg := NewClientSessionCfg()
|
||||
@@ -1261,13 +1259,6 @@ func getClientSession(sessions, towers kvdb.RBucket, idBytes []byte,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Fetch the tower associated with this session.
|
||||
tower, err := getTower(towers, session.TowerID.Bytes())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
session.Tower = tower
|
||||
|
||||
// Can't fail because client session body has already been read.
|
||||
sessionBkt := sessions.NestedReadBucket(idBytes)
|
||||
|
||||
|
||||
Reference in new issue
Block a user