Compare commits

..

No commits in common. "2e3183092fc462802fa830552b874de259513627" and "cfd06c0fc708ad512dd43d5d35e864f90e43dff8" have entirely different histories.

5 changed files with 12 additions and 12 deletions

View file

@ -6,8 +6,8 @@ jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
python-version: [3.8]
os: [ubuntu-latest, macOS-latest, windows-latest]
python-version: [3.7]
runs-on: ${{ matrix.os }}
env:
# TODO: remove this when github actions support "if" in expressions

View file

@ -1,8 +1,8 @@
# p2pfs
[![Github Actions](https://github.com/yuxincs/p2pfs/workflows/build/badge.svg)](https://github.com/yuxincs/p2pfs/actions?workflow=build) [![codecov](https://codecov.io/gh/yuxincs/p2pfs/branch/master/graph/badge.svg?token=EDGIegqh8K)](https://codecov.io/gh/yuxincs/p2pfs)
[![Github Actions](https://github.com/yxwangcs/p2pfs/workflows/build/badge.svg)](https://github.com/yxwangcs/p2pfs/actions?workflow=build) [![codecov](https://codecov.io/gh/yxwangcs/p2pfs/branch/master/graph/badge.svg?token=EDGIegqh8K)](https://codecov.io/gh/yxwangcs/p2pfs)
<p align="center">
<img src="https://github.com/yuxincs/p2pfs/raw/main/demo.svg" width="85%"/>
<img src="https://yxwangcs.github.io/p2pfs/demo.svg" width="80%"/>
</p>
File System based on P2P.
@ -111,4 +111,4 @@ Peer reads the chunk of the file and sends it back.
Peer sends back the exact message.
## License
[MIT](https://github.com/yuxincs/p2pfs/blob/master/LICENSE).
[MIT](https://github.com/yxwangcs/p2pfs/blob/master/LICENSE).

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 205 KiB

View file

@ -2,7 +2,7 @@ from enum import Enum, auto
import logging
import asyncio
import struct
import msgpack
import pbjson
logger = logging.getLogger(__name__)
@ -30,12 +30,12 @@ def _message_log(message):
async def read_message(reader):
assert isinstance(reader, asyncio.StreamReader)
# receive length header -> msgpack load (dict)
# receive length header -> pbjson load (dict)
raw_msg_len = await reader.readexactly(4)
msglen = struct.unpack('>I', raw_msg_len)[0]
raw_msg = await reader.readexactly(msglen)
msg = msgpack.loads(raw_msg)
msg = pbjson.loads(raw_msg)
logger.debug('Message received {}'.format(_message_log(msg)))
return msg
@ -46,8 +46,8 @@ async def write_message(writer, message):
# use value of enum since Enum is not JSON serializable
if isinstance(message['type'], MessageType):
message['type'] = message['type'].value
# msgpack (bytes) -> add length header (bytes)
raw_msg = msgpack.dumps(message)
# pbjson string (bytes) -> add length header (bytes)
raw_msg = pbjson.dumps(message)
raw_msg = struct.pack('>I', len(raw_msg)) + raw_msg
writer.write(raw_msg)
await writer.drain()

View file

@ -25,7 +25,7 @@ setup(
],
keywords='P2P, Networking',
packages=find_packages(exclude=['tests']),
install_requires=['coloredlogs', 'beautifultable', 'tqdm', 'aioconsole', 'msgpack',
install_requires=['coloredlogs', 'beautifultable', 'tqdm', 'aioconsole', 'pbjson',
'uvloop ; platform_system != "Windows"'],
extras_require={
'test': ['pytest', 'pytest-asyncio', 'pytest-cov', 'coverage'],