no need to export sessionCache methods

rename upsert to insert since we only call it if there isn't a session.
This commit is contained in:
onyx-and-iris 2024-10-23 17:22:03 +01:00
parent abc1ea9d3f
commit bfe31c28c8
2 changed files with 9 additions and 9 deletions

View File

@ -15,8 +15,8 @@ func newSessionCache() sessionCache {
} }
} }
// Read returns the associated session for an addr // read returns the associated session for an addr
func (sc *sessionCache) Read(addr string) (*session, bool) { func (sc *sessionCache) read(addr string) (*session, bool) {
sc.mu.RLock() sc.mu.RLock()
defer sc.mu.RUnlock() defer sc.mu.RUnlock()
@ -24,16 +24,16 @@ func (sc *sessionCache) Read(addr string) (*session, bool) {
return v, ok return v, ok
} }
// Upsert overrides the session for a given addr. // insert adds a session for a given addr.
func (sc *sessionCache) Upsert(addr string, session *session) { func (sc *sessionCache) insert(addr string, session *session) {
sc.mu.Lock() sc.mu.Lock()
defer sc.mu.Unlock() defer sc.mu.Unlock()
sc.data[addr] = session sc.data[addr] = session
} }
// Delete removes the session for the given addr. // delete removes the session for the given addr.
func (sc *sessionCache) Delete(addr string) { func (sc *sessionCache) delete(addr string) {
sc.mu.Lock() sc.mu.Lock()
defer sc.mu.Unlock() defer sc.mu.Unlock()

View File

@ -73,7 +73,7 @@ func (c *Client) ListenAndServe() error {
log.Error(err) log.Error(err)
} }
session, ok := c.sessionCache.Read(caddr.String()) session, ok := c.sessionCache.read(caddr.String())
if !ok { if !ok {
session, err = newSession(caddr, c.raddr, c.proxyConn) session, err = newSession(caddr, c.raddr, c.proxyConn)
if err != nil { if err != nil {
@ -81,7 +81,7 @@ func (c *Client) ListenAndServe() error {
continue continue
} }
c.sessionCache.Upsert(caddr.String(), session) c.sessionCache.insert(caddr.String(), session)
} }
go session.proxyTo(buf[:n]) go session.proxyTo(buf[:n])
@ -94,7 +94,7 @@ func (c *Client) pruneSessions() {
for range ticker.C { for range ticker.C {
for _, session := range c.sessionCache.data { for _, session := range c.sessionCache.data {
if time.Since(session.updateTime) > c.sessionTimeout { if time.Since(session.updateTime) > c.sessionTimeout {
c.sessionCache.Delete(session.caddr.String()) c.sessionCache.delete(session.caddr.String())
log.Tracef("session for %s deleted", session.caddr) log.Tracef("session for %s deleted", session.caddr)
} }
} }