aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2019-06-17 21:36:39 +0200
committerChristian Schneppe <christian@pix-art.de>2019-06-17 21:36:39 +0200
commit4af2b29330f4ed7ba618bf9c27fc93e2d9390eb1 (patch)
tree65e40a2f2ea2c8dcf2bd45e6744c8e02ce71d395
parentd53a616e20494ceb0e5bdd1dc02b40282b6a77dc (diff)
accept direct ibb jingle offers
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java68
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/jingle/Transport.java5
2 files changed, 58 insertions, 15 deletions
diff --git a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java
index 19c9ca8cd..33281adbb 100644
--- a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java
+++ b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java
@@ -77,6 +77,7 @@ public class JingleConnection implements Transferable {
private String contentName;
private String contentCreator;
+ private Transport initialTransport;
private int mProgress = 0;
@@ -169,6 +170,18 @@ public class JingleConnection implements Transferable {
return this.mFileOutputStream;
}
+ private OnTransportConnected onIbbTransportConnected = new OnTransportConnected() {
+ @Override
+ public void failed() {
+ Log.d(Config.LOGTAG, "ibb open failed");
+ }
+
+ @Override
+ public void established() {
+ JingleConnection.this.transport.send(file, onFileTransmissionStatusChanged);
+ }
+ };
+
private OnProxyActivated onProxyActivated = new OnProxyActivated() {
@Override
@@ -368,9 +381,27 @@ public class JingleConnection implements Transferable {
this.sessionId = packet.getSessionId();
Content content = packet.getJingleContent();
this.contentCreator = content.getAttribute("creator");
+ this.initialTransport = content.hasSocks5Transport() ? Transport.SOCKS : Transport.IBB;
this.contentName = content.getAttribute("name");
this.transportId = content.getTransportId();
- this.mergeCandidates(JingleCandidate.parse(content.socks5transport().getChildren()));
+ if (this.initialTransport == Transport.SOCKS) {
+ this.mergeCandidates(JingleCandidate.parse(content.socks5transport().getChildren()));
+ } else if (this.initialTransport == Transport.IBB) {
+ final String receivedBlockSize = content.ibbTransport().getAttribute("block-size");
+ if (receivedBlockSize != null) {
+ try {
+ this.ibbBlockSize = Math.min(Integer.parseInt(receivedBlockSize), this.ibbBlockSize);
+ } catch (NumberFormatException e) {
+ this.sendCancel();
+ this.fail();
+ return;
+ }
+ } else {
+ this.sendCancel();
+ this.fail();
+ return;
+ }
+ }
this.ftVersion = content.getVersion();
if (ftVersion == null) {
this.sendCancel();
@@ -558,6 +589,14 @@ public class JingleConnection implements Transferable {
mJingleStatus = JINGLE_STATUS_ACCEPTED;
this.mStatus = Transferable.STATUS_DOWNLOADING;
this.mJingleConnectionManager.updateConversationUi(true);
+ if (initialTransport == Transport.SOCKS) {
+ sendAcceptSocks();
+ } else {
+ sendAcceptIbb();
+ }
+ }
+
+ private void sendAcceptSocks() {
this.mJingleConnectionManager.getPrimaryCandidate(this.account, new OnPrimaryCandidateFound() {
@Override
public void onPrimaryCandidateFound(boolean success, final JingleCandidate candidate) {
@@ -602,6 +641,17 @@ public class JingleConnection implements Transferable {
});
}
+ private void sendAcceptIbb() {
+ this.transport = new JingleInbandTransport(this, this.transportId, this.ibbBlockSize);
+ final JinglePacket packet = bootstrapPacket("session-accept");
+ final Content content = new Content(contentCreator, contentName);
+ content.setFileOffer(fileOffer, ftVersion);
+ content.setTransportId(transportId);
+ content.ibbTransport().setAttribute("block-size", this.ibbBlockSize);
+ packet.setContent(content);
+ this.sendJinglePacket(packet);
+ }
+
private JinglePacket bootstrapPacket(String action) {
JinglePacket packet = new JinglePacket();
packet.setAction(action);
@@ -811,18 +861,6 @@ public class JingleConnection implements Transferable {
this.sendJinglePacket(packet);
}
- OnTransportConnected onIbbTransportConnected = new OnTransportConnected() {
- @Override
- public void failed() {
- Log.d(Config.LOGTAG, "ibb open failed");
- }
-
- @Override
- public void established() {
- JingleConnection.this.transport.send(file, onFileTransmissionStatusChanged);
- }
- };
-
private boolean receiveFallbackToIbb(JinglePacket packet) {
Log.d(Config.LOGTAG, "receiving fallack to ibb");
String receivedBlockSize = packet.getJingleContent().ibbTransport()
@@ -836,8 +874,8 @@ public class JingleConnection implements Transferable {
this.transportId = packet.getJingleContent().getTransportId();
this.transport = new JingleInbandTransport(this, this.transportId, this.ibbBlockSize);
JinglePacket answer = bootstrapPacket("transport-accept");
- Content content = new Content("initiator", "a-file-offer");
- content.setTransportId(this.transportId);
+ final Content content = new Content(contentCreator, contentName);
+ content.setFileOffer(fileOffer, ftVersion);
content.ibbTransport().setAttribute("block-size", this.ibbBlockSize);
answer.setContent(content);
diff --git a/src/main/java/de/pixart/messenger/xmpp/jingle/Transport.java b/src/main/java/de/pixart/messenger/xmpp/jingle/Transport.java
new file mode 100644
index 000000000..23b7cf3ee
--- /dev/null
+++ b/src/main/java/de/pixart/messenger/xmpp/jingle/Transport.java
@@ -0,0 +1,5 @@
+package de.pixart.messenger.xmpp.jingle;
+
+public enum Transport {
+ SOCKS, IBB
+}