lit: only fetch active sessions on startup

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.
This commit is contained in:
Elle Mouton 2025-02-09 12:31:04 +02:00
parent d2b077b9d5
commit 14cb0be3bc
No known key found for this signature in database
GPG key ID: D7D916376026F177

View file

@ -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)
}
@ -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
}
@ -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",