aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-04-10 14:12:08 +0200
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-04-10 14:12:08 +0200
commit644473205ab261157f500470d496999db665d75f (patch)
treeca059f9b294bfaa79c6ed8dfb3d6fedddcaecf06 /src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java
parentba0bedc5facabc573023925660d7d49b27d5c68c (diff)
incomming jingle packets are routed to their connection. added presence chooser in gui
Diffstat (limited to 'src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java')
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java112
1 files changed, 73 insertions, 39 deletions
diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java b/src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java
index 784d90d4..b28f692a 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java
@@ -17,76 +17,110 @@ import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket;
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
public class JingleConnectionManager {
-
+
private XmppConnectionService xmppConnectionService;
-
- private List<JingleConnection> connections = new ArrayList<JingleConnection>(); //make concurrent
-
+
+ private List<JingleConnection> connections = new ArrayList<JingleConnection>(); // make
+ // concurrent
+
private ConcurrentHashMap<String, Element> primaryCanditates = new ConcurrentHashMap<String, Element>();
-
+
private SecureRandom random = new SecureRandom();
-
+
public JingleConnectionManager(XmppConnectionService service) {
this.xmppConnectionService = service;
}
-
+
public void deliverPacket(Account account, JinglePacket packet) {
- String id = generateInternalId(account.getJid(), packet.getFrom(), packet.getSessionId());
+ for (JingleConnection connection : connections) {
+ if (connection.getAccountJid().equals(account.getJid()) && connection
+ .getSessionId().equals(packet.getSessionId()) && connection
+ .getCounterPart().equals(packet.getFrom())) {
+ connection.deliverPacket(packet);
+ return;
+ }
+ }
+ Log.d("xmppService","delivering packet failed "+packet.toString());
}
-
+
public JingleConnection createNewConnection(Message message) {
Account account = message.getConversation().getAccount();
JingleConnection connection = new JingleConnection(this);
- String id = generateInternalId(account.getJid(), message.getCounterpart(), connection.getSessionId());
connection.init(message);
+ connections.add(connection);
return connection;
}
-
- private String generateInternalId(String account, String counterpart, String sid) {
- return account+"#"+counterpart+"#"+sid;
-
+
+ public JingleConnection createNewConnection(JinglePacket packet) {
+ JingleConnection connection = new JingleConnection(this);
+ connections.add(connection);
+ return connection;
+ }
+
+ private String generateInternalId(String account, String counterpart,
+ String sid) {
+ return account + "#" + counterpart + "#" + sid;
+
}
public XmppConnectionService getXmppConnectionService() {
return this.xmppConnectionService;
}
- public void getPrimaryCanditate(Account account, final OnPrimaryCanditateFound listener) {
+ public void getPrimaryCanditate(Account account,
+ final OnPrimaryCanditateFound listener) {
if (!this.primaryCanditates.containsKey(account.getJid())) {
String xmlns = "http://jabber.org/protocol/bytestreams";
- String proxy = account.getXmppConnection().findDiscoItemByFeature(xmlns);
- if (proxy!=null) {
+ final String proxy = account.getXmppConnection()
+ .findDiscoItemByFeature(xmlns);
+ if (proxy != null) {
IqPacket iq = new IqPacket(IqPacket.TYPE_GET);
iq.setTo(proxy);
iq.query(xmlns);
- 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) {
- Log.d("xmppService","streamhost found "+streamhost.toString());
- Element canditate = new Element("canditate");
- canditate.setAttribute("cid",nextRandomId());
- canditate.setAttribute("host", streamhost.getAttribute("host"));
- canditate.setAttribute("port",streamhost.getAttribute("port"));
- canditate.setAttribute("type", "proxy");
- primaryCanditates.put(account.getJid(), canditate);
- listener.onPrimaryCanditateFound(true, canditate);
- } else {
- listener.onPrimaryCanditateFound(false, null);
- }
- }
- });
+ 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) {
+ Log.d("xmppService", "streamhost found "
+ + streamhost.toString());
+ Element canditate = new Element("canditate");
+ canditate.setAttribute("cid",
+ nextRandomId());
+ canditate.setAttribute("host",
+ streamhost.getAttribute("host"));
+ canditate.setAttribute("port",
+ streamhost.getAttribute("port"));
+ canditate.setAttribute("type", "proxy");
+ canditate.setAttribute("jid", proxy);
+ canditate
+ .setAttribute("priority", "655360");
+ primaryCanditates.put(account.getJid(),
+ canditate);
+ listener.onPrimaryCanditateFound(true,
+ canditate);
+ } else {
+ listener.onPrimaryCanditateFound(false,
+ null);
+ }
+ }
+ });
} else {
listener.onPrimaryCanditateFound(false, null);
}
-
+
} else {
- listener.onPrimaryCanditateFound(true, this.primaryCanditates.get(account.getJid()));
+ listener.onPrimaryCanditateFound(true,
+ this.primaryCanditates.get(account.getJid()));
}
}
-
+
public String nextRandomId() {
return new BigInteger(50, random).toString(32);
}