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