Skip to content

Commit 01410f7

Browse files
committed
session: remove the filter fn in ListSessions
And replace with ListAllSessions since no callers of ListSessions currently make use of the filter function.
1 parent 6c36b01 commit 01410f7

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

session/interface.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ type Store interface {
161161
// GetSession fetches the session with the given key.
162162
GetSession(key *btcec.PublicKey) (*Session, error)
163163

164-
// ListSessions returns all sessions currently known to the store.
165-
ListSessions(filterFn func(s *Session) bool) ([]*Session, error)
164+
// ListAllSessions returns all sessions currently known to the store.
165+
ListAllSessions() ([]*Session, error)
166166

167167
// ListSessionsByType returns all sessions of the given type.
168168
ListSessionsByType(t Type) ([]*Session, error)

session/kvdb_store.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,13 @@ func (db *BoltStore) GetSession(key *btcec.PublicKey) (*Session, error) {
364364
return session, nil
365365
}
366366

367-
// ListSessions returns all sessions currently known to the store.
367+
// ListAllSessions returns all sessions currently known to the store.
368368
//
369369
// NOTE: this is part of the Store interface.
370-
func (db *BoltStore) ListSessions(filterFn func(s *Session) bool) ([]*Session, error) {
371-
return db.listSessions(filterFn)
370+
func (db *BoltStore) ListAllSessions() ([]*Session, error) {
371+
return db.listSessions(func(s *Session) bool {
372+
return true
373+
})
372374
}
373375

374376
// ListSessionsByType returns all sessions currently known to the store that

session/store_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,8 @@ func TestBasicSessionStore(t *testing.T) {
5656
require.NoError(t, db.CreateSession(s2))
5757
require.NoError(t, db.CreateSession(s3))
5858

59-
// Check that all sessions are returned in ListSessions.
60-
sessions, err := db.ListSessions(nil)
61-
require.NoError(t, err)
62-
require.Equal(t, 3, len(sessions))
63-
assertEqualSessions(t, s1, sessions[0])
64-
assertEqualSessions(t, s2, sessions[1])
65-
assertEqualSessions(t, s3, sessions[2])
66-
6759
// Test the ListSessionsByType method.
68-
sessions, err = db.ListSessionsByType(TypeMacaroonAdmin)
60+
sessions, err := db.ListSessionsByType(TypeMacaroonAdmin)
6961
require.NoError(t, err)
7062
require.Equal(t, 2, len(sessions))
7163
assertEqualSessions(t, s1, sessions[0])
@@ -115,9 +107,17 @@ func TestBasicSessionStore(t *testing.T) {
115107

116108
// Now revoke the session and assert that the state is revoked.
117109
require.NoError(t, db.RevokeSession(s1.LocalPublicKey))
118-
session1, err = db.GetSession(s1.LocalPublicKey)
110+
s1, err = db.GetSession(s1.LocalPublicKey)
119111
require.NoError(t, err)
120-
require.Equal(t, session1.State, StateRevoked)
112+
require.Equal(t, s1.State, StateRevoked)
113+
114+
// Test that ListAllSessions works.
115+
sessions, err = db.ListAllSessions()
116+
require.NoError(t, err)
117+
require.Equal(t, 3, len(sessions))
118+
assertEqualSessions(t, s1, sessions[0])
119+
assertEqualSessions(t, s2, sessions[1])
120+
assertEqualSessions(t, s3, sessions[2])
121121
}
122122

123123
// TestLinkingSessions tests that session linking works as expected.

session_rpcserver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func newSessionRPCServer(cfg *sessionRpcServerConfig) (*sessionRpcServer,
101101
// requests. This includes resuming all non-revoked sessions.
102102
func (s *sessionRpcServer) start(ctx context.Context) error {
103103
// Start up all previously created sessions.
104-
sessions, err := s.cfg.db.ListSessions(nil)
104+
sessions, err := s.cfg.db.ListAllSessions()
105105
if err != nil {
106106
return fmt.Errorf("error listing sessions: %v", err)
107107
}
@@ -536,7 +536,7 @@ func (s *sessionRpcServer) resumeSession(ctx context.Context,
536536
func (s *sessionRpcServer) ListSessions(_ context.Context,
537537
_ *litrpc.ListSessionsRequest) (*litrpc.ListSessionsResponse, error) {
538538

539-
sessions, err := s.cfg.db.ListSessions(nil)
539+
sessions, err := s.cfg.db.ListAllSessions()
540540
if err != nil {
541541
return nil, fmt.Errorf("error fetching sessions: %v", err)
542542
}

0 commit comments

Comments
 (0)