# Path: xwing/exceptions.py
# class HandshakeTimeoutError(HandshakeError):
#     pass
# 
# class HandshakeProtocolError(HandshakeError):
#     pass


import asyncio
from xwing.exceptions import HandshakeTimeoutError, HandshakeProtocolError


HANDSHAKE_SIGNAL = b'HANDSHAKE'
HANDSHAKE_ACK_SIGNAL = b'HANDSHAKE_ACK'


async def connect_handshake(connection, local_identity, timeout=10):
    connection.send(b''.join([HANDSHAKE_SIGNAL, b';',
                    local_identity.encode('utf-8')]))
    await connection.stream.drain()

    try:
        handshake_ack = await asyncio.wait_for(connection.recv(), timeout)
    except asyncio.TimeoutError:

# Path: xwing/exceptions.py
# class HandshakeTimeoutError(HandshakeError):
#     pass
# 
# class HandshakeProtocolError(HandshakeError):
#     pass


# Path: xwing/network/handshake.py
import asyncio
from xwing.exceptions import HandshakeTimeoutError, HandshakeProtocolError



HANDSHAKE_SIGNAL = b'HANDSHAKE'
HANDSHAKE_ACK_SIGNAL = b'HANDSHAKE_ACK'


async def connect_handshake(connection, local_identity, timeout=10):
    connection.send(b''.join([HANDSHAKE_SIGNAL, b';',
                    local_identity.encode('utf-8')]))
    await connection.stream.drain()

    try:
        handshake_ack = await asyncio.wait_for(connection.recv(), timeout)
    except asyncio.TimeoutError:

        raise HandshakeTimeoutError