Skip to content

Commit

Permalink
feat(libsession): the default session operator will destroy sessions …
Browse files Browse the repository at this point in the history
…after 30 minutes of inactivity.
  • Loading branch information
razshare committed Feb 16, 2025
1 parent 48bc0de commit ae5cb60
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions libserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ type Server struct {
}

type sessionStore struct {
createdAt time.Time
data map[string]any
createdAt time.Time
lastActivityAt time.Time
data map[string]any
}

// ServerCreate creates a server.
Expand Down Expand Up @@ -91,8 +92,9 @@ func ServerCreate() *Server {
store, exists := memory[id]
if !exists {
store = sessionStore{
data: map[string]any{},
createdAt: time.Now(),
data: map[string]any{},
createdAt: time.Now(),
lastActivityAt: time.Now(),
}
memory[id] = store
}
Expand All @@ -118,7 +120,7 @@ func ServerCreate() *Server {
}

validate = func() (valid bool) {
elapsedSeconds := time.Since(store.createdAt).Minutes()
elapsedSeconds := time.Since(store.lastActivityAt).Minutes()
valid = elapsedSeconds < 30
return
}
Expand Down

0 comments on commit ae5cb60

Please sign in to comment.