# Path: pycoinnet/PeerAddress.py
# class PeerAddress(object):
#     def __init__(self, services, ip_int_or_str, port):
#         ip_address = ipaddress.ip_address(ip_int_or_str)
#         self.services = services
#         self.ip_address = ip_address
#         self.port = port
# 
#     def __repr__(self):
#         return "%s/%d" % (self.ip_address, self.port)
# 
#     def host(self):
#         return self.ip_address.exploded
# 
#     def stream(self, f):
#         f.write(struct.pack("<Q", self.services))
#         ip_bin = self.ip_address.packed
#         if len(ip_bin) < 16:
#             f.write(IP4_HEADER)
#         f.write(ip_bin)
#         f.write(struct.pack("!H", self.port))
# 
#     @classmethod
#     def parse(self, f):
#         services, ip_bin, port = parse_struct("Q@h", f)
#         if ip_bin.startswith(IP4_HEADER):
#             ip_bin = ip_bin[len(IP4_HEADER):]
#         ip_int = int.from_bytes(ip_bin, byteorder="big")
#         return self(services, ip_int, port)
# 
#     def __lt__(self, other):
#         return self.ip_address.packed < other.ip_address.packed
# 
#     def __eq__(self, other):
#         return self.services == other.services and \
#             self.ip_address == other.ip_address and self.port == other.port


import asyncio
import logging
import os
import time
from pycoinnet.PeerAddress import PeerAddress
                    protocol_factory, host=host, port=port)
                logging.info("connected (tcp) to %s:%d", host, port)
                event_q.put_nowait(("connect", (host, port), protocol))
                yield from asyncio.wait_for(protocol.connection_lost_future, timeout=None)
                event_q.put_nowait(("disconnect", (host, port), protocol))
            except Exception:
                logging.exception("failed to connect to %s:%d", host, port)

    for i in range(connection_count):
        # we add the tasks to a set on event_q so they're not garbage
        # collected until event_q is.
        event_q.tasks.add(asyncio.Task(run()))

    return event_q


@asyncio.coroutine
def create_server(protocol_factory, port):
    """
    Listen on a port and create new peers on that connection.
    """
    abstract_server = yield from asyncio.get_event_loop().create_server(
        protocol_factory=protocol_factory, port=port)
    return abstract_server


def version_data_for_peer(
        peer, version=70001, local_ip="127.0.0.1", local_port=6111, last_block_index=0,
        nonce=None, subversion=b"/Notoshi/", timestamp=None, want_relay=True):
    remote_ip, remote_port = peer.peername[:2]

# Path: pycoinnet/PeerAddress.py
# class PeerAddress(object):
#     def __init__(self, services, ip_int_or_str, port):
#         ip_address = ipaddress.ip_address(ip_int_or_str)
#         self.services = services
#         self.ip_address = ip_address
#         self.port = port
# 
#     def __repr__(self):
#         return "%s/%d" % (self.ip_address, self.port)
# 
#     def host(self):
#         return self.ip_address.exploded
# 
#     def stream(self, f):
#         f.write(struct.pack("<Q", self.services))
#         ip_bin = self.ip_address.packed
#         if len(ip_bin) < 16:
#             f.write(IP4_HEADER)
#         f.write(ip_bin)
#         f.write(struct.pack("!H", self.port))
# 
#     @classmethod
#     def parse(self, f):
#         services, ip_bin, port = parse_struct("Q@h", f)
#         if ip_bin.startswith(IP4_HEADER):
#             ip_bin = ip_bin[len(IP4_HEADER):]
#         ip_int = int.from_bytes(ip_bin, byteorder="big")
#         return self(services, ip_int, port)
# 
#     def __lt__(self, other):
#         return self.ip_address.packed < other.ip_address.packed
# 
#     def __eq__(self, other):
#         return self.services == other.services and \
#             self.ip_address == other.ip_address and self.port == other.port


# Path: pycoinnet/helpers/standards.py
import asyncio
import logging
import os
import time
from pycoinnet.PeerAddress import PeerAddress

                    protocol_factory, host=host, port=port)
                logging.info("connected (tcp) to %s:%d", host, port)
                event_q.put_nowait(("connect", (host, port), protocol))
                yield from asyncio.wait_for(protocol.connection_lost_future, timeout=None)
                event_q.put_nowait(("disconnect", (host, port), protocol))
            except Exception:
                logging.exception("failed to connect to %s:%d", host, port)

    for i in range(connection_count):
        # we add the tasks to a set on event_q so they're not garbage
        # collected until event_q is.
        event_q.tasks.add(asyncio.Task(run()))

    return event_q


@asyncio.coroutine
def create_server(protocol_factory, port):
    """
    Listen on a port and create new peers on that connection.
    """
    abstract_server = yield from asyncio.get_event_loop().create_server(
        protocol_factory=protocol_factory, port=port)
    return abstract_server


def version_data_for_peer(
        peer, version=70001, local_ip="127.0.0.1", local_port=6111, last_block_index=0,
        nonce=None, subversion=b"/Notoshi/", timestamp=None, want_relay=True):
    remote_ip, remote_port = peer.peername[:2]

    remote_addr = PeerAddress(1, remote_ip, remote_port)