Configurable limit for number of tracks (#197)

* configurable node track limit

* sample config

* todos

* end of file new line

* default max num tracks

* bandwidth limit

* client message for limit exceeded node

* 10 Gbps default network limit
This commit is contained in:
Mathew Kamkar
2021-11-23 15:48:07 -08:00
committed by GitHub
parent 5cdb1c4848
commit e3c91de594
10 changed files with 117 additions and 16 deletions
+11 -2
View File
@@ -14,26 +14,29 @@ import (
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/routing"
"github.com/livekit/livekit-server/pkg/routing/selector"
"github.com/livekit/livekit-server/pkg/rtc"
"github.com/livekit/livekit-server/pkg/rtc/types"
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
)
type RTCService struct {
router routing.MessageRouter
router routing.Router
roomAllocator RoomAllocator
upgrader websocket.Upgrader
currentNode routing.LocalNode
isDev bool
limits config.LimitConfig
}
func NewRTCService(conf *config.Config, ra RoomAllocator, router routing.MessageRouter, currentNode routing.LocalNode) *RTCService {
func NewRTCService(conf *config.Config, ra RoomAllocator, router routing.Router, currentNode routing.LocalNode) *RTCService {
s := &RTCService{
router: router,
roomAllocator: ra,
upgrader: websocket.Upgrader{},
currentNode: currentNode,
isDev: conf.Development,
limits: conf.Limit,
}
// allow connections from any origin, since script may be hosted anywhere
@@ -74,6 +77,12 @@ func (s *RTCService) validate(r *http.Request) (string, routing.ParticipantInit,
roomName = onlyName
}
if foundNode, err := s.router.GetNodeForRoom(r.Context(), roomName); err == nil {
if selector.LimitsReached(s.limits, foundNode.Stats) {
return "", routing.ParticipantInit{}, http.StatusServiceUnavailable, rtc.ErrLimitExceeded
}
}
pi := routing.ParticipantInit{
Reconnect: boolValue(reconnectParam),
Identity: claims.Identity,