# Path: pycoinnet/InvItem.py
# ITEM_TYPE_TX, ITEM_TYPE_BLOCK, ITEM_TYPE_MERKLEBLOCK = (1, 2, 3)
#         INV_TYPES = [None, "Tx", "Block", "Merkle"]
# class InvItem(object):
#     def __init__(self, item_type, data):
#     def __str__(self):
#     def __repr__(self):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def stream(self, f):
#     def parse(self, f):


import asyncio
import logging
import time
from pycoinnet.InvItem import InvItem, ITEM_TYPE_BLOCK, ITEM_TYPE_MERKLEBLOCK

# it goes to the list of known peers who have the blocks in question

# manages block peers
# fetch block




class Blockfetcher:
    """
    Blockfetcher

    This class is created once for each PeerGroup. It's used to accept a set of blocks
    and download them in an overlapping way.

    It accepts new peers via add_peer.

    It fetches new blocks via get_block_future or get_block.
    """
    def __init__(self, max_q_size=0):
        # this queue accepts tuples of the form:
        #  (block_index, InvItem(ITEM_TYPE_BLOCK, block_hash), future)
        self.block_hash_priority_queue = asyncio.PriorityQueue(max_q_size)

    def add_peer(self, peer, fetcher, last_block_index):
        peer.add_task(self.fetch_from_peer(peer, fetcher, last_block_index))

    def get_block_future(self, block_hash, block_index):
        future = asyncio.Future()

# Path: pycoinnet/InvItem.py
# ITEM_TYPE_TX, ITEM_TYPE_BLOCK, ITEM_TYPE_MERKLEBLOCK = (1, 2, 3)
#         INV_TYPES = [None, "Tx", "Block", "Merkle"]
# class InvItem(object):
#     def __init__(self, item_type, data):
#     def __str__(self):
#     def __repr__(self):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def stream(self, f):
#     def parse(self, f):


# Path: pycoinnet/peergroup/Blockfetcher.py
import asyncio
import logging
import time
from pycoinnet.InvItem import InvItem, ITEM_TYPE_BLOCK, ITEM_TYPE_MERKLEBLOCK


# it goes to the list of known peers who have the blocks in question

# manages block peers
# fetch block




class Blockfetcher:
    """
    Blockfetcher

    This class is created once for each PeerGroup. It's used to accept a set of blocks
    and download them in an overlapping way.

    It accepts new peers via add_peer.

    It fetches new blocks via get_block_future or get_block.
    """
    def __init__(self, max_q_size=0):
        # this queue accepts tuples of the form:
        #  (block_index, InvItem(ITEM_TYPE_BLOCK, block_hash), future)
        self.block_hash_priority_queue = asyncio.PriorityQueue(max_q_size)

    def add_peer(self, peer, fetcher, last_block_index):
        peer.add_task(self.fetch_from_peer(peer, fetcher, last_block_index))

    def get_block_future(self, block_hash, block_index):
        future = asyncio.Future()

        item = (block_index, InvItem(ITEM_TYPE_BLOCK, block_hash), future)