|
|
|
@ -56,6 +56,7 @@ type Session struct {
@@ -56,6 +56,7 @@ type Session struct {
|
|
|
|
|
subscriptions map[string]*Session |
|
|
|
|
subscribers map[string]*Session |
|
|
|
|
disconnected bool |
|
|
|
|
replaced bool |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func NewSession(manager SessionManager, unicaster Unicaster, broadcaster Broadcaster, rooms RoomStatusManager, buddyImages ImageCache, attestations *securecookie.SecureCookie, id, sid string) *Session { |
|
|
|
@ -209,6 +210,9 @@ func (s *Session) Close() {
@@ -209,6 +210,9 @@ func (s *Session) Close() {
|
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO(longsleep): Verify that it is ok to not do all this when replaced is true.
|
|
|
|
|
if !s.replaced { |
|
|
|
|
|
|
|
|
|
outgoing := &DataOutgoing{ |
|
|
|
|
From: s.Id, |
|
|
|
|
A: s.attestation.Token(), |
|
|
|
@ -237,6 +241,8 @@ func (s *Session) Close() {
@@ -237,6 +241,8 @@ func (s *Session) Close() {
|
|
|
|
|
s.SessionManager.DestroySession(s.Id, s.userid) |
|
|
|
|
s.buddyImages.Delete(s.Id) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
s.subscriptions = make(map[string]*Session) |
|
|
|
|
s.subscribers = make(map[string]*Session) |
|
|
|
|
s.disconnected = true |
|
|
|
@ -244,6 +250,27 @@ func (s *Session) Close() {
@@ -244,6 +250,27 @@ func (s *Session) Close() {
|
|
|
|
|
s.mutex.Unlock() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Session) Replace(oldSession *Session) { |
|
|
|
|
|
|
|
|
|
oldSession.mutex.Lock() |
|
|
|
|
if oldSession.disconnected { |
|
|
|
|
oldSession.mutex.Unlock() |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
s.mutex.Lock() |
|
|
|
|
|
|
|
|
|
s.subscriptions = oldSession.subscriptions |
|
|
|
|
s.subscribers = oldSession.subscribers |
|
|
|
|
|
|
|
|
|
s.mutex.Unlock() |
|
|
|
|
|
|
|
|
|
// Mark old session as replaced.
|
|
|
|
|
oldSession.replaced = true |
|
|
|
|
oldSession.mutex.Unlock() |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Session) Update(update *SessionUpdate) uint64 { |
|
|
|
|
s.mutex.Lock() |
|
|
|
|
defer s.mutex.Unlock() |
|
|
|
|