remove security check that ensures rtp connection was properly finished

this only causes race conditions
This commit is contained in:
Daniel Gultsch 2022-02-25 16:24:13 +01:00
parent d311e39569
commit 1f772df74f
4 changed files with 1239 additions and 610 deletions

View file

@ -646,7 +646,6 @@ public class RtpSessionActivity extends XmppActivity
final RtpEndUserState currentState = requireRtpConnection().getEndUserState(); final RtpEndUserState currentState = requireRtpConnection().getEndUserState();
final boolean verified = requireRtpConnection().isVerified(); final boolean verified = requireRtpConnection().isVerified();
if (currentState == RtpEndUserState.ENDED) { if (currentState == RtpEndUserState.ENDED) {
reference.get().throwStateTransitionException();
finish(); finish();
return true; return true;
} }

View file

@ -1,5 +1,7 @@
package eu.siacs.conversations.xmpp.jingle; package eu.siacs.conversations.xmpp.jingle;
import androidx.annotation.NonNull;
import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
@ -110,6 +112,7 @@ public abstract class AbstractJingleConnection {
} }
@Override @Override
@NonNull
public String toString() { public String toString() {
return MoreObjects.toStringHelper(this) return MoreObjects.toStringHelper(this)
.add("account", account.getJid()) .add("account", account.getJid())

View file

@ -52,14 +52,16 @@ import eu.siacs.conversations.xmpp.stanzas.IqPacket;
import eu.siacs.conversations.xmpp.stanzas.MessagePacket; import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
public class JingleConnectionManager extends AbstractConnectionManager { public class JingleConnectionManager extends AbstractConnectionManager {
static final ScheduledExecutorService SCHEDULED_EXECUTOR_SERVICE = Executors.newSingleThreadScheduledExecutor(); static final ScheduledExecutorService SCHEDULED_EXECUTOR_SERVICE =
Executors.newSingleThreadScheduledExecutor();
final ToneManager toneManager; final ToneManager toneManager;
private final HashMap<RtpSessionProposal, DeviceDiscoveryState> rtpSessionProposals = new HashMap<>(); private final HashMap<RtpSessionProposal, DeviceDiscoveryState> rtpSessionProposals =
private final ConcurrentHashMap<AbstractJingleConnection.Id, AbstractJingleConnection> connections = new ConcurrentHashMap<>(); new HashMap<>();
private final ConcurrentHashMap<AbstractJingleConnection.Id, AbstractJingleConnection>
connections = new ConcurrentHashMap<>();
private final Cache<PersistableSessionId, TerminatedRtpSession> terminatedSessions = CacheBuilder.newBuilder() private final Cache<PersistableSessionId, TerminatedRtpSession> terminatedSessions =
.expireAfterWrite(24, TimeUnit.HOURS) CacheBuilder.newBuilder().expireAfterWrite(24, TimeUnit.HOURS).build();
.build();
private final HashMap<Jid, JingleCandidate> primaryCandidates = new HashMap<>(); private final HashMap<Jid, JingleCandidate> primaryCandidates = new HashMap<>();
@ -87,17 +89,31 @@ public class JingleConnectionManager extends AbstractConnectionManager {
} else if (packet.getAction() == JinglePacket.Action.SESSION_INITIATE) { } else if (packet.getAction() == JinglePacket.Action.SESSION_INITIATE) {
final Jid from = packet.getFrom(); final Jid from = packet.getFrom();
final Content content = packet.getJingleContent(); final Content content = packet.getJingleContent();
final String descriptionNamespace = content == null ? null : content.getDescriptionNamespace(); final String descriptionNamespace =
content == null ? null : content.getDescriptionNamespace();
final AbstractJingleConnection connection; final AbstractJingleConnection connection;
if (FileTransferDescription.NAMESPACES.contains(descriptionNamespace)) { if (FileTransferDescription.NAMESPACES.contains(descriptionNamespace)) {
connection = new JingleFileTransferConnection(this, id, from); connection = new JingleFileTransferConnection(this, id, from);
} else if (Namespace.JINGLE_APPS_RTP.equals(descriptionNamespace) && isUsingClearNet(account)) { } else if (Namespace.JINGLE_APPS_RTP.equals(descriptionNamespace)
final boolean sessionEnded = this.terminatedSessions.asMap().containsKey(PersistableSessionId.of(id)); && isUsingClearNet(account)) {
final boolean stranger = isWithStrangerAndStrangerNotificationsAreOff(account, id.with); final boolean sessionEnded =
this.terminatedSessions.asMap().containsKey(PersistableSessionId.of(id));
final boolean stranger =
isWithStrangerAndStrangerNotificationsAreOff(account, id.with);
if (isBusy() || sessionEnded || stranger) { if (isBusy() || sessionEnded || stranger) {
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": rejected session with " + id.with + " because busy. sessionEnded=" + sessionEnded + ", stranger=" + stranger); Log.d(
mXmppConnectionService.sendIqPacket(account, packet.generateResponse(IqPacket.TYPE.RESULT), null); Config.LOGTAG,
final JinglePacket sessionTermination = new JinglePacket(JinglePacket.Action.SESSION_TERMINATE, id.sessionId); id.account.getJid().asBareJid()
+ ": rejected session with "
+ id.with
+ " because busy. sessionEnded="
+ sessionEnded
+ ", stranger="
+ stranger);
mXmppConnectionService.sendIqPacket(
account, packet.generateResponse(IqPacket.TYPE.RESULT), null);
final JinglePacket sessionTermination =
new JinglePacket(JinglePacket.Action.SESSION_TERMINATE, id.sessionId);
sessionTermination.setTo(id.with); sessionTermination.setTo(id.with);
sessionTermination.setReason(Reason.BUSY, null); sessionTermination.setReason(Reason.BUSY, null);
mXmppConnectionService.sendIqPacket(account, sessionTermination, null); mXmppConnectionService.sendIqPacket(account, sessionTermination, null);
@ -105,7 +121,8 @@ public class JingleConnectionManager extends AbstractConnectionManager {
} }
connection = new JingleRtpConnection(this, id, from); connection = new JingleRtpConnection(this, id, from);
} else { } else {
respondWithJingleError(account, packet, "unsupported-info", "feature-not-implemented", "cancel"); respondWithJingleError(
account, packet, "unsupported-info", "feature-not-implemented", "cancel");
return; return;
} }
connections.put(id, connection); connections.put(id, connection);
@ -136,7 +153,8 @@ public class JingleConnectionManager extends AbstractConnectionManager {
synchronized (this.rtpSessionProposals) { synchronized (this.rtpSessionProposals) {
return this.rtpSessionProposals.containsValue(DeviceDiscoveryState.DISCOVERED) return this.rtpSessionProposals.containsValue(DeviceDiscoveryState.DISCOVERED)
|| this.rtpSessionProposals.containsValue(DeviceDiscoveryState.SEARCHING) || this.rtpSessionProposals.containsValue(DeviceDiscoveryState.SEARCHING)
|| this.rtpSessionProposals.containsValue(DeviceDiscoveryState.SEARCHING_ACKNOWLEDGED); || this.rtpSessionProposals.containsValue(
DeviceDiscoveryState.SEARCHING_ACKNOWLEDGED);
} }
} }
@ -152,14 +170,17 @@ public class JingleConnectionManager extends AbstractConnectionManager {
} }
} }
private Optional<RtpSessionProposal> findMatchingSessionProposal(final Account account, final Jid with, final Set<Media> media) { private Optional<RtpSessionProposal> findMatchingSessionProposal(
final Account account, final Jid with, final Set<Media> media) {
synchronized (this.rtpSessionProposals) { synchronized (this.rtpSessionProposals) {
for (Map.Entry<RtpSessionProposal, DeviceDiscoveryState> entry : this.rtpSessionProposals.entrySet()) { for (Map.Entry<RtpSessionProposal, DeviceDiscoveryState> entry :
this.rtpSessionProposals.entrySet()) {
final RtpSessionProposal proposal = entry.getKey(); final RtpSessionProposal proposal = entry.getKey();
final DeviceDiscoveryState state = entry.getValue(); final DeviceDiscoveryState state = entry.getValue();
final boolean openProposal = state == DeviceDiscoveryState.DISCOVERED final boolean openProposal =
|| state == DeviceDiscoveryState.SEARCHING state == DeviceDiscoveryState.DISCOVERED
|| state == DeviceDiscoveryState.SEARCHING_ACKNOWLEDGED; || state == DeviceDiscoveryState.SEARCHING
|| state == DeviceDiscoveryState.SEARCHING_ACKNOWLEDGED;
if (openProposal if (openProposal
&& proposal.account == account && proposal.account == account
&& proposal.with.equals(with.asBareJid()) && proposal.with.equals(with.asBareJid())
@ -171,7 +192,8 @@ public class JingleConnectionManager extends AbstractConnectionManager {
return Optional.absent(); return Optional.absent();
} }
private boolean hasMatchingRtpSession(final Account account, final Jid with, final Set<Media> media) { private boolean hasMatchingRtpSession(
final Account account, final Jid with, final Set<Media> media) {
for (AbstractJingleConnection connection : this.connections.values()) { for (AbstractJingleConnection connection : this.connections.values()) {
if (connection instanceof JingleRtpConnection) { if (connection instanceof JingleRtpConnection) {
final JingleRtpConnection rtpConnection = (JingleRtpConnection) connection; final JingleRtpConnection rtpConnection = (JingleRtpConnection) connection;
@ -189,7 +211,8 @@ public class JingleConnectionManager extends AbstractConnectionManager {
} }
private boolean isWithStrangerAndStrangerNotificationsAreOff(final Account account, Jid with) { private boolean isWithStrangerAndStrangerNotificationsAreOff(final Account account, Jid with) {
final boolean notifyForStrangers = mXmppConnectionService.getNotificationService().notificationsFromStrangers(); final boolean notifyForStrangers =
mXmppConnectionService.getNotificationService().notificationsFromStrangers();
if (notifyForStrangers) { if (notifyForStrangers) {
return false; return false;
} }
@ -197,11 +220,17 @@ public class JingleConnectionManager extends AbstractConnectionManager {
return !contact.showInContactList(); return !contact.showInContactList();
} }
ScheduledFuture<?> schedule(final Runnable runnable, final long delay, final TimeUnit timeUnit) { ScheduledFuture<?> schedule(
final Runnable runnable, final long delay, final TimeUnit timeUnit) {
return SCHEDULED_EXECUTOR_SERVICE.schedule(runnable, delay, timeUnit); return SCHEDULED_EXECUTOR_SERVICE.schedule(runnable, delay, timeUnit);
} }
void respondWithJingleError(final Account account, final IqPacket original, String jingleCondition, String condition, String conditionType) { void respondWithJingleError(
final Account account,
final IqPacket original,
String jingleCondition,
String condition,
String conditionType) {
final IqPacket response = original.generateResponse(IqPacket.TYPE.ERROR); final IqPacket response = original.generateResponse(IqPacket.TYPE.ERROR);
final Element error = response.addChild("error"); final Element error = response.addChild("error");
error.setAttribute("type", conditionType); error.setAttribute("type", conditionType);
@ -210,7 +239,14 @@ public class JingleConnectionManager extends AbstractConnectionManager {
account.getXmppConnection().sendIqPacket(response, null); account.getXmppConnection().sendIqPacket(response, null);
} }
public void deliverMessage(final Account account, final Jid to, final Jid from, final Element message, String remoteMsgId, String serverMsgId, long timestamp) { public void deliverMessage(
final Account account,
final Jid to,
final Jid from,
final Element message,
String remoteMsgId,
String serverMsgId,
long timestamp) {
Preconditions.checkArgument(Namespace.JINGLE_MESSAGE.equals(message.getNamespace())); Preconditions.checkArgument(Namespace.JINGLE_MESSAGE.equals(message.getNamespace()));
final String sessionId = message.getAttribute("id"); final String sessionId = message.getAttribute("id");
if (sessionId == null) { if (sessionId == null) {
@ -244,16 +280,24 @@ public class JingleConnectionManager extends AbstractConnectionManager {
final AbstractJingleConnection existingJingleConnection = connections.get(id); final AbstractJingleConnection existingJingleConnection = connections.get(id);
if (existingJingleConnection != null) { if (existingJingleConnection != null) {
if (existingJingleConnection instanceof JingleRtpConnection) { if (existingJingleConnection instanceof JingleRtpConnection) {
((JingleRtpConnection) existingJingleConnection).deliveryMessage(from, message, serverMsgId, timestamp); ((JingleRtpConnection) existingJingleConnection)
.deliveryMessage(from, message, serverMsgId, timestamp);
} else { } else {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": " + existingJingleConnection.getClass().getName() + " does not support jingle messages"); Log.d(
Config.LOGTAG,
account.getJid().asBareJid()
+ ": "
+ existingJingleConnection.getClass().getName()
+ " does not support jingle messages");
} }
return; return;
} }
if (fromSelf) { if (fromSelf) {
if ("proceed".equals(message.getName())) { if ("proceed".equals(message.getName())) {
final Conversation c = mXmppConnectionService.findOrCreateConversation(account, id.with, false, false); final Conversation c =
mXmppConnectionService.findOrCreateConversation(
account, id.with, false, false);
final Message previousBusy = c.findRtpSession(sessionId, Message.STATUS_RECEIVED); final Message previousBusy = c.findRtpSession(sessionId, Message.STATUS_RECEIVED);
if (previousBusy != null) { if (previousBusy != null) {
previousBusy.setBody(new RtpSessionStatus(true, 0).toString()); previousBusy.setBody(new RtpSessionStatus(true, 0).toString());
@ -262,84 +306,138 @@ public class JingleConnectionManager extends AbstractConnectionManager {
} }
previousBusy.setTime(timestamp); previousBusy.setTime(timestamp);
mXmppConnectionService.updateMessage(previousBusy, true); mXmppConnectionService.updateMessage(previousBusy, true);
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": updated previous busy because call got picked up by another device"); Log.d(
Config.LOGTAG,
id.account.getJid().asBareJid()
+ ": updated previous busy because call got picked up by another device");
return; return;
} }
} }
//TODO handle reject for cases where we dont have carbon copies (normally reject is to be sent to own bare jid as well) // TODO handle reject for cases where we dont have carbon copies (normally reject is to
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": ignore jingle message from self"); // be sent to own bare jid as well)
Log.d(
Config.LOGTAG,
account.getJid().asBareJid() + ": ignore jingle message from self");
return; return;
} }
if ("propose".equals(message.getName())) { if ("propose".equals(message.getName())) {
final Propose propose = Propose.upgrade(message); final Propose propose = Propose.upgrade(message);
final List<GenericDescription> descriptions = propose.getDescriptions(); final List<GenericDescription> descriptions = propose.getDescriptions();
final Collection<RtpDescription> rtpDescriptions = Collections2.transform( final Collection<RtpDescription> rtpDescriptions =
Collections2.filter(descriptions, d -> d instanceof RtpDescription), Collections2.transform(
input -> (RtpDescription) input Collections2.filter(descriptions, d -> d instanceof RtpDescription),
); input -> (RtpDescription) input);
if (rtpDescriptions.size() > 0 && rtpDescriptions.size() == descriptions.size() && isUsingClearNet(account)) { if (rtpDescriptions.size() > 0
final Collection<Media> media = Collections2.transform(rtpDescriptions, RtpDescription::getMedia); && rtpDescriptions.size() == descriptions.size()
&& isUsingClearNet(account)) {
final Collection<Media> media =
Collections2.transform(rtpDescriptions, RtpDescription::getMedia);
if (media.contains(Media.UNKNOWN)) { if (media.contains(Media.UNKNOWN)) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": encountered unknown media in session proposal. " + propose); Log.d(
Config.LOGTAG,
account.getJid().asBareJid()
+ ": encountered unknown media in session proposal. "
+ propose);
return; return;
} }
final Optional<RtpSessionProposal> matchingSessionProposal = findMatchingSessionProposal(account, id.with, ImmutableSet.copyOf(media)); final Optional<RtpSessionProposal> matchingSessionProposal =
findMatchingSessionProposal(account, id.with, ImmutableSet.copyOf(media));
if (matchingSessionProposal.isPresent()) { if (matchingSessionProposal.isPresent()) {
final String ourSessionId = matchingSessionProposal.get().sessionId; final String ourSessionId = matchingSessionProposal.get().sessionId;
final String theirSessionId = id.sessionId; final String theirSessionId = id.sessionId;
if (ComparisonChain.start() if (ComparisonChain.start()
.compare(ourSessionId, theirSessionId) .compare(ourSessionId, theirSessionId)
.compare(account.getJid().toEscapedString(), id.with.toEscapedString()) .compare(
.result() > 0) { account.getJid().toEscapedString(),
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": our session lost tie break. automatically accepting their session. winning Session=" + theirSessionId); id.with.toEscapedString())
//TODO a retract for this reason should probably include some indication of tie break .result()
> 0) {
Log.d(
Config.LOGTAG,
account.getJid().asBareJid()
+ ": our session lost tie break. automatically accepting their session. winning Session="
+ theirSessionId);
// TODO a retract for this reason should probably include some indication of
// tie break
retractSessionProposal(matchingSessionProposal.get()); retractSessionProposal(matchingSessionProposal.get());
final JingleRtpConnection rtpConnection = new JingleRtpConnection(this, id, from); final JingleRtpConnection rtpConnection =
new JingleRtpConnection(this, id, from);
this.connections.put(id, rtpConnection); this.connections.put(id, rtpConnection);
rtpConnection.setProposedMedia(ImmutableSet.copyOf(media)); rtpConnection.setProposedMedia(ImmutableSet.copyOf(media));
rtpConnection.deliveryMessage(from, message, serverMsgId, timestamp); rtpConnection.deliveryMessage(from, message, serverMsgId, timestamp);
} else { } else {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": our session won tie break. waiting for other party to accept. winningSession=" + ourSessionId); Log.d(
Config.LOGTAG,
account.getJid().asBareJid()
+ ": our session won tie break. waiting for other party to accept. winningSession="
+ ourSessionId);
} }
return; return;
} }
final boolean stranger = isWithStrangerAndStrangerNotificationsAreOff(account, id.with); final boolean stranger =
isWithStrangerAndStrangerNotificationsAreOff(account, id.with);
if (isBusy() || stranger) { if (isBusy() || stranger) {
writeLogMissedIncoming(account, id.with.asBareJid(), id.sessionId, serverMsgId, timestamp); writeLogMissedIncoming(
account, id.with.asBareJid(), id.sessionId, serverMsgId, timestamp);
if (stranger) { if (stranger) {
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": ignoring call proposal from stranger " + id.with); Log.d(
Config.LOGTAG,
id.account.getJid().asBareJid()
+ ": ignoring call proposal from stranger "
+ id.with);
return; return;
} }
final int activeDevices = account.activeDevicesWithRtpCapability(); final int activeDevices = account.activeDevicesWithRtpCapability();
Log.d(Config.LOGTAG, "active devices with rtp capability: " + activeDevices); Log.d(Config.LOGTAG, "active devices with rtp capability: " + activeDevices);
if (activeDevices == 0) { if (activeDevices == 0) {
final MessagePacket reject = mXmppConnectionService.getMessageGenerator().sessionReject(from, sessionId); final MessagePacket reject =
mXmppConnectionService
.getMessageGenerator()
.sessionReject(from, sessionId);
mXmppConnectionService.sendMessagePacket(account, reject); mXmppConnectionService.sendMessagePacket(account, reject);
} else { } else {
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": ignoring proposal because busy on this device but there are other devices"); Log.d(
Config.LOGTAG,
id.account.getJid().asBareJid()
+ ": ignoring proposal because busy on this device but there are other devices");
} }
} else { } else {
final JingleRtpConnection rtpConnection = new JingleRtpConnection(this, id, from); final JingleRtpConnection rtpConnection =
new JingleRtpConnection(this, id, from);
this.connections.put(id, rtpConnection); this.connections.put(id, rtpConnection);
rtpConnection.setProposedMedia(ImmutableSet.copyOf(media)); rtpConnection.setProposedMedia(ImmutableSet.copyOf(media));
rtpConnection.deliveryMessage(from, message, serverMsgId, timestamp); rtpConnection.deliveryMessage(from, message, serverMsgId, timestamp);
} }
} else { } else {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": unable to react to proposed session with " + rtpDescriptions.size() + " rtp descriptions of " + descriptions.size() + " total descriptions"); Log.d(
Config.LOGTAG,
account.getJid().asBareJid()
+ ": unable to react to proposed session with "
+ rtpDescriptions.size()
+ " rtp descriptions of "
+ descriptions.size()
+ " total descriptions");
} }
} else if (addressedDirectly && "proceed".equals(message.getName())) { } else if (addressedDirectly && "proceed".equals(message.getName())) {
synchronized (rtpSessionProposals) { synchronized (rtpSessionProposals) {
final RtpSessionProposal proposal = getRtpSessionProposal(account, from.asBareJid(), sessionId); final RtpSessionProposal proposal =
getRtpSessionProposal(account, from.asBareJid(), sessionId);
if (proposal != null) { if (proposal != null) {
rtpSessionProposals.remove(proposal); rtpSessionProposals.remove(proposal);
final JingleRtpConnection rtpConnection = new JingleRtpConnection(this, id, account.getJid()); final JingleRtpConnection rtpConnection =
new JingleRtpConnection(this, id, account.getJid());
rtpConnection.setProposedMedia(proposal.media); rtpConnection.setProposedMedia(proposal.media);
this.connections.put(id, rtpConnection); this.connections.put(id, rtpConnection);
rtpConnection.transitionOrThrow(AbstractJingleConnection.State.PROPOSED); rtpConnection.transitionOrThrow(AbstractJingleConnection.State.PROPOSED);
rtpConnection.deliveryMessage(from, message, serverMsgId, timestamp); rtpConnection.deliveryMessage(from, message, serverMsgId, timestamp);
} else { } else {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": no rtp session proposal found for " + from + " to deliver proceed"); Log.d(
Config.LOGTAG,
account.getJid().asBareJid()
+ ": no rtp session proposal found for "
+ from
+ " to deliver proceed");
if (remoteMsgId == null) { if (remoteMsgId == null) {
return; return;
} }
@ -355,63 +453,77 @@ public class JingleConnectionManager extends AbstractConnectionManager {
} }
} }
} else if (addressedDirectly && "reject".equals(message.getName())) { } else if (addressedDirectly && "reject".equals(message.getName())) {
final RtpSessionProposal proposal = getRtpSessionProposal(account, from.asBareJid(), sessionId); final RtpSessionProposal proposal =
getRtpSessionProposal(account, from.asBareJid(), sessionId);
synchronized (rtpSessionProposals) { synchronized (rtpSessionProposals) {
if (proposal != null && rtpSessionProposals.remove(proposal) != null) { if (proposal != null && rtpSessionProposals.remove(proposal) != null) {
writeLogMissedOutgoing(account, proposal.with, proposal.sessionId, serverMsgId, timestamp); writeLogMissedOutgoing(
account, proposal.with, proposal.sessionId, serverMsgId, timestamp);
toneManager.transition(RtpEndUserState.DECLINED_OR_BUSY, proposal.media); toneManager.transition(RtpEndUserState.DECLINED_OR_BUSY, proposal.media);
mXmppConnectionService.notifyJingleRtpConnectionUpdate(account, proposal.with, proposal.sessionId, RtpEndUserState.DECLINED_OR_BUSY); mXmppConnectionService.notifyJingleRtpConnectionUpdate(
account,
proposal.with,
proposal.sessionId,
RtpEndUserState.DECLINED_OR_BUSY);
} else { } else {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": no rtp session proposal found for " + from + " to deliver reject"); Log.d(
Config.LOGTAG,
account.getJid().asBareJid()
+ ": no rtp session proposal found for "
+ from
+ " to deliver reject");
} }
} }
} else { } else {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": retrieved out of order jingle message" + message); Log.d(
Config.LOGTAG,
account.getJid().asBareJid()
+ ": retrieved out of order jingle message"
+ message);
} }
} }
private RtpSessionProposal getRtpSessionProposal(final Account account, Jid from, String sessionId) { private RtpSessionProposal getRtpSessionProposal(
final Account account, Jid from, String sessionId) {
for (RtpSessionProposal rtpSessionProposal : rtpSessionProposals.keySet()) { for (RtpSessionProposal rtpSessionProposal : rtpSessionProposals.keySet()) {
if (rtpSessionProposal.sessionId.equals(sessionId) && rtpSessionProposal.with.equals(from) && rtpSessionProposal.account.getJid().equals(account.getJid())) { if (rtpSessionProposal.sessionId.equals(sessionId)
&& rtpSessionProposal.with.equals(from)
&& rtpSessionProposal.account.getJid().equals(account.getJid())) {
return rtpSessionProposal; return rtpSessionProposal;
} }
} }
return null; return null;
} }
private void writeLogMissedOutgoing(final Account account, Jid with, final String sessionId, String serverMsgId, long timestamp) { private void writeLogMissedOutgoing(
final Conversation conversation = mXmppConnectionService.findOrCreateConversation( final Account account,
account, Jid with,
with.asBareJid(), final String sessionId,
false, String serverMsgId,
false long timestamp) {
); final Conversation conversation =
final Message message = new Message( mXmppConnectionService.findOrCreateConversation(
conversation, account, with.asBareJid(), false, false);
Message.STATUS_SEND, final Message message =
Message.TYPE_RTP_SESSION, new Message(conversation, Message.STATUS_SEND, Message.TYPE_RTP_SESSION, sessionId);
sessionId
);
message.setBody(new RtpSessionStatus(false, 0).toString()); message.setBody(new RtpSessionStatus(false, 0).toString());
message.setServerMsgId(serverMsgId); message.setServerMsgId(serverMsgId);
message.setTime(timestamp); message.setTime(timestamp);
writeMessage(message); writeMessage(message);
} }
private void writeLogMissedIncoming(final Account account, Jid with, final String sessionId, String serverMsgId, long timestamp) { private void writeLogMissedIncoming(
final Conversation conversation = mXmppConnectionService.findOrCreateConversation( final Account account,
account, Jid with,
with.asBareJid(), final String sessionId,
false, String serverMsgId,
false long timestamp) {
); final Conversation conversation =
final Message message = new Message( mXmppConnectionService.findOrCreateConversation(
conversation, account, with.asBareJid(), false, false);
Message.STATUS_RECEIVED, final Message message =
Message.TYPE_RTP_SESSION, new Message(
sessionId conversation, Message.STATUS_RECEIVED, Message.TYPE_RTP_SESSION, sessionId);
);
message.setBody(new RtpSessionStatus(false, 0).toString()); message.setBody(new RtpSessionStatus(false, 0).toString());
message.setServerMsgId(serverMsgId); message.setServerMsgId(serverMsgId);
message.setTime(timestamp); message.setTime(timestamp);
@ -430,34 +542,41 @@ public class JingleConnectionManager extends AbstractConnectionManager {
} }
public void startJingleFileTransfer(final Message message) { public void startJingleFileTransfer(final Message message) {
Preconditions.checkArgument(message.isFileOrImage(), "Message is not of type file or image"); Preconditions.checkArgument(
message.isFileOrImage(), "Message is not of type file or image");
final Transferable old = message.getTransferable(); final Transferable old = message.getTransferable();
if (old != null) { if (old != null) {
old.cancel(); old.cancel();
} }
final Account account = message.getConversation().getAccount(); final Account account = message.getConversation().getAccount();
final AbstractJingleConnection.Id id = AbstractJingleConnection.Id.of(message); final AbstractJingleConnection.Id id = AbstractJingleConnection.Id.of(message);
final JingleFileTransferConnection connection = new JingleFileTransferConnection(this, id, account.getJid()); final JingleFileTransferConnection connection =
new JingleFileTransferConnection(this, id, account.getJid());
mXmppConnectionService.markMessage(message, Message.STATUS_WAITING); mXmppConnectionService.markMessage(message, Message.STATUS_WAITING);
this.connections.put(id, connection); this.connections.put(id, connection);
connection.init(message); connection.init(message);
} }
public Optional<OngoingRtpSession> getOngoingRtpConnection(final Contact contact) { public Optional<OngoingRtpSession> getOngoingRtpConnection(final Contact contact) {
for (final Map.Entry<AbstractJingleConnection.Id, AbstractJingleConnection> entry : this.connections.entrySet()) { for (final Map.Entry<AbstractJingleConnection.Id, AbstractJingleConnection> entry :
this.connections.entrySet()) {
if (entry.getValue() instanceof JingleRtpConnection) { if (entry.getValue() instanceof JingleRtpConnection) {
final AbstractJingleConnection.Id id = entry.getKey(); final AbstractJingleConnection.Id id = entry.getKey();
if (id.account == contact.getAccount() && id.with.asBareJid().equals(contact.getJid().asBareJid())) { if (id.account == contact.getAccount()
&& id.with.asBareJid().equals(contact.getJid().asBareJid())) {
return Optional.of(id); return Optional.of(id);
} }
} }
} }
synchronized (this.rtpSessionProposals) { synchronized (this.rtpSessionProposals) {
for (Map.Entry<RtpSessionProposal, DeviceDiscoveryState> entry : this.rtpSessionProposals.entrySet()) { for (Map.Entry<RtpSessionProposal, DeviceDiscoveryState> entry :
this.rtpSessionProposals.entrySet()) {
RtpSessionProposal proposal = entry.getKey(); RtpSessionProposal proposal = entry.getKey();
if (proposal.account == contact.getAccount() && contact.getJid().asBareJid().equals(proposal.with)) { if (proposal.account == contact.getAccount()
&& contact.getJid().asBareJid().equals(proposal.with)) {
final DeviceDiscoveryState preexistingState = entry.getValue(); final DeviceDiscoveryState preexistingState = entry.getValue();
if (preexistingState != null && preexistingState != DeviceDiscoveryState.FAILED) { if (preexistingState != null
&& preexistingState != DeviceDiscoveryState.FAILED) {
return Optional.of(proposal); return Optional.of(proposal);
} }
} }
@ -473,7 +592,8 @@ public class JingleConnectionManager extends AbstractConnectionManager {
void finishConnectionOrThrow(final AbstractJingleConnection connection) { void finishConnectionOrThrow(final AbstractJingleConnection connection) {
final AbstractJingleConnection.Id id = connection.getId(); final AbstractJingleConnection.Id id = connection.getId();
if (this.connections.remove(id) == null) { if (this.connections.remove(id) == null) {
throw new IllegalStateException(String.format("Unable to finish connection with id=%s", id.toString())); throw new IllegalStateException(
String.format("Unable to finish connection with id=%s", id.toString()));
} }
} }
@ -492,49 +612,70 @@ public class JingleConnectionManager extends AbstractConnectionManager {
return firedUpdates; return firedUpdates;
} }
void getPrimaryCandidate(final Account account, final boolean initiator, final OnPrimaryCandidateFound listener) { void getPrimaryCandidate(
final Account account,
final boolean initiator,
final OnPrimaryCandidateFound listener) {
if (Config.DISABLE_PROXY_LOOKUP) { if (Config.DISABLE_PROXY_LOOKUP) {
listener.onPrimaryCandidateFound(false, null); listener.onPrimaryCandidateFound(false, null);
return; return;
} }
if (!this.primaryCandidates.containsKey(account.getJid().asBareJid())) { if (!this.primaryCandidates.containsKey(account.getJid().asBareJid())) {
final Jid proxy = account.getXmppConnection().findDiscoItemByFeature(Namespace.BYTE_STREAMS); final Jid proxy =
account.getXmppConnection().findDiscoItemByFeature(Namespace.BYTE_STREAMS);
if (proxy != null) { if (proxy != null) {
IqPacket iq = new IqPacket(IqPacket.TYPE.GET); IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
iq.setTo(proxy); iq.setTo(proxy);
iq.query(Namespace.BYTE_STREAMS); iq.query(Namespace.BYTE_STREAMS);
account.getXmppConnection().sendIqPacket(iq, new OnIqPacketReceived() { account.getXmppConnection()
.sendIqPacket(
iq,
new OnIqPacketReceived() {
@Override @Override
public void onIqPacketReceived(Account account, IqPacket packet) { public void onIqPacketReceived(
final Element streamhost = packet.query().findChild("streamhost", Namespace.BYTE_STREAMS); Account account, IqPacket packet) {
final String host = streamhost == null ? null : streamhost.getAttribute("host"); final Element streamhost =
final String port = streamhost == null ? null : streamhost.getAttribute("port"); packet.query()
if (host != null && port != null) { .findChild(
try { "streamhost",
JingleCandidate candidate = new JingleCandidate(nextRandomId(), true); Namespace.BYTE_STREAMS);
candidate.setHost(host); final String host =
candidate.setPort(Integer.parseInt(port)); streamhost == null
candidate.setType(JingleCandidate.TYPE_PROXY); ? null
candidate.setJid(proxy); : streamhost.getAttribute("host");
candidate.setPriority(655360 + (initiator ? 30 : 0)); final String port =
primaryCandidates.put(account.getJid().asBareJid(), candidate); streamhost == null
listener.onPrimaryCandidateFound(true, candidate); ? null
} catch (final NumberFormatException e) { : streamhost.getAttribute("port");
listener.onPrimaryCandidateFound(false, null); if (host != null && port != null) {
} try {
} else { JingleCandidate candidate =
listener.onPrimaryCandidateFound(false, null); new JingleCandidate(nextRandomId(), true);
} candidate.setHost(host);
} candidate.setPort(Integer.parseInt(port));
}); candidate.setType(JingleCandidate.TYPE_PROXY);
candidate.setJid(proxy);
candidate.setPriority(
655360 + (initiator ? 30 : 0));
primaryCandidates.put(
account.getJid().asBareJid(), candidate);
listener.onPrimaryCandidateFound(true, candidate);
} catch (final NumberFormatException e) {
listener.onPrimaryCandidateFound(false, null);
}
} else {
listener.onPrimaryCandidateFound(false, null);
}
}
});
} else { } else {
listener.onPrimaryCandidateFound(false, null); listener.onPrimaryCandidateFound(false, null);
} }
} else { } else {
listener.onPrimaryCandidateFound(true, listener.onPrimaryCandidateFound(
this.primaryCandidates.get(account.getJid().asBareJid())); true, this.primaryCandidates.get(account.getJid().asBareJid()));
} }
} }
@ -556,64 +697,77 @@ public class JingleConnectionManager extends AbstractConnectionManager {
private void retractSessionProposal(RtpSessionProposal rtpSessionProposal) { private void retractSessionProposal(RtpSessionProposal rtpSessionProposal) {
final Account account = rtpSessionProposal.account; final Account account = rtpSessionProposal.account;
toneManager.transition(RtpEndUserState.ENDED, rtpSessionProposal.media); toneManager.transition(RtpEndUserState.ENDED, rtpSessionProposal.media);
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": retracting rtp session proposal with " + rtpSessionProposal.with); Log.d(
Config.LOGTAG,
account.getJid().asBareJid()
+ ": retracting rtp session proposal with "
+ rtpSessionProposal.with);
this.rtpSessionProposals.remove(rtpSessionProposal); this.rtpSessionProposals.remove(rtpSessionProposal);
final MessagePacket messagePacket = mXmppConnectionService.getMessageGenerator().sessionRetract(rtpSessionProposal); final MessagePacket messagePacket =
writeLogMissedOutgoing(account, rtpSessionProposal.with, rtpSessionProposal.sessionId, null, System.currentTimeMillis()); mXmppConnectionService.getMessageGenerator().sessionRetract(rtpSessionProposal);
writeLogMissedOutgoing(
account,
rtpSessionProposal.with,
rtpSessionProposal.sessionId,
null,
System.currentTimeMillis());
mXmppConnectionService.sendMessagePacket(account, messagePacket); mXmppConnectionService.sendMessagePacket(account, messagePacket);
} }
public String initializeRtpSession(final Account account, final Jid with, final Set<Media> media) { public String initializeRtpSession(
final Account account, final Jid with, final Set<Media> media) {
final AbstractJingleConnection.Id id = AbstractJingleConnection.Id.of(account, with); final AbstractJingleConnection.Id id = AbstractJingleConnection.Id.of(account, with);
final JingleRtpConnection rtpConnection = new JingleRtpConnection(this, id, account.getJid()); final JingleRtpConnection rtpConnection =
new JingleRtpConnection(this, id, account.getJid());
rtpConnection.setProposedMedia(media); rtpConnection.setProposedMedia(media);
this.connections.put(id, rtpConnection); this.connections.put(id, rtpConnection);
rtpConnection.sendSessionInitiate(); rtpConnection.sendSessionInitiate();
return id.sessionId; return id.sessionId;
} }
public void proposeJingleRtpSession(final Account account, final Jid with, final Set<Media> media) { public void proposeJingleRtpSession(
final Account account, final Jid with, final Set<Media> media) {
synchronized (this.rtpSessionProposals) { synchronized (this.rtpSessionProposals) {
for (Map.Entry<RtpSessionProposal, DeviceDiscoveryState> entry : this.rtpSessionProposals.entrySet()) { for (Map.Entry<RtpSessionProposal, DeviceDiscoveryState> entry :
this.rtpSessionProposals.entrySet()) {
RtpSessionProposal proposal = entry.getKey(); RtpSessionProposal proposal = entry.getKey();
if (proposal.account == account && with.asBareJid().equals(proposal.with)) { if (proposal.account == account && with.asBareJid().equals(proposal.with)) {
final DeviceDiscoveryState preexistingState = entry.getValue(); final DeviceDiscoveryState preexistingState = entry.getValue();
if (preexistingState != null && preexistingState != DeviceDiscoveryState.FAILED) { if (preexistingState != null
&& preexistingState != DeviceDiscoveryState.FAILED) {
final RtpEndUserState endUserState = preexistingState.toEndUserState(); final RtpEndUserState endUserState = preexistingState.toEndUserState();
toneManager.transition(endUserState, media); toneManager.transition(endUserState, media);
mXmppConnectionService.notifyJingleRtpConnectionUpdate( mXmppConnectionService.notifyJingleRtpConnectionUpdate(
account, account, with, proposal.sessionId, endUserState);
with,
proposal.sessionId,
endUserState
);
return; return;
} }
} }
} }
if (isBusy()) { if (isBusy()) {
if (hasMatchingRtpSession(account, with, media)) { if (hasMatchingRtpSession(account, with, media)) {
Log.d(Config.LOGTAG, "ignoring request to propose jingle session because the other party already created one for us"); Log.d(
Config.LOGTAG,
"ignoring request to propose jingle session because the other party already created one for us");
return; return;
} }
throw new IllegalStateException("There is already a running RTP session. This should have been caught by the UI"); throw new IllegalStateException(
"There is already a running RTP session. This should have been caught by the UI");
} }
final RtpSessionProposal proposal = RtpSessionProposal.of(account, with.asBareJid(), media); final RtpSessionProposal proposal =
RtpSessionProposal.of(account, with.asBareJid(), media);
this.rtpSessionProposals.put(proposal, DeviceDiscoveryState.SEARCHING); this.rtpSessionProposals.put(proposal, DeviceDiscoveryState.SEARCHING);
mXmppConnectionService.notifyJingleRtpConnectionUpdate( mXmppConnectionService.notifyJingleRtpConnectionUpdate(
account, account, proposal.with, proposal.sessionId, RtpEndUserState.FINDING_DEVICE);
proposal.with, final MessagePacket messagePacket =
proposal.sessionId, mXmppConnectionService.getMessageGenerator().sessionProposal(proposal);
RtpEndUserState.FINDING_DEVICE
);
final MessagePacket messagePacket = mXmppConnectionService.getMessageGenerator().sessionProposal(proposal);
mXmppConnectionService.sendMessagePacket(account, messagePacket); mXmppConnectionService.sendMessagePacket(account, messagePacket);
} }
} }
public boolean hasMatchingProposal(final Account account, final Jid with) { public boolean hasMatchingProposal(final Account account, final Jid with) {
synchronized (this.rtpSessionProposals) { synchronized (this.rtpSessionProposals) {
for (Map.Entry<RtpSessionProposal, DeviceDiscoveryState> entry : this.rtpSessionProposals.entrySet()) { for (Map.Entry<RtpSessionProposal, DeviceDiscoveryState> entry :
this.rtpSessionProposals.entrySet()) {
final RtpSessionProposal proposal = entry.getKey(); final RtpSessionProposal proposal = entry.getKey();
if (proposal.account == account && with.asBareJid().equals(proposal.with)) { if (proposal.account == account && with.asBareJid().equals(proposal.with)) {
return true; return true;
@ -642,10 +796,12 @@ public class JingleConnectionManager extends AbstractConnectionManager {
if (sid != null) { if (sid != null) {
for (final AbstractJingleConnection connection : this.connections.values()) { for (final AbstractJingleConnection connection : this.connections.values()) {
if (connection instanceof JingleFileTransferConnection) { if (connection instanceof JingleFileTransferConnection) {
final JingleFileTransferConnection fileTransfer = (JingleFileTransferConnection) connection; final JingleFileTransferConnection fileTransfer =
(JingleFileTransferConnection) connection;
final JingleTransport transport = fileTransfer.getTransport(); final JingleTransport transport = fileTransfer.getTransport();
if (transport instanceof JingleInBandTransport) { if (transport instanceof JingleInBandTransport) {
final JingleInBandTransport inBandTransport = (JingleInBandTransport) transport; final JingleInBandTransport inBandTransport =
(JingleInBandTransport) transport;
if (inBandTransport.matches(account, sid)) { if (inBandTransport.matches(account, sid)) {
inBandTransport.deliverPayload(packet, payload); inBandTransport.deliverPayload(packet, payload);
} }
@ -655,7 +811,8 @@ public class JingleConnectionManager extends AbstractConnectionManager {
} }
} }
Log.d(Config.LOGTAG, "unable to deliver ibb packet: " + packet.toString()); Log.d(Config.LOGTAG, "unable to deliver ibb packet: " + packet.toString());
account.getXmppConnection().sendIqPacket(packet.generateResponse(IqPacket.TYPE.ERROR), null); account.getXmppConnection()
.sendIqPacket(packet.generateResponse(IqPacket.TYPE.ERROR), null);
} }
public void notifyRebound(final Account account) { public void notifyRebound(final Account account) {
@ -668,8 +825,10 @@ public class JingleConnectionManager extends AbstractConnectionManager {
} }
} }
public WeakReference<JingleRtpConnection> findJingleRtpConnection(Account account, Jid with, String sessionId) { public WeakReference<JingleRtpConnection> findJingleRtpConnection(
final AbstractJingleConnection.Id id = AbstractJingleConnection.Id.of(account, with, sessionId); Account account, Jid with, String sessionId) {
final AbstractJingleConnection.Id id =
AbstractJingleConnection.Id.of(account, with, sessionId);
final AbstractJingleConnection connection = connections.get(id); final AbstractJingleConnection connection = connections.get(id);
if (connection instanceof JingleRtpConnection) { if (connection instanceof JingleRtpConnection) {
return new WeakReference<>((JingleRtpConnection) connection); return new WeakReference<>((JingleRtpConnection) connection);
@ -679,34 +838,53 @@ public class JingleConnectionManager extends AbstractConnectionManager {
private void resendSessionProposals(final Account account) { private void resendSessionProposals(final Account account) {
synchronized (this.rtpSessionProposals) { synchronized (this.rtpSessionProposals) {
for (final Map.Entry<RtpSessionProposal, DeviceDiscoveryState> entry : this.rtpSessionProposals.entrySet()) { for (final Map.Entry<RtpSessionProposal, DeviceDiscoveryState> entry :
this.rtpSessionProposals.entrySet()) {
final RtpSessionProposal proposal = entry.getKey(); final RtpSessionProposal proposal = entry.getKey();
if (entry.getValue() == DeviceDiscoveryState.SEARCHING && proposal.account == account) { if (entry.getValue() == DeviceDiscoveryState.SEARCHING
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": resending session proposal to " + proposal.with); && proposal.account == account) {
final MessagePacket messagePacket = mXmppConnectionService.getMessageGenerator().sessionProposal(proposal); Log.d(
Config.LOGTAG,
account.getJid().asBareJid()
+ ": resending session proposal to "
+ proposal.with);
final MessagePacket messagePacket =
mXmppConnectionService.getMessageGenerator().sessionProposal(proposal);
mXmppConnectionService.sendMessagePacket(account, messagePacket); mXmppConnectionService.sendMessagePacket(account, messagePacket);
} }
} }
} }
} }
public void updateProposedSessionDiscovered(Account account, Jid from, String sessionId, final DeviceDiscoveryState target) { public void updateProposedSessionDiscovered(
Account account, Jid from, String sessionId, final DeviceDiscoveryState target) {
synchronized (this.rtpSessionProposals) { synchronized (this.rtpSessionProposals) {
final RtpSessionProposal sessionProposal = getRtpSessionProposal(account, from.asBareJid(), sessionId); final RtpSessionProposal sessionProposal =
final DeviceDiscoveryState currentState = sessionProposal == null ? null : rtpSessionProposals.get(sessionProposal); getRtpSessionProposal(account, from.asBareJid(), sessionId);
final DeviceDiscoveryState currentState =
sessionProposal == null ? null : rtpSessionProposals.get(sessionProposal);
if (currentState == null) { if (currentState == null) {
Log.d(Config.LOGTAG, "unable to find session proposal for session id " + sessionId); Log.d(Config.LOGTAG, "unable to find session proposal for session id " + sessionId);
return; return;
} }
if (currentState == DeviceDiscoveryState.DISCOVERED) { if (currentState == DeviceDiscoveryState.DISCOVERED) {
Log.d(Config.LOGTAG, "session proposal already at discovered. not going to fall back"); Log.d(
Config.LOGTAG,
"session proposal already at discovered. not going to fall back");
return; return;
} }
this.rtpSessionProposals.put(sessionProposal, target); this.rtpSessionProposals.put(sessionProposal, target);
final RtpEndUserState endUserState = target.toEndUserState(); final RtpEndUserState endUserState = target.toEndUserState();
toneManager.transition(endUserState, sessionProposal.media); toneManager.transition(endUserState, sessionProposal.media);
mXmppConnectionService.notifyJingleRtpConnectionUpdate(account, sessionProposal.with, sessionProposal.sessionId, endUserState); mXmppConnectionService.notifyJingleRtpConnectionUpdate(
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": flagging session " + sessionId + " as " + target); account, sessionProposal.with, sessionProposal.sessionId, endUserState);
Log.d(
Config.LOGTAG,
account.getJid().asBareJid()
+ ": flagging session "
+ sessionId
+ " as "
+ target);
} }
} }
@ -731,7 +909,8 @@ public class JingleConnectionManager extends AbstractConnectionManager {
} }
public void failProceed(Account account, final Jid with, String sessionId) { public void failProceed(Account account, final Jid with, String sessionId) {
final AbstractJingleConnection.Id id = AbstractJingleConnection.Id.of(account, with, sessionId); final AbstractJingleConnection.Id id =
AbstractJingleConnection.Id.of(account, with, sessionId);
final AbstractJingleConnection existingJingleConnection = connections.get(id); final AbstractJingleConnection existingJingleConnection = connections.get(id);
if (existingJingleConnection instanceof JingleRtpConnection) { if (existingJingleConnection instanceof JingleRtpConnection) {
((JingleRtpConnection) existingJingleConnection).deliverFailedProceed(); ((JingleRtpConnection) existingJingleConnection).deliverFailedProceed();
@ -742,13 +921,17 @@ public class JingleConnectionManager extends AbstractConnectionManager {
if (connections.containsValue(connection)) { if (connections.containsValue(connection)) {
return; return;
} }
final IllegalStateException e = new IllegalStateException("JingleConnection has not been registered with connection manager"); final IllegalStateException e =
new IllegalStateException(
"JingleConnection has not been registered with connection manager");
Log.e(Config.LOGTAG, "ensureConnectionIsRegistered() failed. Going to throw", e); Log.e(Config.LOGTAG, "ensureConnectionIsRegistered() failed. Going to throw", e);
throw e; throw e;
} }
void setTerminalSessionState(AbstractJingleConnection.Id id, final RtpEndUserState state, final Set<Media> media) { void setTerminalSessionState(
this.terminatedSessions.put(PersistableSessionId.of(id), new TerminatedRtpSession(state, media)); AbstractJingleConnection.Id id, final RtpEndUserState state, final Set<Media> media) {
this.terminatedSessions.put(
PersistableSessionId.of(id), new TerminatedRtpSession(state, media));
} }
public TerminatedRtpSession getTerminalSessionState(final Jid with, final String sessionId) { public TerminatedRtpSession getTerminalSessionState(final Jid with, final String sessionId) {
@ -773,8 +956,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
PersistableSessionId that = (PersistableSessionId) o; PersistableSessionId that = (PersistableSessionId) o;
return Objects.equal(with, that.with) && return Objects.equal(with, that.with) && Objects.equal(sessionId, that.sessionId);
Objects.equal(sessionId, that.sessionId);
} }
@Override @Override
@ -794,7 +976,10 @@ public class JingleConnectionManager extends AbstractConnectionManager {
} }
public enum DeviceDiscoveryState { public enum DeviceDiscoveryState {
SEARCHING, SEARCHING_ACKNOWLEDGED, DISCOVERED, FAILED; SEARCHING,
SEARCHING_ACKNOWLEDGED,
DISCOVERED,
FAILED;
public RtpEndUserState toEndUserState() { public RtpEndUserState toEndUserState() {
switch (this) { switch (this) {
@ -835,9 +1020,9 @@ public class JingleConnectionManager extends AbstractConnectionManager {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
RtpSessionProposal proposal = (RtpSessionProposal) o; RtpSessionProposal proposal = (RtpSessionProposal) o;
return Objects.equal(account.getJid(), proposal.account.getJid()) && return Objects.equal(account.getJid(), proposal.account.getJid())
Objects.equal(with, proposal.with) && && Objects.equal(with, proposal.with)
Objects.equal(sessionId, proposal.sessionId); && Objects.equal(sessionId, proposal.sessionId);
} }
@Override @Override