code cleanup for jingle proxy discovery
This commit is contained in:
parent
d9f88c4669
commit
0a48f777ac
|
@ -4,4 +4,5 @@ public final class Xmlns {
|
||||||
public static final String BLOCKING = "urn:xmpp:blocking";
|
public static final String BLOCKING = "urn:xmpp:blocking";
|
||||||
public static final String ROSTER = "jabber:iq:roster";
|
public static final String ROSTER = "jabber:iq:roster";
|
||||||
public static final String REGISTER = "jabber:iq:register";
|
public static final String REGISTER = "jabber:iq:register";
|
||||||
|
public static final String BYTE_STREAMS = "http://jabber.org/protocol/bytestreams";
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,8 +85,7 @@ public class JingleCandidate {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equalValues(JingleCandidate other) {
|
public boolean equalValues(JingleCandidate other) {
|
||||||
return other.getHost().equals(this.getHost())
|
return other != null && other.getHost().equals(this.getHost()) && (other.getPort() == this.getPort());
|
||||||
&& (other.getPort() == this.getPort());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOurs() {
|
public boolean isOurs() {
|
||||||
|
|
|
@ -396,29 +396,24 @@ public class JingleConnection implements Downloadable {
|
||||||
mJingleStatus = JINGLE_STATUS_ACCEPTED;
|
mJingleStatus = JINGLE_STATUS_ACCEPTED;
|
||||||
this.mStatus = Downloadable.STATUS_DOWNLOADING;
|
this.mStatus = Downloadable.STATUS_DOWNLOADING;
|
||||||
mXmppConnectionService.updateConversationUi();
|
mXmppConnectionService.updateConversationUi();
|
||||||
this.mJingleConnectionManager.getPrimaryCandidate(this.account,
|
this.mJingleConnectionManager.getPrimaryCandidate(this.account, new OnPrimaryCandidateFound() {
|
||||||
new OnPrimaryCandidateFound() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPrimaryCandidateFound(boolean success,
|
public void onPrimaryCandidateFound(boolean success, final JingleCandidate candidate) {
|
||||||
final JingleCandidate candidate) {
|
|
||||||
final JinglePacket packet = bootstrapPacket("session-accept");
|
final JinglePacket packet = bootstrapPacket("session-accept");
|
||||||
final Content content = new Content(contentCreator,
|
final Content content = new Content(contentCreator,contentName);
|
||||||
contentName);
|
|
||||||
content.setFileOffer(fileOffer);
|
content.setFileOffer(fileOffer);
|
||||||
content.setTransportId(transportId);
|
content.setTransportId(transportId);
|
||||||
if ((success) && (!equalCandidateExists(candidate))) {
|
if (success && candidate != null && !equalCandidateExists(candidate)) {
|
||||||
final JingleSocks5Transport socksConnection = new JingleSocks5Transport(
|
final JingleSocks5Transport socksConnection = new JingleSocks5Transport(
|
||||||
JingleConnection.this, candidate);
|
JingleConnection.this,
|
||||||
|
candidate);
|
||||||
connections.put(candidate.getCid(), socksConnection);
|
connections.put(candidate.getCid(), socksConnection);
|
||||||
socksConnection.connect(new OnTransportConnected() {
|
socksConnection.connect(new OnTransportConnected() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void failed() {
|
public void failed() {
|
||||||
Log.d(Config.LOGTAG,
|
Log.d(Config.LOGTAG,"connection to our own primary candidate failed");
|
||||||
"connection to our own primary candidate failed");
|
content.socks5transport().setChildren(getCandidatesAsElements());
|
||||||
content.socks5transport().setChildren(
|
|
||||||
getCandidatesAsElements());
|
|
||||||
packet.setContent(content);
|
packet.setContent(content);
|
||||||
sendJinglePacket(packet);
|
sendJinglePacket(packet);
|
||||||
connectNextCandidate();
|
connectNextCandidate();
|
||||||
|
@ -426,28 +421,23 @@ public class JingleConnection implements Downloadable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void established() {
|
public void established() {
|
||||||
Log.d(Config.LOGTAG,
|
Log.d(Config.LOGTAG, "connected to primary candidate");
|
||||||
"connected to primary candidate");
|
|
||||||
mergeCandidate(candidate);
|
mergeCandidate(candidate);
|
||||||
content.socks5transport().setChildren(
|
content.socks5transport().setChildren(getCandidatesAsElements());
|
||||||
getCandidatesAsElements());
|
|
||||||
packet.setContent(content);
|
packet.setContent(content);
|
||||||
sendJinglePacket(packet);
|
sendJinglePacket(packet);
|
||||||
connectNextCandidate();
|
connectNextCandidate();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Log.d(Config.LOGTAG,
|
Log.d(Config.LOGTAG,"did not find a primary candidate for ourself");
|
||||||
"did not find a primary candidate for ourself");
|
content.socks5transport().setChildren(getCandidatesAsElements());
|
||||||
content.socks5transport().setChildren(
|
|
||||||
getCandidatesAsElements());
|
|
||||||
packet.setContent(content);
|
packet.setContent(content);
|
||||||
sendJinglePacket(packet);
|
sendJinglePacket(packet);
|
||||||
connectNextCandidate();
|
connectNextCandidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private JinglePacket bootstrapPacket(String action) {
|
private JinglePacket bootstrapPacket(String action) {
|
||||||
|
@ -479,16 +469,13 @@ public class JingleConnection implements Downloadable {
|
||||||
Content content = packet.getJingleContent();
|
Content content = packet.getJingleContent();
|
||||||
if (content.hasSocks5Transport()) {
|
if (content.hasSocks5Transport()) {
|
||||||
if (content.socks5transport().hasChild("activated")) {
|
if (content.socks5transport().hasChild("activated")) {
|
||||||
if ((this.transport != null)
|
if ((this.transport != null) && (this.transport instanceof JingleSocks5Transport)) {
|
||||||
&& (this.transport instanceof JingleSocks5Transport)) {
|
|
||||||
onProxyActivated.success();
|
onProxyActivated.success();
|
||||||
} else {
|
} else {
|
||||||
String cid = content.socks5transport()
|
String cid = content.socks5transport().findChild("activated").getAttribute("cid");
|
||||||
.findChild("activated").getAttribute("cid");
|
|
||||||
Log.d(Config.LOGTAG, "received proxy activated (" + cid
|
Log.d(Config.LOGTAG, "received proxy activated (" + cid
|
||||||
+ ")prior to choosing our own transport");
|
+ ")prior to choosing our own transport");
|
||||||
JingleSocks5Transport connection = this.connections
|
JingleSocks5Transport connection = this.connections.get(cid);
|
||||||
.get(cid);
|
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
connection.setActivated(true);
|
connection.setActivated(true);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -12,6 +12,7 @@ import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.entities.Message;
|
import eu.siacs.conversations.entities.Message;
|
||||||
import eu.siacs.conversations.services.AbstractConnectionManager;
|
import eu.siacs.conversations.services.AbstractConnectionManager;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService;
|
import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
|
import eu.siacs.conversations.utils.Xmlns;
|
||||||
import eu.siacs.conversations.xml.Element;
|
import eu.siacs.conversations.xml.Element;
|
||||||
import eu.siacs.conversations.xmpp.OnIqPacketReceived;
|
import eu.siacs.conversations.xmpp.OnIqPacketReceived;
|
||||||
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
||||||
|
@ -80,46 +81,34 @@ public class JingleConnectionManager extends AbstractConnectionManager {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!this.primaryCandidates.containsKey(account.getJid().toBareJid())) {
|
if (!this.primaryCandidates.containsKey(account.getJid().toBareJid())) {
|
||||||
String xmlns = "http://jabber.org/protocol/bytestreams";
|
final String proxy = account.getXmppConnection().findDiscoItemByFeature(Xmlns.BYTE_STREAMS);
|
||||||
final String proxy = account.getXmppConnection()
|
|
||||||
.findDiscoItemByFeature(xmlns);
|
|
||||||
if (proxy != null) {
|
if (proxy != null) {
|
||||||
IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
|
IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
|
||||||
iq.setAttribute("to", proxy);
|
iq.setAttribute("to", proxy);
|
||||||
iq.query(xmlns);
|
iq.query(Xmlns.BYTE_STREAMS);
|
||||||
account.getXmppConnection().sendIqPacket(iq,
|
account.getXmppConnection().sendIqPacket(iq,new OnIqPacketReceived() {
|
||||||
new OnIqPacketReceived() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onIqPacketReceived(Account account,
|
public void onIqPacketReceived(Account account, IqPacket packet) {
|
||||||
IqPacket packet) {
|
Element streamhost = packet.query().findChild("streamhost",Xmlns.BYTE_STREAMS);
|
||||||
Element streamhost = packet
|
final String host = streamhost == null ? null : streamhost.getAttribute("host");
|
||||||
.query()
|
final String port = streamhost == null ? null : streamhost.getAttribute("port");
|
||||||
.findChild("streamhost",
|
if (host != null && port != null) {
|
||||||
"http://jabber.org/protocol/bytestreams");
|
|
||||||
if (streamhost != null) {
|
|
||||||
JingleCandidate candidate = new JingleCandidate(
|
|
||||||
nextRandomId(), true);
|
|
||||||
candidate.setHost(streamhost
|
|
||||||
.getAttribute("host"));
|
|
||||||
candidate.setPort(Integer
|
|
||||||
.parseInt(streamhost
|
|
||||||
.getAttribute("port")));
|
|
||||||
candidate
|
|
||||||
.setType(JingleCandidate.TYPE_PROXY);
|
|
||||||
try {
|
try {
|
||||||
|
JingleCandidate candidate = new JingleCandidate(nextRandomId(), true);
|
||||||
|
candidate.setHost(host);
|
||||||
|
candidate.setPort(Integer.parseInt(port));
|
||||||
|
candidate.setType(JingleCandidate.TYPE_PROXY);
|
||||||
candidate.setJid(Jid.fromString(proxy));
|
candidate.setJid(Jid.fromString(proxy));
|
||||||
} catch (final InvalidJidException e) {
|
|
||||||
candidate.setJid(null);
|
|
||||||
}
|
|
||||||
candidate.setPriority(655360 + 65535);
|
candidate.setPriority(655360 + 65535);
|
||||||
primaryCandidates.put(account.getJid().toBareJid(),
|
primaryCandidates.put(account.getJid().toBareJid(),candidate);
|
||||||
candidate);
|
listener.onPrimaryCandidateFound(true,candidate);
|
||||||
listener.onPrimaryCandidateFound(true,
|
} catch (final NumberFormatException | InvalidJidException e) {
|
||||||
candidate);
|
listener.onPrimaryCandidateFound(false,null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
listener.onPrimaryCandidateFound(false,
|
listener.onPrimaryCandidateFound(false,null);
|
||||||
null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -141,12 +130,10 @@ public class JingleConnectionManager extends AbstractConnectionManager {
|
||||||
String sid = null;
|
String sid = null;
|
||||||
Element payload = null;
|
Element payload = null;
|
||||||
if (packet.hasChild("open", "http://jabber.org/protocol/ibb")) {
|
if (packet.hasChild("open", "http://jabber.org/protocol/ibb")) {
|
||||||
payload = packet
|
payload = packet.findChild("open", "http://jabber.org/protocol/ibb");
|
||||||
.findChild("open", "http://jabber.org/protocol/ibb");
|
|
||||||
sid = payload.getAttribute("sid");
|
sid = payload.getAttribute("sid");
|
||||||
} else if (packet.hasChild("data", "http://jabber.org/protocol/ibb")) {
|
} else if (packet.hasChild("data", "http://jabber.org/protocol/ibb")) {
|
||||||
payload = packet
|
payload = packet.findChild("data", "http://jabber.org/protocol/ibb");
|
||||||
.findChild("data", "http://jabber.org/protocol/ibb");
|
|
||||||
sid = payload.getAttribute("sid");
|
sid = payload.getAttribute("sid");
|
||||||
}
|
}
|
||||||
if (sid != null) {
|
if (sid != null) {
|
||||||
|
@ -161,10 +148,9 @@ public class JingleConnectionManager extends AbstractConnectionManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.d(Config.LOGTAG,
|
Log.d(Config.LOGTAG,"couldn't deliver payload: " + payload.toString());
|
||||||
"couldnt deliver payload: " + payload.toString());
|
|
||||||
} else {
|
} else {
|
||||||
Log.d(Config.LOGTAG, "no sid found in incomming ibb packet");
|
Log.d(Config.LOGTAG, "no sid found in incoming ibb packet");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue