本文整理汇总了Python中Tribler.Core.DownloadConfig.DownloadStartupConfig.set_hops方法的典型用法代码示例。如果您正苦于以下问题:Python DownloadStartupConfig.set_hops方法的具体用法?Python DownloadStartupConfig.set_hops怎么用?Python DownloadStartupConfig.set_hops使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tribler.Core.DownloadConfig.DownloadStartupConfig
的用法示例。
在下文中一共展示了DownloadStartupConfig.set_hops方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_tunnel_seeder
# 需要导入模块: from Tribler.Core.DownloadConfig import DownloadStartupConfig [as 别名]
# 或者: from Tribler.Core.DownloadConfig.DownloadStartupConfig import set_hops [as 别名]
def setup_tunnel_seeder(self, hops):
"""
Setup the seeder.
"""
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)
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: # Safe seeding enabled
self.tunnel_community_seeder = self.load_tunnel_community_in_session(self.session2)
self.tunnel_community_seeder.build_tunnels(hops)
else:
self.sanitize_network(self.session2)
dscfg = DownloadStartupConfig()
dscfg.set_dest_dir(TESTS_DATA_DIR) # basedir of the file we are seeding
dscfg.set_hops(hops)
d = self.session2.start_download_from_tdef(tdef, dscfg)
d.set_state_callback(self.seeder_state_callback)
示例2: setupSeeder
# 需要导入模块: from Tribler.Core.DownloadConfig import DownloadStartupConfig [as 别名]
# 或者: from Tribler.Core.DownloadConfig.DownloadStartupConfig import set_hops [as 别名]
def setupSeeder(self, hops=0, session=None):
from Tribler.Core.Session import Session
from Tribler.Core.TorrentDef import TorrentDef
from Tribler.Core.DownloadConfig import DownloadStartupConfig
self.setUpPreSession()
self.config.set_libtorrent(True)
self.config2 = self.config.copy()
self.config2.set_state_dir(self.getStateDir(2))
if session is None:
self.session2 = Session(self.config2, ignore_singleton=True, autoload_discovery=False)
upgrader = self.session2.prestart()
while not upgrader.is_done:
time.sleep(0.1)
self.session2.start()
session = self.session2
tdef = TorrentDef()
tdef.add_content(os.path.join(TESTS_DATA_DIR, "video.avi"))
tdef.set_tracker("http://fake.net/announce")
tdef.set_private() # disable dht
tdef.finalize()
torrentfn = os.path.join(session.get_state_dir(), "gen.torrent")
tdef.save(torrentfn)
dscfg = DownloadStartupConfig()
dscfg.set_dest_dir(TESTS_DATA_DIR) # basedir of the file we are seeding
dscfg.set_hops(hops)
d = session.start_download(tdef, dscfg)
d.set_state_callback(self.seeder_state_callback)
return torrentfn
示例3: start_anon_download
# 需要导入模块: from Tribler.Core.DownloadConfig import DownloadStartupConfig [as 别名]
# 或者: from Tribler.Core.DownloadConfig.DownloadStartupConfig import set_hops [as 别名]
def start_anon_download(self, hops=1):
"""
Start an anonymous download in the main Tribler session.
"""
dscfg = DownloadStartupConfig()
dscfg.set_dest_dir(self.getDestDir())
dscfg.set_hops(hops)
download = self.session.start_download_from_tdef(self.seed_tdef, dscfg)
download.add_peer(("127.0.0.1", self.session2.config.get_libtorrent_port()))
return download
示例4: start_anon_download
# 需要导入模块: from Tribler.Core.DownloadConfig import DownloadStartupConfig [as 别名]
# 或者: from Tribler.Core.DownloadConfig.DownloadStartupConfig import set_hops [as 别名]
def start_anon_download(self, hops=1):
"""
Start an anonymous download in the main Tribler session.
"""
dscfg = DownloadStartupConfig()
dscfg.set_dest_dir(self.getDestDir())
dscfg.set_hops(hops)
download = self.session.start_download_from_tdef(self.seed_tdef, dscfg)
tc = self.session.lm.tunnel_community
tc.bittorrent_peers[download] = [("127.0.0.1", self.session2.config.get_libtorrent_port())]
return download
示例5: on_torrent_insert
# 需要导入模块: from Tribler.Core.DownloadConfig import DownloadStartupConfig [as 别名]
# 或者: from Tribler.Core.DownloadConfig.DownloadStartupConfig import set_hops [as 别名]
def on_torrent_insert(self, source_str, infohash, name):
"""
Callback function called by the source when a new torrent is discovered
"""
self._logger.debug('Received torrent %s from %s', infohash, source_str)
if source_str not in self.sources:
self._logger.debug('Skipping torrent %s (unknown source %s)', infohash, source_str)
return
# Did we already get this torrent from another source?
if infohash in self.torrents:
self.torrents[infohash].sources.add(source_str)
self._logger.debug('Skipping torrent %s (already known)', infohash)
return
# If a download already exists or already has a checkpoint, skip this torrent
if self.session.get_download(unhexlify(infohash)) or \
os.path.exists(os.path.join(self.session.get_downloads_pstate_dir(), infohash + '.state')):
self._logger.debug('Skipping torrent %s (download already running or scheduled to run)', infohash)
return
if len(self.torrents) >= self.settings.max_torrents_listed:
self._logger.debug('Skipping torrent %s (limit reached)', infohash)
return
self.torrents[infohash] = CreditMiningTorrent(infohash, name)
self.torrents[infohash].sources.add(source_str)
self._logger.info('Starting torrent %s', infohash)
magnet = u'magnet:?xt=urn:btih:%s&dn=%s' % (infohash, name)
dl_config = DownloadStartupConfig()
dl_config.set_hops(self.settings.hops)
dl_config.set_dest_dir(self.settings.save_path)
dl_config.set_credit_mining(True)
dl_config.set_user_stopped(True)
self.session.lm.add(TorrentDefNoMetainfo(unhexlify(infohash), name, magnet), dl_config, hidden=True)
示例6: create_dconfig_from_params
# 需要导入模块: from Tribler.Core.DownloadConfig import DownloadStartupConfig [as 别名]
# 或者: from Tribler.Core.DownloadConfig.DownloadStartupConfig import set_hops [as 别名]
def create_dconfig_from_params(parameters):
"""
Create a download configuration based on some given parameters. Possible parameters are:
- anon_hops: the number of hops for the anonymous download. 0 hops is equivalent to a plain download
- safe_seeding: whether the seeding of the download should be anonymous or not (0 = off, 1 = on)
- destination: the destination path of the torrent (where it is saved on disk)
"""
download_config = DownloadStartupConfig()
anon_hops = 0
if 'anon_hops' in parameters and len(parameters['anon_hops']) > 0:
if parameters['anon_hops'][0].isdigit():
anon_hops = int(parameters['anon_hops'][0])
safe_seeding = False
if 'safe_seeding' in parameters and len(parameters['safe_seeding']) > 0 \
and parameters['safe_seeding'][0] == "1":
safe_seeding = True
if anon_hops > 0 and not safe_seeding:
return None, "Cannot set anonymous download without safe seeding enabled"
if anon_hops > 0:
download_config.set_hops(anon_hops)
if safe_seeding:
download_config.set_safe_seeding(True)
if 'destination' in parameters and len(parameters['destination']) > 0:
dest_dir = cast_to_unicode_utf8(parameters['destination'][0])
download_config.set_dest_dir(dest_dir)
if 'selected_files[]' in parameters:
selected_files_list = [cast_to_unicode_utf8(f) for f in parameters['selected_files[]']]
download_config.set_selected_files(selected_files_list)
return download_config, None