use ibb if other party doesn’t annouce s5b feature

This commit is contained in:
Daniel Gultsch 2019-06-16 22:57:10 +02:00
parent fe6c981ae2
commit 9fc1ead74f
6 changed files with 1128 additions and 1132 deletions

View file

@ -101,7 +101,7 @@ public final class Config {
public static final boolean DISABLE_PROXY_LOOKUP = false; //useful to debug ibb
public static final boolean DISABLE_HTTP_UPLOAD = false;
public static final boolean DISABLE_HTTP_UPLOAD = true;
public static final boolean EXTENDED_SM_LOGGING = false; // log stanza counts
public static final boolean BACKGROUND_STANZA_LOGGING = false; //log all stanzas that were received while the app is in background
public static final boolean RESET_ATTEMPT_COUNT_ON_NETWORK_CHANGE = true; //setting to true might increase power consumption

View file

@ -27,8 +27,8 @@ public abstract class AbstractGenerator {
Content.Version.FT_3.getNamespace(),
Content.Version.FT_4.getNamespace(),
Content.Version.FT_5.getNamespace(),
"urn:xmpp:jingle:transports:s5b:1",
"urn:xmpp:jingle:transports:ibb:1",
Namespace.JINGLE_TRANSPORTS_S5B,
Namespace.JINGLE_TRANSPORTS_IBB,
"http://jabber.org/protocol/muc",
"jabber:x:conference",
Namespace.OOB,

View file

@ -25,4 +25,6 @@ public final class Namespace {
public static final String BOOKMARKS = "storage:bookmarks";
public static final String SYNCHRONIZATION = "im.quicksy.synchronization:0";
public static final String AVATAR_CONVERSION = "urn:xmpp:pep-vcard-conversion:0";
public static final String JINGLE_TRANSPORTS_S5B = "urn:xmpp:jingle:transports:s5b:1";
public static final String JINGLE_TRANSPORTS_IBB = "urn:xmpp:jingle:transports:ibb:1";
}

View file

@ -154,6 +154,7 @@ public class JingleInbandTransport extends JingleTransport {
if (count == -1) {
sendClose();
file.setSha1Sum(digest.digest());
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": sendNextBlock() count was -1");
this.onFileTransmissionStatusChanged.onFileTransmitted(file);
fileInputStream.close();
return;
@ -181,6 +182,7 @@ public class JingleInbandTransport extends JingleTransport {
} else {
sendClose();
file.setSha1Sum(digest.digest());
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": sendNextBlock() remaining size");
this.onFileTransmissionStatusChanged.onFileTransmitted(file);
fileInputStream.close();
}
@ -204,6 +206,7 @@ public class JingleInbandTransport extends JingleTransport {
file.setSha1Sum(digest.digest());
fileOutputStream.flush();
fileOutputStream.close();
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": receive next block nothing remaining");
this.onFileTransmissionStatusChanged.onFileTransmitted(file);
} else {
connection.updateProgress((int) ((((double) (this.fileSize - this.remainingSize)) / this.fileSize) * 100));

View file

@ -2,132 +2,129 @@ package eu.siacs.conversations.xmpp.jingle.stanzas;
import eu.siacs.conversations.entities.DownloadableFile;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xml.Namespace;
public class Content extends Element {
public enum Version {
FT_3("urn:xmpp:jingle:apps:file-transfer:3"),
FT_4("urn:xmpp:jingle:apps:file-transfer:4"),
FT_5("urn:xmpp:jingle:apps:file-transfer:5");
public enum Version {
FT_3("urn:xmpp:jingle:apps:file-transfer:3"),
FT_4("urn:xmpp:jingle:apps:file-transfer:4"),
FT_5("urn:xmpp:jingle:apps:file-transfer:5");
private final String namespace;
private final String namespace;
Version(String namespace) {
this.namespace = namespace;
}
Version(String namespace) {
this.namespace = namespace;
}
public String getNamespace() {
return namespace;
}
}
public String getNamespace() {
return namespace;
}
}
private String transportId;
private String transportId;
public Content() {
super("content");
}
public Content() {
super("content");
}
public Content(String creator, String name) {
super("content");
this.setAttribute("creator", creator);
this.setAttribute("senders", creator);
this.setAttribute("name", name);
}
public Content(String creator, String name) {
super("content");
this.setAttribute("creator", creator);
this.setAttribute("senders", creator);
this.setAttribute("name", name);
}
public Version getVersion() {
if (hasChild("description", Version.FT_3.namespace)) {
return Version.FT_3;
} else if (hasChild("description" , Version.FT_4.namespace)) {
return Version.FT_4;
} else if (hasChild("description" , Version.FT_5.namespace)) {
return Version.FT_5;
}
return null;
}
public Version getVersion() {
if (hasChild("description", Version.FT_3.namespace)) {
return Version.FT_3;
} else if (hasChild("description", Version.FT_4.namespace)) {
return Version.FT_4;
} else if (hasChild("description", Version.FT_5.namespace)) {
return Version.FT_5;
}
return null;
}
public void setTransportId(String sid) {
this.transportId = sid;
}
public void setTransportId(String sid) {
this.transportId = sid;
}
public Element setFileOffer(DownloadableFile actualFile, boolean otr, Version version) {
Element description = this.addChild("description", version.namespace);
Element file;
if (version == Version.FT_3) {
Element offer = description.addChild("offer");
file = offer.addChild("file");
} else {
file = description.addChild("file");
}
file.addChild("size").setContent(Long.toString(actualFile.getExpectedSize()));
if (otr) {
file.addChild("name").setContent(actualFile.getName() + ".otr");
} else {
file.addChild("name").setContent(actualFile.getName());
}
return file;
}
public Element setFileOffer(DownloadableFile actualFile, boolean otr, Version version) {
Element description = this.addChild("description", version.namespace);
Element file;
if (version == Version.FT_3) {
Element offer = description.addChild("offer");
file = offer.addChild("file");
} else {
file = description.addChild("file");
}
file.addChild("size").setContent(Long.toString(actualFile.getExpectedSize()));
if (otr) {
file.addChild("name").setContent(actualFile.getName() + ".otr");
} else {
file.addChild("name").setContent(actualFile.getName());
}
return file;
}
public Element getFileOffer(Version version) {
Element description = this.findChild("description", version.namespace);
if (description == null) {
return null;
}
if (version == Version.FT_3) {
Element offer = description.findChild("offer");
if (offer == null) {
return null;
}
return offer.findChild("file");
} else {
return description.findChild("file");
}
}
public Element getFileOffer(Version version) {
Element description = this.findChild("description", version.namespace);
if (description == null) {
return null;
}
if (version == Version.FT_3) {
Element offer = description.findChild("offer");
if (offer == null) {
return null;
}
return offer.findChild("file");
} else {
return description.findChild("file");
}
}
public void setFileOffer(Element fileOffer, Version version) {
Element description = this.addChild("description", version.namespace);
if (version == Version.FT_3) {
description.addChild("offer").addChild(fileOffer);
} else {
description.addChild(fileOffer);
}
}
public void setFileOffer(Element fileOffer, Version version) {
Element description = this.addChild("description", version.namespace);
if (version == Version.FT_3) {
description.addChild("offer").addChild(fileOffer);
} else {
description.addChild(fileOffer);
}
}
public String getTransportId() {
if (hasSocks5Transport()) {
this.transportId = socks5transport().getAttribute("sid");
} else if (hasIbbTransport()) {
this.transportId = ibbTransport().getAttribute("sid");
}
return this.transportId;
}
public String getTransportId() {
if (hasSocks5Transport()) {
this.transportId = socks5transport().getAttribute("sid");
} else if (hasIbbTransport()) {
this.transportId = ibbTransport().getAttribute("sid");
}
return this.transportId;
}
public Element socks5transport() {
Element transport = this.findChild("transport",
"urn:xmpp:jingle:transports:s5b:1");
if (transport == null) {
transport = this.addChild("transport",
"urn:xmpp:jingle:transports:s5b:1");
transport.setAttribute("sid", this.transportId);
}
return transport;
}
public Element socks5transport() {
Element transport = this.findChild("transport", Namespace.JINGLE_TRANSPORTS_S5B);
if (transport == null) {
transport = this.addChild("transport", Namespace.JINGLE_TRANSPORTS_S5B);
transport.setAttribute("sid", this.transportId);
}
return transport;
}
public Element ibbTransport() {
Element transport = this.findChild("transport",
"urn:xmpp:jingle:transports:ibb:1");
if (transport == null) {
transport = this.addChild("transport",
"urn:xmpp:jingle:transports:ibb:1");
transport.setAttribute("sid", this.transportId);
}
return transport;
}
public Element ibbTransport() {
Element transport = this.findChild("transport", Namespace.JINGLE_TRANSPORTS_IBB);
if (transport == null) {
transport = this.addChild("transport", Namespace.JINGLE_TRANSPORTS_IBB);
transport.setAttribute("sid", this.transportId);
}
return transport;
}
public boolean hasSocks5Transport() {
return this.hasChild("transport", "urn:xmpp:jingle:transports:s5b:1");
}
public boolean hasSocks5Transport() {
return this.hasChild("transport", Namespace.JINGLE_TRANSPORTS_S5B);
}
public boolean hasIbbTransport() {
return this.hasChild("transport", "urn:xmpp:jingle:transports:ibb:1");
}
public boolean hasIbbTransport() {
return this.hasChild("transport", Namespace.JINGLE_TRANSPORTS_IBB);
}
}