Keep list of possible dialout sessions.

This commit is contained in:
Joachim Bauch 2023-09-20 13:01:07 +02:00
parent d1544dcb2c
commit e1273a3c52
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
2 changed files with 17 additions and 9 deletions

View file

@ -674,15 +674,11 @@ func (b *BackendServer) startDialout(roomid string, backend *Backend, request *B
return returnDialoutError(http.StatusBadRequest, err) return returnDialoutError(http.StatusBadRequest, err)
} }
// TODO: Add direct lookup of internal sessions that are not in a room and support dialout.
var session *ClientSession var session *ClientSession
for _, s := range b.hub.sessions { for s := range b.hub.dialoutSessions {
if s.GetRoom() == nil && s.ClientType() == HelloClientTypeInternal { if s.GetClient() != nil {
clientSession, ok := s.(*ClientSession) session = s
if ok && clientSession.GetClient() != nil && clientSession.HasFeature(ClientFeatureStartDialout) { break
session = clientSession
break
}
} }
} }
if session == nil { if session == nil {

14
hub.go
View file

@ -150,6 +150,7 @@ type Hub struct {
expiredSessions map[Session]bool expiredSessions map[Session]bool
anonymousSessions map[*ClientSession]time.Time anonymousSessions map[*ClientSession]time.Time
expectHelloClients map[*Client]time.Time expectHelloClients map[*Client]time.Time
dialoutSessions map[*ClientSession]bool
backendTimeout time.Duration backendTimeout time.Duration
backend *BackendClient backend *BackendClient
@ -338,6 +339,7 @@ func NewHub(config *goconf.ConfigFile, events AsyncEvents, rpcServer *GrpcServer
expiredSessions: make(map[Session]bool), expiredSessions: make(map[Session]bool),
anonymousSessions: make(map[*ClientSession]time.Time), anonymousSessions: make(map[*ClientSession]time.Time),
expectHelloClients: make(map[*Client]time.Time), expectHelloClients: make(map[*Client]time.Time),
dialoutSessions: make(map[*ClientSession]bool),
backendTimeout: backendTimeout, backendTimeout: backendTimeout,
backend: backend, backend: backend,
@ -641,6 +643,7 @@ func (h *Hub) removeSession(session Session) (removed bool) {
delete(h.expiredSessions, session) delete(h.expiredSessions, session)
if session, ok := session.(*ClientSession); ok { if session, ok := session.(*ClientSession); ok {
delete(h.anonymousSessions, session) delete(h.anonymousSessions, session)
delete(h.dialoutSessions, session)
} }
h.mu.Unlock() h.mu.Unlock()
return return
@ -802,8 +805,12 @@ func (h *Hub) processRegister(client *Client, message *ClientMessage, backend *B
h.sessions[sessionIdData.Sid] = session h.sessions[sessionIdData.Sid] = session
h.clients[sessionIdData.Sid] = client h.clients[sessionIdData.Sid] = client
delete(h.expectHelloClients, client) delete(h.expectHelloClients, client)
if userId == "" && auth.Type != HelloClientTypeInternal { if userId == "" && session.ClientType() != HelloClientTypeInternal {
h.startWaitAnonymousSessionRoomLocked(session) h.startWaitAnonymousSessionRoomLocked(session)
} else if session.ClientType() == HelloClientTypeInternal && session.HasFeature(ClientFeatureStartDialout) {
// TODO: There is a small race condition for sessions that take some time
// between connecting and joining a room.
h.dialoutSessions[session] = true
} }
h.mu.Unlock() h.mu.Unlock()
@ -1250,6 +1257,7 @@ func (h *Hub) processRoom(client *Client, message *ClientMessage) {
h.startWaitAnonymousSessionRoom(session) h.startWaitAnonymousSessionRoom(session)
} }
} }
return return
} }
@ -1389,6 +1397,10 @@ func (h *Hub) processJoinRoom(session *ClientSession, message *ClientMessage, ro
h.mu.Lock() h.mu.Lock()
// The session now joined a room, don't expire if it is anonymous. // The session now joined a room, don't expire if it is anonymous.
delete(h.anonymousSessions, session) delete(h.anonymousSessions, session)
if session.ClientType() == HelloClientTypeInternal && session.HasFeature(ClientFeatureStartDialout) {
// An internal session in a room can not be used for dialout.
delete(h.dialoutSessions, session)
}
h.mu.Unlock() h.mu.Unlock()
session.SetRoom(r) session.SetRoom(r)
if room.Room.Permissions != nil { if room.Room.Permissions != nil {