summaryrefslogtreecommitdiffstats
path: root/back/cmd/authfs/sessdir.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/sessdir.go
parent7d622695ae19e518fded6aa5fbf001dae4652211 (diff)
downloadbuth-harveyos.zip
authfs: rewrite with Harvey-OS/ninep, implement Rattachharveyos
Diffstat (limited to 'back/cmd/authfs/sessdir.go')
-rw-r--r--back/cmd/authfs/sessdir.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/back/cmd/authfs/sessdir.go b/back/cmd/authfs/sessdir.go
new file mode 100644
index 0000000..186484f
--- /dev/null
+++ b/back/cmd/authfs/sessdir.go
@@ -0,0 +1,60 @@
+package main
+
+import (
+ "sync"
+
+ "git.samanthony.xyz/buth/back/auth"
+ "git.samanthony.xyz/buth/back/qver"
+)
+
+type SessionsDir struct {
+ *qver.Version
+
+ mu sync.Mutex // guards below
+ sessions map[auth.SessId]*Session
+}
+
+func NewSessionsDir(rootVer *qver.Version) *SessionsDir {
+ return &SessionsDir{
+ qver.New(qver.Parent(rootVer)),
+ sync.Mutex{},
+ make(map[auth.SessId]*Session),
+ }
+}
+
+func (dir *SessionsDir) Close() {
+ dir.mu.Lock()
+ // Don't unlock
+
+ dir.Version.Close()
+ for id, sess := range dir.sessions {
+ sess.Close()
+ delete(dir.sessions, id)
+ }
+}
+
+// Get returns the session with the given ID if it exists, or false if it doesn't.
+func (dir *SessionsDir) Get(id auth.SessId) (*Session, bool) {
+ dir.mu.Lock()
+ defer dir.mu.Unlock()
+ sess, ok := dir.sessions[id]
+ return sess, ok
+}
+
+// Owner returns the owner of the given session if it exists, or false if it doesn't.
+func (dir *SessionsDir) Owner(id auth.SessId) (auth.Uname, bool) {
+ if sess, ok := dir.Get(id); ok {
+ return sess.Uname, ok
+ }
+ return "", false
+}
+
+func (dir *SessionsDir) Kill(id auth.SessId) {
+ dir.mu.Lock()
+ defer dir.mu.Unlock()
+ if sess, ok := dir.sessions[id]; ok {
+ sess.Close()
+ delete(dir.sessions, id)
+ dir.Version.Bump()
+ }
+}