Skip to content

Commit 92575c8

Browse files
committed
session: update the session Store interface
1 parent 21d59a0 commit 92575c8

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

session/db.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ type DB struct {
3737
*bbolt.DB
3838
}
3939

40+
// A compile-time check to ensure that DB implements the Store interface.
41+
var _ Store = (*DB)(nil)
42+
4043
// NewDB creates a new bolt database that can be found at the given directory.
4144
func NewDB(dir, fileName string) (*DB, error) {
4245
firstInit := false

session/interface.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,11 @@ type Store interface {
128128
// overwritten instead.
129129
StoreSession(*Session) error
130130

131+
// GetSession fetches the session with the given key.
132+
GetSession(key *btcec.PublicKey) (*Session, error)
133+
131134
// ListSessions returns all sessions currently known to the store.
132-
ListSessions() ([]*Session, error)
135+
ListSessions(filterFn func(s *Session) bool) ([]*Session, error)
133136

134137
// RevokeSession updates the state of the session with the given local
135138
// public key to be revoked.

session/store.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ func getSessionKey(session *Session) []byte {
2828
// StoreSession stores a session in the store. If a session with the
2929
// same local public key already exists, the existing record is updated/
3030
// overwritten instead.
31+
//
32+
// NOTE: this is part of the Store interface.
3133
func (db *DB) StoreSession(session *Session) error {
3234
var buf bytes.Buffer
3335
if err := SerializeSession(&buf, session); err != nil {
@@ -46,6 +48,8 @@ func (db *DB) StoreSession(session *Session) error {
4648
}
4749

4850
// GetSession fetches the session with the given key.
51+
//
52+
// NOTE: this is part of the Store interface.
4953
func (db *DB) GetSession(key *btcec.PublicKey) (*Session, error) {
5054
var session *Session
5155
err := db.View(func(tx *bbolt.Tx) error {
@@ -74,6 +78,8 @@ func (db *DB) GetSession(key *btcec.PublicKey) (*Session, error) {
7478
}
7579

7680
// ListSessions returns all sessions currently known to the store.
81+
//
82+
// NOTE: this is part of the Store interface.
7783
func (db *DB) ListSessions(filterFn func(s *Session) bool) ([]*Session, error) {
7884
var sessions []*Session
7985
err := db.View(func(tx *bbolt.Tx) error {
@@ -112,6 +118,8 @@ func (db *DB) ListSessions(filterFn func(s *Session) bool) ([]*Session, error) {
112118

113119
// RevokeSession updates the state of the session with the given local
114120
// public key to be revoked.
121+
//
122+
// NOTE: this is part of the Store interface.
115123
func (db *DB) RevokeSession(key *btcec.PublicKey) error {
116124
var session *Session
117125
err := db.View(func(tx *bbolt.Tx) error {

0 commit comments

Comments
 (0)