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,58 +396,48 @@ 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
|
||||||
|
public void onPrimaryCandidateFound(boolean success, final JingleCandidate candidate) {
|
||||||
|
final JinglePacket packet = bootstrapPacket("session-accept");
|
||||||
|
final Content content = new Content(contentCreator,contentName);
|
||||||
|
content.setFileOffer(fileOffer);
|
||||||
|
content.setTransportId(transportId);
|
||||||
|
if (success && candidate != null && !equalCandidateExists(candidate)) {
|
||||||
|
final JingleSocks5Transport socksConnection = new JingleSocks5Transport(
|
||||||
|
JingleConnection.this,
|
||||||
|
candidate);
|
||||||
|
connections.put(candidate.getCid(), socksConnection);
|
||||||
|
socksConnection.connect(new OnTransportConnected() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPrimaryCandidateFound(boolean success,
|
public void failed() {
|
||||||
final JingleCandidate candidate) {
|
Log.d(Config.LOGTAG,"connection to our own primary candidate failed");
|
||||||
final JinglePacket packet = bootstrapPacket("session-accept");
|
content.socks5transport().setChildren(getCandidatesAsElements());
|
||||||
final Content content = new Content(contentCreator,
|
|
||||||
contentName);
|
|
||||||
content.setFileOffer(fileOffer);
|
|
||||||
content.setTransportId(transportId);
|
|
||||||
if ((success) && (!equalCandidateExists(candidate))) {
|
|
||||||
final JingleSocks5Transport socksConnection = new JingleSocks5Transport(
|
|
||||||
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());
|
|
||||||
packet.setContent(content);
|
|
||||||
sendJinglePacket(packet);
|
|
||||||
connectNextCandidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void established() {
|
|
||||||
Log.d(Config.LOGTAG,
|
|
||||||
"connected to primary candidate");
|
|
||||||
mergeCandidate(candidate);
|
|
||||||
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());
|
|
||||||
packet.setContent(content);
|
packet.setContent(content);
|
||||||
sendJinglePacket(packet);
|
sendJinglePacket(packet);
|
||||||
connectNextCandidate();
|
connectNextCandidate();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void established() {
|
||||||
|
Log.d(Config.LOGTAG, "connected to primary candidate");
|
||||||
|
mergeCandidate(candidate);
|
||||||
|
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());
|
||||||
|
packet.setContent(content);
|
||||||
|
sendJinglePacket(packet);
|
||||||
|
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,49 +81,37 @@ 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");
|
try {
|
||||||
if (streamhost != null) {
|
JingleCandidate candidate = new JingleCandidate(nextRandomId(), true);
|
||||||
JingleCandidate candidate = new JingleCandidate(
|
candidate.setHost(host);
|
||||||
nextRandomId(), true);
|
candidate.setPort(Integer.parseInt(port));
|
||||||
candidate.setHost(streamhost
|
candidate.setType(JingleCandidate.TYPE_PROXY);
|
||||||
.getAttribute("host"));
|
candidate.setJid(Jid.fromString(proxy));
|
||||||
candidate.setPort(Integer
|
candidate.setPriority(655360 + 65535);
|
||||||
.parseInt(streamhost
|
primaryCandidates.put(account.getJid().toBareJid(),candidate);
|
||||||
.getAttribute("port")));
|
listener.onPrimaryCandidateFound(true,candidate);
|
||||||
candidate
|
} catch (final NumberFormatException | InvalidJidException e) {
|
||||||
.setType(JingleCandidate.TYPE_PROXY);
|
listener.onPrimaryCandidateFound(false,null);
|
||||||
try {
|
return;
|
||||||
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);
|
|
||||||
} else {
|
|
||||||
listener.onPrimaryCandidateFound(false,
|
|
||||||
null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
listener.onPrimaryCandidateFound(false,null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
listener.onPrimaryCandidateFound(false, null);
|
listener.onPrimaryCandidateFound(false, 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 New Issue