M2-PT-DRP/source/packets/PeerPacket.py

31 lines
743 B
Python

import dataclasses
import msgpack
from . import base
@dataclasses.dataclass
class PeerPacket(base.BasePacket):
"""
Represent a packet used to send information about a peer
"""
# public RSA key of the machine
public_key: bytes = dataclasses.field(repr=False)
# is the machine a master
master: bool = dataclasses.field()
# TODO(Faraphel): share our trusted / banned peers with the other peer so that only one machine need to trust / ban it
# to propagate it to the whole network ?
def pack(self) -> bytes:
return msgpack.packb((
self.public_key,
self.master
))
@classmethod
def unpack(cls, data: bytes):
return cls(*msgpack.unpackb(data))