2020-06-30 13:09:04 +00:00
|
|
|
"""Sans I/O wire protocol for Hypercore"""
|
2020-06-30 14:02:55 +00:00
|
|
|
from typing import List, Optional
|
2020-06-30 13:09:04 +00:00
|
|
|
|
2020-06-30 14:02:55 +00:00
|
|
|
import attr
|
2020-07-07 22:20:39 +00:00
|
|
|
import pyvarint
|
2020-06-30 14:02:55 +00:00
|
|
|
|
2020-07-07 22:20:39 +00:00
|
|
|
__all__ = ["SimpleMessageChannel"]
|
2020-06-30 14:02:55 +00:00
|
|
|
|
|
|
|
@attr.s(auto_attribs=True)
|
2020-06-30 13:09:04 +00:00
|
|
|
class SimpleMessageChannel:
|
|
|
|
"""A simple message channel."""
|
|
|
|
|
2020-06-30 14:02:55 +00:00
|
|
|
message: Optional[bytes] = None
|
|
|
|
ptr: int = 0
|
|
|
|
varint: int = 0
|
|
|
|
factor: int = 1
|
|
|
|
length: int = 0
|
|
|
|
header: int = 0
|
|
|
|
state: int = 0
|
|
|
|
consumed: int = 0
|
|
|
|
max_size: int = 8 * 1024 * 1024
|
|
|
|
types: List = attr.Factory(list)
|
|
|
|
|
|
|
|
receiving: bool = False
|
|
|
|
destroyed: bool = False
|
|
|
|
error: Optional[Exception] = None
|
|
|
|
|
|
|
|
# TODO(decentral1se): need to lookup type of what is being passed in
|
|
|
|
# context: ???
|
|
|
|
|
|
|
|
# TODO(decentral1se): allow to override instead of callback interface!?
|
|
|
|
# onmissing: ???
|
|
|
|
# onmessage: ???
|
|
|
|
|
2020-06-30 13:09:04 +00:00
|
|
|
async def send(self, channel: int, type: int, message: bytes) -> bytes:
|
|
|
|
pass
|
|
|
|
|
|
|
|
# TODO(decentral1se): spec out the context manager API of recv
|