watchtower: add FetchSessionCommittedUpdates func to DB

In this commit, a new tower client db function is added that can be used
to fetch all the committed updates for a given session ID. This is done
in preparation for an upcoming commit where the CommittedUpdates will be
removed from the ClientSession struct.
This commit is contained in:
Elle Mouton
2022-09-30 11:47:54 +02:00
parent 15858cae1c
commit fe3d9174ea
4 changed files with 72 additions and 4 deletions

View File

@@ -242,6 +242,22 @@ func (m *ClientDB) listClientSessions(tower *wtdb.TowerID,
return sessions, nil
}
// FetchSessionCommittedUpdates retrieves the current set of un-acked updates
// of the given session.
func (m *ClientDB) FetchSessionCommittedUpdates(id *wtdb.SessionID) (
[]wtdb.CommittedUpdate, error) {
m.mu.Lock()
defer m.mu.Unlock()
sess, ok := m.activeSessions[*id]
if !ok {
return nil, wtdb.ErrClientSessionNotFound
}
return sess.CommittedUpdates, nil
}
// CreateClientSession records a newly negotiated client session in the set of
// active sessions. The session can be identified by its SessionID.
func (m *ClientDB) CreateClientSession(session *wtdb.ClientSession) error {