watchtower: refactor getClientSession helper funcs

Small refactor to some of the tower client db helper functions in order
to simplify upcoming commits.
This commit is contained in:
Elle Mouton
2022-09-30 10:47:10 +02:00
parent 707546e2f0
commit 3ac3b6a90d

View File

@@ -1174,14 +1174,17 @@ func getClientSession(sessions, towers kvdb.RBucket,
return nil, err return nil, err
} }
// Can't fail because client session body has already been read.
sessionBkt := sessions.NestedReadBucket(idBytes)
// Fetch the committed updates for this session. // Fetch the committed updates for this session.
commitedUpdates, err := getClientSessionCommits(sessions, idBytes) commitedUpdates, err := getClientSessionCommits(sessionBkt)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// Fetch the acked updates for this session. // Fetch the acked updates for this session.
ackedUpdates, err := getClientSessionAcks(sessions, idBytes) ackedUpdates, err := getClientSessionAcks(sessionBkt)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -1195,11 +1198,8 @@ func getClientSession(sessions, towers kvdb.RBucket,
// getClientSessionCommits retrieves all committed updates for the session // getClientSessionCommits retrieves all committed updates for the session
// identified by the serialized session id. // identified by the serialized session id.
func getClientSessionCommits(sessions kvdb.RBucket, func getClientSessionCommits(sessionBkt kvdb.RBucket) ([]CommittedUpdate,
idBytes []byte) ([]CommittedUpdate, error) { error) {
// Can't fail because client session body has already been read.
sessionBkt := sessions.NestedReadBucket(idBytes)
// Initialize commitedUpdates so that we can return an initialized map // Initialize commitedUpdates so that we can return an initialized map
// if no committed updates exist. // if no committed updates exist.
@@ -1231,11 +1231,8 @@ func getClientSessionCommits(sessions kvdb.RBucket,
// getClientSessionAcks retrieves all acked updates for the session identified // getClientSessionAcks retrieves all acked updates for the session identified
// by the serialized session id. // by the serialized session id.
func getClientSessionAcks(sessions kvdb.RBucket, func getClientSessionAcks(sessionBkt kvdb.RBucket) (map[uint16]BackupID,
idBytes []byte) (map[uint16]BackupID, error) { error) {
// Can't fail because client session body has already been read.
sessionBkt := sessions.NestedReadBucket(idBytes)
// Initialize ackedUpdates so that we can return an initialized map if // Initialize ackedUpdates so that we can return an initialized map if
// no acked updates exist. // no acked updates exist.