def write_to_secure_socket(self, payload): if not payload: return; userdata = packet.DataPacket(); userdata.set_payload(payload); try: self.client_socket.send(userdata.get_buffer()); except:
def write_to_secure_socket(self, payload): if not payload: return; #print("Got data on TUN interface"); userdata = packet.DataPacket(); #print("Writing %d bytes to socket" % (len(payload))) userdata.set_payload(payload); #print("Total packet length %d" % (len(userdata.get_buffer()))); self.secure_socket.send(userdata.get_buffer());
def write_to_secure_socket(self, payload): if not payload: return userdata = packet.DataPacket() userdata.set_payload(payload) try: self.client_socket.send(userdata.get_buffer()) except: raise Exception("Socket was closed")
def read_from_secure_socket(self): buf = self.client_socket.recv(self.buffer_size); if len(buf) == 0: raise Exception("Socket was closed"); self.secure_socket_buffer += buf; if len(self.secure_socket_buffer) <= packet.Packet.get_header_length(): return None; packet_length = packet.Packet.get_total_length(self.secure_socket_buffer); if packet_length > len(self.secure_socket_buffer): return None; buf = self.secure_socket_buffer[:packet_length]; self.secure_socket_buffer = self.secure_socket_buffer[packet_length:]; userdata = packet.DataPacket(buf); if userdata.get_type() != packet.PACKET_TYPE_DATA: return None; return userdata.get_payload();
def read_from_secure_socket(self): buf = bytearray(self.secure_socket.recv(self.buffer_size)) if len(buf) == 0: raise Exception("Socket was closed") self.secure_socket_buffer += buf if len(self.secure_socket_buffer) <= packet.Packet.get_header_length(): return None packet_length = packet.Packet.get_total_length( self.secure_socket_buffer) #print("Packet length %d" % (packet_length)); if packet_length > len(self.secure_socket_buffer): return None buf = self.secure_socket_buffer[0:packet_length] self.secure_socket_buffer = self.secure_socket_buffer[packet_length:] userdata = packet.DataPacket(buf) if userdata.get_type() != packet.PACKET_TYPE_DATA: return None return userdata.get_payload()