From e092f7ef4b7370307a5100f2630589d1ad124bb5 Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 13 Apr 2018 21:20:16 +0900 Subject: [PATCH] ing --- server/server.go | 2 ++ servlet/webapp-servlet.go | 57 ++------------------------------------- 2 files changed, 4 insertions(+), 55 deletions(-) diff --git a/server/server.go b/server/server.go index d2e9e66..f9ec7ee 100644 --- a/server/server.go +++ b/server/server.go @@ -11,6 +11,8 @@ func New(_config *config.Config) *csgw.Server { VerifyKey: _config.VerifyKey, SignKey: _config.SignKey, } + ws.UseSession = true + sh := &ServerHandlers{ ServerHandlers: *_config.ServerHandler, Config: _config, diff --git a/servlet/webapp-servlet.go b/servlet/webapp-servlet.go index 409913f..92e7ca8 100644 --- a/servlet/webapp-servlet.go +++ b/servlet/webapp-servlet.go @@ -3,7 +3,6 @@ package servlet import ( "crypto/rsa" "fmt" - "sync" "git.loafle.net/commons/logging-go" "git.loafle.net/commons/server-go" @@ -27,8 +26,6 @@ type WebappServlets struct { VerifyKey *rsa.PublicKey SignKey *rsa.PrivateKey - - sessions sync.Map } func (s *WebappServlets) Init(serverCtx server.ServerCtx) error { @@ -100,21 +97,10 @@ func (s *WebappServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.R func (s *WebappServlets) 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 *WebappServlets) OnDisconnect(servletCtx server.ServletCtx) { s.RPCServlets.OnDisconnect(servletCtx) - - sessionID := servletCtx.GetAttribute(og.SessionIDKey) - if nil != sessionID { - s.sessions.Delete(sessionID.(string)) - } } func (s *WebappServlets) handleSubscribe(serverCtx server.ServerCtx, subscribeChan <-chan *ogs.Message) { @@ -130,9 +116,9 @@ LOOP: switch msg.TargetType { case ogs.MEMBER: - sessions = s.getMemberSessionsByTargetIDs(msg.Targets) + sessions = s.GetSessionsByTargetIDs(msg.Targets) case ogs.MEMBER_SESSION: - sessions = s.getMemberSessions(msg.Targets) + sessions = s.GetSessions(msg.Targets) default: logging.Logger().Warnf("Subscriber: Unknown TargetType %s", msg.TargetType) continue LOOP @@ -152,42 +138,3 @@ LOOP: } } } - -func (s *WebappServlets) getMemberSessions(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 -} - -func (s *WebappServlets) getMemberSessionsByTargetIDs(targetIDs []string) []*ogrs.Session { - var sessions []*ogrs.Session - if nil == targetIDs || 0 == len(targetIDs) { - return sessions - } - - s.sessions.Range(func(k, v interface{}) bool { - session := v.(*ogrs.Session) - - for _, targetID := range targetIDs { - if session.TargetID == targetID { - sessions = append(sessions, session) - break - } - } - - return true - }) - - return sessions -}