def run(self): self.loop1 = interval(self.host, self.announce_timeout, self.proxy, "announce") self.loop2 = interval(self.host, self.discovery_period, self.proxy, "update_peers") self.loop3 = interval(self.host, self.gossip_cycle, self.proxy, "active_thread")
def init_combinado(self, idTorrent): self.mida_torrent = self.tracker.getMidaTorrent(idTorrent) for i in range (0, self.mida_torrent): self.falten.append(i) self.interval = interval(self.host, 3, self.proxy, 'notify', idTorrent) self.interval_combinado = interval(self.host, 1, self.proxy, 'combinado', idTorrent)
def init_start(self, torrent): self.peerAnounce = interval(h, 6, self.proxy, "announce", t, torrent) self.peerPush = interval(h, 1, self.proxy, "pushGossip", torrent) if self.proxy != ps: self.peerPull = interval(h, 1, self.proxy, "pullGossip", torrent) later(60, self.proxy, "stop_interval")
def init_start(self, tracker, torrent_hash, time, option, file=None): """ Metodo para inicializar el peer :param tracker: tracker :param torrent_hash: id torrent :param time: tiempo para parar el peer :param option: opcion a ejecutar :param file: fichero """ if (option >= 1) and (option <= 3): self._set_tracker(tracker) self._set_torrent_hash(torrent_hash) self.option = option self.file = file if not self._KEY_DATA in self.torrent: self.torrent[self._KEY_DATA] = {} if ((option == self._KEY_PULL_ACTION) or (option == self._KEY_PUSH_PULL_ACTION)) and (not self.seed): self._init_structs() self.announce__set_peers_interval = interval( self.host, 5, self.proxy, 'announce_set_peers') if option == self._KEY_PUSH_ACTION: self.push_interval = interval(self.host, 1, self.proxy, 'push') elif option == self._KEY_PULL_ACTION: if not self.seed: # if not seed self.pull_interval = interval(self.host, 1, self.proxy, 'pull') else: self.push_interval = interval(self.host, 1, self.proxy, 'push') if not self.seed: self.pull_interval = interval(self.host, 1, self.proxy, 'pull') self.result_interval = interval(self.host, 1, self.proxy, 'save_result') later(time, self.proxy, 'stop_interval')
def start_peer(self, operacion, protocolo, longitud_archivo, fileX, tracker, printer): self.torrenthash = fileX self.long_archivo = longitud_archivo self.tracker = tracker self.interval1 = interval(self.host, 1, self.proxy, "announce") if operacion == "up": # UPLOAD self.printer = printer self.chunks_restantes = None self.cargar_fichero(fileX) self.interval2 = interval(self.host, 2, self.proxy, "get_peers") else: # DOWNLOAD self.printer = printer self.printer.start( self.proxy) #iniciamos el printer con nuestro proxy self.chunks_restantes = list(xrange(longitud_archivo)) self.interval2 = interval(self.host, 2, self.proxy, "get_peers") # Inicia el proceso para la grafica self.progreso = interval(self.host, 1, self.proxy, "envia_progreso") if protocolo == 1 or protocolo == 3: # Inicia el processo pull para descargar self.proceso_pull = interval(self.host, 1, self.proxy, "pull_start") if protocolo == 2 or protocolo == 3: # Inicia el processo push para compartir self.proceso_push = interval(self.host, 1, self.proxy, "push_start")
def init_peer(self, torrent_hash, data_lenght, protocol): self.tracker = self.host.lookup('tracker') self.assistant = self.host.lookup('assistant') self.torrent_hash = torrent_hash self.total_length = data_lenght # Get a list of the missing ID's self.missing_chunks = list(xrange(data_lenght)) # Announce the peer every 10 seconds self.interval = interval(self.host, 10, self.proxy, "announce") # Check the data for accounting self.interval_check_data = interval(self.host, 1, self.proxy, "check_data") interval(self.host, 2, self.proxy, "get_peers") if protocol == "push" or protocol == "push-pull": # Push data among neighbors every second self.interval_push_data = interval(self.host, 1, self.proxy, "push_data") if protocol == "pull" or protocol == "push-pull": # Request chunks among neighbors every second self.interval_pull_request = interval(self.host, 1, self.proxy, "pull")
def init_hybrid(self): self.cycle = 0 self.interval = interval(self.host, 3, self.proxy, 'announce_me') self.interval_hybrid = interval(self.host, 1, self.proxy, 'make_hybrid') later(20, self.proxy, 'make_graph', 'Hybrid', 'hybrid')
def init_start(self): self.interval_check = interval(self.host, 1, self.proxy, 'comprovarPeers')
def init_start(self): self.interval = interval(self.host, 3, self.proxy, 'announce_me') later(5, self.proxy, 'stop_interval')
def init_pull(self): self.cycle = 0 self.interval = interval(self.host, 3, self.proxy, 'announce_me') self.interval_pull = interval(self.host, 1, self.proxy, 'make_pull') later(20, self.proxy, 'make_graph', 'Pull', 'pull')
def init_start(self, torrent): self.timeCheck = interval(h, 1, self.proxy, "trackerTimeCheck", torrent) later(60, self.proxy, "stop_interval")
def init_start(self): self.cnt = 0 self.interval = interval(self.host, 0.1, self.proxy, 'update')
def init_start(self): self.cnt = 0 self.interval = interval(self.host, 0.1, self.proxy, "update")
if __name__ == '__main__': set_context('green_thread') host = create_host() # Create and initialize nodes for i in range(len(nodes)): nodes_h[i] = host.spawn(str(nodes[i]), Node) nodes_h[i].init_node() for i in range(len(nodes_h)): j = 0 if i is 0 else i - 1 try: if nodes_h[i].join(nodes_h[j], timeout=20): print("JOIN OK", nodes_h[i].get_id()) else: print("Node %s fails" % str(i)) except Exception: raise else: interval(host, 0.5, nodes_h[i], "update") # Wait to give time to chord to fix its tables. sleep(5) found = nodes_h[0].find_successor(40) print("found", found.get_id()) shutdown()
def init_start(self): self.interval1 = interval(self.host, 1, self.proxy, "send_message")
def init_start(self, hostPeer): self.peerAnounce = interval(hostPeer, 3, self.proxy, "announce") later(300, self.proxy, "stop_interval")
def init_time(self): self.start_time = -1 self.interval2 = interval(self.host, 1, self.proxy, "show_time")
def run(self): self.loop1 = interval(self.host, self.announce_timeout, self.proxy, "update")
def init_start(self): self.timeCheck = interval(h,1, self.proxy, "trackerTimeCheck") later(300, self.proxy, "stop_interval")
def init_start(self): self.interval1 = interval(self.host, 1, self.proxy, "hello", "you") later(5, self.proxy, "stop_interval")
nodes_h = {} set_context('green_thread') host = create_host() # Create and initialize nodes for i in range(len(nodes)): nodes_h[i] = host.spawn(str(nodes[i]), Node) nodes_h[i].init_node() for i in range(len(nodes_h)): j = 0 if i is 0 else i-1 try: if nodes_h[i].join(nodes_h[j], timeout=20): print 'JOIN OK', nodes_h[i].get_id() else: print 'Node %s fails' % str(i) except Exception: raise else: interval(host, 0.5, nodes_h[i], "update") # Wait to give time to chord to fix its tables. sleep(5) found = nodes_h[0].find_successor(40) print 'found', found.get_id() shutdown()