Compare commits
10 commits
cfd06c0fc7
...
2e3183092f
Author | SHA1 | Date | |
---|---|---|---|
|
2e3183092f | ||
|
adcbf99901 | ||
|
57e90d8f91 | ||
|
2ec3c0e6bc | ||
|
b991b3a3a3 | ||
|
0c2d4df787 | ||
|
39e281e1bb | ||
|
8ddc2ae848 | ||
|
4b8064fb60 | ||
|
c860c8c0ff |
5 changed files with 12 additions and 12 deletions
4
.github/workflows/main.yml
vendored
4
.github/workflows/main.yml
vendored
|
@ -6,8 +6,8 @@ jobs:
|
|||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macOS-latest, windows-latest]
|
||||
python-version: [3.7]
|
||||
os: [ubuntu-latest, macOS-latest]
|
||||
python-version: [3.8]
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
# TODO: remove this when github actions support "if" in expressions
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# 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)
|
||||
[![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)
|
||||
|
||||
<p align="center">
|
||||
<img src="https://yxwangcs.github.io/p2pfs/demo.svg" width="80%"/>
|
||||
<img src="https://github.com/yuxincs/p2pfs/raw/main/demo.svg" width="85%"/>
|
||||
</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/yxwangcs/p2pfs/blob/master/LICENSE).
|
||||
[MIT](https://github.com/yuxincs/p2pfs/blob/master/LICENSE).
|
||||
|
|
2
demo.svg
2
demo.svg
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 205 KiB After Width: | Height: | Size: 106 KiB |
|
@ -2,7 +2,7 @@ from enum import Enum, auto
|
|||
import logging
|
||||
import asyncio
|
||||
import struct
|
||||
import pbjson
|
||||
import msgpack
|
||||
|
||||
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 -> pbjson load (dict)
|
||||
# receive length header -> msgpack load (dict)
|
||||
raw_msg_len = await reader.readexactly(4)
|
||||
msglen = struct.unpack('>I', raw_msg_len)[0]
|
||||
raw_msg = await reader.readexactly(msglen)
|
||||
|
||||
msg = pbjson.loads(raw_msg)
|
||||
msg = msgpack.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
|
||||
# pbjson string (bytes) -> add length header (bytes)
|
||||
raw_msg = pbjson.dumps(message)
|
||||
# msgpack (bytes) -> add length header (bytes)
|
||||
raw_msg = msgpack.dumps(message)
|
||||
raw_msg = struct.pack('>I', len(raw_msg)) + raw_msg
|
||||
writer.write(raw_msg)
|
||||
await writer.drain()
|
||||
|
|
2
setup.py
2
setup.py
|
@ -25,7 +25,7 @@ setup(
|
|||
],
|
||||
keywords='P2P, Networking',
|
||||
packages=find_packages(exclude=['tests']),
|
||||
install_requires=['coloredlogs', 'beautifultable', 'tqdm', 'aioconsole', 'pbjson',
|
||||
install_requires=['coloredlogs', 'beautifultable', 'tqdm', 'aioconsole', 'msgpack',
|
||||
'uvloop ; platform_system != "Windows"'],
|
||||
extras_require={
|
||||
'test': ['pytest', 'pytest-asyncio', 'pytest-cov', 'coverage'],
|
||||
|
|
Loading…
Reference in a new issue