@@ -1108,7 +1108,59 @@ func (pc *PeerConnection) SetRemoteDescription(desc SessionDescription) error {
1108
1108
pc .ops .Enqueue (func () {
1109
1109
pc .startRTP (true , & desc , currentTransceivers )
1110
1110
})
1111
+ } else if pc .dtlsTransport .State () != DTLSTransportStateNew {
1112
+ fingerprint , fingerprintHash , fErr := extractFingerprint (desc .parsed )
1113
+ if fErr != nil {
1114
+ return fErr
1115
+ }
1116
+
1117
+ fingerPrintDidChange := true
1118
+
1119
+ for _ , fp := range pc .dtlsTransport .remoteParameters .Fingerprints {
1120
+ if fingerprint == fp .Value && fingerprintHash == fp .Algorithm {
1121
+ fingerPrintDidChange = false
1122
+ break
1123
+ }
1124
+ }
1125
+
1126
+ if fingerPrintDidChange {
1127
+ pc .ops .Enqueue (func () {
1128
+ // SCTP uses DTLS, so prevent any use, by locking, while
1129
+ // DTLS is restarting.
1130
+ pc .sctpTransport .lock .Lock ()
1131
+ defer pc .sctpTransport .lock .Unlock ()
1132
+
1133
+ if dErr := pc .dtlsTransport .Stop (); dErr != nil {
1134
+ pc .log .Warnf ("Failed to stop DTLS: %s" , dErr )
1135
+ }
1136
+
1137
+ // libwebrtc switches the connection back to `new`.
1138
+ pc .dtlsTransport .lock .Lock ()
1139
+ pc .dtlsTransport .onStateChange (DTLSTransportStateNew )
1140
+ pc .dtlsTransport .lock .Unlock ()
1141
+
1142
+ // Restart the dtls transport with updated fingerprints
1143
+ err = pc .dtlsTransport .Start (DTLSParameters {
1144
+ Role : dtlsRoleFromRemoteSDP (desc .parsed ),
1145
+ Fingerprints : []DTLSFingerprint {{Algorithm : fingerprintHash , Value : fingerprint }},
1146
+ })
1147
+ pc .updateConnectionState (pc .ICEConnectionState (), pc .dtlsTransport .State ())
1148
+ if err != nil {
1149
+ pc .log .Warnf ("Failed to restart DTLS: %s" , err )
1150
+ return
1151
+ }
1152
+
1153
+ // If SCTP was enabled, restart it with the new DTLS transport.
1154
+ if pc .sctpTransport .isStarted {
1155
+ if dErr := pc .sctpTransport .restart (pc .dtlsTransport .conn ); dErr != nil {
1156
+ pc .log .Warnf ("Failed to restart SCTP: %s" , dErr )
1157
+ return
1158
+ }
1159
+ }
1160
+ })
1161
+ }
1111
1162
}
1163
+
1112
1164
return nil
1113
1165
}
1114
1166
@@ -1317,7 +1369,7 @@ func (pc *PeerConnection) startSCTP() {
1317
1369
var openedDCCount uint32
1318
1370
for _ , d := range dataChannels {
1319
1371
if d .ReadyState () == DataChannelStateConnecting {
1320
- err := d .open (pc .sctpTransport )
1372
+ err := d .open (pc .sctpTransport , false )
1321
1373
if err != nil {
1322
1374
pc .log .Warnf ("failed to open data channel: %s" , err )
1323
1375
continue
@@ -1775,7 +1827,7 @@ func (pc *PeerConnection) CreateDataChannel(label string, options *DataChannelIn
1775
1827
1776
1828
// If SCTP already connected open all the channels
1777
1829
if pc .sctpTransport .State () == SCTPTransportStateConnected {
1778
- if err = d .open (pc .sctpTransport ); err != nil {
1830
+ if err = d .open (pc .sctpTransport , false ); err != nil {
1779
1831
return nil , err
1780
1832
}
1781
1833
}
0 commit comments