watchtower/wtserver/interface: add DeleteSession + mock impl

This commit is contained in:
Conner Fromknecht 2019-03-19 19:38:34 -07:00
parent 25b2a352cb
commit 8e4a20e1a5
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
2 changed files with 31 additions and 0 deletions

View File

@ -70,6 +70,33 @@ func (db *MockDB) InsertSessionInfo(info *SessionInfo) error {
return nil
}
func (db *MockDB) DeleteSession(target SessionID) error {
db.mu.Lock()
defer db.mu.Unlock()
// Fail if the session doesn't exit.
if _, ok := db.sessions[target]; !ok {
return ErrSessionNotFound
}
// Remove the target session.
delete(db.sessions, target)
// Remove the state updates for any blobs stored under the target
// session identifier.
for hint, sessionUpdates := range db.blobs {
delete(sessionUpdates, target)
//If this was the last state update, we can also remove the hint
//that would map to an empty set.
if len(sessionUpdates) == 0 {
delete(db.blobs, hint)
}
}
return nil
}
func (db *MockDB) GetLookoutTip() (*chainntnfs.BlockEpoch, error) {
db.mu.Lock()
defer db.mu.Unlock()

View File

@ -63,4 +63,8 @@ type DB interface {
// validates the update against the current SessionInfo stored under the
// update's session id..
InsertStateUpdate(*wtdb.SessionStateUpdate) (uint16, error)
// DeleteSession removes all data associated with a particular session
// id from the tower's database.
DeleteSession(wtdb.SessionID) error
}