Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/andrioid/ublproxy. andrioid.github.io/ublproxy
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455package main
import ( "log/slog" "sync")
// sessionEntry holds the session token and credential ID for an// authenticated client. The credential ID identifies the user (passkey)// and is used to look up per-user rules.type sessionEntry struct { Token string CredentialID string}
// sessionMap maps client IP addresses to their active sessions.// When a user authenticates on the portal (via passkey), their session// is associated with their IP. The proxy uses this to embed the// correct token in the bootstrap script and to resolve per-user rules.type sessionMap struct { mu sync.RWMutex entries map[string]sessionEntry // client IP -> session}
func newSessionMap() *sessionMap { return &sessionMap{entries: make(map[string]sessionEntry)}}
// Set associates a session with a client IP.func (m *sessionMap) Set(clientIP string, entry sessionEntry) { m.mu.Lock() m.entries[clientIP] = entry m.mu.Unlock() slog.Debug("session stored", "ip", clientIP, "user", shortUserID(entry.CredentialID))}
// Get returns the session entry for a client IP, or nil if none.func (m *sessionMap) Get(clientIP string) *sessionEntry { m.mu.RLock() entry, ok := m.entries[clientIP] m.mu.RUnlock() if !ok { return nil } return &entry}
// Delete removes the session for a client IP.func (m *sessionMap) Delete(clientIP string) { m.mu.Lock() delete(m.entries, clientIP) m.mu.Unlock() slog.Debug("session deleted", "ip", clientIP)}