Exemple #1
0
  def test_allocate_connections(self):
      torrent, seeders, leechers = make_ensemble(
          self.io_loop, num_seeders=1, num_leechers=1, fs=MemoryFilesystem())
      seeder_scheduler = seeders[0]
      leecher_scheduler = leechers[0]

      connections = seeder_scheduler._allocate_connections()
      assert connections == []
      connections = leecher_scheduler._allocate_connections()
      assert connections == [(torrent, ('127.0.0.1', seeder_scheduler.client.port))]
  def test_single_seeder_single_leecher(self):
    torrent, seeders, leechers = make_ensemble(
        self.io_loop, num_seeders=1, num_leechers=1, fs=MemoryFilesystem())
    seeder = seeders[0].client
    leecher = leechers[0].client

    # check connection initiation
    assert seeder.peer_id not in leecher.get_session(torrent).peer_ids
    assert leecher.peer_id not in seeder.get_session(torrent).peer_ids
    yield gen.Task(leecher.initiate_connection, torrent, ('127.0.0.1', seeder.port))
    assert seeder.peer_id in leecher.get_session(torrent).peer_ids
    assert leecher.peer_id in seeder.get_session(torrent).peer_ids
  def test_integrate(self):
    torrent, seeders, leechers = make_ensemble(
        self.io_loop,
        num_seeders=1,
        num_leechers=1,
        scheduler_impl=FastScheduler,
        fs=MemoryFilesystem())
    seeder_scheduler, seeder = seeders[0], seeders[0].client
    leecher_scheduler, leecher = leechers[0], leechers[0].client

    # run the torrent!
    leecher.get_session(torrent).register_done_callback(self.stop)
    leecher_scheduler.start()
    seeder_scheduler.start()
    self.wait()
def run(io_loop, options):
  torrent, seeders, leechers = make_ensemble(
      io_loop,
      num_seeders=options.num_seeders,
      num_leechers=options.num_leechers,
      piece_size=options.piece_size,
      max_filesize=options.max_filesize,
      total_filesize=options.total_filesize,
      fs=MemoryFilesystem() if options.inmemory else DiskFilesystem())

  finishes = []

  for leecher in leechers:
    leecher.client.get_session(torrent).register_done_callback(
       functools.partial(finishes.append, leecher.client.peer_id))
    leecher.start()

  for seeder in seeders:
    seeder.start()

  while len(finishes) != options.num_leechers:
    yield gen.Task(io_loop.add_timeout, io_loop.time() + 0.1)