rpc: various python fixes

This commit is contained in:
Koushik Dutta
2023-03-12 22:09:50 -07:00
parent a1c8ce754e
commit 940d4b7fd4
5 changed files with 114 additions and 29 deletions

View File

@@ -41,12 +41,20 @@ async def readLoop(loop, peer: rpc.RpcPeer, reader: asyncio.StreamReader):
'buffers': []
}
if isinstance(reader, asyncio.StreamReader):
async def read(n):
return await reader.readexactly(n)
else:
async def read(n):
return await reader.read(n)
while True:
lengthBytes = await reader.read(4)
typeBytes = await reader.read(1)
lengthBytes = await read(4)
typeBytes = await read(1)
type = typeBytes[0]
length = int.from_bytes(lengthBytes, 'big')
data = await reader.read(length - 1)
data = await read(length - 1)
if type == 1:
deserializationContext['buffers'].append(data)
@@ -73,6 +81,7 @@ async def prepare_peer_readloop(loop: AbstractEventLoop, readFd: int = None, wri
except Exception as e:
if reject:
reject(e)
return None
else:
def write(buffers, reject):
try: