Esempio n. 1
0
File: file.py Progetto: B3rs/P2P
    def is_completed(self):
        local_peer = Peer.get_local_peer()

        for part_num in range(0, self.parts_count):
            if not self.peer_has_part(local_peer, part_num):
                return False
        return True
Esempio n. 2
0
    def get_completed_file_parts_nums(cls, file_id):
        file = cls.find_file_by_id(file_id)
        parts = []
        if file:
            for i in range(0, file.parts_count):
                if file.peer_has_part(Peer.get_local_peer(), i):
                    parts.append(i)
            return parts

        else:
            raise Exception("File %s not found" %file_id)
Esempio n. 3
0
    def load_my_files(cls):
        peer_me = Peer.get_local_peer()
        for dirname, dirnames, filenames in os.walk(SHARED_PATH):
            for filename in filenames:
                path = dirname + "/" + filename
                file = File(hashing.generate_file_id(), filename,path)

                #Set that I have all this file
                for p in range(0, file.parts_count):
                    file.set_peer_has_part(peer_me, p, True)

                cls.get_files().append(file)
Esempio n. 4
0
    def get_ordered_parts_number(cls, file_id):
        file = cls.find_file_by_id(file_id)
        if file:
            part_counter = Counter()
            ordered_parts = []

            for p_num in range(0, file.parts_count):
                if file.parts_mask_for_peer(Peer.get_local_peer()).is_not_started(p_num):
                    peers_count = len(file.get_peers_for_file_part(p_num))
                    part_counter[p_num] = peers_count

            for (part_num, frequency) in part_counter.most_common():
                ordered_parts.append(part_num)

            return list(reversed(ordered_parts))
        else:
            raise Exception("File not found: %s" %file_id)
Esempio n. 5
0
 def set_status_part_for_file(cls, file_id, part_num, status):
     file = cls.find_file_by_id(file_id)
     if file:
         file.set_peer_status_for_part(Peer.get_local_peer(), part_num, status)
     else:
         raise Exception("File %s not found" %file_id)