X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=lib%2Fxdsserver%2Fsessions.go;h=0c16b995ec10fa5b12efc48c79e6fd4d5b2963b1;hb=65e09e831cf13343ac713fbf15281174d1f13a94;hp=6da9fd80d700406e67f09000cacabc4cee3a0cfb;hpb=2f7828d01f4c4ca2909f95f098627cd5475ed225;p=src%2Fxds%2Fxds-server.git diff --git a/lib/xdsserver/sessions.go b/lib/xdsserver/sessions.go index 6da9fd8..0c16b99 100644 --- a/lib/xdsserver/sessions.go +++ b/lib/xdsserver/sessions.go @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2017-2018 "IoT.bzh" + * Author Sebastien Douheret + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package xdsserver import ( @@ -5,9 +22,8 @@ import ( "strconv" "time" - "github.com/Sirupsen/logrus" "github.com/gin-gonic/gin" - "github.com/googollee/go-socket.io" + socketio "github.com/googollee/go-socket.io" uuid "github.com/satori/go.uuid" "github.com/syncthing/syncthing/lib/sync" ) @@ -37,16 +53,14 @@ type ClientSession struct { // Sessions holds client sessions type Sessions struct { *Context - cookieMaxAge int64 - sessMap map[string]ClientSession - mutex sync.Mutex - log *logrus.Logger - LogLevelSilly bool - stop chan struct{} // signals intentional stop + cookieMaxAge int64 + sessMap map[string]ClientSession + mutex sync.Mutex + stop chan struct{} // signals intentional stop } -// NewClientSessions . -func NewClientSessions(ctx *Context, cookieMaxAge string) *Sessions { +// ClientSessionsConstructor . +func ClientSessionsConstructor(ctx *Context, cookieMaxAge string) *Sessions { ckMaxAge, err := strconv.ParseInt(cookieMaxAge, 10, 0) if err != nil { ckMaxAge = 0 @@ -174,7 +188,7 @@ func (s *Sessions) newSession(prefix string) *ClientSession { s.sessMap[se.ID] = se - s.log.Debugf("NEW session (%d): %s", len(s.sessMap), id) + s.Log.Debugf("NEW session (%d): %s", len(s.sessMap), id) return &se } @@ -200,22 +214,20 @@ func (s *Sessions) monitorSessMap() { for { select { case <-s.stop: - s.log.Debugln("Stop monitorSessMap") + s.Log.Debugln("Stop monitorSessMap") return case <-time.After(sessionMonitorTime * time.Second): - if s.LogLevelSilly { - s.log.Debugf("Sessions Map size: %d", len(s.sessMap)) - s.log.Debugf("Sessions Map : %v", s.sessMap) - } + s.LogSillyf("Sessions Map size: %d", len(s.sessMap)) + s.LogSillyf("Sessions Map : %v", s.sessMap) if len(s.sessMap) > maxSessions { - s.log.Errorln("TOO MUCH sessions, cleanup old ones !") + s.Log.Errorln("TOO MUCH sessions, cleanup old ones !") } s.mutex.Lock() for _, ss := range s.sessMap { - if ss.expireAt.Sub(time.Now()) < 0 { - s.log.Debugf("Delete expired session id: %s", ss.ID) + if ss.expireAt.Sub(time.Now()) <= 0 { + s.Log.Debugf("Delete expired session id: %s", ss.ID) delete(s.sessMap, ss.ID) } }