store peer dtls setup for later use in ice restart

This commit is contained in:
Daniel Gultsch 2021-11-16 11:21:11 +01:00
parent 70b5d8d81a
commit 0698fa0d8c
2 changed files with 30 additions and 10 deletions

View file

@ -150,6 +150,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
private Set<Media> proposedMedia; private Set<Media> proposedMedia;
private RtpContentMap initiatorRtpContentMap; private RtpContentMap initiatorRtpContentMap;
private RtpContentMap responderRtpContentMap; private RtpContentMap responderRtpContentMap;
private IceUdpTransportInfo.Setup peerDtlsSetup;
private final Stopwatch sessionDuration = Stopwatch.createUnstarted(); private final Stopwatch sessionDuration = Stopwatch.createUnstarted();
private final Queue<PeerConnection.PeerConnectionState> stateHistory = new LinkedList<>(); private final Queue<PeerConnection.PeerConnectionState> stateHistory = new LinkedList<>();
private ScheduledFuture<?> ringingTimeoutFuture; private ScheduledFuture<?> ringingTimeoutFuture;
@ -332,11 +333,18 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
} }
private IceUdpTransportInfo.Setup getPeerDtlsSetup() { private IceUdpTransportInfo.Setup getPeerDtlsSetup() {
final IceUdpTransportInfo.Setup responderSetup = this.responderRtpContentMap.getDtlsSetup(); final IceUdpTransportInfo.Setup peerSetup = this.peerDtlsSetup;
if (responderSetup == null || responderSetup == IceUdpTransportInfo.Setup.ACTPASS) { if (peerSetup == null || peerSetup == IceUdpTransportInfo.Setup.ACTPASS) {
throw new IllegalStateException("Invalid DTLS setup value in responder content map"); throw new IllegalStateException("Invalid peer setup");
} }
return isInitiator() ? responderSetup : responderSetup.flip(); return peerSetup;
}
private void storePeerDtlsSetup(final IceUdpTransportInfo.Setup setup) {
if (setup == null || setup == IceUdpTransportInfo.Setup.ACTPASS) {
throw new IllegalArgumentException("Trying to store invalid peer dtls setup");
}
this.peerDtlsSetup = setup;
} }
private boolean applyIceRestart(final JinglePacket jinglePacket, final RtpContentMap restartContentMap, final boolean isOffer) throws ExecutionException, InterruptedException { private boolean applyIceRestart(final JinglePacket jinglePacket, final RtpContentMap restartContentMap, final boolean isOffer) throws ExecutionException, InterruptedException {
@ -352,11 +360,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
webRTCWrapper.rollbackLocalDescription().get(); webRTCWrapper.rollbackLocalDescription().get();
} }
webRTCWrapper.setRemoteDescription(sdp).get(); webRTCWrapper.setRemoteDescription(sdp).get();
if (isInitiator()) { setRemoteContentMap(restartContentMap);
this.responderRtpContentMap = restartContentMap;
} else {
this.initiatorRtpContentMap = restartContentMap;
}
if (isOffer) { if (isOffer) {
webRTCWrapper.setIsReadyToReceiveIceCandidates(false); webRTCWrapper.setIsReadyToReceiveIceCandidates(false);
final SessionDescription localSessionDescription = setLocalSessionDescription(); final SessionDescription localSessionDescription = setLocalSessionDescription();
@ -364,6 +368,8 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
//We need to respond OK before sending any candidates //We need to respond OK before sending any candidates
respondOk(jinglePacket); respondOk(jinglePacket);
webRTCWrapper.setIsReadyToReceiveIceCandidates(true); webRTCWrapper.setIsReadyToReceiveIceCandidates(true);
} else {
storePeerDtlsSetup(restartContentMap.getDtlsSetup());
} }
return true; return true;
} }
@ -569,6 +575,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
private void receiveSessionAccept(final RtpContentMap contentMap) { private void receiveSessionAccept(final RtpContentMap contentMap) {
this.responderRtpContentMap = contentMap; this.responderRtpContentMap = contentMap;
this.storePeerDtlsSetup(contentMap.getDtlsSetup());
final SessionDescription sessionDescription; final SessionDescription sessionDescription;
try { try {
sessionDescription = SessionDescription.of(contentMap); sessionDescription = SessionDescription.of(contentMap);
@ -663,6 +670,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
final SessionDescription sessionDescription = SessionDescription.parse(webRTCSessionDescription.description); final SessionDescription sessionDescription = SessionDescription.parse(webRTCSessionDescription.description);
final RtpContentMap respondingRtpContentMap = RtpContentMap.of(sessionDescription); final RtpContentMap respondingRtpContentMap = RtpContentMap.of(sessionDescription);
this.responderRtpContentMap = respondingRtpContentMap; this.responderRtpContentMap = respondingRtpContentMap;
storePeerDtlsSetup(respondingRtpContentMap.getDtlsSetup().flip());
webRTCWrapper.setIsReadyToReceiveIceCandidates(true); webRTCWrapper.setIsReadyToReceiveIceCandidates(true);
final ListenableFuture<RtpContentMap> outgoingContentMapFuture = prepareOutgoingContentMap(respondingRtpContentMap); final ListenableFuture<RtpContentMap> outgoingContentMapFuture = prepareOutgoingContentMap(respondingRtpContentMap);
Futures.addCallback(outgoingContentMapFuture, Futures.addCallback(outgoingContentMapFuture,
@ -1520,6 +1528,14 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
} }
} }
private void setRemoteContentMap(final RtpContentMap rtpContentMap) {
if (isInitiator()) {
this.responderRtpContentMap = rtpContentMap;
} else {
this.initiatorRtpContentMap = rtpContentMap;
}
}
private SessionDescription setLocalSessionDescription() throws ExecutionException, InterruptedException { private SessionDescription setLocalSessionDescription() throws ExecutionException, InterruptedException {
final org.webrtc.SessionDescription sessionDescription = this.webRTCWrapper.setLocalDescription().get(); final org.webrtc.SessionDescription sessionDescription = this.webRTCWrapper.setLocalDescription().get();
return SessionDescription.parse(sessionDescription.description); return SessionDescription.parse(sessionDescription.description);

View file

@ -155,7 +155,11 @@ public class RtpContentMap {
contents.values(), contents.values(),
dt->dt.transport.getFingerprint().getSetup() dt->dt.transport.getFingerprint().getSetup()
)); ));
return setups.size() == 1 ? Iterables.getFirst(setups, null) : null; final IceUdpTransportInfo.Setup setup = Iterables.getFirst(setups, null);
if (setups.size() == 1 && setup != null) {
return setup;
}
throw new IllegalStateException("Content map doesn't have distinct DTLS setup");
} }
public boolean emptyCandidates() { public boolean emptyCandidates() {