use final varible to mark initiator once connection object has been created
This commit is contained in:
parent
5b15348f13
commit
b2aa0e3352
|
@ -14,11 +14,17 @@ public abstract class AbstractJingleConnection {
|
||||||
protected final JingleConnectionManager jingleConnectionManager;
|
protected final JingleConnectionManager jingleConnectionManager;
|
||||||
protected final XmppConnectionService xmppConnectionService;
|
protected final XmppConnectionService xmppConnectionService;
|
||||||
protected final Id id;
|
protected final Id id;
|
||||||
|
protected final Jid initiator;
|
||||||
|
|
||||||
public AbstractJingleConnection(final JingleConnectionManager jingleConnectionManager, final Id id) {
|
AbstractJingleConnection(final JingleConnectionManager jingleConnectionManager, final Id id, final Jid initiator) {
|
||||||
this.jingleConnectionManager = jingleConnectionManager;
|
this.jingleConnectionManager = jingleConnectionManager;
|
||||||
this.xmppConnectionService = jingleConnectionManager.getXmppConnectionService();
|
this.xmppConnectionService = jingleConnectionManager.getXmppConnectionService();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
this.initiator = initiator;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isInitiator() {
|
||||||
|
return initiator.equals(id.account.getJid());
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract void deliverPacket(JinglePacket jinglePacket);
|
abstract void deliverPacket(JinglePacket jinglePacket);
|
||||||
|
|
|
@ -22,7 +22,6 @@ import eu.siacs.conversations.xmpp.jingle.stanzas.Content;
|
||||||
import eu.siacs.conversations.xmpp.jingle.stanzas.FileTransferDescription;
|
import eu.siacs.conversations.xmpp.jingle.stanzas.FileTransferDescription;
|
||||||
import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket;
|
import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket;
|
||||||
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
|
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
|
||||||
import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
|
|
||||||
import rocks.xmpp.addr.Jid;
|
import rocks.xmpp.addr.Jid;
|
||||||
|
|
||||||
public class JingleConnectionManager extends AbstractConnectionManager {
|
public class JingleConnectionManager extends AbstractConnectionManager {
|
||||||
|
@ -40,13 +39,14 @@ public class JingleConnectionManager extends AbstractConnectionManager {
|
||||||
if (existingJingleConnection != null) {
|
if (existingJingleConnection != null) {
|
||||||
existingJingleConnection.deliverPacket(packet);
|
existingJingleConnection.deliverPacket(packet);
|
||||||
} else if (packet.getAction() == JinglePacket.Action.SESSION_INITIATE) {
|
} else if (packet.getAction() == JinglePacket.Action.SESSION_INITIATE) {
|
||||||
|
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);
|
connection = new JingleFileTransferConnection(this, id, from);
|
||||||
} else if (Namespace.JINGLE_APPS_RTP.equals(descriptionNamespace)) {
|
} else if (Namespace.JINGLE_APPS_RTP.equals(descriptionNamespace)) {
|
||||||
connection = new JingleRtpConnection(this, id);
|
connection = new JingleRtpConnection(this, id, from);
|
||||||
} else {
|
} else {
|
||||||
//TODO return feature-not-implemented
|
//TODO return feature-not-implemented
|
||||||
return;
|
return;
|
||||||
|
@ -89,7 +89,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
|
||||||
final Element description = message.findChild("description");
|
final Element description = message.findChild("description");
|
||||||
final String namespace = description == null ? null : description.getNamespace();
|
final String namespace = description == null ? null : description.getNamespace();
|
||||||
if (Namespace.JINGLE_APPS_RTP.equals(namespace)) {
|
if (Namespace.JINGLE_APPS_RTP.equals(namespace)) {
|
||||||
final JingleRtpConnection rtpConnection = new JingleRtpConnection(this, id);
|
final JingleRtpConnection rtpConnection = new JingleRtpConnection(this, id, with);
|
||||||
this.connections.put(id, rtpConnection);
|
this.connections.put(id, rtpConnection);
|
||||||
rtpConnection.deliveryMessage(to, from, message);
|
rtpConnection.deliveryMessage(to, from, message);
|
||||||
} else {
|
} else {
|
||||||
|
@ -107,11 +107,12 @@ public class JingleConnectionManager extends AbstractConnectionManager {
|
||||||
if (old != null) {
|
if (old != null) {
|
||||||
old.cancel();
|
old.cancel();
|
||||||
}
|
}
|
||||||
|
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);
|
final JingleFileTransferConnection connection = new JingleFileTransferConnection(this, id, account.getJid());
|
||||||
mXmppConnectionService.markMessage(message, Message.STATUS_WAITING);
|
mXmppConnectionService.markMessage(message, Message.STATUS_WAITING);
|
||||||
connection.init(message);
|
|
||||||
this.connections.put(id, connection);
|
this.connections.put(id, connection);
|
||||||
|
connection.init(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void finishConnection(final AbstractJingleConnection connection) {
|
void finishConnection(final AbstractJingleConnection connection) {
|
||||||
|
|
|
@ -66,7 +66,6 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
|
||||||
private int mJingleStatus = JINGLE_STATUS_OFFERED; //migrate to enum
|
private int mJingleStatus = JINGLE_STATUS_OFFERED; //migrate to enum
|
||||||
private int mStatus = Transferable.STATUS_UNKNOWN;
|
private int mStatus = Transferable.STATUS_UNKNOWN;
|
||||||
private Message message;
|
private Message message;
|
||||||
private Jid initiator;
|
|
||||||
private Jid responder;
|
private Jid responder;
|
||||||
private List<JingleCandidate> candidates = new ArrayList<>();
|
private List<JingleCandidate> candidates = new ArrayList<>();
|
||||||
private ConcurrentHashMap<String, JingleSocks5Transport> connections = new ConcurrentHashMap<>();
|
private ConcurrentHashMap<String, JingleSocks5Transport> connections = new ConcurrentHashMap<>();
|
||||||
|
@ -178,7 +177,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void success() {
|
public void success() {
|
||||||
if (initiator.equals(id.account.getJid())) {
|
if (isInitiator()) {
|
||||||
Log.d(Config.LOGTAG, "we were initiating. sending file");
|
Log.d(Config.LOGTAG, "we were initiating. sending file");
|
||||||
transport.send(file, onFileTransmissionStatusChanged);
|
transport.send(file, onFileTransmissionStatusChanged);
|
||||||
} else {
|
} else {
|
||||||
|
@ -191,14 +190,14 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
|
||||||
public void failed() {
|
public void failed() {
|
||||||
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": proxy activation failed");
|
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": proxy activation failed");
|
||||||
proxyActivationFailed = true;
|
proxyActivationFailed = true;
|
||||||
if (initiating()) {
|
if (isInitiator()) {
|
||||||
sendFallbackToIbb();
|
sendFallbackToIbb();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public JingleFileTransferConnection(JingleConnectionManager jingleConnectionManager, Id id) {
|
public JingleFileTransferConnection(JingleConnectionManager jingleConnectionManager, Id id, Jid initiator) {
|
||||||
super(jingleConnectionManager, id);
|
super(jingleConnectionManager, id, initiator);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long parseLong(final Element element, final long l) {
|
private static long parseLong(final Element element, final long l) {
|
||||||
|
@ -213,13 +212,11 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO get rid and use isInitiator() instead
|
||||||
private boolean responding() {
|
private boolean responding() {
|
||||||
return responder != null && responder.equals(id.account.getJid());
|
return responder != null && responder.equals(id.account.getJid());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean initiating() {
|
|
||||||
return initiator.equals(id.account.getJid());
|
|
||||||
}
|
|
||||||
|
|
||||||
InputStream getFileInputStream() {
|
InputStream getFileInputStream() {
|
||||||
return this.mFileInputStream;
|
return this.mFileInputStream;
|
||||||
|
@ -346,7 +343,6 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
|
||||||
this.remoteSupportsOmemoJet = remoteFeatures.contains(Namespace.JINGLE_ENCRYPTED_TRANSPORT_OMEMO);
|
this.remoteSupportsOmemoJet = remoteFeatures.contains(Namespace.JINGLE_ENCRYPTED_TRANSPORT_OMEMO);
|
||||||
this.message.setTransferable(this);
|
this.message.setTransferable(this);
|
||||||
this.mStatus = Transferable.STATUS_UPLOADING;
|
this.mStatus = Transferable.STATUS_UPLOADING;
|
||||||
this.initiator = this.id.account.getJid();
|
|
||||||
this.responder = this.id.with;
|
this.responder = this.id.with;
|
||||||
this.transportId = JingleConnectionManager.nextRandomId();
|
this.transportId = JingleConnectionManager.nextRandomId();
|
||||||
this.setupDescription(remoteVersion);
|
this.setupDescription(remoteVersion);
|
||||||
|
@ -354,7 +350,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
|
||||||
this.sendInitRequest();
|
this.sendInitRequest();
|
||||||
} else {
|
} else {
|
||||||
gatherAndConnectDirectCandidates();
|
gatherAndConnectDirectCandidates();
|
||||||
this.jingleConnectionManager.getPrimaryCandidate(id.account, initiating(), (success, candidate) -> {
|
this.jingleConnectionManager.getPrimaryCandidate(id.account, isInitiator(), (success, candidate) -> {
|
||||||
if (success) {
|
if (success) {
|
||||||
final JingleSocks5Transport socksConnection = new JingleSocks5Transport(this, candidate);
|
final JingleSocks5Transport socksConnection = new JingleSocks5Transport(this, candidate);
|
||||||
connections.put(candidate.getCid(), socksConnection);
|
connections.put(candidate.getCid(), socksConnection);
|
||||||
|
@ -432,7 +428,6 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
|
||||||
this.mStatus = Transferable.STATUS_OFFER;
|
this.mStatus = Transferable.STATUS_OFFER;
|
||||||
this.message.setTransferable(this);
|
this.message.setTransferable(this);
|
||||||
this.message.setCounterpart(this.id.with);
|
this.message.setCounterpart(this.id.with);
|
||||||
this.initiator = this.id.with;
|
|
||||||
this.responder = this.id.account.getJid();
|
this.responder = this.id.account.getJid();
|
||||||
final Content content = packet.getJingleContent();
|
final Content content = packet.getJingleContent();
|
||||||
final GenericTransportInfo transportInfo = content.getTransport();
|
final GenericTransportInfo transportInfo = content.getTransport();
|
||||||
|
@ -643,7 +638,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
|
||||||
|
|
||||||
private void sendAcceptSocks() {
|
private void sendAcceptSocks() {
|
||||||
gatherAndConnectDirectCandidates();
|
gatherAndConnectDirectCandidates();
|
||||||
this.jingleConnectionManager.getPrimaryCandidate(this.id.account, initiating(), (success, candidate) -> {
|
this.jingleConnectionManager.getPrimaryCandidate(this.id.account, isInitiator(), (success, candidate) -> {
|
||||||
final JinglePacket packet = bootstrapPacket(JinglePacket.Action.SESSION_ACCEPT);
|
final JinglePacket packet = bootstrapPacket(JinglePacket.Action.SESSION_ACCEPT);
|
||||||
final Content content = new Content(contentCreator, contentName);
|
final Content content = new Content(contentCreator, contentName);
|
||||||
content.setDescription(this.description);
|
content.setDescription(this.description);
|
||||||
|
@ -810,7 +805,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
|
||||||
if (connection == null) {
|
if (connection == null) {
|
||||||
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": could not find suitable candidate");
|
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": could not find suitable candidate");
|
||||||
this.disconnectSocks5Connections();
|
this.disconnectSocks5Connections();
|
||||||
if (initiating()) {
|
if (isInitiator()) {
|
||||||
this.sendFallbackToIbb();
|
this.sendFallbackToIbb();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -852,7 +847,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
|
||||||
+ " was a proxy. waiting for other party to activate");
|
+ " was a proxy. waiting for other party to activate");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (initiating()) {
|
if (isInitiator()) {
|
||||||
Log.d(Config.LOGTAG, "we were initiating. sending file");
|
Log.d(Config.LOGTAG, "we were initiating. sending file");
|
||||||
connection.send(file, onFileTransmissionStatusChanged);
|
connection.send(file, onFileTransmissionStatusChanged);
|
||||||
} else {
|
} else {
|
||||||
|
@ -882,7 +877,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
|
||||||
} else if (connection.getCandidate().getPriority() == currentConnection
|
} else if (connection.getCandidate().getPriority() == currentConnection
|
||||||
.getCandidate().getPriority()) {
|
.getCandidate().getPriority()) {
|
||||||
// Log.d(Config.LOGTAG,"found two candidates with same priority");
|
// Log.d(Config.LOGTAG,"found two candidates with same priority");
|
||||||
if (initiating()) {
|
if (isInitiator()) {
|
||||||
if (currentConnection.getCandidate().isOurs()) {
|
if (currentConnection.getCandidate().isOurs()) {
|
||||||
connection = currentConnection;
|
connection = currentConnection;
|
||||||
}
|
}
|
||||||
|
@ -920,7 +915,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
|
||||||
|
|
||||||
|
|
||||||
private void receiveFallbackToIbb(final JinglePacket packet, final IbbTransportInfo transportInfo) {
|
private void receiveFallbackToIbb(final JinglePacket packet, final IbbTransportInfo transportInfo) {
|
||||||
if (initiating()) {
|
if (isInitiator()) {
|
||||||
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": received out of order transport-replace (we were initiating)");
|
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": received out of order transport-replace (we were initiating)");
|
||||||
respondToIqWithOutOfOrder(packet);
|
respondToIqWithOutOfOrder(packet);
|
||||||
return;
|
return;
|
||||||
|
@ -950,7 +945,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
|
||||||
|
|
||||||
respondToIq(packet, true);
|
respondToIq(packet, true);
|
||||||
|
|
||||||
if (initiating()) {
|
if (isInitiator()) {
|
||||||
this.sendJinglePacket(answer, (account, response) -> {
|
this.sendJinglePacket(answer, (account, response) -> {
|
||||||
if (response.getType() == IqPacket.TYPE.RESULT) {
|
if (response.getType() == IqPacket.TYPE.RESULT) {
|
||||||
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + " recipient ACKed our transport-accept. creating ibb");
|
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + " recipient ACKed our transport-accept. creating ibb");
|
||||||
|
@ -992,7 +987,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
|
||||||
}
|
}
|
||||||
respondToIq(packet, true);
|
respondToIq(packet, true);
|
||||||
//might be receive instead if we are not initiating
|
//might be receive instead if we are not initiating
|
||||||
if (initiating()) {
|
if (isInitiator()) {
|
||||||
this.transport.connect(onIbbTransportConnected);
|
this.transport.connect(onIbbTransportConnected);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1002,7 +997,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
|
||||||
}
|
}
|
||||||
|
|
||||||
private void receiveSuccess() {
|
private void receiveSuccess() {
|
||||||
if (initiating()) {
|
if (isInitiator()) {
|
||||||
this.mJingleStatus = JINGLE_STATUS_FINISHED;
|
this.mJingleStatus = JINGLE_STATUS_FINISHED;
|
||||||
this.xmppConnectionService.markMessage(this.message, Message.STATUS_SEND_RECEIVED);
|
this.xmppConnectionService.markMessage(this.message, Message.STATUS_SEND_RECEIVED);
|
||||||
this.disconnectSocks5Connections();
|
this.disconnectSocks5Connections();
|
||||||
|
|
|
@ -29,8 +29,8 @@ public class JingleRtpConnection extends AbstractJingleConnection {
|
||||||
private State state = State.NULL;
|
private State state = State.NULL;
|
||||||
|
|
||||||
|
|
||||||
public JingleRtpConnection(JingleConnectionManager jingleConnectionManager, Id id) {
|
public JingleRtpConnection(JingleConnectionManager jingleConnectionManager, Id id, Jid initiator) {
|
||||||
super(jingleConnectionManager, id);
|
super(jingleConnectionManager, id, initiator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -8,6 +8,7 @@ import com.google.common.base.Preconditions;
|
||||||
import eu.siacs.conversations.xml.Element;
|
import eu.siacs.conversations.xml.Element;
|
||||||
import eu.siacs.conversations.xml.Namespace;
|
import eu.siacs.conversations.xml.Namespace;
|
||||||
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
|
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
|
||||||
|
import rocks.xmpp.addr.Jid;
|
||||||
|
|
||||||
public class JinglePacket extends IqPacket {
|
public class JinglePacket extends IqPacket {
|
||||||
|
|
||||||
|
@ -52,6 +53,18 @@ public class JinglePacket extends IqPacket {
|
||||||
jingle.addChild(reason);
|
jingle.addChild(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//RECOMMENDED for session-initiate, NOT RECOMMENDED otherwise
|
||||||
|
public void setInitiator(final Jid initiator) {
|
||||||
|
Preconditions.checkArgument(initiator.isFullJid(), "initiator should be a full JID");
|
||||||
|
findChild("jingle", Namespace.JINGLE).setAttribute("initiator", initiator.toEscapedString());
|
||||||
|
}
|
||||||
|
|
||||||
|
//RECOMMENDED for session-accept, NOT RECOMMENDED otherwise
|
||||||
|
public void setResponder(Jid responder) {
|
||||||
|
Preconditions.checkArgument(responder.isFullJid(), "responder should be a full JID");
|
||||||
|
findChild("jingle", Namespace.JINGLE).setAttribute("responder", responder.toEscapedString());
|
||||||
|
}
|
||||||
|
|
||||||
public Element getJingleChild(final String name) {
|
public Element getJingleChild(final String name) {
|
||||||
final Element jingle = findChild("jingle", Namespace.JINGLE);
|
final Element jingle = findChild("jingle", Namespace.JINGLE);
|
||||||
return jingle == null ? null : jingle.findChild(name);
|
return jingle == null ? null : jingle.findChild(name);
|
||||||
|
|
Loading…
Reference in a new issue