add room/participant name limit (#2704)
* add room/participant name limit * defaults * simplify * omitempty * handle 0 config * fix race * unlock * tidy
This commit is contained in:
+15
-11
@@ -229,15 +229,17 @@ type VideoConfig struct {
|
|||||||
|
|
||||||
type RoomConfig struct {
|
type RoomConfig struct {
|
||||||
// enable rooms to be automatically created
|
// enable rooms to be automatically created
|
||||||
AutoCreate bool `yaml:"auto_create,omitempty"`
|
AutoCreate bool `yaml:"auto_create,omitempty"`
|
||||||
EnabledCodecs []CodecSpec `yaml:"enabled_codecs,omitempty"`
|
EnabledCodecs []CodecSpec `yaml:"enabled_codecs,omitempty"`
|
||||||
MaxParticipants uint32 `yaml:"max_participants,omitempty"`
|
MaxParticipants uint32 `yaml:"max_participants,omitempty"`
|
||||||
EmptyTimeout uint32 `yaml:"empty_timeout,omitempty"`
|
EmptyTimeout uint32 `yaml:"empty_timeout,omitempty"`
|
||||||
DepartureTimeout uint32 `yaml:"departure_timeout,omitempty"`
|
DepartureTimeout uint32 `yaml:"departure_timeout,omitempty"`
|
||||||
EnableRemoteUnmute bool `yaml:"enable_remote_unmute,omitempty"`
|
EnableRemoteUnmute bool `yaml:"enable_remote_unmute,omitempty"`
|
||||||
MaxMetadataSize uint32 `yaml:"max_metadata_size,omitempty"`
|
MaxMetadataSize uint32 `yaml:"max_metadata_size,omitempty"`
|
||||||
PlayoutDelay PlayoutDelayConfig `yaml:"playout_delay,omitempty"`
|
PlayoutDelay PlayoutDelayConfig `yaml:"playout_delay,omitempty"`
|
||||||
SyncStreams bool `yaml:"sync_streams,omitempty"`
|
SyncStreams bool `yaml:"sync_streams,omitempty"`
|
||||||
|
MaxRoomNameLength int `yaml:"max_room_name_length,omitempty"`
|
||||||
|
MaxParticipantIdentityLength int `yaml:"max_participant_identity_length,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CodecSpec struct {
|
type CodecSpec struct {
|
||||||
@@ -484,8 +486,10 @@ var DefaultConfig = Config{
|
|||||||
{Mime: webrtc.MimeTypeVP9},
|
{Mime: webrtc.MimeTypeVP9},
|
||||||
{Mime: webrtc.MimeTypeAV1},
|
{Mime: webrtc.MimeTypeAV1},
|
||||||
},
|
},
|
||||||
EmptyTimeout: 5 * 60,
|
EmptyTimeout: 5 * 60,
|
||||||
DepartureTimeout: 20,
|
DepartureTimeout: 20,
|
||||||
|
MaxRoomNameLength: 256,
|
||||||
|
MaxParticipantIdentityLength: 256,
|
||||||
},
|
},
|
||||||
Logging: LoggingConfig{
|
Logging: LoggingConfig{
|
||||||
PionLevel: "error",
|
PionLevel: "error",
|
||||||
|
|||||||
+21
-19
@@ -19,23 +19,25 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrEgressNotFound = psrpc.NewErrorf(psrpc.NotFound, "egress does not exist")
|
ErrEgressNotFound = psrpc.NewErrorf(psrpc.NotFound, "egress does not exist")
|
||||||
ErrEgressNotConnected = psrpc.NewErrorf(psrpc.Internal, "egress not connected (redis required)")
|
ErrEgressNotConnected = psrpc.NewErrorf(psrpc.Internal, "egress not connected (redis required)")
|
||||||
ErrIdentityEmpty = psrpc.NewErrorf(psrpc.InvalidArgument, "identity cannot be empty")
|
ErrIdentityEmpty = psrpc.NewErrorf(psrpc.InvalidArgument, "identity cannot be empty")
|
||||||
ErrIngressNotConnected = psrpc.NewErrorf(psrpc.Internal, "ingress not connected (redis required)")
|
ErrIngressNotConnected = psrpc.NewErrorf(psrpc.Internal, "ingress not connected (redis required)")
|
||||||
ErrIngressNotFound = psrpc.NewErrorf(psrpc.NotFound, "ingress does not exist")
|
ErrIngressNotFound = psrpc.NewErrorf(psrpc.NotFound, "ingress does not exist")
|
||||||
ErrIngressNonReusable = psrpc.NewErrorf(psrpc.InvalidArgument, "ingress is not reusable and cannot be modified")
|
ErrIngressNonReusable = psrpc.NewErrorf(psrpc.InvalidArgument, "ingress is not reusable and cannot be modified")
|
||||||
ErrMetadataExceedsLimits = psrpc.NewErrorf(psrpc.InvalidArgument, "metadata size exceeds limits")
|
ErrMetadataExceedsLimits = psrpc.NewErrorf(psrpc.InvalidArgument, "metadata size exceeds limits")
|
||||||
ErrOperationFailed = psrpc.NewErrorf(psrpc.Internal, "operation cannot be completed")
|
ErrRoomNameExceedsLimits = psrpc.NewErrorf(psrpc.InvalidArgument, "room name length exceeds limits")
|
||||||
ErrParticipantNotFound = psrpc.NewErrorf(psrpc.NotFound, "participant does not exist")
|
ErrParticipantIdentityExceedsLimits = psrpc.NewErrorf(psrpc.InvalidArgument, "participant identity length exceeds limits")
|
||||||
ErrRoomNotFound = psrpc.NewErrorf(psrpc.NotFound, "requested room does not exist")
|
ErrOperationFailed = psrpc.NewErrorf(psrpc.Internal, "operation cannot be completed")
|
||||||
ErrRoomLockFailed = psrpc.NewErrorf(psrpc.Internal, "could not lock room")
|
ErrParticipantNotFound = psrpc.NewErrorf(psrpc.NotFound, "participant does not exist")
|
||||||
ErrRoomUnlockFailed = psrpc.NewErrorf(psrpc.Internal, "could not unlock room, lock token does not match")
|
ErrRoomNotFound = psrpc.NewErrorf(psrpc.NotFound, "requested room does not exist")
|
||||||
ErrRemoteUnmuteNoteEnabled = psrpc.NewErrorf(psrpc.FailedPrecondition, "remote unmute not enabled")
|
ErrRoomLockFailed = psrpc.NewErrorf(psrpc.Internal, "could not lock room")
|
||||||
ErrTrackNotFound = psrpc.NewErrorf(psrpc.NotFound, "track is not found")
|
ErrRoomUnlockFailed = psrpc.NewErrorf(psrpc.Internal, "could not unlock room, lock token does not match")
|
||||||
ErrWebHookMissingAPIKey = psrpc.NewErrorf(psrpc.InvalidArgument, "api_key is required to use webhooks")
|
ErrRemoteUnmuteNoteEnabled = psrpc.NewErrorf(psrpc.FailedPrecondition, "remote unmute not enabled")
|
||||||
ErrSIPNotConnected = psrpc.NewErrorf(psrpc.Internal, "sip not connected (redis required)")
|
ErrTrackNotFound = psrpc.NewErrorf(psrpc.NotFound, "track is not found")
|
||||||
ErrSIPTrunkNotFound = psrpc.NewErrorf(psrpc.NotFound, "requested sip trunk does not exist")
|
ErrWebHookMissingAPIKey = psrpc.NewErrorf(psrpc.InvalidArgument, "api_key is required to use webhooks")
|
||||||
ErrSIPDispatchRuleNotFound = psrpc.NewErrorf(psrpc.NotFound, "requested sip dispatch rule does not exist")
|
ErrSIPNotConnected = psrpc.NewErrorf(psrpc.Internal, "sip not connected (redis required)")
|
||||||
ErrSIPParticipantNotFound = psrpc.NewErrorf(psrpc.NotFound, "requested sip participant does not exist")
|
ErrSIPTrunkNotFound = psrpc.NewErrorf(psrpc.NotFound, "requested sip trunk does not exist")
|
||||||
|
ErrSIPDispatchRuleNotFound = psrpc.NewErrorf(psrpc.NotFound, "requested sip dispatch rule does not exist")
|
||||||
|
ErrSIPParticipantNotFound = psrpc.NewErrorf(psrpc.NotFound, "requested sip participant does not exist")
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/avast/retry-go/v4"
|
"github.com/avast/retry-go/v4"
|
||||||
@@ -83,6 +84,10 @@ func (s *RoomService) CreateRoom(ctx context.Context, req *livekit.CreateRoomReq
|
|||||||
return nil, ErrEgressNotConnected
|
return nil, ErrEgressNotConnected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if limit := s.roomConf.MaxRoomNameLength; limit > 0 && len(req.Name) > limit {
|
||||||
|
return nil, fmt.Errorf("%w: max length %d", ErrRoomNameExceedsLimits, limit)
|
||||||
|
}
|
||||||
|
|
||||||
rm, created, err := s.roomAllocator.CreateRoom(ctx, req)
|
rm, created, err := s.roomAllocator.CreateRoom(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "could not create room")
|
err = errors.Wrap(err, "could not create room")
|
||||||
|
|||||||
@@ -120,6 +120,9 @@ func (s *RTCService) validate(r *http.Request) (livekit.RoomName, routing.Partic
|
|||||||
if claims.Identity == "" {
|
if claims.Identity == "" {
|
||||||
return "", pi, http.StatusBadRequest, ErrIdentityEmpty
|
return "", pi, http.StatusBadRequest, ErrIdentityEmpty
|
||||||
}
|
}
|
||||||
|
if limit := s.config.Room.MaxParticipantIdentityLength; limit > 0 && len(claims.Identity) > limit {
|
||||||
|
return "", pi, http.StatusBadRequest, fmt.Errorf("%w: max length %d", ErrParticipantIdentityExceedsLimits, limit)
|
||||||
|
}
|
||||||
|
|
||||||
roomName := livekit.RoomName(r.FormValue("room"))
|
roomName := livekit.RoomName(r.FormValue("room"))
|
||||||
reconnectParam := r.FormValue("reconnect")
|
reconnectParam := r.FormValue("reconnect")
|
||||||
@@ -133,6 +136,9 @@ func (s *RTCService) validate(r *http.Request) (livekit.RoomName, routing.Partic
|
|||||||
if onlyName != "" {
|
if onlyName != "" {
|
||||||
roomName = onlyName
|
roomName = onlyName
|
||||||
}
|
}
|
||||||
|
if limit := s.config.Room.MaxRoomNameLength; limit > 0 && len(roomName) > limit {
|
||||||
|
return "", pi, http.StatusBadRequest, fmt.Errorf("%w: max length %d", ErrRoomNameExceedsLimits, limit)
|
||||||
|
}
|
||||||
|
|
||||||
// this is new connection for existing participant - with publish only permissions
|
// this is new connection for existing participant - with publish only permissions
|
||||||
if publishParam != "" {
|
if publishParam != "" {
|
||||||
|
|||||||
@@ -162,8 +162,10 @@ func (c *WSSignalConnection) WriteServerMessage(msg *livekit.ServerMessage) (int
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *WSSignalConnection) pingWorker() {
|
func (c *WSSignalConnection) pingWorker() {
|
||||||
for {
|
ticker := time.NewTicker(pingFrequency)
|
||||||
<-time.After(pingFrequency)
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
for range ticker.C {
|
||||||
err := c.conn.WriteControl(websocket.PingMessage, []byte(""), time.Now().Add(pingTimeout))
|
err := c.conn.WriteControl(websocket.PingMessage, []byte(""), time.Now().Add(pingTimeout))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -698,13 +698,12 @@ func (s *StreamAllocator) handleSignalProbeClusterDone(event Event) {
|
|||||||
func (s *StreamAllocator) handleSignalResume(event Event) {
|
func (s *StreamAllocator) handleSignalResume(event Event) {
|
||||||
s.videoTracksMu.Lock()
|
s.videoTracksMu.Lock()
|
||||||
track := s.videoTracks[event.TrackID]
|
track := s.videoTracks[event.TrackID]
|
||||||
|
updated := track != nil && track.SetStreamState(StreamStateActive)
|
||||||
s.videoTracksMu.Unlock()
|
s.videoTracksMu.Unlock()
|
||||||
|
|
||||||
if track != nil {
|
if updated {
|
||||||
update := NewStreamStateUpdate()
|
update := NewStreamStateUpdate()
|
||||||
if track.SetStreamState(StreamStateActive) {
|
update.HandleStreamingChange(track, StreamStateActive)
|
||||||
update.HandleStreamingChange(track, StreamStateActive)
|
|
||||||
}
|
|
||||||
s.maybeSendUpdate(update)
|
s.maybeSendUpdate(update)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,8 +129,9 @@ func (t *telemetryService) FlushStats() {
|
|||||||
t.workersMu.RUnlock()
|
t.workersMu.RUnlock()
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
var prev, reapHead, reapTail *StatsWorker
|
var prev, reap *StatsWorker
|
||||||
for worker != nil {
|
for worker != nil {
|
||||||
|
next := worker.next
|
||||||
if closed := worker.Flush(now); closed {
|
if closed := worker.Flush(now); closed {
|
||||||
if prev == nil {
|
if prev == nil {
|
||||||
// this worker was at the head of the list
|
// this worker was at the head of the list
|
||||||
@@ -148,27 +149,19 @@ func (t *telemetryService) FlushStats() {
|
|||||||
prev.next = worker.next
|
prev.next = worker.next
|
||||||
}
|
}
|
||||||
|
|
||||||
if reapHead == nil {
|
worker.next = reap
|
||||||
reapHead = worker
|
reap = worker
|
||||||
reapTail = worker
|
|
||||||
} else {
|
|
||||||
reapTail.next = worker
|
|
||||||
reapTail = worker
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
prev = worker
|
prev = worker
|
||||||
}
|
}
|
||||||
worker = worker.next
|
worker = next
|
||||||
}
|
}
|
||||||
|
|
||||||
if reapHead != nil {
|
if reap != nil {
|
||||||
t.workersMu.Lock()
|
t.workersMu.Lock()
|
||||||
for {
|
for reap != nil {
|
||||||
delete(t.workers, reapHead.participantID)
|
delete(t.workers, reap.participantID)
|
||||||
if reapHead == reapTail {
|
reap = reap.next
|
||||||
break
|
|
||||||
}
|
|
||||||
reapHead = reapHead.next
|
|
||||||
}
|
}
|
||||||
t.workersMu.Unlock()
|
t.workersMu.Unlock()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user