diff --git a/hub.go b/hub.go index a2ec81e..70b6e27 100644 --- a/hub.go +++ b/hub.go @@ -1709,7 +1709,7 @@ func (h *Hub) removeRoom(room *Room) { statsHubRoomsCurrent.WithLabelValues(room.Backend().Id()).Dec() } h.ru.Unlock() - h.roomPing.DeleteRoom(room) + h.roomPing.DeleteRoom(room.Id()) } func (h *Hub) createRoom(id string, properties json.RawMessage, backend *Backend) (*Room, error) { diff --git a/room.go b/room.go index 2ef1f89..35047d0 100644 --- a/room.go +++ b/room.go @@ -963,7 +963,7 @@ func (r *Room) publishActiveSessions() (int, *sync.WaitGroup) { ctx, cancel := context.WithTimeout(context.Background(), r.hub.backendTimeout) defer cancel() - if err := r.hub.roomPing.SendPings(ctx, r, url, entries); err != nil { + if err := r.hub.roomPing.SendPings(ctx, r.id, url, entries); err != nil { log.Printf("Error pinging room %s for active entries %+v: %s", r.id, entries, err) } }(urls[u], e) diff --git a/room_ping.go b/room_ping.go index c51cb91..5902068 100644 --- a/room_ping.go +++ b/room_ping.go @@ -32,28 +32,28 @@ import ( type pingEntries struct { url *url.URL - entries map[*Room][]BackendPingEntry + entries map[string][]BackendPingEntry } -func newPingEntries(url *url.URL, room *Room, entries []BackendPingEntry) *pingEntries { +func newPingEntries(url *url.URL, roomId string, entries []BackendPingEntry) *pingEntries { return &pingEntries{ url: url, - entries: map[*Room][]BackendPingEntry{ - room: entries, + entries: map[string][]BackendPingEntry{ + roomId: entries, }, } } -func (e *pingEntries) Add(room *Room, entries []BackendPingEntry) { - if existing, found := e.entries[room]; found { - e.entries[room] = append(existing, entries...) +func (e *pingEntries) Add(roomId string, entries []BackendPingEntry) { + if existing, found := e.entries[roomId]; found { + e.entries[roomId] = append(existing, entries...) } else { - e.entries[room] = entries + e.entries[roomId] = entries } } -func (e *pingEntries) RemoveRoom(room *Room) { - delete(e.entries, room) +func (e *pingEntries) RemoveRoom(roomId string) { + delete(e.entries, roomId) } // RoomPing sends ping requests for active sessions in rooms. It evaluates the @@ -120,12 +120,12 @@ func (p *RoomPing) publishEntries(entries *pingEntries, timeout time.Duration) { if !found || limit <= 0 { // Limit disabled while waiting for the next iteration, fallback to sending // one request per room. - for room, e := range entries.entries { + for roomId, e := range entries.entries { ctx2, cancel2 := context.WithTimeout(context.Background(), timeout) defer cancel2() - if err := p.sendPingsDirect(ctx2, room, entries.url, e); err != nil { - log.Printf("Error pinging room %s for active entries %+v: %s", room.Id(), e, err) + if err := p.sendPingsDirect(ctx2, roomId, entries.url, e); err != nil { + log.Printf("Error pinging room %s for active entries %+v: %s", roomId, e, err) } } return @@ -158,8 +158,8 @@ func (p *RoomPing) publishActiveSessions() { wg.Wait() } -func (p *RoomPing) sendPingsDirect(ctx context.Context, room *Room, url *url.URL, entries []BackendPingEntry) error { - request := NewBackendClientPingRequest(room.Id(), entries) +func (p *RoomPing) sendPingsDirect(ctx context.Context, roomId string, url *url.URL, entries []BackendPingEntry) error { + request := NewBackendClientPingRequest(roomId, entries) var response BackendClientResponse return p.backend.PerformJSONRequest(ctx, url, request, &response) } @@ -184,13 +184,13 @@ func (p *RoomPing) sendPingsCombined(url *url.URL, entries []BackendPingEntry, l } } -func (p *RoomPing) SendPings(ctx context.Context, room *Room, url *url.URL, entries []BackendPingEntry) error { +func (p *RoomPing) SendPings(ctx context.Context, roomId string, url *url.URL, entries []BackendPingEntry) error { limit, _, found := p.capabilities.GetIntegerConfig(ctx, url, ConfigGroupSignaling, ConfigKeySessionPingLimit) if !found || limit <= 0 { // Old-style Nextcloud or session limit not configured. Perform one request // per room. Don't queue to avoid sending all ping requests to old-style // instances at the same time but distribute across the interval. - return p.sendPingsDirect(ctx, room, url, entries) + return p.sendPingsDirect(ctx, roomId, url, entries) } key := url.String() @@ -198,7 +198,7 @@ func (p *RoomPing) SendPings(ctx context.Context, room *Room, url *url.URL, entr p.mu.Lock() defer p.mu.Unlock() if existing, found := p.entries[key]; found { - existing.Add(room, entries) + existing.Add(roomId, entries) return nil } @@ -206,15 +206,15 @@ func (p *RoomPing) SendPings(ctx context.Context, room *Room, url *url.URL, entr p.entries = make(map[string]*pingEntries) } - p.entries[key] = newPingEntries(url, room, entries) + p.entries[key] = newPingEntries(url, roomId, entries) return nil } -func (p *RoomPing) DeleteRoom(room *Room) { +func (p *RoomPing) DeleteRoom(roomId string) { p.mu.Lock() defer p.mu.Unlock() for _, entries := range p.entries { - entries.RemoveRoom(room) + entries.RemoveRoom(roomId) } } diff --git a/room_ping_test.go b/room_ping_test.go index 59b705d..1b9ec76 100644 --- a/room_ping_test.go +++ b/room_ping_test.go @@ -78,7 +78,7 @@ func TestSingleRoomPing(t *testing.T) { SessionId: "123", }, } - if err := ping.SendPings(ctx, room1, u, entries1); err != nil { + if err := ping.SendPings(ctx, room1.Id(), u, entries1); err != nil { t.Error(err) } if requests := getPingRequests(t); len(requests) != 1 { @@ -97,7 +97,7 @@ func TestSingleRoomPing(t *testing.T) { SessionId: "456", }, } - if err := ping.SendPings(ctx, room2, u, entries2); err != nil { + if err := ping.SendPings(ctx, room2.Id(), u, entries2); err != nil { t.Error(err) } if requests := getPingRequests(t); len(requests) != 1 { @@ -129,7 +129,7 @@ func TestMultiRoomPing(t *testing.T) { SessionId: "123", }, } - if err := ping.SendPings(ctx, room1, u, entries1); err != nil { + if err := ping.SendPings(ctx, room1.Id(), u, entries1); err != nil { t.Error(err) } if requests := getPingRequests(t); len(requests) != 0 { @@ -145,7 +145,7 @@ func TestMultiRoomPing(t *testing.T) { SessionId: "456", }, } - if err := ping.SendPings(ctx, room2, u, entries2); err != nil { + if err := ping.SendPings(ctx, room2.Id(), u, entries2); err != nil { t.Error(err) } if requests := getPingRequests(t); len(requests) != 0 { @@ -176,7 +176,7 @@ func TestMultiRoomPing_Separate(t *testing.T) { SessionId: "123", }, } - if err := ping.SendPings(ctx, room1, u, entries1); err != nil { + if err := ping.SendPings(ctx, room1.Id(), u, entries1); err != nil { t.Error(err) } if requests := getPingRequests(t); len(requests) != 0 { @@ -188,7 +188,7 @@ func TestMultiRoomPing_Separate(t *testing.T) { SessionId: "456", }, } - if err := ping.SendPings(ctx, room1, u, entries2); err != nil { + if err := ping.SendPings(ctx, room1.Id(), u, entries2); err != nil { t.Error(err) } if requests := getPingRequests(t); len(requests) != 0 { @@ -219,7 +219,7 @@ func TestMultiRoomPing_DeleteRoom(t *testing.T) { SessionId: "123", }, } - if err := ping.SendPings(ctx, room1, u, entries1); err != nil { + if err := ping.SendPings(ctx, room1.Id(), u, entries1); err != nil { t.Error(err) } if requests := getPingRequests(t); len(requests) != 0 { @@ -235,14 +235,14 @@ func TestMultiRoomPing_DeleteRoom(t *testing.T) { SessionId: "456", }, } - if err := ping.SendPings(ctx, room2, u, entries2); err != nil { + if err := ping.SendPings(ctx, room2.Id(), u, entries2); err != nil { t.Error(err) } if requests := getPingRequests(t); len(requests) != 0 { t.Errorf("expected no ping requests, got %+v", requests) } - ping.DeleteRoom(room2) + ping.DeleteRoom(room2.Id()) ping.publishActiveSessions() if requests := getPingRequests(t); len(requests) != 1 {