wtclient: add TerminateSession method

This commit is contained in:
Elle Mouton
2023-12-05 13:12:38 +02:00
parent 05c03400a9
commit 24702ede14
3 changed files with 231 additions and 19 deletions

View File

@@ -43,6 +43,10 @@ type ClientManager interface {
// be used while the tower is inactive.
DeactivateTower(pubKey *btcec.PublicKey) error
// TerminateSession sets the given session's status to CSessionTerminal
// meaning that it will not be used again.
TerminateSession(id wtdb.SessionID) error
// Stats returns the in-memory statistics of the client since startup.
Stats() ClientStats
@@ -436,6 +440,23 @@ func (m *Manager) RemoveTower(key *btcec.PublicKey, addr net.Addr) error {
return nil
}
// TerminateSession sets the given session's status to CSessionTerminal meaning
// that it will not be used again.
func (m *Manager) TerminateSession(id wtdb.SessionID) error {
m.clientsMu.Lock()
defer m.clientsMu.Unlock()
for _, client := range m.clients {
err := client.terminateSession(id)
if err != nil {
return err
}
}
// Finally, mark the session as terminated in the DB.
return m.cfg.DB.TerminateSession(id)
}
// DeactivateTower sets the given tower's status to inactive so that it is not
// considered for session negotiation. Its sessions will also not be used while
// the tower is inactive.