def task_read_polling(self, task): if self.reader.dataAvailable(): logging.debug('data available from server') datagram = Datagram() if self.reader.getData(datagram): logging.debug('received data from server: %s', datagram) logging.debug('received data from server: %s', datagram.getMessage()) # TODO: provide a way to supply a data callback self._data_last_received = 0 else: # no data received logging.debug('no data') self._data_last_received += self.get_dt() if self._data_last_received >= 10: logging.error('connection to server lost') return return task.cont
def process_modules(self): # TODO: Compression dg = Datagram() dg.addUint32(len(self.modules)) for moduleName in self.modules: data, size = self.modules[moduleName] dg.addString(moduleName) dg.addInt32(size) dg.appendData(data) data = dg.getMessage() iv = self.generate_key(16) key = self.generate_key(16) fixed_key = ''.join( chr((i ^ (7 * i + 16)) % ((i + 5) * 3)) for i in xrange(16)) fixed_iv = ''.join( chr((i ^ (2 * i + 53)) % ((i + 9) * 6)) for i in xrange(16)) securekeyandiv = aes.encrypt(iv + key, fixed_key, fixed_iv) return securekeyandiv + aes.encrypt(data, key, iv)
def write(self, f): dg = Datagram() dg.appendData(self.HEADER) if self.version >= (6, 27): header_size = 6 elif self.version >= (5, 0): header_size = 5 else: header_size = 4 bam_major_ver, bam_minor_ver = self.version dg.add_uint32(header_size) dg.add_uint16(bam_major_ver) dg.add_uint16(bam_minor_ver) if header_size >= 5: dg.add_uint8(self.file_endian) if header_size >= 6: dg.add_bool(self.stdfloat_double) self.written_handles = [] self.write_long_pointers = False if self.objects: objects = list(self.objects.values()) self.write_object(dg, BamGlobals.BOC_push, objects[0], self.written_handles) for obj in objects[1:]: self.write_object(dg, BamGlobals.BOC_adjunct, obj, self.written_handles) for data in self.file_datas: self.write_file_data(dg, data) if self.version >= (6, 21): self.write_object(dg, BamGlobals.BOC_pop) f.write(dg.getMessage())
def write(self, f, target_version): dg = Datagram() dg.appendData(self.HEADER) if target_version >= (6, 27): header_size = 6 elif target_version >= (5, 0): header_size = 5 else: header_size = 4 bam_major_ver, bam_minor_ver = target_version dg.add_uint32(header_size) dg.add_uint16(bam_major_ver) dg.add_uint16(bam_minor_ver) if header_size >= 5: dg.add_uint8(self.file_endian) if header_size >= 6: dg.add_bool(self.stdfloat_double) written_handles = [] if self.objects: self.write_object(dg, BOC_push, self.objects[0], written_handles) for obj in self.objects[1:]: self.write_object(dg, BOC_adjunct, obj, written_handles) for data in self.file_datas: self.write_file_data(dg, data) if self.version >= (6, 21): self.write_object(dg, BOC_pop) f.write(dg.getMessage())