Search in sources :

Example 1 with Item

use of org.jivesoftware.smackx.packet.DiscoverItems.Item in project ecf by eclipse.

the class Socks5BytestreamManager method determineProxies.

/**
 * Returns a list of JIDs of SOCKS5 proxies by querying the XMPP server. The SOCKS5 proxies are
 * in the same order as returned by the XMPP server.
 *
 * @return list of JIDs of SOCKS5 proxies
 * @throws XMPPException if there was an error querying the XMPP server for SOCKS5 proxies
 */
private List<String> determineProxies() throws XMPPException {
    ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(this.connection);
    List<String> proxies = new ArrayList<String>();
    // get all items form XMPP server
    DiscoverItems discoverItems = serviceDiscoveryManager.discoverItems(this.connection.getServiceName());
    Iterator<Item> itemIterator = discoverItems.getItems();
    // query all items if they are SOCKS5 proxies
    while (itemIterator.hasNext()) {
        Item item = itemIterator.next();
        // skip blacklisted servers
        if (this.proxyBlacklist.contains(item.getEntityID())) {
            continue;
        }
        try {
            DiscoverInfo proxyInfo;
            proxyInfo = serviceDiscoveryManager.discoverInfo(item.getEntityID());
            Iterator<Identity> identities = proxyInfo.getIdentities();
            // item must have category "proxy" and type "bytestream"
            while (identities.hasNext()) {
                Identity identity = identities.next();
                if ("proxy".equalsIgnoreCase(identity.getCategory()) && "bytestreams".equalsIgnoreCase(identity.getType())) {
                    proxies.add(item.getEntityID());
                    break;
                }
                /*
                     * server is not a SOCKS5 proxy, blacklist server to skip next time a Socks5
                     * bytestream should be established
                     */
                this.proxyBlacklist.add(item.getEntityID());
            }
        } catch (XMPPException e) {
            // blacklist errornous server
            this.proxyBlacklist.add(item.getEntityID());
        }
    }
    return proxies;
}
Also used : Item(org.jivesoftware.smackx.packet.DiscoverItems.Item) DiscoverInfo(org.jivesoftware.smackx.packet.DiscoverInfo) ArrayList(java.util.ArrayList) DiscoverItems(org.jivesoftware.smackx.packet.DiscoverItems) Identity(org.jivesoftware.smackx.packet.DiscoverInfo.Identity) XMPPException(org.jivesoftware.smack.XMPPException) ServiceDiscoveryManager(org.jivesoftware.smackx.ServiceDiscoveryManager)

Aggregations

ArrayList (java.util.ArrayList)1 XMPPException (org.jivesoftware.smack.XMPPException)1 ServiceDiscoveryManager (org.jivesoftware.smackx.ServiceDiscoveryManager)1 DiscoverInfo (org.jivesoftware.smackx.packet.DiscoverInfo)1 Identity (org.jivesoftware.smackx.packet.DiscoverInfo.Identity)1 DiscoverItems (org.jivesoftware.smackx.packet.DiscoverItems)1 Item (org.jivesoftware.smackx.packet.DiscoverItems.Item)1