From bfe31c28c8c2129ff05717fbf6a17e9c15d126bd Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Wed, 23 Oct 2024 17:22:03 +0100 Subject: [PATCH] no need to export sessionCache methods rename upsert to insert since we only call it if there isn't a session. --- pkg/udpproxy/sessioncache.go | 12 ++++++------ pkg/udpproxy/udpproxy.go | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/udpproxy/sessioncache.go b/pkg/udpproxy/sessioncache.go index b7d9927..7808364 100644 --- a/pkg/udpproxy/sessioncache.go +++ b/pkg/udpproxy/sessioncache.go @@ -15,8 +15,8 @@ func newSessionCache() sessionCache { } } -// Read returns the associated session for an addr -func (sc *sessionCache) Read(addr string) (*session, bool) { +// read returns the associated session for an addr +func (sc *sessionCache) read(addr string) (*session, bool) { sc.mu.RLock() defer sc.mu.RUnlock() @@ -24,16 +24,16 @@ func (sc *sessionCache) Read(addr string) (*session, bool) { return v, ok } -// Upsert overrides the session for a given addr. -func (sc *sessionCache) Upsert(addr string, session *session) { +// 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) { +// delete removes the session for the given addr. +func (sc *sessionCache) delete(addr string) { sc.mu.Lock() defer sc.mu.Unlock() diff --git a/pkg/udpproxy/udpproxy.go b/pkg/udpproxy/udpproxy.go index 69a318d..7885370 100644 --- a/pkg/udpproxy/udpproxy.go +++ b/pkg/udpproxy/udpproxy.go @@ -73,7 +73,7 @@ func (c *Client) ListenAndServe() error { log.Error(err) } - session, ok := c.sessionCache.Read(caddr.String()) + session, ok := c.sessionCache.read(caddr.String()) if !ok { session, err = newSession(caddr, c.raddr, c.proxyConn) if err != nil { @@ -81,7 +81,7 @@ func (c *Client) ListenAndServe() error { continue } - c.sessionCache.Upsert(caddr.String(), session) + c.sessionCache.insert(caddr.String(), session) } go session.proxyTo(buf[:n]) @@ -94,7 +94,7 @@ func (c *Client) pruneSessions() { for range ticker.C { for _, session := range c.sessionCache.data { 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) } }