'Setup the seeder.'

@blocking_call_on_reactor_thread
@inlineCallbacks
def setup_tunnel_seeder(self, hops):

    from Tribler.Core.Session import Session
    self.seed_config = self.config.copy()
    self.seed_config.set_state_dir(self.getStateDir(2))
    self.seed_config.set_megacache_enabled(True)
    self.seed_config.set_tunnel_community_socks5_listen_ports(self.get_socks5_ports())
    if (self.session2 is None):
        self.session2 = Session(self.seed_config, ignore_singleton=True, autoload_discovery=False)
        self.session2.start()
    tdef = TorrentDef()
    tdef.add_content(os.path.join(TESTS_DATA_DIR, 'video.avi'))
    tdef.set_tracker('http://localhost/announce')
    tdef.finalize()
    torrentfn = os.path.join(self.session2.config.get_state_dir(), 'gen.torrent')
    tdef.save(torrentfn)
    self.seed_tdef = tdef
    if (hops > 0):
        self.tunnel_community_seeder = self.load_tunnel_community_in_session(self.session2)
        self.tunnel_community_seeder.build_tunnels(hops)
        from twisted.internet import reactor, task
        while (not list(self.tunnel_community_seeder.active_data_circuits())):
            (yield task.deferLater(reactor, 0.05, (lambda : None)))
    dscfg = DownloadStartupConfig()
    dscfg.set_dest_dir(TESTS_DATA_DIR)
    dscfg.set_hops(hops)
    d = self.session2.start_download_from_tdef(tdef, dscfg)
    d.set_state_callback(self.seeder_state_callback)
