From 6bc3cad7de4afb9d1f065411d1d8681012a463a2 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 4 Oct 2023 10:43:27 +0200 Subject: [PATCH] apply ice-options when adding content or restarting ice --- .../xmpp/jingle/RtpContentMap.java | 13 +++++---- .../jingle/stanzas/IceUdpTransportInfo.java | 27 +++++++++++++------ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/RtpContentMap.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/RtpContentMap.java index 994c3a233..08671ae03 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/RtpContentMap.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/RtpContentMap.java @@ -210,6 +210,12 @@ public class RtpContentMap { throw new IllegalStateException("Content map does not have distinct credentials"); } + private Set getCombinedIceOptions() { + final Collection> combinedIceOptions = + Collections2.transform(contents.values(), dt -> dt.transport.getIceOptions()); + return ImmutableSet.copyOf(Iterables.concat(combinedIceOptions)); + } + public Set getCredentials() { final Set credentials = ImmutableSet.copyOf( @@ -339,14 +345,11 @@ public class RtpContentMap { public RtpContentMap addContent( final RtpContentMap modification, final IceUdpTransportInfo.Setup setup) { final IceUdpTransportInfo.Credentials credentials = getDistinctCredentials(); + final Collection iceOptions = getCombinedIceOptions(); final DTLS dtls = getDistinctDtls(); final IceUdpTransportInfo iceUdpTransportInfo = - IceUdpTransportInfo.of(credentials, setup, dtls.hash, dtls.fingerprint); + IceUdpTransportInfo.of(credentials, iceOptions, setup, dtls.hash, dtls.fingerprint); final Map combined = merge(contents, modification.contents); - /*new ImmutableMap.Builder() - .putAll(contents) - .putAll(modification.contents) - .build();*/ final Map combinedFixedTransport = Maps.transformValues( combined, diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/IceUdpTransportInfo.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/IceUdpTransportInfo.java index bd7e44501..35251f929 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/IceUdpTransportInfo.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/IceUdpTransportInfo.java @@ -15,6 +15,11 @@ import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; +import eu.siacs.conversations.Config; +import eu.siacs.conversations.xml.Element; +import eu.siacs.conversations.xml.Namespace; +import eu.siacs.conversations.xmpp.jingle.SessionDescription; + import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -26,11 +31,6 @@ import java.util.Locale; import java.util.Map; import java.util.UUID; -import eu.siacs.conversations.Config; -import eu.siacs.conversations.xml.Element; -import eu.siacs.conversations.xml.Namespace; -import eu.siacs.conversations.xmpp.jingle.SessionDescription; - public class IceUdpTransportInfo extends GenericTransportInfo { public static final IceUdpTransportInfo STUB = new IceUdpTransportInfo(); @@ -73,11 +73,18 @@ public class IceUdpTransportInfo extends GenericTransportInfo { } public static IceUdpTransportInfo of( - final Credentials credentials, final Setup setup, final String hash, final String fingerprint) { + final Credentials credentials, + final Collection iceOptions, + final Setup setup, + final String hash, + final String fingerprint) { final IceUdpTransportInfo iceUdpTransportInfo = new IceUdpTransportInfo(); iceUdpTransportInfo.addChild(Fingerprint.of(setup, hash, fingerprint)); iceUdpTransportInfo.setAttribute("ufrag", credentials.ufrag); iceUdpTransportInfo.setAttribute("pwd", credentials.password); + for(final String iceOption : iceOptions) { + iceUdpTransportInfo.addChild(new IceOption(iceOption)); + } return iceUdpTransportInfo; } @@ -88,8 +95,9 @@ public class IceUdpTransportInfo extends GenericTransportInfo { public List getIceOptions() { final ImmutableList.Builder optionBuilder = new ImmutableList.Builder<>(); - for(final Element child : this.children) { - if (Namespace.JINGLE_TRANSPORT_ICE_OPTION.equals(child.getNamespace()) && IceOption.WELL_KNOWN.contains(child.getName())) { + for (final Element child : this.children) { + if (Namespace.JINGLE_TRANSPORT_ICE_OPTION.equals(child.getNamespace()) + && IceOption.WELL_KNOWN.contains(child.getName())) { optionBuilder.add(child.getName()); } } @@ -132,6 +140,9 @@ public class IceUdpTransportInfo extends GenericTransportInfo { transportInfo.addChild(fingerprint); } } + for (final String iceOption : this.getIceOptions()) { + transportInfo.addChild(new IceOption(iceOption)); + } return transportInfo; }