mirror of
https://github.com/markqvist/Reticulum.git
synced 2025-05-06 08:25:57 -04:00
Serial interface implemented
This commit is contained in:
parent
9a9630cfd2
commit
be8fa4f7bb
15 changed files with 2789 additions and 30 deletions
35
FPE/Packet.py
Normal file
35
FPE/Packet.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
import struct
|
||||
from Transport import *
|
||||
|
||||
class Packet:
|
||||
|
||||
def __init__(self, destination, data):
|
||||
self.destination = destination
|
||||
self.data = data
|
||||
self.flags = 0x00
|
||||
self.header = 0x00
|
||||
self.raw = None
|
||||
self.sent = False
|
||||
self.mtu = 0
|
||||
|
||||
def send(self):
|
||||
if not self.sent:
|
||||
self.MTU = self.destination.MTU
|
||||
self.header = struct.pack("!B", self.header ^ self.destination.type ^ self.flags)
|
||||
self.header += self.destination.hash
|
||||
self.ciphertext = self.destination.encrypt(self.data)
|
||||
self.raw = self.header + self.ciphertext
|
||||
|
||||
if len(self.raw) > self.MTU:
|
||||
raise IOError("Packet size exceeds MTU of "+Packet.MTU+" bytes")
|
||||
|
||||
Transport.outbound(self.raw)
|
||||
self.sent = True
|
||||
else:
|
||||
raise IOError("Packet was already sent")
|
||||
|
||||
def resend(self):
|
||||
if self.sent:
|
||||
Transport.outbound(self.raw)
|
||||
else:
|
||||
raise IOError("Packet was not sent yet")
|
Loading…
Add table
Add a link
Reference in a new issue