Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.

Commit d3cff27

Browse files
committed
Implement SRTP resumption
1 parent 8864993 commit d3cff27

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/pion/dtls/v2 v2.2.6
77
github.com/pion/ice/v2 v2.3.1
88
github.com/pion/rtcp v1.2.10
9-
github.com/pion/webrtc/v3 v3.1.59-0.20230317181827-3638bce3b6f0
9+
github.com/pion/webrtc/v3 v3.1.59-0.20230326035336-9a0eb473514a
1010
)
1111

1212
require (
@@ -19,7 +19,7 @@ require (
1919
github.com/pion/rtp v1.7.13 // indirect
2020
github.com/pion/sctp v1.8.6 // indirect
2121
github.com/pion/sdp/v3 v3.0.6 // indirect
22-
github.com/pion/srtp/v2 v2.0.12 // indirect
22+
github.com/pion/srtp/v2 v2.0.13-0.20230326035121-5f7175086aae // indirect
2323
github.com/pion/stun v0.4.0 // indirect
2424
github.com/pion/transport/v2 v2.0.2 // indirect
2525
github.com/pion/turn/v2 v2.1.0 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ github.com/pion/sdp/v3 v3.0.6 h1:WuDLhtuFUUVpTfus9ILC4HRyHsW6TdugjEX/QY9OiUw=
5757
github.com/pion/sdp/v3 v3.0.6/go.mod h1:iiFWFpQO8Fy3S5ldclBkpXqmWy02ns78NOKoLLL0YQw=
5858
github.com/pion/srtp/v2 v2.0.12 h1:WrmiVCubGMOAObBU1vwWjG0H3VSyQHawKeer2PVA5rY=
5959
github.com/pion/srtp/v2 v2.0.12/go.mod h1:C3Ep44hlOo2qEYaq4ddsmK5dL63eLehXFbHaZ9F5V9Y=
60+
github.com/pion/srtp/v2 v2.0.13-0.20230326035121-5f7175086aae h1:GGa/BGQD+wVviFJC8umocBj276dYn4PhqTEtL6yyHq0=
61+
github.com/pion/srtp/v2 v2.0.13-0.20230326035121-5f7175086aae/go.mod h1:FA7u5fWpVITMYNL70TA3csQuMQJA5/+6ZMajGxveHgM=
6062
github.com/pion/stun v0.4.0 h1:vgRrbBE2htWHy7l3Zsxckk7rkjnjOsSM7PHZnBwo8rk=
6163
github.com/pion/stun v0.4.0/go.mod h1:QPsh1/SbXASntw3zkkrIk3ZJVKz4saBY2G7S10P3wCw=
6264
github.com/pion/transport v0.14.1 h1:XSM6olwW+o8J4SCmOBb/BpwZypkHeyM0PGFCxNQBr40=
@@ -70,6 +72,8 @@ github.com/pion/udp/v2 v2.0.1 h1:xP0z6WNux1zWEjhC7onRA3EwwSliXqu1ElUZAQhUP54=
7072
github.com/pion/udp/v2 v2.0.1/go.mod h1:B7uvTMP00lzWdyMr/1PVZXtV3wpPIxBRd4Wl6AksXn8=
7173
github.com/pion/webrtc/v3 v3.1.59-0.20230317181827-3638bce3b6f0 h1:c0m8hGGG1KvIzwKm36mgWQRIysbTmb0Sul5eZ6BAFjc=
7274
github.com/pion/webrtc/v3 v3.1.59-0.20230317181827-3638bce3b6f0/go.mod h1:jJdqoqGBlZiE3y8Z1tg1fjSkyEDCZLL+foypUBn0Lhk=
75+
github.com/pion/webrtc/v3 v3.1.59-0.20230326035336-9a0eb473514a h1:rw8OZ//s6GeGcntBOuXvtfIBHFEFgXxmhRWcyBRJQis=
76+
github.com/pion/webrtc/v3 v3.1.59-0.20230326035336-9a0eb473514a/go.mod h1:4M9wYG6b6vJIoMGMmd4lVrOt/dc/JS5leIV0AaGLPbE=
7377
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
7478
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7579
github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw=

main.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ type PeerConnectionState struct {
103103
DTLSConnectionState dtls.State
104104

105105
SSRCAudio, SSRCVideo webrtc.SSRC
106+
SRTPState map[uint32]uint32
106107
}
107108

108109
var (
@@ -140,17 +141,25 @@ func main() {
140141
json.NewEncoder(w).Encode(&out)
141142
})
142143

144+
go func() {
145+
for range time.NewTicker(2 * time.Second).C {
146+
serialize()
147+
}
148+
}()
149+
143150
fmt.Println("Open http://localhost:8080 to access this demo")
144151
panic(http.ListenAndServe(":8080", nil))
145152
}
146153

147154
func doSignaling(w http.ResponseWriter, r *http.Request) {
155+
s := webrtc.SettingEngine{}
156+
s.SetSRTPProtectionProfiles(dtls.SRTP_AEAD_AES_128_GCM)
148157
m := &webrtc.MediaEngine{}
149158
if err := m.RegisterDefaultCodecs(); err != nil {
150159
panic(err)
151160
}
152161

153-
peerConnection, err := webrtc.NewAPI(webrtc.WithMediaEngine(m)).NewPeerConnection(webrtc.Configuration{})
162+
peerConnection, err := webrtc.NewAPI(webrtc.WithMediaEngine(m), webrtc.WithSettingEngine(s)).NewPeerConnection(webrtc.Configuration{})
154163
if err != nil {
155164
panic(err)
156165
}
@@ -246,10 +255,10 @@ func serialize() {
246255
DTLSConnectionState: dtlsConn.ConnectionState(),
247256
SSRCAudio: SSRCAudio,
248257
SSRCVideo: SSRCVideo,
258+
SRTPState: dtlsTransport.GetSRTPState(),
249259
})
250260
}
251261

252-
fmt.Printf("Saving %d sessions to '%s'\n", len(state.PeerConnectionState), serializedPeerConnectionsFile)
253262
var toSave bytes.Buffer
254263
enc := gob.NewEncoder(&toSave)
255264
if err := enc.Encode(state); err != nil {
@@ -273,11 +282,13 @@ func deserialize(state GlobalState) {
273282
}
274283

275284
s := webrtc.SettingEngine{}
285+
s.SetSRTPProtectionProfiles(dtls.SRTP_AEAD_AES_128_GCM)
276286
s.SetICECredentials(state.PeerConnectionState[i].ICEUsernameFragment, state.PeerConnectionState[i].ICEPassword)
277287
if err := s.SetEphemeralUDPPortRange(state.PeerConnectionState[i].ICEPort, state.PeerConnectionState[i].ICEPort); err != nil {
278288
panic(err)
279289
}
280290
s.SetDTLSConnectionState(&state.PeerConnectionState[i].DTLSConnectionState)
291+
s.SetSRTPState(state.PeerConnectionState[i].SRTPState)
281292

282293
peerConnection, err := webrtc.NewAPI(webrtc.WithSettingEngine(s), webrtc.WithMediaEngine(m)).NewPeerConnection(webrtc.Configuration{})
283294
if err != nil {

0 commit comments

Comments
 (0)