mirror of
https://github.com/onyx-and-iris/q3rcon-proxy.git
synced 2026-04-07 07:43:30 +00:00
move udpproxy files into repo root
This commit is contained in:
41
sessioncache.go
Normal file
41
sessioncache.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package udpproxy
|
||||
|
||||
import "sync"
|
||||
|
||||
// sessionCache tracks connection sessions
|
||||
type sessionCache struct {
|
||||
mu sync.RWMutex
|
||||
data map[string]*session
|
||||
}
|
||||
|
||||
// newSessionCache creates a usable sessionCache.
|
||||
func newSessionCache() sessionCache {
|
||||
return sessionCache{
|
||||
data: make(map[string]*session),
|
||||
}
|
||||
}
|
||||
|
||||
// read returns the associated session for an addr
|
||||
func (sc *sessionCache) read(addr string) (*session, bool) {
|
||||
sc.mu.RLock()
|
||||
defer sc.mu.RUnlock()
|
||||
|
||||
v, ok := sc.data[addr]
|
||||
return v, ok
|
||||
}
|
||||
|
||||
// insert adds a session for a given addr.
|
||||
func (sc *sessionCache) insert(addr string, session *session) {
|
||||
sc.mu.Lock()
|
||||
defer sc.mu.Unlock()
|
||||
|
||||
sc.data[addr] = session
|
||||
}
|
||||
|
||||
// delete removes the session for the given addr.
|
||||
func (sc *sessionCache) delete(addr string) {
|
||||
sc.mu.Lock()
|
||||
defer sc.mu.Unlock()
|
||||
|
||||
delete(sc.data, addr)
|
||||
}
|
||||
Reference in New Issue
Block a user