'Auto-discover the JIDs of SOCKS5 proxies on an XMPP server.'

def discover_proxies(self, jid=None, ifrom=None, timeout=None):

    if (jid is None):
        if self.xmpp.is_component:
            jid = self.xmpp.server
        else:
            jid = self.xmpp.boundjid.server
    discovered = set()
    disco_items = self.xmpp['xep_0030'].get_items(jid, timeout=timeout)
    for item in disco_items['disco_items']['items']:
        try:
            disco_info = self.xmpp['xep_0030'].get_info(item[0], timeout=timeout)
        except XMPPError:
            continue
        else:
            identities = disco_info['disco_info']['identities']
            for identity in identities:
                if ((identity[0] == 'proxy') and (identity[1] == 'bytestreams')):
                    discovered.add(disco_info['from'])
    for jid in discovered:
        try:
            addr = self.get_network_address(jid, ifrom=ifrom, timeout=timeout)
            self._proxies[jid] = (addr['socks']['streamhost']['host'], addr['socks']['streamhost']['port'])
        except XMPPError:
            continue
    return self._proxies
