'Establishes a connection between the client and the server-side
Socks5 proxy.
sid        : The StreamID. <str>
requester  : The JID of the requester. <str>
target     : The JID of the target. <str>
proxy_host : The hostname or the IP of the proxy. <str>
proxy_port : The port of the proxy. <str> or <int>
peer       : The JID for the other side of the stream, regardless
of target or requester status.'

def _connect_proxy(self, sid, requester, target, proxy, proxy_port, peer=None):

    proxy_port = int(proxy_port)
    sock = socksocket()
    sock.setproxy(PROXY_TYPE_SOCKS5, proxy, port=proxy_port)
    digest = sha1()
    digest.update(sid.encode('utf-8'))
    digest.update(str(requester).encode('utf-8'))
    digest.update(str(target).encode('utf-8'))
    dest = digest.hexdigest()
    sock.connect((dest, 0))
    log.info('Socket    connected.')
    _close = sock.close
    def close(*args, **kwargs):
        with self._sessions_lock:
            if (sid in self._sessions):
                del self._sessions[sid]
        _close()
        log.info('Socket    closed.')
    sock.close = close
    sock.peer_jid = peer
    sock.self_jid = (target if (requester == peer) else requester)
    self.xmpp.event('socks_connected', sid)
    return sock
