Add deadline handler for SRTP server

This commit is contained in:
Alexey Khit
2023-07-23 17:09:09 +03:00
parent 6e9574a1bd
commit 3defbd60db
2 changed files with 25 additions and 13 deletions
+16 -10
View File
@@ -1,11 +1,12 @@
package srtp
import (
"time"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/pion/rtcp"
"github.com/pion/rtp"
"github.com/pion/srtp/v2"
"time"
)
type Session struct {
@@ -19,6 +20,8 @@ type Session struct {
Track *core.Receiver
Recv uint32
Deadline *time.Timer
lastSequence uint32
lastTimestamp uint32
//lastPacket *rtp.Packet
@@ -28,17 +31,16 @@ type Session struct {
totalLost uint32
}
func (s *Session) SetKeys(
localKey, localSalt, remoteKey, remoteSalt []byte,
) (err error) {
if s.localCtx, err = srtp.CreateContext(
localKey, localSalt, GuessProfile(localKey),
); err != nil {
func (s *Session) LastTime() time.Time {
return s.lastTime
}
func (s *Session) SetKeys(localKey, localSalt, remoteKey, remoteSalt []byte) (err error) {
s.localCtx, err = srtp.CreateContext(localKey, localSalt, GuessProfile(localKey))
if err != nil {
return
}
s.remoteCtx, err = srtp.CreateContext(
remoteKey, remoteSalt, GuessProfile(remoteKey),
)
s.remoteCtx, err = srtp.CreateContext(remoteKey, remoteSalt, GuessProfile(remoteKey))
return
}
@@ -56,6 +58,10 @@ func (s *Session) HandleRTP(data []byte) (err error) {
return
}
if s.Deadline != nil {
s.Deadline.Reset(core.ConnDeadline)
}
now := time.Now()
// https://www.ietf.org/rfc/rfc3550.txt