'Starts the handshake to establish the socks5 bytestreams
connection.'

def handshake(self, to, ifrom=None, sid=None, timeout=None):

    if (not self._proxies):
        self._proxies = self.discover_proxies()
    if (sid is None):
        sid = uuid4().hex
    used = self.request_stream(to, sid=sid, ifrom=ifrom, timeout=timeout)
    proxy = used['socks']['streamhost_used']['jid']
    if (proxy not in self._proxies):
        log.warning('Received    unknown    SOCKS5    proxy:    %s', proxy)
        return
    with self._sessions_lock:
        self._sessions[sid] = self._connect_proxy(sid, self.xmpp.boundjid, to, self._proxies[proxy][0], self._proxies[proxy][1], peer=to)
    self.activate(proxy, sid, to, timeout=timeout)
    socket = self.get_socket(sid)
    self.xmpp.event(('stream:%s:%s' % (sid, to)), socket)
    return socket
