Switch message buffers to blocking queues and update reading logic (#83)

* working on blocking queues

* my mplex and delete muxer

* progress

* dont understand error

* tests passing

* cleaning up

* working on reading messages

* implmented varint reading from stream, rewrote message reading logic

* linting error in utils fix

* Update tcp.py

* removed unused vars

* removed prints

* added doc strings
This commit is contained in:
Alex Haynes
2018-11-28 12:58:16 -05:00
committed by GitHub
parent 6ff97ebb3e
commit f8963d628c
3 changed files with 99 additions and 33 deletions

View File

@ -20,7 +20,7 @@ async def test_simple_messages():
# Associate the peer with local ip address (see default parameters of Libp2p())
node_a.get_peerstore().add_addr("node_b", "/ip4/127.0.0.1/tcp/8000", 10)
print("node_a about to open stream")
stream = await node_a.new_stream("node_b", "/echo/1.0.0")
messages = ["hello" + str(x) for x in range(10)]
for message in messages:
@ -36,8 +36,8 @@ async def test_simple_messages():
@pytest.mark.asyncio
async def test_double_response():
hostA = await new_node(transport_opt=["/ip4/127.0.0.1/tcp/8002/ipfs/hostA"])
hostB = await new_node(transport_opt=["/ip4/127.0.0.1/tcp/8003/ipfs/hostB"])
node_a = await new_node(transport_opt=["/ip4/127.0.0.1/tcp/8002/ipfs/node_a"])
node_b = await new_node(transport_opt=["/ip4/127.0.0.1/tcp/8003/ipfs/node_b"])
async def stream_handler(stream):
while True:
@ -52,12 +52,12 @@ async def test_double_response():
print("sending response:" + response)
await stream.write(response.encode())
hostB.set_stream_handler("/echo/1.0.0", stream_handler)
node_b.set_stream_handler("/echo/1.0.0", stream_handler)
# Associate the peer with local ip address (see default parameters of Libp2p())
hostA.get_peerstore().add_addr("hostB", "/ip4/127.0.0.1/tcp/8003", 10)
print("hostA about to open stream")
stream = await hostA.new_stream("hostB", "/echo/1.0.0")
node_a.get_peerstore().add_addr("node_b", "/ip4/127.0.0.1/tcp/8003", 10)
print("node_a about to open stream")
stream = await node_a.new_stream("node_b", "/echo/1.0.0")
messages = ["hello" + str(x) for x in range(10)]
for message in messages:
await stream.write(message.encode())