Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions pkg/service/rtcservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ func decodeAttributes(str string) (map[string]string, error) {
return attrs, nil
}

var gzipReaderPool = sync.Pool{
New: func() any { return &gzip.Reader{} },
}

func (s *RTCService) validateInternal(lgr logger.Logger, r *http.Request, strict bool) (livekit.RoomName, routing.ParticipantInit, int, error) {
var params ValidateConnectRequestParams
useSinglePeerConnection := false
Expand Down Expand Up @@ -154,19 +158,16 @@ func (s *RTCService) validateInternal(lgr logger.Logger, r *http.Request, strict
}

case livekit.WrappedJoinRequest_GZIP:
b := bytes.NewReader(wrappedJoinRequest.JoinRequest)
if reader, err := gzip.NewReader(b); err != nil {
return "", routing.ParticipantInit{}, http.StatusBadRequest, errors.New("cannot decompress join request")
} else {
protoBytes, err := io.ReadAll(reader)
reader.Close()
if err != nil {
return "", routing.ParticipantInit{}, http.StatusBadRequest, errors.New("cannot read decompressed join request")
}
reader := gzipReaderPool.Get().(*gzip.Reader)
defer gzipReaderPool.Put(reader)
reader.Reset(bytes.NewReader(wrappedJoinRequest.JoinRequest))
protoBytes, err := io.ReadAll(reader)
if err != nil {
return "", routing.ParticipantInit{}, http.StatusBadRequest, errors.New("cannot read decompressed join request")
}

if err := proto.Unmarshal(protoBytes, joinRequest); err != nil {
return "", routing.ParticipantInit{}, http.StatusBadRequest, errors.New("cannot unmarshal join request")
}
if err := proto.Unmarshal(protoBytes, joinRequest); err != nil {
return "", routing.ParticipantInit{}, http.StatusBadRequest, errors.New("cannot unmarshal join request")
}
}

Expand Down
Loading