Browse Source

reload only rtsp server when authMethods is changed

pull/483/head
aler9 5 years ago
parent
commit
f0a283d141
  1. 6
      internal/core/core.go
  2. 7
      internal/core/path.go
  3. 8
      internal/core/path_manager.go
  4. 5
      internal/core/rtmp_conn.go
  5. 10
      internal/core/rtsp_conn.go
  6. 5
      internal/core/rtsp_server.go
  7. 9
      internal/core/rtsp_session.go

6
internal/core/core.go

@ -205,7 +205,6 @@ func (p *Core) createResources(initial bool) error { @@ -205,7 +205,6 @@ func (p *Core) createResources(initial bool) error {
p.conf.WriteTimeout,
p.conf.ReadBufferCount,
p.conf.ReadBufferSize,
p.conf.AuthMethodsParsed,
p.conf.Paths,
p.stats,
p)
@ -220,6 +219,7 @@ func (p *Core) createResources(initial bool) error { @@ -220,6 +219,7 @@ func (p *Core) createResources(initial bool) error {
p.rtspServerPlain, err = newRTSPServer(
p.ctx,
p.conf.RTSPAddress,
p.conf.AuthMethodsParsed,
p.conf.ReadTimeout,
p.conf.WriteTimeout,
p.conf.ReadBufferCount,
@ -254,6 +254,7 @@ func (p *Core) createResources(initial bool) error { @@ -254,6 +254,7 @@ func (p *Core) createResources(initial bool) error {
p.rtspServerTLS, err = newRTSPServer(
p.ctx,
p.conf.RTSPSAddress,
p.conf.AuthMethodsParsed,
p.conf.ReadTimeout,
p.conf.WriteTimeout,
p.conf.ReadBufferCount,
@ -359,7 +360,6 @@ func (p *Core) closeResources(newConf *conf.Conf) { @@ -359,7 +360,6 @@ func (p *Core) closeResources(newConf *conf.Conf) {
newConf.WriteTimeout != p.conf.WriteTimeout ||
newConf.ReadBufferCount != p.conf.ReadBufferCount ||
newConf.ReadBufferSize != p.conf.ReadBufferSize ||
!reflect.DeepEqual(newConf.AuthMethodsParsed, p.conf.AuthMethodsParsed) ||
closeStats {
closePathManager = true
} else if !reflect.DeepEqual(newConf.Paths, p.conf.Paths) {
@ -371,6 +371,7 @@ func (p *Core) closeResources(newConf *conf.Conf) { @@ -371,6 +371,7 @@ func (p *Core) closeResources(newConf *conf.Conf) {
newConf.RTSPDisable != p.conf.RTSPDisable ||
newConf.EncryptionParsed != p.conf.EncryptionParsed ||
newConf.RTSPAddress != p.conf.RTSPAddress ||
!reflect.DeepEqual(newConf.AuthMethodsParsed, p.conf.AuthMethodsParsed) ||
newConf.ReadTimeout != p.conf.ReadTimeout ||
newConf.WriteTimeout != p.conf.WriteTimeout ||
newConf.ReadBufferCount != p.conf.ReadBufferCount ||
@ -394,6 +395,7 @@ func (p *Core) closeResources(newConf *conf.Conf) { @@ -394,6 +395,7 @@ func (p *Core) closeResources(newConf *conf.Conf) {
newConf.RTSPDisable != p.conf.RTSPDisable ||
newConf.EncryptionParsed != p.conf.EncryptionParsed ||
newConf.RTSPSAddress != p.conf.RTSPSAddress ||
!reflect.DeepEqual(newConf.AuthMethodsParsed, p.conf.AuthMethodsParsed) ||
newConf.ReadTimeout != p.conf.ReadTimeout ||
newConf.WriteTimeout != p.conf.WriteTimeout ||
newConf.ReadBufferCount != p.conf.ReadBufferCount ||

7
internal/core/path.go

@ -12,7 +12,6 @@ import ( @@ -12,7 +12,6 @@ import (
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/base"
"github.com/aler9/gortsplib/pkg/headers"
"github.com/aler9/rtsp-simple-server/internal/conf"
"github.com/aler9/rtsp-simple-server/internal/externalcmd"
"github.com/aler9/rtsp-simple-server/internal/logger"
@ -110,7 +109,7 @@ type pathDescribeReq struct { @@ -110,7 +109,7 @@ type pathDescribeReq struct {
PathName string
URL *base.URL
IP net.IP
ValidateCredentials func(authMethods []headers.AuthMethod, pathUser string, pathPass string) error
ValidateCredentials func(pathUser string, pathPass string) error
Res chan pathDescribeRes
}
@ -124,7 +123,7 @@ type pathReaderSetupPlayReq struct { @@ -124,7 +123,7 @@ type pathReaderSetupPlayReq struct {
Author reader
PathName string
IP net.IP
ValidateCredentials func(authMethods []headers.AuthMethod, pathUser string, pathPass string) error
ValidateCredentials func(pathUser string, pathPass string) error
Res chan pathReaderSetupPlayRes
}
@ -138,7 +137,7 @@ type pathPublisherAnnounceReq struct { @@ -138,7 +137,7 @@ type pathPublisherAnnounceReq struct {
PathName string
Tracks gortsplib.Tracks
IP net.IP
ValidateCredentials func(authMethods []headers.AuthMethod, pathUser string, pathPass string) error
ValidateCredentials func(pathUser string, pathPass string) error
Res chan pathPublisherAnnounceRes
}

8
internal/core/path_manager.go

@ -8,7 +8,6 @@ import ( @@ -8,7 +8,6 @@ import (
"time"
"github.com/aler9/gortsplib/pkg/base"
"github.com/aler9/gortsplib/pkg/headers"
"github.com/aler9/rtsp-simple-server/internal/conf"
"github.com/aler9/rtsp-simple-server/internal/logger"
@ -24,7 +23,6 @@ type pathManager struct { @@ -24,7 +23,6 @@ type pathManager struct {
writeTimeout time.Duration
readBufferCount int
readBufferSize int
authMethods []headers.AuthMethod
pathConfs map[string]*conf.PathConf
stats *stats
parent pathManagerParent
@ -52,7 +50,6 @@ func newPathManager( @@ -52,7 +50,6 @@ func newPathManager(
writeTimeout time.Duration,
readBufferCount int,
readBufferSize int,
authMethods []headers.AuthMethod,
pathConfs map[string]*conf.PathConf,
stats *stats,
parent pathManagerParent) *pathManager {
@ -64,7 +61,6 @@ func newPathManager( @@ -64,7 +61,6 @@ func newPathManager(
writeTimeout: writeTimeout,
readBufferCount: readBufferCount,
readBufferSize: readBufferSize,
authMethods: authMethods,
pathConfs: pathConfs,
stats: stats,
parent: parent,
@ -289,7 +285,7 @@ func (pm *pathManager) findPathConf(name string) (string, *conf.PathConf, error) @@ -289,7 +285,7 @@ func (pm *pathManager) findPathConf(name string) (string, *conf.PathConf, error)
func (pm *pathManager) authenticate(
ip net.IP,
validateCredentials func(authMethods []headers.AuthMethod, pathUser string, pathPass string) error,
validateCredentials func(pathUser string, pathPass string) error,
pathName string,
pathIPs []interface{},
pathUser string,
@ -309,7 +305,7 @@ func (pm *pathManager) authenticate( @@ -309,7 +305,7 @@ func (pm *pathManager) authenticate(
// validate user
if pathUser != "" && validateCredentials != nil {
err := validateCredentials(pm.authMethods, pathUser, pathPass)
err := validateCredentials(pathUser, pathPass)
if err != nil {
return err
}

5
internal/core/rtmp_conn.go

@ -12,7 +12,6 @@ import ( @@ -12,7 +12,6 @@ import (
"time"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/headers"
"github.com/aler9/gortsplib/pkg/ringbuffer"
"github.com/aler9/gortsplib/pkg/rtpaac"
"github.com/aler9/gortsplib/pkg/rtph264"
@ -194,7 +193,7 @@ func (c *rtmpConn) runRead(ctx context.Context) error { @@ -194,7 +193,7 @@ func (c *rtmpConn) runRead(ctx context.Context) error {
Author: c,
PathName: pathName,
IP: c.ip(),
ValidateCredentials: func(authMethods []headers.AuthMethod, pathUser string, pathPass string) error {
ValidateCredentials: func(pathUser string, pathPass string) error {
return c.validateCredentials(pathUser, pathPass, query)
},
})
@ -391,7 +390,7 @@ func (c *rtmpConn) runPublish(ctx context.Context) error { @@ -391,7 +390,7 @@ func (c *rtmpConn) runPublish(ctx context.Context) error {
PathName: pathName,
Tracks: tracks,
IP: c.ip(),
ValidateCredentials: func(authMethods []headers.AuthMethod, pathUser string, pathPass string) error {
ValidateCredentials: func(pathUser string, pathPass string) error {
return c.validateCredentials(pathUser, pathPass, query)
},
})

10
internal/core/rtsp_conn.go

@ -36,6 +36,7 @@ type rtspConnParent interface { @@ -36,6 +36,7 @@ type rtspConnParent interface {
type rtspConn struct {
rtspAddress string
authMethods []headers.AuthMethod
readTimeout time.Duration
runOnConnect string
runOnConnectRestart bool
@ -53,6 +54,7 @@ type rtspConn struct { @@ -53,6 +54,7 @@ type rtspConn struct {
func newRTSPConn(
rtspAddress string,
authMethods []headers.AuthMethod,
readTimeout time.Duration,
runOnConnect string,
runOnConnectRestart bool,
@ -62,6 +64,7 @@ func newRTSPConn( @@ -62,6 +64,7 @@ func newRTSPConn(
parent rtspConnParent) *rtspConn {
c := &rtspConn{
rtspAddress: rtspAddress,
authMethods: authMethods,
readTimeout: readTimeout,
runOnConnect: runOnConnect,
runOnConnectRestart: runOnConnectRestart,
@ -111,7 +114,6 @@ func (c *rtspConn) ip() net.IP { @@ -111,7 +114,6 @@ func (c *rtspConn) ip() net.IP {
}
func (c *rtspConn) validateCredentials(
authMethods []headers.AuthMethod,
pathUser string,
pathPass string,
pathName string,
@ -121,7 +123,7 @@ func (c *rtspConn) validateCredentials( @@ -121,7 +123,7 @@ func (c *rtspConn) validateCredentials(
if c.authValidator == nil || c.authUser != pathUser || c.authPass != pathPass {
c.authUser = pathUser
c.authPass = pathPass
c.authValidator = auth.NewValidator(pathUser, pathPass, authMethods)
c.authValidator = auth.NewValidator(pathUser, pathPass, c.authMethods)
}
// VLC strips the control attribute
@ -192,8 +194,8 @@ func (c *rtspConn) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base. @@ -192,8 +194,8 @@ func (c *rtspConn) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base.
PathName: ctx.Path,
URL: ctx.Req.URL,
IP: c.ip(),
ValidateCredentials: func(authMethods []headers.AuthMethod, pathUser string, pathPass string) error {
return c.validateCredentials(authMethods, pathUser, pathPass, ctx.Path, ctx.Req)
ValidateCredentials: func(pathUser string, pathPass string) error {
return c.validateCredentials(pathUser, pathPass, ctx.Path, ctx.Req)
},
})

5
internal/core/rtsp_server.go

@ -11,6 +11,7 @@ import ( @@ -11,6 +11,7 @@ import (
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/base"
"github.com/aler9/gortsplib/pkg/headers"
"github.com/aler9/rtsp-simple-server/internal/conf"
"github.com/aler9/rtsp-simple-server/internal/logger"
@ -45,6 +46,7 @@ type rtspServerParent interface { @@ -45,6 +46,7 @@ type rtspServerParent interface {
}
type rtspServer struct {
authMethods []headers.AuthMethod
readTimeout time.Duration
isTLS bool
rtspAddress string
@ -67,6 +69,7 @@ type rtspServer struct { @@ -67,6 +69,7 @@ type rtspServer struct {
func newRTSPServer(
parentCtx context.Context,
address string,
authMethods []headers.AuthMethod,
readTimeout time.Duration,
writeTimeout time.Duration,
readBufferCount int,
@ -91,6 +94,7 @@ func newRTSPServer( @@ -91,6 +94,7 @@ func newRTSPServer(
ctx, ctxCancel := context.WithCancel(parentCtx)
s := &rtspServer{
authMethods: authMethods,
readTimeout: readTimeout,
isTLS: isTLS,
rtspAddress: rtspAddress,
@ -203,6 +207,7 @@ outer: @@ -203,6 +207,7 @@ outer:
func (s *rtspServer) OnConnOpen(ctx *gortsplib.ServerHandlerOnConnOpenCtx) {
c := newRTSPConn(
s.rtspAddress,
s.authMethods,
s.readTimeout,
s.runOnConnect,
s.runOnConnectRestart,

9
internal/core/rtsp_session.go

@ -8,7 +8,6 @@ import ( @@ -8,7 +8,6 @@ import (
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/base"
"github.com/aler9/gortsplib/pkg/headers"
"github.com/aler9/rtsp-simple-server/internal/conf"
"github.com/aler9/rtsp-simple-server/internal/externalcmd"
@ -113,8 +112,8 @@ func (s *rtspSession) OnAnnounce(c *rtspConn, ctx *gortsplib.ServerHandlerOnAnno @@ -113,8 +112,8 @@ func (s *rtspSession) OnAnnounce(c *rtspConn, ctx *gortsplib.ServerHandlerOnAnno
PathName: ctx.Path,
Tracks: ctx.Tracks,
IP: ctx.Conn.NetConn().RemoteAddr().(*net.TCPAddr).IP,
ValidateCredentials: func(authMethods []headers.AuthMethod, pathUser string, pathPass string) error {
return c.validateCredentials(authMethods, pathUser, pathPass, ctx.Path, ctx.Req)
ValidateCredentials: func(pathUser string, pathPass string) error {
return c.validateCredentials(pathUser, pathPass, ctx.Path, ctx.Req)
},
})
@ -171,8 +170,8 @@ func (s *rtspSession) OnSetup(c *rtspConn, ctx *gortsplib.ServerHandlerOnSetupCt @@ -171,8 +170,8 @@ func (s *rtspSession) OnSetup(c *rtspConn, ctx *gortsplib.ServerHandlerOnSetupCt
Author: s,
PathName: ctx.Path,
IP: ctx.Conn.NetConn().RemoteAddr().(*net.TCPAddr).IP,
ValidateCredentials: func(authMethods []headers.AuthMethod, pathUser string, pathPass string) error {
return c.validateCredentials(authMethods, pathUser, pathPass, ctx.Path, ctx.Req)
ValidateCredentials: func(pathUser string, pathPass string) error {
return c.validateCredentials(pathUser, pathPass, ctx.Path, ctx.Req)
},
})

Loading…
Cancel
Save