Add deadline handler for SRTP server
This commit is contained in:
+9
-3
@@ -1,12 +1,18 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
cryptorand "crypto/rand"
|
"crypto/rand"
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ConnDialTimeout = time.Second * 3
|
||||||
|
ConnDeadline = time.Second * 3
|
||||||
)
|
)
|
||||||
|
|
||||||
// Now90000 - timestamp for Video (clock rate = 90000 samples per second)
|
// Now90000 - timestamp for Video (clock rate = 90000 samples per second)
|
||||||
@@ -19,7 +25,7 @@ const symbols = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-
|
|||||||
// RandString base10 - numbers, base16 - hex, base36 - digits+letters, base64 - URL safe symbols
|
// RandString base10 - numbers, base16 - hex, base36 - digits+letters, base64 - URL safe symbols
|
||||||
func RandString(size, base byte) string {
|
func RandString(size, base byte) string {
|
||||||
b := make([]byte, size)
|
b := make([]byte, size)
|
||||||
if _, err := cryptorand.Read(b); err != nil {
|
if _, err := rand.Read(b); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
for i := byte(0); i < size; i++ {
|
for i := byte(0); i < size; i++ {
|
||||||
|
|||||||
+16
-10
@@ -1,11 +1,12 @@
|
|||||||
package srtp
|
package srtp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||||
"github.com/pion/rtcp"
|
"github.com/pion/rtcp"
|
||||||
"github.com/pion/rtp"
|
"github.com/pion/rtp"
|
||||||
"github.com/pion/srtp/v2"
|
"github.com/pion/srtp/v2"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Session struct {
|
type Session struct {
|
||||||
@@ -19,6 +20,8 @@ type Session struct {
|
|||||||
Track *core.Receiver
|
Track *core.Receiver
|
||||||
Recv uint32
|
Recv uint32
|
||||||
|
|
||||||
|
Deadline *time.Timer
|
||||||
|
|
||||||
lastSequence uint32
|
lastSequence uint32
|
||||||
lastTimestamp uint32
|
lastTimestamp uint32
|
||||||
//lastPacket *rtp.Packet
|
//lastPacket *rtp.Packet
|
||||||
@@ -28,17 +31,16 @@ type Session struct {
|
|||||||
totalLost uint32
|
totalLost uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Session) SetKeys(
|
func (s *Session) LastTime() time.Time {
|
||||||
localKey, localSalt, remoteKey, remoteSalt []byte,
|
return s.lastTime
|
||||||
) (err error) {
|
}
|
||||||
if s.localCtx, err = srtp.CreateContext(
|
|
||||||
localKey, localSalt, GuessProfile(localKey),
|
func (s *Session) SetKeys(localKey, localSalt, remoteKey, remoteSalt []byte) (err error) {
|
||||||
); err != nil {
|
s.localCtx, err = srtp.CreateContext(localKey, localSalt, GuessProfile(localKey))
|
||||||
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.remoteCtx, err = srtp.CreateContext(
|
s.remoteCtx, err = srtp.CreateContext(remoteKey, remoteSalt, GuessProfile(remoteKey))
|
||||||
remoteKey, remoteSalt, GuessProfile(remoteKey),
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,6 +58,10 @@ func (s *Session) HandleRTP(data []byte) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.Deadline != nil {
|
||||||
|
s.Deadline.Reset(core.ConnDeadline)
|
||||||
|
}
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
// https://www.ietf.org/rfc/rfc3550.txt
|
// https://www.ietf.org/rfc/rfc3550.txt
|
||||||
|
|||||||
Reference in New Issue
Block a user