fixes from review

This commit is contained in:
Victor Shyba 2019-05-13 14:57:58 -03:00
parent 2439743804
commit 124fdb7d31

View file

@ -171,14 +171,14 @@ class Node:
) )
) )
def get_iterative_node_finder(self, key: bytes, shortlist: typing.Optional[typing.List] = None, def get_iterative_node_finder(self, key: bytes, shortlist: typing.Optional[typing.List['KademliaPeer']] = None,
bottom_out_limit: int = constants.bottom_out_limit, bottom_out_limit: int = constants.bottom_out_limit,
max_results: int = constants.k) -> IterativeNodeFinder: max_results: int = constants.k) -> IterativeNodeFinder:
return IterativeNodeFinder(self.loop, self.protocol.peer_manager, self.protocol.routing_table, self.protocol, return IterativeNodeFinder(self.loop, self.protocol.peer_manager, self.protocol.routing_table, self.protocol,
key, bottom_out_limit, max_results, None, shortlist) key, bottom_out_limit, max_results, None, shortlist)
def get_iterative_value_finder(self, key: bytes, shortlist: typing.Optional[typing.List] = None, def get_iterative_value_finder(self, key: bytes, shortlist: typing.Optional[typing.List['KademliaPeer']] = None,
bottom_out_limit: int = 40, bottom_out_limit: int = 40,
max_results: int = -1) -> IterativeValueFinder: max_results: int = -1) -> IterativeValueFinder:
@ -186,7 +186,7 @@ class Node:
key, bottom_out_limit, max_results, None, shortlist) key, bottom_out_limit, max_results, None, shortlist)
async def peer_search(self, node_id: bytes, count=constants.k, max_results=constants.k*2, async def peer_search(self, node_id: bytes, count=constants.k, max_results=constants.k*2,
bottom_out_limit=20, shortlist: typing.Optional[typing.List] = None bottom_out_limit=20, shortlist: typing.Optional[typing.List['KademliaPeer']] = None
) -> typing.List['KademliaPeer']: ) -> typing.List['KademliaPeer']:
peers = [] peers = []
async for iteration_peers in self.get_iterative_node_finder( async for iteration_peers in self.get_iterative_node_finder(
@ -202,7 +202,7 @@ class Node:
try: try:
while True: while True:
blob_hash = await search_queue.get() blob_hash = await search_queue.get()
tasks.append(asyncio.create_task(self._value_producer(blob_hash, result_queue))) tasks.append(self.loop.create_task(self._value_producer(blob_hash, result_queue)))
finally: finally:
for task in tasks: for task in tasks:
task.cancel() task.cancel()
@ -214,5 +214,5 @@ class Node:
def accumulate_peers(self, search_queue: asyncio.Queue, def accumulate_peers(self, search_queue: asyncio.Queue,
peer_queue: typing.Optional[asyncio.Queue] = None) -> typing.Tuple[ peer_queue: typing.Optional[asyncio.Queue] = None) -> typing.Tuple[
asyncio.Queue, asyncio.Task]: asyncio.Queue, asyncio.Task]:
q = peer_queue or asyncio.Queue() q = peer_queue or asyncio.Queue(loop=self.loop)
return q, asyncio.create_task(self._accumulate_search_junction(search_queue, q)) return q, self.loop.create_task(self._accumulate_search_junction(search_queue, q))