mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-21 00:24:37 +03:00
a48fd43100
* streamable: Merge `strictdataclass` into `Streamable` class * tests: Test not supported streamable types * streamable: Reorder decorators * streamable: Simplify streamable decorator and force correct usage/syntax * streamable: Just move some stuff around in the file * streamable: Improve syntax error messages * mypy: Drop `type_checking.py` and `test_type_checking.py` from exclusion * streamable: Use cached fields instead of `__annotations__` This is now possible after merging `__post_init__` into `Streamable` * Introduce `DefinitionError` as `StreamableError` * `/t` -> ` `
46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
from dataclasses import dataclass
|
|
from enum import IntEnum
|
|
from typing import Any, Optional
|
|
|
|
from chia.protocols.protocol_message_types import ProtocolMessageTypes
|
|
from chia.util.ints import uint8, uint16
|
|
from chia.util.streamable import Streamable, streamable
|
|
|
|
|
|
class NodeType(IntEnum):
|
|
FULL_NODE = 1
|
|
HARVESTER = 2
|
|
FARMER = 3
|
|
TIMELORD = 4
|
|
INTRODUCER = 5
|
|
WALLET = 6
|
|
|
|
|
|
class Delivery(IntEnum):
|
|
# A message is sent to the same peer that we received a message from
|
|
RESPOND = 1
|
|
# A message is sent to all peers
|
|
BROADCAST = 2
|
|
# A message is sent to all peers except the one from which we received the API call
|
|
BROADCAST_TO_OTHERS = 3
|
|
# A message is sent to a random peer
|
|
RANDOM = 4
|
|
# Pseudo-message to close the current connection
|
|
CLOSE = 5
|
|
# A message is sent to a speicific peer
|
|
SPECIFIC = 6
|
|
|
|
|
|
@streamable
|
|
@dataclass(frozen=True)
|
|
class Message(Streamable):
|
|
type: uint8 # one of ProtocolMessageTypes
|
|
# message id
|
|
id: Optional[uint16]
|
|
# Message data for that type
|
|
data: bytes
|
|
|
|
|
|
def make_msg(msg_type: ProtocolMessageTypes, data: Any) -> Message:
|
|
return Message(uint8(msg_type.value), None, bytes(data))
|