implemented stream io interactions

This commit is contained in:
Alex Haynes 2018-10-21 13:35:56 -04:00
parent 48dfd9a77a
commit 007d9915e2
2 changed files with 12 additions and 4 deletions

View File

@ -9,6 +9,8 @@ class Stream(IStream):
peer_store = context.peer_store
peer_addr = peer_store.get(peer_id)
ip = peer_addr.get_protocol("ip4")
port = peer_addr.get_protocol("tcp")
# look up peer_id -> multiaddr in peer store
# parse multiaddr and set_protocol based on it
@ -37,18 +39,23 @@ class Stream(IStream):
read from stream
:return: bytes of input
"""
pass
return self.reader.read(-1)
def write(self, _bytes):
"""
write to stream
:return: number of bytes written
"""
pass
return self.write_to_stream(_bytes)
async def write_to_stream(self, _bytes):
to_return = self.writer.write(_bytes)
await self.writer.drain()
return to_return
def close(self):
"""
close stream
:return: true if successful
"""
pass
self.writer.close()

View File

@ -1 +1,2 @@
asyncio
multiaddr