def response(self, typ, addr, id, rtr): if self.mode == SCUMode.SendMode: raise Exception if typ == SCUPacketType.Rtr.value: header = SCUHeader() header.from_dict({ "typ": typ, "id": id, "seq": rtr, }) packet = SCUPacket() packet.from_dict({ "header": header, "payload": b'', }) self.socket.sendto(packet.raw(), addr) elif typ == SCUPacketType.Fin.value: header = SCUHeader() header.from_dict({ "typ": typ, "id": id, "seq": rtr, }) packet = SCUPacket() packet.from_dict({ "header": header, "payload": b'', }) self.socket.sendto(packet.raw(), addr)
def response(self, typ, addr, key, seq, resendID, content=b""): """ responses a single packet of retry, or fin. it can be used to just send packets. """ if self.mode == SCUMode.SendMode: raise Exception header = SCUHeader() packet = SCUPacket() header.from_dict({ "typ": typ, "id": key, "seq": seq, "resendID": resendID }) if typ == SCUPacketType.Rtr.value: packet.from_dict({"header": header, "payload": content.encode()}) elif typ == SCUPacketType.Fin.value: packet.from_dict({"header": header, "payload": b''}) else: raise Exception() self.socket.sendto(packet.raw(), addr)