From c33a743a25e6f5d4e833b5f3ba32ba33cefe2211 Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 13 Apr 2018 21:17:58 +0900 Subject: [PATCH] ing --- server/server.go | 2 ++ servlet/auth-servlet.go | 32 +------------------------------- servlet/probe-servlet.go | 32 +------------------------------- 3 files changed, 4 insertions(+), 62 deletions(-) diff --git a/server/server.go b/server/server.go index 3041430..4500bd4 100644 --- a/server/server.go +++ b/server/server.go @@ -9,7 +9,9 @@ import ( func New(_config *config.Config) *cssw.Server { as := &servlet.AuthServlets{} + as.UseSession = true ps := &servlet.ProbeServlets{} + ps.UseSession = true ds := &servlet.DataServlets{} sh := &ServerHandlers{ diff --git a/servlet/auth-servlet.go b/servlet/auth-servlet.go index d198ef3..c36a0d9 100644 --- a/servlet/auth-servlet.go +++ b/servlet/auth-servlet.go @@ -5,7 +5,6 @@ import ( "encoding/base64" "encoding/json" "fmt" - "sync" "github.com/valyala/fasthttp" @@ -27,7 +26,6 @@ type AuthServlet interface { type AuthServlets struct { ogrs.RPCServlets - sessions sync.Map } func (s *AuthServlets) Init(serverCtx server.ServerCtx) error { @@ -132,21 +130,10 @@ func (s *AuthServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.Req func (s *AuthServlets) OnConnect(servletCtx server.ServletCtx, conn socket.Conn) { s.RPCServlets.OnConnect(servletCtx, conn) - - sessionID := servletCtx.GetAttribute(og.SessionIDKey) - targetID := servletCtx.GetAttribute(og.SessionTargetIDKey) - if nil != sessionID && nil != targetID { - s.sessions.Store(sessionID.(string), ogrs.RetainSession(targetID.(string), servletCtx)) - } } func (s *AuthServlets) OnDisconnect(servletCtx server.ServletCtx) { s.RPCServlets.OnDisconnect(servletCtx) - - sessionID := servletCtx.GetAttribute(og.SessionIDKey) - if nil != sessionID { - s.sessions.Delete(sessionID.(string)) - } } func (s *AuthServlets) handleSubscribe(serverCtx server.ServerCtx, subscribeChan <-chan *ogs.Message) { @@ -162,7 +149,7 @@ LOOP: switch msg.TargetType { case ogs.PROBE: - sessions = s.getAuthSessions(msg.Targets) + sessions = s.GetSessions(msg.Targets) default: logging.Logger().Warnf("Subscriber: Unknown TargetType %s", msg.TargetType) continue LOOP @@ -181,20 +168,3 @@ LOOP: } } } - -func (s *AuthServlets) getAuthSessions(sessionIDs []string) []*ogrs.Session { - var sessions []*ogrs.Session - - if nil == sessionIDs || 0 == len(sessionIDs) { - return sessions - } - - for _, sessionID := range sessionIDs { - session, ok := s.sessions.Load(sessionID) - if ok { - sessions = append(sessions, session.(*ogrs.Session)) - } - } - - return sessions -} diff --git a/servlet/probe-servlet.go b/servlet/probe-servlet.go index 5c83ff1..05b4c76 100644 --- a/servlet/probe-servlet.go +++ b/servlet/probe-servlet.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "sync" "github.com/valyala/fasthttp" @@ -26,7 +25,6 @@ type ProbeServlet interface { type ProbeServlets struct { ogrs.RPCServlets - sessions sync.Map } func (s *ProbeServlets) Init(serverCtx server.ServerCtx) error { @@ -109,21 +107,10 @@ func (s *ProbeServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.Re func (s *ProbeServlets) OnConnect(servletCtx server.ServletCtx, conn socket.Conn) { s.RPCServlets.OnConnect(servletCtx, conn) - - sessionID := servletCtx.GetAttribute(og.SessionIDKey) - targetID := servletCtx.GetAttribute(og.SessionTargetIDKey) - if nil != sessionID && nil != targetID { - s.sessions.Store(sessionID.(string), ogrs.RetainSession(targetID.(string), servletCtx)) - } } func (s *ProbeServlets) OnDisconnect(servletCtx server.ServletCtx) { s.RPCServlets.OnDisconnect(servletCtx) - - sessionID := servletCtx.GetAttribute(og.SessionIDKey) - if nil != sessionID { - s.sessions.Delete(sessionID.(string)) - } } func (s *ProbeServlets) handleSubscribe(serverCtx server.ServerCtx, subscribeChan <-chan *ogs.Message) { @@ -139,7 +126,7 @@ LOOP: switch msg.TargetType { case ogs.PROBE: - sessions = s.getProbeSessions(msg.Targets) + sessions = s.GetSessions(msg.Targets) default: logging.Logger().Warnf("Subscriber: Unknown TargetType %s", msg.TargetType) continue LOOP @@ -160,20 +147,3 @@ LOOP: } } } - -func (s *ProbeServlets) getProbeSessions(sessionIDs []string) []*ogrs.Session { - var sessions []*ogrs.Session - - if nil == sessionIDs || 0 == len(sessionIDs) { - return sessions - } - - for _, sessionID := range sessionIDs { - session, ok := s.sessions.Load(sessionID) - if ok { - sessions = append(sessions, session.(*ogrs.Session)) - } - } - - return sessions -}