accept direct ibb jingle offers
This commit is contained in:
parent
1cfba86aff
commit
fe6c981ae2
|
@ -2,7 +2,6 @@ package eu.siacs.conversations.xmpp.jingle;
|
||||||
|
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
@ -74,6 +73,7 @@ public class JingleConnection implements Transferable {
|
||||||
|
|
||||||
private String contentName;
|
private String contentName;
|
||||||
private String contentCreator;
|
private String contentCreator;
|
||||||
|
private Transport initialTransport;
|
||||||
|
|
||||||
private int mProgress = 0;
|
private int mProgress = 0;
|
||||||
|
|
||||||
|
@ -167,6 +167,18 @@ public class JingleConnection implements Transferable {
|
||||||
return this.mFileOutputStream;
|
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() {
|
private OnProxyActivated onProxyActivated = new OnProxyActivated() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -368,9 +380,27 @@ public class JingleConnection implements Transferable {
|
||||||
this.sessionId = packet.getSessionId();
|
this.sessionId = packet.getSessionId();
|
||||||
Content content = packet.getJingleContent();
|
Content content = packet.getJingleContent();
|
||||||
this.contentCreator = content.getAttribute("creator");
|
this.contentCreator = content.getAttribute("creator");
|
||||||
|
this.initialTransport = content.hasSocks5Transport() ? Transport.SOCKS : Transport.IBB;
|
||||||
this.contentName = content.getAttribute("name");
|
this.contentName = content.getAttribute("name");
|
||||||
this.transportId = content.getTransportId();
|
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();
|
this.ftVersion = content.getVersion();
|
||||||
if (ftVersion == null) {
|
if (ftVersion == null) {
|
||||||
this.sendCancel();
|
this.sendCancel();
|
||||||
|
@ -532,6 +562,14 @@ public class JingleConnection implements Transferable {
|
||||||
mJingleStatus = JINGLE_STATUS_ACCEPTED;
|
mJingleStatus = JINGLE_STATUS_ACCEPTED;
|
||||||
this.mStatus = Transferable.STATUS_DOWNLOADING;
|
this.mStatus = Transferable.STATUS_DOWNLOADING;
|
||||||
this.mJingleConnectionManager.updateConversationUi(true);
|
this.mJingleConnectionManager.updateConversationUi(true);
|
||||||
|
if (initialTransport == Transport.SOCKS) {
|
||||||
|
sendAcceptSocks();
|
||||||
|
} else {
|
||||||
|
sendAcceptIbb();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendAcceptSocks() {
|
||||||
this.mJingleConnectionManager.getPrimaryCandidate(this.account, new OnPrimaryCandidateFound() {
|
this.mJingleConnectionManager.getPrimaryCandidate(this.account, new OnPrimaryCandidateFound() {
|
||||||
@Override
|
@Override
|
||||||
public void onPrimaryCandidateFound(boolean success, final JingleCandidate candidate) {
|
public void onPrimaryCandidateFound(boolean success, final JingleCandidate candidate) {
|
||||||
|
@ -576,6 +614,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) {
|
private JinglePacket bootstrapPacket(String action) {
|
||||||
JinglePacket packet = new JinglePacket();
|
JinglePacket packet = new JinglePacket();
|
||||||
packet.setAction(action);
|
packet.setAction(action);
|
||||||
|
@ -785,17 +834,6 @@ public class JingleConnection implements Transferable {
|
||||||
this.sendJinglePacket(packet);
|
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) {
|
private boolean receiveFallbackToIbb(JinglePacket packet) {
|
||||||
Log.d(Config.LOGTAG, "receiving fallack to ibb");
|
Log.d(Config.LOGTAG, "receiving fallack to ibb");
|
||||||
|
@ -811,8 +849,9 @@ public class JingleConnection implements Transferable {
|
||||||
this.transport = new JingleInbandTransport(this, this.transportId, this.ibbBlockSize);
|
this.transport = new JingleInbandTransport(this, this.transportId, this.ibbBlockSize);
|
||||||
|
|
||||||
JinglePacket answer = bootstrapPacket("transport-accept");
|
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);
|
content.ibbTransport().setAttribute("block-size",this.ibbBlockSize);
|
||||||
answer.setContent(content);
|
answer.setContent(content);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package eu.siacs.conversations.xmpp.jingle;
|
||||||
|
|
||||||
|
public enum Transport {
|
||||||
|
SOCKS, IBB
|
||||||
|
}
|
Loading…
Reference in a new issue