Initial commit

This commit is contained in:
Mark Qvist 2016-05-29 22:20:44 +02:00
commit 9a9630cfd2
3 changed files with 218 additions and 0 deletions

24
Packet.py Normal file
View file

@ -0,0 +1,24 @@
import struct
from Transport import *
class Packet:
MTU = 960
def __init__(self, destination, data):
self.destination = destination
self.data = data
self.flags = 0x00
self.header = 0x00
self.raw = None
self.sent = False
def send(self):
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) > Packet.MTU:
raise IOError("Packet size exceeds MTU of "+Packet.MTU+" bytes")
Transport.outbound(self.raw)