diff --git a/session/session.go b/session/session.go index eb99d96..7a158f4 100644 --- a/session/session.go +++ b/session/session.go @@ -1,31 +1,25 @@ // Package session builds the session/ file tree for the 9P namespace. -// The tree IS the session collection — sessions are mounted children. -// No manager, no store. Package functions for lifecycle. +// The tree IS the session collection — rootState holds the sessions map. +// Package functions for lifecycle, lookup, and enumeration. package session import ( "olliesrv/fs" ) -// Get returns the Session mounted at id, or nil. +// Get returns the Session for id, or nil. func Get(root *fs.Tree, id string) *Session { - child := root.Child(id) - if child == nil { - return nil - } - if sess, ok := child.Data.(*Session); ok { - return sess - } - return nil + return Lookup(root, id) } -// All returns all mounted sessions. +// All returns all active sessions. func All(root *fs.Tree) []*Session { - var sessions []*Session - for _, child := range root.Children() { - if sess, ok := child.Data.(*Session); ok { - sessions = append(sessions, sess) - } + rs := state(root) + rs.mu.RLock() + defer rs.mu.RUnlock() + sessions := make([]*Session, 0, len(rs.sessions)) + for _, sess := range rs.sessions { + sessions = append(sessions, sess) } return sessions }