diff options
author | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-04-08 23:15:55 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-04-08 23:15:55 +0200 |
commit | 298c7adcd1fabccb06d14905041cb7e008f109ad (patch) | |
tree | c4378136a4130854c94f1c55ffe3aab0aab6e0e0 /src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java | |
parent | 92dcf857014bfec919d62a7c0457093bd9056d94 (diff) |
disocover stream hosts (xep-0065) cleaned up disco
Diffstat (limited to 'src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java')
-rw-r--r-- | src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java b/src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java new file mode 100644 index 00000000..784d90d4 --- /dev/null +++ b/src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java @@ -0,0 +1,93 @@ +package eu.siacs.conversations.xmpp.jingle; + +import java.math.BigInteger; +import java.security.SecureRandom; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + +import android.util.Log; + +import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.services.XmppConnectionService; +import eu.siacs.conversations.xml.Element; +import eu.siacs.conversations.xmpp.OnIqPacketReceived; +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 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()); + } + + 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); + 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) { + if (!this.primaryCanditates.containsKey(account.getJid())) { + String xmlns = "http://jabber.org/protocol/bytestreams"; + 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); + } + } + }); + } else { + listener.onPrimaryCanditateFound(false, null); + } + + } else { + listener.onPrimaryCanditateFound(true, this.primaryCanditates.get(account.getJid())); + } + } + + public String nextRandomId() { + return new BigInteger(50, random).toString(32); + } +} |