def buildPacket(header, body): p = Packet() p.session_id = header[0:Offsets.SESSION_ID] p.seq_number = header[Offsets.SESSION_ID:Offsets.SEQ_NUMBER] p.ack = header[Offsets.SEQ_NUMBER:Offsets.ACK] p.data_len = header[Offsets.ACK:Offsets.DATA_LEN] p.flags = header[Offsets.DATA_LEN:Offsets.FLAGS] p.sync_type = None p.content = None if p.isFlagActive(Flags.SYNC): p.sync_type = BitArray(bin=body.bin[0:Offsets.SYNC_TYPE]) p.content = BitArray(bin=body.bin[Offsets.SYNC_TYPE:]) p.optional_headers = True else: p.sync_type = BitArray() p.content = BitArray(bin=body.bin) return p
def generateAckPacket(self, packt): p = Packet() p.session_id = self.sid self.seqnumber += 1 p.seq_number = BitArray(uint=self.seqnumber, length=Header.SEQ_NUMBER) p.ack = packt.seq_number p.data_len = BitArray(bin='0' * Header.DATA_LEN) p.flags = BitArray(bin='0' * Header.FLAGS) p.sync_type = BitArray() p.content = BitArray() return p
def generateInitPacket(self): p = Packet() p.session_id = BitArray(bin='0'*Header.SESSION_ID) p.seq_number = BitArray(uint=self.seqnumber,length=Header.SEQ_NUMBER) p.ack = BitArray(bin='0'*Header.ACK) p.data_len = BitArray(uint=len(self.tag),length=Header.DATA_LEN) p.flags = BitArray(uint=Flags.SYNC,length=Header.FLAGS) p.optional_headers = True p.sync_type = BitArray(uint=Sync.REQUEST_AUTH,length=OptionalHeader.SYNC_TYPE) p.content = BitArray(bytes=BitArray(hex=self.tag).bytes, length=Sizes.TAG) return p
def generateAuthResponsePacket(self, req, sessionID): p = Packet() p.session_id = sessionID p.seq_number = BitArray(uint=1, length=Header.SEQ_NUMBER) p.ack = req.seq_number p.data_len = BitArray(bin='0' * Header.DATA_LEN) p.flags = BitArray(uint=Flags.SYNC, length=Header.FLAGS) p.optional_headers = True p.sync_type = BitArray(uint=Sync.RESPONSE_AUTH, length=OptionalHeader.SYNC_TYPE) p.content = BitArray() return p
def generateTerminatePacket(self,packt): p = Packet() p.session_id = self.sid self.seqnumber+=1 p.seq_number = BitArray(uint=self.seqnumber,length=Header.SEQ_NUMBER) p.ack = packt.seq_number p.data_len = BitArray(bin='0'*Header.DATA_LEN) p.flags = BitArray(uint=Flags.SYNC,length=Header.FLAGS) p.optional_headers = True p.sync_type = BitArray(uint=Sync.SESSION_TERMINATION,length=OptionalHeader.SYNC_TYPE) p.content = BitArray() return p
def generateReintializationPacket(self,packt): p = Packet() p.session_id = self.sid self.seqnumber+=1 p.seq_number = BitArray(uint=self.seqnumber,length=Header.SEQ_NUMBER) p.ack = packt.seq_number p.data_len = BitArray(bin='0'*Header.DATA_LEN) p.flags = BitArray(uint=Flags.SYNC,length=Header.FLAGS) p.optional_headers = True p.sync_type = BitArray(uint=Sync.REINITIALIZING,length=OptionalHeader.SYNC_TYPE) p.content = BitArray() return p
def generateTransferPacket(self, packt, content, push): p = Packet() p.session_id = self.sid self.seqnumber += 1 p.seq_number = BitArray(uint=self.seqnumber, length=Header.SEQ_NUMBER) p.ack = packt.seq_number p.data_len = BitArray(uint=len(content), length=Header.DATA_LEN) if push: p.flags = BitArray(uint=Flags.PUSH, length=Header.FLAGS) else: p.flags = BitArray(bin='0' * Header.FLAGS) p.sync_type = BitArray() p.content = BitArray(bytes=content) return p