server: return error in case of unexpected interleaved frames

This commit is contained in:
aler9
2022-12-11 17:59:58 +01:00
parent fa95f5a86b
commit 2a5b3e3ee5
3 changed files with 31 additions and 9 deletions

View File

@@ -253,3 +253,11 @@ type ErrServerSessionNotInUse struct{}
func (e ErrServerSessionNotInUse) Error() string {
return "not in use"
}
// ErrServerUnexpectedFrame is an error that can be returned by a server.
type ErrServerUnexpectedFrame struct{}
// Error implements the error interface.
func (e ErrServerUnexpectedFrame) Error() string {
return "received unexpected interleaved frame"
}

View File

@@ -832,8 +832,14 @@ func TestServerPublish(t *testing.T) {
}
func TestServerPublishErrorInvalidProtocol(t *testing.T) {
errorRecv := make(chan struct{})
s := &Server{
Handler: &testServerHandler{
onConnClose: func(ctx *ServerHandlerOnConnCloseCtx) {
require.EqualError(t, ctx.Error, "received unexpected interleaved frame")
close(errorRecv)
},
onAnnounce: func(ctx *ServerHandlerOnAnnounceCtx) (*base.Response, error) {
return &base.Response{
StatusCode: base.StatusOK,
@@ -937,6 +943,8 @@ func TestServerPublishErrorInvalidProtocol(t *testing.T) {
Payload: []byte{0x01, 0x02, 0x03, 0x04},
}, make([]byte, 1024))
require.NoError(t, err)
<-errorRecv
}
func TestServerPublishRTCPReport(t *testing.T) {

View File

@@ -210,14 +210,16 @@ func (sc *ServerConn) readFuncStandard(readRequest chan readReq) error {
sc.nconn.SetReadDeadline(time.Time{})
for {
req, err := sc.conn.ReadRequest()
any, err := sc.conn.ReadInterleavedFrameOrRequest()
if err != nil {
return err
}
switch what := any.(type) {
case *base.Request:
cres := make(chan error)
select {
case readRequest <- readReq{req: req, res: cres}:
case readRequest <- readReq{req: what, res: cres}:
err = <-cres
if err != nil {
return err
@@ -226,6 +228,10 @@ func (sc *ServerConn) readFuncStandard(readRequest chan readReq) error {
case <-sc.ctx.Done():
return liberrors.ErrServerTerminated{}
}
default:
return liberrors.ErrServerUnexpectedFrame{}
}
}
}