summaryrefslogtreecommitdiffstats
path: root/back/cmd/authfs/sess.go
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2026-03-14 11:23:50 -0400
committerSam Anthony <sam@samanthony.xyz>2026-03-14 11:23:50 -0400
commit700096b078f6e16f2c5c967ea140f0b93e799986 (patch)
treee1d9965e9bf09ebe01a96d8faa6d2bc027e6984c /back/cmd/authfs/sess.go
parent7d622695ae19e518fded6aa5fbf001dae4652211 (diff)
downloadbuth-700096b078f6e16f2c5c967ea140f0b93e799986.zip
authfs: rewrite with Harvey-OS/ninep, implement Rattachharveyos
Diffstat (limited to 'back/cmd/authfs/sess.go')
-rw-r--r--back/cmd/authfs/sess.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/back/cmd/authfs/sess.go b/back/cmd/authfs/sess.go
new file mode 100644
index 0000000..138ea84
--- /dev/null
+++ b/back/cmd/authfs/sess.go
@@ -0,0 +1,48 @@
+package main
+
+import (
+ "sync/atomic"
+ "time"
+
+ "git.samanthony.xyz/buth/back/auth"
+)
+
+type Session struct {
+ auth.SessId
+ auth.Uname
+ timer *time.Timer
+ dead *atomic.Bool
+}
+
+func NewSession(id auth.SessId, uname auth.Uname) *Session {
+ dead := new(atomic.Bool)
+ timer := time.AfterFunc(auth.SessTimeout, func() { dead.Store(true) })
+ return &Session{
+ id,
+ uname,
+ timer,
+ dead,
+ }
+}
+
+// Close expires the session immediately.
+func (s *Session) Close() {
+ s.timer.Stop()
+ s.dead.Store(true)
+}
+
+// IsActive returns true if the session has not yet expired.
+func (s *Session) IsActive() bool {
+ return !s.dead.Load()
+}
+
+// Extend resets the session's timer or returns false if it has
+// already expired.
+func (s *Session) Extend() bool {
+ if s.timer.Stop() {
+ s.timer.Reset(auth.SessTimeout)
+ return true
+ }
+ // already expired
+ return false
+}