Improve dht shutdown. Notice writing pauses.

This commit is contained in:
Richard Kiss 2017-05-14 13:43:15 -07:00
parent 4515fa8b0a
commit d04634b57b
2 changed files with 10 additions and 0 deletions

View File

@ -52,6 +52,7 @@ class DisposablePeer:
self._metadata_future = loop.create_future()
self._writer = None
self._is_paused = False
try:
self._reader, self._writer = await asyncio.open_connection(
@ -88,6 +89,12 @@ class DisposablePeer:
self._writer.close()
return self._metadata_future.result()
def pause_writing(self):
self._is_paused = True
def resume_writing(self):
self._is_paused = False
def __on_message(self, message: bytes) -> None:
length = len(message)

View File

@ -84,6 +84,9 @@ class SybilNode:
if addr[1] == 0:
return
if self._transport.is_closing():
return
try:
message = bencode.loads(data)
except bencode.BencodeDecodingError: