Compare commits

..

10 commits

Author SHA1 Message Date
Yuxin Wang
2e3183092f
Update README.md
Some checks failed
build / build (macOS-latest, 3.8) (push) Has been cancelled
build / build (ubuntu-latest, 3.8) (push) Has been cancelled
2022-07-21 21:48:53 -04:00
Yuxin Wang
adcbf99901
Update README.md 2022-04-21 16:03:02 -04:00
Yuxin Wang
57e90d8f91
Drop support for windows-latest. 2020-11-21 12:56:31 -05:00
Yuxin Wang
2ec3c0e6bc
Make demo picture bigger. 2020-11-20 23:19:50 -05:00
Yuxin Wang
b991b3a3a3
Fix removed imports. 2020-10-14 14:28:27 -04:00
Yuxin Wang
0c2d4df787 Fix notes. 2020-10-14 14:21:14 -04:00
Yuxin Wang
39e281e1bb Merge branch 'use-msgpack' 2020-10-14 14:20:38 -04:00
Yuxin Wang
8ddc2ae848 Use msgpack instead of pbjson as it is a more widely-adopted library. 2020-10-14 14:19:42 -04:00
Yuxin Wang
4b8064fb60
Test against python 3.8. 2020-10-14 14:09:52 -04:00
Yuxin Wang
c860c8c0ff Update demo terminal svg. 2020-10-14 14:08:09 -04:00
5 changed files with 12 additions and 12 deletions

View file

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

View file

@ -1,8 +1,8 @@
# p2pfs # 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"> <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> </p>
File System based on P2P. 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. Peer sends back the exact message.
## License ## License
[MIT](https://github.com/yxwangcs/p2pfs/blob/master/LICENSE). [MIT](https://github.com/yuxincs/p2pfs/blob/master/LICENSE).

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 205 KiB

After

Width:  |  Height:  |  Size: 106 KiB

View file

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

View file

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