Ejemplo n.º 1
0
 def updatePackets(self, packet: Packet) -> bool:
     if (packet.get_degree() == 1 and
             next(iter(packet.get_used_packets())) < self.number_of_chunks
             and (next(iter(packet.get_used_packets())) != 0
                  or not self.use_headerchunk)):
         # Directly add Packets that are degree == 1 (except for HeaderPacket)
         self.decodedPackets.add(packet)
         return self.is_decoded()
     self.queue.append(packet)
     self.solve()
Ejemplo n.º 2
0
 def __init__(self, packet: Packet, last_chunk_len_format: str = "I"):
     assert packet.get_used_packets().issubset({0}), "only first packet can be HeaderPacket"
     if isinstance(packet.data, numpy.ndarray):
         self.data: bytes = packet.data.tobytes()
     else:
         self.data: bytes = packet.data
     self.last_chunk_len_format: str = last_chunk_len_format
     self.last_chunk_length, self.file_name = self.decode_header_info()
Ejemplo n.º 3
0
 def compareAndReduce(self, packet: Packet, other: Packet) -> typing.Union[bool, int]:
     if self.file is None:  # In case of PseudoDecode: DO NOT REALLY COMPUTE XOR
         packet.remove_packets(other.get_used_packets())
     else:
         packet.xor_and_remove_packet(other)
     degree = packet.get_degree()
     if (degree not in self.degreeToPacket) or (not isinstance(self.degreeToPacket[degree], set)):
         self.degreeToPacket[degree] = set()
     self.degreeToPacket[degree].add(packet)
     if self.is_decoded():
         return True
     self.queue.append(packet)
     return degree
Ejemplo n.º 4
0
 def reduceAll(self, packet: Packet) -> bool:
     # lookup all packets for this to solve with ( when this packet has a subset of used Packets)
     fin: bool = False
     lookup: typing.List[int] = [
         i for i in self.degreeToPacket.keys() if packet.get_degree() < i
     ]
     for i in lookup:
         if not isinstance(self.degreeToPacket[i], set):
             self.degreeToPacket[i] = set()
         for p in self.degreeToPacket[i].copy():
             p_used = p.get_used_packets()
             pack_used = packet.get_used_packets()
             if len(pack_used) < len(p_used) and pack_used.issubset(p_used):
                 self.degreeToPacket[i].remove(p)
                 degree = self.compareAndReduce(p, packet)
                 if isinstance(degree, bool) and degree is True:
                     return degree
     degree: int = packet.get_degree()
     lookup: typing.List[int] = [
         i for i in self.degreeToPacket.keys() if packet.get_degree() > i
     ]
     for i in lookup:
         if not isinstance(self.degreeToPacket[i], set):
             self.degreeToPacket[i] = set()
         for p in self.degreeToPacket[i].copy():
             p_used = p.get_used_packets()
             pack_used = packet.get_used_packets()
             if len(pack_used) > len(p_used) and p_used.issubset(pack_used):
                 try:
                     self.degreeToPacket[degree].remove(packet)
                     degree = self.compareAndReduce(packet, p)
                     if isinstance(degree, bool) and degree is True:
                         return degree
                 except:
                     continue
                 # If we already reduced a Packet with the same used_packets, there is no need to do it again
     return fin or self.is_decoded()
Ejemplo n.º 5
0
 def compareAndReduce(self, packet: Packet,
                      other: Packet) -> typing.Union[bool, int]:
     if self.file is None:
         packet.remove_packets(other.get_used_packets())
     else:
         packet.xor_and_remove_packet(other)
     degree = packet.get_degree()
     if (degree not in self.degreeToPacket) or (not isinstance(
             self.degreeToPacket[degree], set)):
         self.degreeToPacket[degree] = set()
     if degree == 1:
         [x] = (packet.get_used_packets()
                )  # Unpacking -> Fastest way to extract Element from Set
         if x > self.number_of_chunks:  # we got a new AUX-Packet
             raise RuntimeError("this should not have happened!")
         else:
             if x != 0 or not self.use_headerchunk:
                 self.decodedPackets.add(
                     packet)  # Add Packet to decoded Packets
     self.degreeToPacket[degree].add(packet)
     if self.is_decoded():
         return True
     self.queue.append(packet)
     return degree
Ejemplo n.º 6
0
def __handle_lt(packet: Packet):
    return packet.get_used_packets()