Skip to content

Commit

Permalink
lit: only fetch active sessions on startup
Browse files Browse the repository at this point in the history
Using the new ListSessions by type method, we no longer need to fetch
and iterate through all our sessions on start up to figure out which
ones to spin up.
  • Loading branch information
ellemouton committed Feb 13, 2025
1 parent d2b077b commit 14cb0be
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions session_rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ func newSessionRPCServer(cfg *sessionRpcServerConfig) (*sessionRpcServer,
// requests. This includes resuming all non-revoked sessions.
func (s *sessionRpcServer) start(ctx context.Context) error {
// Start up all previously created sessions.
sessions, err := s.cfg.db.ListAllSessions()
sessions, err := s.cfg.db.ListSessionsByState(
session.StateCreated,
session.StateInUse,
)
if err != nil {
return fmt.Errorf("error listing sessions: %v", err)
}
Expand All @@ -126,12 +129,6 @@ func (s *sessionRpcServer) start(ctx context.Context) error {
continue
}

if sess.State != session.StateInUse &&
sess.State != session.StateCreated {

continue
}

if sess.Expiry.Before(time.Now()) {
continue
}
Expand Down Expand Up @@ -345,24 +342,13 @@ func (s *sessionRpcServer) AddSession(ctx context.Context,
}, nil
}

// resumeSession tries to start an existing session if it is not expired, not
// revoked and a LiT session.
// resumeSession tries to start the given session if it is not expired.
func (s *sessionRpcServer) resumeSession(ctx context.Context,
sess *session.Session) error {

pubKey := sess.LocalPublicKey
pubKeyBytes := pubKey.SerializeCompressed()

// We only start non-revoked, non-expired LiT sessions. Everything else
// we just skip.
if sess.State != session.StateInUse &&
sess.State != session.StateCreated {

log.Debugf("Not resuming session %x with state %d", pubKeyBytes,
sess.State)
return nil
}

// Don't resume an expired session.
if sess.Expiry.Before(time.Now()) {
log.Debugf("Not resuming session %x with expiry %s",
Expand Down

0 comments on commit 14cb0be

Please sign in to comment.