2024-07-28 11:21:15 +00:00
|
|
|
from Packets.Packet import Packet
|
2024-08-01 01:00:46 +00:00
|
|
|
from Daisy.Daisy import Daisy
|
2024-07-28 11:21:15 +00:00
|
|
|
import msgpack
|
|
|
|
|
|
|
|
|
|
|
|
class Header(Packet):
|
2024-08-01 01:00:46 +00:00
|
|
|
"""
|
|
|
|
Metadata packet for messages
|
|
|
|
|
2024-08-01 22:03:59 +00:00
|
|
|
`🔗 Source <https://git.utopic.work/PierMesh/piermesh/src/branch/main/Packets/HeaderPacket.py>`__
|
|
|
|
|
2024-08-01 01:00:46 +00:00
|
|
|
Attributes
|
|
|
|
----------
|
|
|
|
sender: int
|
|
|
|
6 digit (maximum) node or peer ID
|
|
|
|
|
|
|
|
senderDisplayName: int
|
|
|
|
3 digit (maximum) ID for mapping display names to a given user
|
|
|
|
|
|
|
|
recipient: int
|
|
|
|
6 digit (maximum) node or peer ID
|
|
|
|
|
|
|
|
recipientNode: int
|
|
|
|
6 digit (maximum) node ID to route the packet to
|
|
|
|
|
|
|
|
subpacket: bool
|
|
|
|
Whether this is a subpacket
|
|
|
|
|
|
|
|
wantFullResponse: bool
|
|
|
|
Whether a response should be sent when the message completes reception (TODO)
|
|
|
|
|
|
|
|
pAction: int
|
|
|
|
3 digit (maximum) pAction ID for mapping precise actions within a protocol (TODO)
|
|
|
|
"""
|
|
|
|
|
2024-07-28 11:21:15 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
2024-08-01 01:00:46 +00:00
|
|
|
packetsID: int,
|
|
|
|
packetCount: int,
|
|
|
|
sender: int,
|
|
|
|
senderDisplayName: int,
|
|
|
|
recipient: int,
|
|
|
|
recipientNode: int,
|
|
|
|
subpacket: bool = False,
|
|
|
|
wantFullResponse: bool = False,
|
|
|
|
packetsClass: int = 0,
|
|
|
|
pAction: int = -1,
|
2024-07-28 11:21:15 +00:00
|
|
|
):
|
|
|
|
super().__init__(
|
|
|
|
"", packetsID=packetsID, packetCount=packetCount, packetsClass=packetsClass
|
|
|
|
)
|
|
|
|
self.sender = sender
|
|
|
|
self.senderDisplayName = senderDisplayName
|
|
|
|
self.recipient = recipient
|
|
|
|
self.recipientNode = recipientNode
|
|
|
|
self.subpacket = subpacket
|
|
|
|
self.wantFullResponse = wantFullResponse
|
2024-08-01 01:00:46 +00:00
|
|
|
self.pAction = pAction
|
2024-07-28 11:21:15 +00:00
|
|
|
|
2024-08-01 01:00:46 +00:00
|
|
|
def usePreset(self, path: str):
|
|
|
|
"""
|
|
|
|
Add preset fields to the packet
|
|
|
|
"""
|
|
|
|
preset = Daisy(path)
|
2024-07-28 11:21:15 +00:00
|
|
|
for key in preset.get().keys():
|
|
|
|
self.msg[key] = preset.get()[key]
|
|
|
|
|
|
|
|
def dump(self):
|
2024-08-01 01:00:46 +00:00
|
|
|
"""
|
|
|
|
Dump packet to msgpack encoded binary for transmission
|
|
|
|
"""
|
2024-07-28 11:21:15 +00:00
|
|
|
res = msgpack.loads(super().dump())
|
|
|
|
res["sender"] = self.sender
|
|
|
|
res["senderDisplayName"] = self.senderDisplayName
|
|
|
|
res["recipient"] = self.recipient
|
|
|
|
res["recipientNode"] = self.recipientNode
|
|
|
|
res["subpacket"] = self.subpacket
|
|
|
|
res["wantFullResponse"] = self.wantFullResponse
|
2024-08-01 01:00:46 +00:00
|
|
|
res["packetsClass"] = self.packetsClass
|
|
|
|
res["pAction"] = self.pAction
|
|
|
|
|
2024-07-28 11:21:15 +00:00
|
|
|
return msgpack.dumps(res)
|