def add_peer(self, peer): with self._peers: if not peer in self._peers and self.need_more(): self._peers.append(peer) peer.bitfield(self._storage.bitfield)
self._torrent = t def has(self, piece): return False def completed(self): return False def piece(self, index): return storage.Piece.create_empty_piece(\ index, 256000, self._torrent.piece_hash(index)) def write_piece(self, piece): print("Writting piece ", piece) manager = PeerManager(peer_id, t, None, None, StorageMock(t)) peer = peer.handshake(sock, addr, peer_id, t, manager) field = bitfield.Bitfield(t.number_of_pieces) #for i in range(len(field)): # if random.random() < 0.5: # field.set(i) field.set(8) peer.bitfield(field) peer.choke(True) peer.choke(False) peer.have(9) time.sleep(5) peer.close()