1package eu.siacs.conversations.xmpp.jingle;
2
3import android.os.SystemClock;
4import android.util.Base64;
5import android.util.Log;
6
7import com.google.common.base.Function;
8import com.google.common.base.Objects;
9import com.google.common.base.Preconditions;
10import com.google.common.collect.Collections2;
11import com.google.common.collect.ImmutableSet;
12
13import org.checkerframework.checker.nullness.compatqual.NullableDecl;
14
15import java.lang.ref.WeakReference;
16import java.security.SecureRandom;
17import java.util.Collection;
18import java.util.Collections;
19import java.util.HashMap;
20import java.util.List;
21import java.util.Map;
22import java.util.Set;
23import java.util.concurrent.ConcurrentHashMap;
24
25import eu.siacs.conversations.Config;
26import eu.siacs.conversations.entities.Account;
27import eu.siacs.conversations.entities.Conversation;
28import eu.siacs.conversations.entities.Conversational;
29import eu.siacs.conversations.entities.Message;
30import eu.siacs.conversations.entities.RtpSessionStatus;
31import eu.siacs.conversations.entities.Transferable;
32import eu.siacs.conversations.services.AbstractConnectionManager;
33import eu.siacs.conversations.services.XmppConnectionService;
34import eu.siacs.conversations.xml.Element;
35import eu.siacs.conversations.xml.Namespace;
36import eu.siacs.conversations.xmpp.OnIqPacketReceived;
37import eu.siacs.conversations.xmpp.jingle.stanzas.Content;
38import eu.siacs.conversations.xmpp.jingle.stanzas.FileTransferDescription;
39import eu.siacs.conversations.xmpp.jingle.stanzas.GenericDescription;
40import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket;
41import eu.siacs.conversations.xmpp.jingle.stanzas.Propose;
42import eu.siacs.conversations.xmpp.jingle.stanzas.Reason;
43import eu.siacs.conversations.xmpp.jingle.stanzas.RtpDescription;
44import eu.siacs.conversations.xmpp.stanzas.IqPacket;
45import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
46import rocks.xmpp.addr.Jid;
47
48public class JingleConnectionManager extends AbstractConnectionManager {
49 private final HashMap<RtpSessionProposal, DeviceDiscoveryState> rtpSessionProposals = new HashMap<>();
50 private final Map<AbstractJingleConnection.Id, AbstractJingleConnection> connections = new ConcurrentHashMap<>();
51
52 private HashMap<Jid, JingleCandidate> primaryCandidates = new HashMap<>();
53
54 public JingleConnectionManager(XmppConnectionService service) {
55 super(service);
56 }
57
58 static String nextRandomId() {
59 final byte[] id = new byte[16];
60 new SecureRandom().nextBytes(id);
61 return Base64.encodeToString(id, Base64.NO_WRAP | Base64.NO_PADDING);
62 }
63
64 public void deliverPacket(final Account account, final JinglePacket packet) {
65 final String sessionId = packet.getSessionId();
66 if (sessionId == null) {
67 respondWithJingleError(account, packet, "unknown-session", "item-not-found", "cancel");
68 return;
69 }
70 final AbstractJingleConnection.Id id = AbstractJingleConnection.Id.of(account, packet);
71 final AbstractJingleConnection existingJingleConnection = connections.get(id);
72 if (existingJingleConnection != null) {
73 existingJingleConnection.deliverPacket(packet);
74 } else if (packet.getAction() == JinglePacket.Action.SESSION_INITIATE) {
75 final Jid from = packet.getFrom();
76 final Content content = packet.getJingleContent();
77 final String descriptionNamespace = content == null ? null : content.getDescriptionNamespace();
78 final AbstractJingleConnection connection;
79 if (FileTransferDescription.NAMESPACES.contains(descriptionNamespace)) {
80 connection = new JingleFileTransferConnection(this, id, from);
81 } else if (Namespace.JINGLE_APPS_RTP.equals(descriptionNamespace) && !usesTor(account)) {
82 if (isBusy()) {
83 mXmppConnectionService.sendIqPacket(account, packet.generateResponse(IqPacket.TYPE.RESULT), null);
84 final JinglePacket sessionTermination = new JinglePacket(JinglePacket.Action.SESSION_TERMINATE, id.sessionId);
85 sessionTermination.setTo(id.with);
86 sessionTermination.setReason(Reason.BUSY, null);
87 mXmppConnectionService.sendIqPacket(account, sessionTermination, null);
88 return;
89 }
90 connection = new JingleRtpConnection(this, id, from);
91 } else {
92 respondWithJingleError(account, packet, "unsupported-info", "feature-not-implemented", "cancel");
93 return;
94 }
95 connections.put(id, connection);
96 connection.deliverPacket(packet);
97 } else {
98 Log.d(Config.LOGTAG, "unable to route jingle packet: " + packet);
99 respondWithJingleError(account, packet, "unknown-session", "item-not-found", "cancel");
100 }
101 }
102
103 private boolean usesTor(final Account account) {
104 return account.isOnion() || mXmppConnectionService.useTorToConnect();
105 }
106
107 private boolean isBusy() {
108 for (AbstractJingleConnection connection : this.connections.values()) {
109 if (connection instanceof JingleRtpConnection) {
110 return true;
111 }
112 }
113 synchronized (this.rtpSessionProposals) {
114 return this.rtpSessionProposals.containsValue(DeviceDiscoveryState.DISCOVERED) || this.rtpSessionProposals.containsValue(DeviceDiscoveryState.SEARCHING);
115 }
116 }
117
118 public void respondWithJingleError(final Account account, final IqPacket original, String jingleCondition, String condition, String conditionType) {
119 final IqPacket response = original.generateResponse(IqPacket.TYPE.ERROR);
120 final Element error = response.addChild("error");
121 error.setAttribute("type", conditionType);
122 error.addChild(condition, "urn:ietf:params:xml:ns:xmpp-stanzas");
123 error.addChild(jingleCondition, "urn:xmpp:jingle:errors:1");
124 account.getXmppConnection().sendIqPacket(response, null);
125 }
126
127 public void deliverMessage(final Account account, final Jid to, final Jid from, final Element message, String serverMsgId, long timestamp) {
128 Preconditions.checkArgument(Namespace.JINGLE_MESSAGE.equals(message.getNamespace()));
129 final String sessionId = message.getAttribute("id");
130 if (sessionId == null) {
131 return;
132 }
133 if ("accept".equals(message.getName())) {
134 for (AbstractJingleConnection connection : connections.values()) {
135 if (connection instanceof JingleRtpConnection) {
136 final JingleRtpConnection rtpConnection = (JingleRtpConnection) connection;
137 final AbstractJingleConnection.Id id = connection.getId();
138 if (id.account == account && id.sessionId.equals(sessionId)) {
139 rtpConnection.deliveryMessage(from, message, serverMsgId, timestamp);
140 return;
141 }
142 }
143 }
144 return;
145 }
146 final boolean fromSelf = from.asBareJid().equals(account.getJid().asBareJid());
147 final AbstractJingleConnection.Id id;
148 if (fromSelf) {
149 if (to.isFullJid()) {
150 id = AbstractJingleConnection.Id.of(account, to, sessionId);
151 } else {
152 return;
153 }
154 } else {
155 id = AbstractJingleConnection.Id.of(account, from, sessionId);
156 }
157 final AbstractJingleConnection existingJingleConnection = connections.get(id);
158 if (existingJingleConnection != null) {
159 if (existingJingleConnection instanceof JingleRtpConnection) {
160 ((JingleRtpConnection) existingJingleConnection).deliveryMessage(from, message, serverMsgId, timestamp);
161 } else {
162 Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": " + existingJingleConnection.getClass().getName() + " does not support jingle messages");
163 }
164 return;
165 }
166
167 if (fromSelf) {
168 if ("proceed".equals(message.getName())) {
169 final Conversation c = mXmppConnectionService.findOrCreateConversation(account, id.with, false, false);
170 final Message previousBusy = c.findRtpSession(sessionId, Message.STATUS_RECEIVED);
171 if (previousBusy != null) {
172 previousBusy.setBody(new RtpSessionStatus(true, 0).toString());
173 if (serverMsgId != null) {
174 previousBusy.setServerMsgId(serverMsgId);
175 }
176 previousBusy.setTime(timestamp);
177 mXmppConnectionService.updateMessage(previousBusy, true);
178 Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": updated previous busy because call got picked up by another device");
179 return;
180 }
181 }
182 Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": ignore jingle message from self");
183 return;
184 }
185
186 if ("propose".equals(message.getName())) {
187 final Propose propose = Propose.upgrade(message);
188 final List<GenericDescription> descriptions = propose.getDescriptions();
189 final Collection<RtpDescription> rtpDescriptions = Collections2.transform(
190 Collections2.filter(descriptions, d -> d instanceof RtpDescription),
191 input -> (RtpDescription) input
192 );
193 if (rtpDescriptions.size() > 0 && rtpDescriptions.size() == descriptions.size() && !usesTor(account)) {
194 final Collection<Media> media = Collections2.transform(rtpDescriptions, RtpDescription::getMedia);
195 if (media.contains(Media.UNKNOWN)) {
196 Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": encountered unknown media in session proposal. " + propose);
197 return;
198 }
199 if (isBusy()) {
200 writeLogMissedIncoming(account, id.with.asBareJid(), id.sessionId, serverMsgId, timestamp);
201 final int activeDevices = account.countPresences();
202 Log.d(Config.LOGTAG, "active devices: " + activeDevices);
203 if (activeDevices == 0) {
204 final MessagePacket reject = mXmppConnectionService.getMessageGenerator().sessionReject(from, sessionId);
205 mXmppConnectionService.sendMessagePacket(account, reject);
206 } else {
207 Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": ignoring proposal because busy on this device but there are other devices");
208 }
209 } else {
210 final JingleRtpConnection rtpConnection = new JingleRtpConnection(this, id, from);
211 this.connections.put(id, rtpConnection);
212 rtpConnection.setProposedMedia(ImmutableSet.copyOf(media));
213 rtpConnection.deliveryMessage(from, message, serverMsgId, timestamp);
214 }
215 } else {
216 Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": unable to react to proposed session with " + rtpDescriptions.size() + " rtp descriptions of " + descriptions.size() + " total descriptions");
217 }
218 } else if ("proceed".equals(message.getName())) {
219 synchronized (rtpSessionProposals) {
220 final RtpSessionProposal proposal = getRtpSessionProposal(account, from.asBareJid(), sessionId);
221 if (proposal != null) {
222 rtpSessionProposals.remove(proposal);
223 final JingleRtpConnection rtpConnection = new JingleRtpConnection(this, id, account.getJid());
224 rtpConnection.setProposedMedia(proposal.media);
225 this.connections.put(id, rtpConnection);
226 rtpConnection.transitionOrThrow(AbstractJingleConnection.State.PROPOSED);
227 rtpConnection.deliveryMessage(from, message, serverMsgId, timestamp);
228 } else {
229 Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": no rtp session proposal found for " + from + " to deliver proceed");
230 }
231 }
232 } else if ("reject".equals(message.getName())) {
233 final RtpSessionProposal proposal = new RtpSessionProposal(account, from.asBareJid(), sessionId);
234 synchronized (rtpSessionProposals) {
235 if (rtpSessionProposals.remove(proposal) != null) {
236 writeLogMissedOutgoing(account, proposal.with, proposal.sessionId, serverMsgId, timestamp);
237 mXmppConnectionService.notifyJingleRtpConnectionUpdate(account, proposal.with, proposal.sessionId, RtpEndUserState.DECLINED_OR_BUSY);
238 } else {
239 Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": no rtp session proposal found for " + from + " to deliver reject");
240 }
241 }
242 } else {
243 Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": retrieved out of order jingle message");
244 }
245
246 }
247
248 private RtpSessionProposal getRtpSessionProposal(final Account account, Jid from, String sessionId) {
249 for (RtpSessionProposal rtpSessionProposal : rtpSessionProposals.keySet()) {
250 if (rtpSessionProposal.sessionId.equals(sessionId) && rtpSessionProposal.with.equals(from) && rtpSessionProposal.account.getJid().equals(account.getJid())) {
251 return rtpSessionProposal;
252 }
253 }
254 return null;
255 }
256
257 private void writeLogMissedOutgoing(final Account account, Jid with, final String sessionId, String serverMsgId, long timestamp) {
258 final Conversation conversation = mXmppConnectionService.findOrCreateConversation(
259 account,
260 with.asBareJid(),
261 false,
262 false
263 );
264 final Message message = new Message(
265 conversation,
266 Message.STATUS_SEND,
267 Message.TYPE_RTP_SESSION,
268 sessionId
269 );
270 message.setBody(new RtpSessionStatus(false, 0).toString());
271 message.setServerMsgId(serverMsgId);
272 message.setTime(timestamp);
273 writeMessage(message);
274 }
275
276 private void writeLogMissedIncoming(final Account account, Jid with, final String sessionId, String serverMsgId, long timestamp) {
277 final Conversation conversation = mXmppConnectionService.findOrCreateConversation(
278 account,
279 with.asBareJid(),
280 false,
281 false
282 );
283 final Message message = new Message(
284 conversation,
285 Message.STATUS_RECEIVED,
286 Message.TYPE_RTP_SESSION,
287 sessionId
288 );
289 message.setBody(new RtpSessionStatus(false, 0).toString());
290 message.setServerMsgId(serverMsgId);
291 message.setTime(timestamp);
292 writeMessage(message);
293 }
294
295 private void writeMessage(final Message message) {
296 final Conversational conversational = message.getConversation();
297 if (conversational instanceof Conversation) {
298 ((Conversation) conversational).add(message);
299 mXmppConnectionService.databaseBackend.createMessage(message);
300 mXmppConnectionService.updateConversationUi();
301 } else {
302 throw new IllegalStateException("Somehow the conversation in a message was a stub");
303 }
304 }
305
306 public void startJingleFileTransfer(final Message message) {
307 Preconditions.checkArgument(message.isFileOrImage(), "Message is not of type file or image");
308 final Transferable old = message.getTransferable();
309 if (old != null) {
310 old.cancel();
311 }
312 final Account account = message.getConversation().getAccount();
313 final AbstractJingleConnection.Id id = AbstractJingleConnection.Id.of(message);
314 final JingleFileTransferConnection connection = new JingleFileTransferConnection(this, id, account.getJid());
315 mXmppConnectionService.markMessage(message, Message.STATUS_WAITING);
316 this.connections.put(id, connection);
317 connection.init(message);
318 }
319
320 void finishConnection(final AbstractJingleConnection connection) {
321 this.connections.remove(connection.getId());
322 }
323
324 void getPrimaryCandidate(final Account account, final boolean initiator, final OnPrimaryCandidateFound listener) {
325 if (Config.DISABLE_PROXY_LOOKUP) {
326 listener.onPrimaryCandidateFound(false, null);
327 return;
328 }
329 if (!this.primaryCandidates.containsKey(account.getJid().asBareJid())) {
330 final Jid proxy = account.getXmppConnection().findDiscoItemByFeature(Namespace.BYTE_STREAMS);
331 if (proxy != null) {
332 IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
333 iq.setTo(proxy);
334 iq.query(Namespace.BYTE_STREAMS);
335 account.getXmppConnection().sendIqPacket(iq, new OnIqPacketReceived() {
336
337 @Override
338 public void onIqPacketReceived(Account account, IqPacket packet) {
339 final Element streamhost = packet.query().findChild("streamhost", Namespace.BYTE_STREAMS);
340 final String host = streamhost == null ? null : streamhost.getAttribute("host");
341 final String port = streamhost == null ? null : streamhost.getAttribute("port");
342 if (host != null && port != null) {
343 try {
344 JingleCandidate candidate = new JingleCandidate(nextRandomId(), true);
345 candidate.setHost(host);
346 candidate.setPort(Integer.parseInt(port));
347 candidate.setType(JingleCandidate.TYPE_PROXY);
348 candidate.setJid(proxy);
349 candidate.setPriority(655360 + (initiator ? 30 : 0));
350 primaryCandidates.put(account.getJid().asBareJid(), candidate);
351 listener.onPrimaryCandidateFound(true, candidate);
352 } catch (final NumberFormatException e) {
353 listener.onPrimaryCandidateFound(false, null);
354 }
355 } else {
356 listener.onPrimaryCandidateFound(false, null);
357 }
358 }
359 });
360 } else {
361 listener.onPrimaryCandidateFound(false, null);
362 }
363
364 } else {
365 listener.onPrimaryCandidateFound(true,
366 this.primaryCandidates.get(account.getJid().asBareJid()));
367 }
368 }
369
370 public void retractSessionProposal(final Account account, final Jid with) {
371 synchronized (this.rtpSessionProposals) {
372 RtpSessionProposal matchingProposal = null;
373 for (RtpSessionProposal proposal : this.rtpSessionProposals.keySet()) {
374 if (proposal.account == account && with.asBareJid().equals(proposal.with)) {
375 matchingProposal = proposal;
376 break;
377 }
378 }
379 if (matchingProposal != null) {
380 this.rtpSessionProposals.remove(matchingProposal);
381 final MessagePacket messagePacket = mXmppConnectionService.getMessageGenerator().sessionRetract(matchingProposal);
382 writeLogMissedOutgoing(account, matchingProposal.with, matchingProposal.sessionId, null, System.currentTimeMillis());
383 mXmppConnectionService.sendMessagePacket(account, messagePacket);
384
385 }
386 }
387 }
388
389 public void proposeJingleRtpSession(final Account account, final Jid with, final Set<Media> media) {
390 synchronized (this.rtpSessionProposals) {
391 for (Map.Entry<RtpSessionProposal, DeviceDiscoveryState> entry : this.rtpSessionProposals.entrySet()) {
392 RtpSessionProposal proposal = entry.getKey();
393 if (proposal.account == account && with.asBareJid().equals(proposal.with)) {
394 final DeviceDiscoveryState preexistingState = entry.getValue();
395 if (preexistingState != null && preexistingState != DeviceDiscoveryState.FAILED) {
396 mXmppConnectionService.notifyJingleRtpConnectionUpdate(
397 account,
398 with,
399 proposal.sessionId,
400 preexistingState.toEndUserState()
401 );
402 return;
403 }
404 }
405 }
406 final RtpSessionProposal proposal = RtpSessionProposal.of(account, with.asBareJid(), media);
407 this.rtpSessionProposals.put(proposal, DeviceDiscoveryState.SEARCHING);
408 mXmppConnectionService.notifyJingleRtpConnectionUpdate(
409 account,
410 proposal.with,
411 proposal.sessionId,
412 RtpEndUserState.FINDING_DEVICE
413 );
414 final MessagePacket messagePacket = mXmppConnectionService.getMessageGenerator().sessionProposal(proposal);
415 Log.d(Config.LOGTAG, messagePacket.toString());
416 mXmppConnectionService.sendMessagePacket(account, messagePacket);
417 }
418 }
419
420 public void deliverIbbPacket(Account account, IqPacket packet) {
421 final String sid;
422 final Element payload;
423 if (packet.hasChild("open", Namespace.IBB)) {
424 payload = packet.findChild("open", Namespace.IBB);
425 sid = payload.getAttribute("sid");
426 } else if (packet.hasChild("data", Namespace.IBB)) {
427 payload = packet.findChild("data", Namespace.IBB);
428 sid = payload.getAttribute("sid");
429 } else if (packet.hasChild("close", Namespace.IBB)) {
430 payload = packet.findChild("close", Namespace.IBB);
431 sid = payload.getAttribute("sid");
432 } else {
433 payload = null;
434 sid = null;
435 }
436 if (sid != null) {
437 for (final AbstractJingleConnection connection : this.connections.values()) {
438 if (connection instanceof JingleFileTransferConnection) {
439 final JingleFileTransferConnection fileTransfer = (JingleFileTransferConnection) connection;
440 final JingleTransport transport = fileTransfer.getTransport();
441 if (transport instanceof JingleInBandTransport) {
442 final JingleInBandTransport inBandTransport = (JingleInBandTransport) transport;
443 if (inBandTransport.matches(account, sid)) {
444 inBandTransport.deliverPayload(packet, payload);
445 }
446 return;
447 }
448 }
449 }
450 }
451 Log.d(Config.LOGTAG, "unable to deliver ibb packet: " + packet.toString());
452 account.getXmppConnection().sendIqPacket(packet.generateResponse(IqPacket.TYPE.ERROR), null);
453 }
454
455 public void notifyRebound() {
456 for (final AbstractJingleConnection connection : this.connections.values()) {
457 connection.notifyRebound();
458 }
459 }
460
461 public WeakReference<JingleRtpConnection> findJingleRtpConnection(Account account, Jid with, String sessionId) {
462 final AbstractJingleConnection.Id id = AbstractJingleConnection.Id.of(account, Jid.ofEscaped(with), sessionId);
463 final AbstractJingleConnection connection = connections.get(id);
464 if (connection instanceof JingleRtpConnection) {
465 return new WeakReference<>((JingleRtpConnection) connection);
466 }
467 return null;
468 }
469
470 public void updateProposedSessionDiscovered(Account account, Jid from, String sessionId, final DeviceDiscoveryState target) {
471 synchronized (this.rtpSessionProposals) {
472 final RtpSessionProposal sessionProposal = getRtpSessionProposal(account, from.asBareJid(), sessionId);
473 final DeviceDiscoveryState currentState = sessionProposal == null ? null : rtpSessionProposals.get(sessionProposal);
474 if (currentState == null) {
475 Log.d(Config.LOGTAG, "unable to find session proposal for session id " + sessionId);
476 return;
477 }
478 if (currentState == DeviceDiscoveryState.DISCOVERED) {
479 Log.d(Config.LOGTAG, "session proposal already at discovered. not going to fall back");
480 return;
481 }
482 this.rtpSessionProposals.put(sessionProposal, target);
483 mXmppConnectionService.notifyJingleRtpConnectionUpdate(account, sessionProposal.with, sessionProposal.sessionId, target.toEndUserState());
484 Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": flagging session " + sessionId + " as " + target);
485 }
486 }
487
488 public void rejectRtpSession(final String sessionId) {
489 for (final AbstractJingleConnection connection : this.connections.values()) {
490 if (connection.getId().sessionId.equals(sessionId)) {
491 if (connection instanceof JingleRtpConnection) {
492 ((JingleRtpConnection) connection).rejectCall();
493 }
494 }
495 }
496 }
497
498 public void endRtpSession(final String sessionId) {
499 for (final AbstractJingleConnection connection : this.connections.values()) {
500 if (connection.getId().sessionId.equals(sessionId)) {
501 if (connection instanceof JingleRtpConnection) {
502 ((JingleRtpConnection) connection).endCall();
503 }
504 }
505 }
506 }
507
508 public void failProceed(Account account, final Jid with, String sessionId) {
509 final AbstractJingleConnection.Id id = AbstractJingleConnection.Id.of(account, with, sessionId);
510 final AbstractJingleConnection existingJingleConnection = connections.get(id);
511 if (existingJingleConnection instanceof JingleRtpConnection) {
512 ((JingleRtpConnection) existingJingleConnection).deliverFailedProceed();
513 }
514 }
515
516 void ensureConnectionIsRegistered(final AbstractJingleConnection connection) {
517 if (connections.containsValue(connection)) {
518 return;
519 }
520 throw new IllegalStateException("JingleConnection has not been registered with connection manager");
521 }
522
523 public enum DeviceDiscoveryState {
524 SEARCHING, DISCOVERED, FAILED;
525
526 public RtpEndUserState toEndUserState() {
527 switch (this) {
528 case SEARCHING:
529 return RtpEndUserState.FINDING_DEVICE;
530 case DISCOVERED:
531 return RtpEndUserState.RINGING;
532 default:
533 return RtpEndUserState.CONNECTIVITY_ERROR;
534 }
535 }
536 }
537
538 public static class RtpSessionProposal {
539 public final Jid with;
540 public final String sessionId;
541 public final Set<Media> media;
542 private final Account account;
543
544 private RtpSessionProposal(Account account, Jid with, String sessionId) {
545 this(account, with, sessionId, Collections.emptySet());
546 }
547
548 private RtpSessionProposal(Account account, Jid with, String sessionId, Set<Media> media) {
549 this.account = account;
550 this.with = with;
551 this.sessionId = sessionId;
552 this.media = media;
553 }
554
555 public static RtpSessionProposal of(Account account, Jid with, Set<Media> media) {
556 return new RtpSessionProposal(account, with, nextRandomId(), media);
557 }
558
559 @Override
560 public boolean equals(Object o) {
561 if (this == o) return true;
562 if (o == null || getClass() != o.getClass()) return false;
563 RtpSessionProposal proposal = (RtpSessionProposal) o;
564 return Objects.equal(account.getJid(), proposal.account.getJid()) &&
565 Objects.equal(with, proposal.with) &&
566 Objects.equal(sessionId, proposal.sessionId);
567 }
568
569 @Override
570 public int hashCode() {
571 return Objects.hashCode(account.getJid(), with, sessionId);
572 }
573 }
574}