def generate_intermediate_blocks(self) -> typing.List[bytes]: """ Generates intermediate blocks used to generate the complete auxblocks afterwards. :return: Self.chunks containing the intermediate blocks """ _, s, h = intermediate_symbols(self.number_of_chunks, self.dist) k = self.number_of_chunks compositions: typing.List[typing.List[int]] = [[] for _ in range(s)] for i in range(0, k): a = 1 + (int(floor(np.float64(i) / np.float64(s))) % (s - 1)) b = int(i % s) compositions[b].append(i) b = (b + a) % s compositions[b].append(i) b = (b + a) % s compositions[b].append(i) for i in range(0, s): b = listXOR([self.chunks[x] for x in compositions[i]]) self.chunks.append(b) if self.debug: print(str(len(self.chunks) - 1) + " : " + str(compositions[i])) hprime = int(ceil(np.float64(h) / 2)) m = buildGraySequence(k + s, hprime) for i in range(0, h): hcomposition: typing.List[int] = [] for j in range(0, k + s): if bitSet(np.uint32(m[j]), np.uint32(i)): hcomposition.append(j) b = listXOR([self.chunks[x] for x in hcomposition]) self.chunks.append(b) if self.debug: print(str(len(self.chunks) - 1) + " : " + str(hcomposition)) return self.chunks
def create_new_packet(self, seed=None) -> Packet: if seed is None: seed: int = self.generate_new_checkblock_id(self.sequential_seed) if self.implicit_mode: # in implicit mode we want to be able derive the used chunks from having only the seed self.dist.set_seed(seed) degree: int = self.dist.getNumber() packet_numbers: typing.Set[int] = self.choose_packet_numbers(degree, seed=seed) chunks: typing.List[bytes] = [self.chunks[i] for i in packet_numbers] self.setOfEncodedPackets |= set(packet_numbers) return Packet( listXOR(chunks), packet_numbers, self.number_of_chunks, read_only=False, seed=seed, error_correction=self.error_correction, implicit_mode=self.implicit_mode, packet_len_format=self.packet_len_format, crc_len_format=self.crc_len_format, number_of_chunks_len_format=self.number_of_chunks_len_format, used_packets_len_format=self.used_packets_len_format, id_len_format=self.id_len_format, save_number_of_chunks_in_packet=self. save_number_of_chunks_in_packet)
def create_new_packet(self, systematic: bool = False, seed: typing.Optional[int] = None) -> RU10Packet: """ Creates a new RU10Packet with an ID, the number of participated packets and the XORed payload. :param seed: :param systematic: :return: A new RU10Packet """ if seed is None: seed = self.generate_new_id() packet_numbers = choose_packet_numbers(self.number_of_chunks, seed, self.dist, systematic=systematic) packets = [self.chunks[i] for i in packet_numbers] if self.debug: print("----") print("Id = " + str(seed)) print(packet_numbers) print(calc_crc(listXOR(packets))) print("----") return RU10Packet( listXOR(packets), packet_numbers, self.number_of_chunks, seed, dist=self.dist, read_only=False, error_correction=self.error_correction, packet_len_format=self.packet_len_format, crc_len_format=self.crc_len_format, number_of_chunks_len_format=self.number_of_chunks_len_format, id_len_format=self.id_len_format, save_number_of_chunks_in_packet=self. save_number_of_chunks_in_packet, prepend=self.prepend, append=self.append)
def createAuxBlocks(self): """ Fuer jeden Chunk eine Anzahl an Aux-Bloecken auswaehlen, in welchen der jeweilige Chunk eingefuegt wird """ if self.debug: print("Using " + str(self.getNumberOfAuxBlocks()) + " Aux-Blocks") self.rng.seed(self.number_of_chunks) for i in range(0, self.getNumberOfAuxBlocks()): self.auxBlockNumbers[i] = set() for chunk_num in range(0, self.number_of_chunks): # Insert this Chunk into quality different Aux-Packets for i in range(0, self.quality): # uniform choose a number of aux blocks aux_no = self.rng.randint(0, self.getNumberOfAuxBlocks()) self.auxBlockNumbers[aux_no].add(chunk_num) # XOR all Chunks into the corresponding AUX-Block for aux_number in self.auxBlockNumbers.keys(): self.auxBlocks[aux_number] = OnlineAuxPacket( listXOR([ self.chunks[i] for i in self.auxBlockNumbers[aux_number] ]), self.auxBlockNumbers[aux_number], aux_number=aux_number, )
def create_new_packet(self, seed=None) -> OnlinePacket: """ Creates a new CheckBlock """ if seed is None: check_block_id = self.generate_new_checkblock_id() else: check_block_id = seed self.distribution.set_seed(check_block_id) degree = self.distribution.getNumber() packet_numbers: typing.Set[int] = self.choose_packet_numbers( degree, check_block_id) packets = [] for i in packet_numbers: if i < len(self.chunks): # Add Chunk to list packets.append(self.chunks[i]) else: # Add AUX-Block to list packets.append(self.auxBlocks[i - len(self.chunks)].get_data()) self.setOfEncodedPackets |= set(packet_numbers) return OnlinePacket( listXOR(packets), self.number_of_chunks, self.quality, self.epsilon, check_block_id, packet_numbers, dist=self.distribution, read_only=False, error_correction=self.error_correction, crc_len_format=self.crc_len_format, number_of_chunks_len_format=self.number_of_chunks_len_format, quality_len_format=self.quality_len_format, epsilon_len_format=self.epsilon_len_format, check_block_number_len_format=self.check_block_number_len_format, save_number_of_chunks_in_packet=self. save_number_of_chunks_in_packet)
def create_new_packet_from_chunks( self, method: str, systematic: bool = False, seed: typing.Optional[int] = None, window: int = 0) -> typing.Optional[RU10Packet]: """ Creates a new packet only using chunks based on the choosen method. You can use "even" or "odd" which basically uses chunks with even or odd numbers. "window_30" and "window_40" are methods, that split the whole chunklist into windows with 30 or 40 chunks overlapping by 10 chunks for each window. "window" says what window the packet should be generated for, starting with 0 for the window that contains the first 30 or 40 chunks. The packets will be added to the encoders packets and can be saved with the save_packets method like normal packets. To decode the packets set use_method = True while creating a decoder. :param method: :param systematic: :param seed: :param window: :return: A new RU10Packet """ if method == "window_30": window_size = 30 start = window * (window_size - 10) if start > self.number_of_chunks: print("Please select a valid window.") return None chunk_lst: typing.List[int] = [ ch for ch in range(start, start + window_size) if ch <= self.number_of_chunks ] elif method == "window_40": window_size = 40 start = window * (window_size - 10) if start > self.number_of_chunks: print("Please select a valid window.") return None chunk_lst = [ ch for ch in range(start, start + window_size) if ch <= self.number_of_chunks ] elif method == "even": chunk_lst = [ ch for ch in range(0, self.number_of_chunks + 1) if ch % 2 == 0 ] elif method == "odd": chunk_lst = [ ch for ch in range(0, self.number_of_chunks + 1) if ch % 2 != 0 ] else: raise RuntimeError( "Please select a valid method (even, odd, window (including window_size and start_ind)" ) if seed is None: seed = self.generate_new_id() packet_numbers = choose_packet_numbers(len(chunk_lst), seed, self.dist, systematic=systematic, max_l=len(chunk_lst)) packets = [self.chunks[chunk_lst[i]] for i in packet_numbers] packet = RU10Packet( listXOR(packets), [chunk_lst[i] for i in packet_numbers], self.number_of_chunks, seed, read_only=False, error_correction=self.error_correction, packet_len_format=self.packet_len_format, crc_len_format=self.crc_len_format, number_of_chunks_len_format=self.number_of_chunks_len_format, id_len_format=self.id_len_format, save_number_of_chunks_in_packet=self. save_number_of_chunks_in_packet, method=method, window=window, prepend=self.prepend, append=self.append) self.encodedPackets.add(packet) return packet