本文整理汇总了Python中Tribler.Core.DownloadConfig.DownloadStartupConfig.set_proxyservice_role方法的典型用法代码示例。如果您正苦于以下问题:Python DownloadStartupConfig.set_proxyservice_role方法的具体用法?Python DownloadStartupConfig.set_proxyservice_role怎么用?Python DownloadStartupConfig.set_proxyservice_role使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tribler.Core.DownloadConfig.DownloadStartupConfig
的用法示例。
在下文中一共展示了DownloadStartupConfig.set_proxyservice_role方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_download
# 需要导入模块: from Tribler.Core.DownloadConfig import DownloadStartupConfig [as 别名]
# 或者: from Tribler.Core.DownloadConfig.DownloadStartupConfig import set_proxyservice_role [as 别名]
def new_download(self, permid, infohash, torrent_data):
""" Start a new download in order to get the pieces that will be requested by the doe.
After the download is started, find the appropriate proxy object and call it's method.
@param permid: The permid of the peer who sent the message
@param infohash: the infohash of the torrent for which relay is requested
@param torrent_data: the content of the .torrent file
"""
# Create the name for the .torrent file in the proxy cache
basename = binascii.hexlify(infohash) + ".torrent"
torrentfilename = os.path.join(self.proxydir, basename)
# Write the .torrent information in the .torrent proxy cache file
tfile = open(torrentfilename, "wb")
tfile.write(torrent_data)
tfile.close()
if DEBUG:
print >>sys.stderr, "proxy: new_download: Got metadata required for relaying"
print >>sys.stderr, "proxy: new_download: torrent: ", torrentfilename
tdef = TorrentDef.load(torrentfilename)
if self.dlconfig is None:
dscfg = DownloadStartupConfig()
else:
dscfg = DownloadStartupConfig(self.dlconfig)
dscfg.set_proxyservice_role(PROXYSERVICE_ROLE_PROXY)
dscfg.set_dest_dir(self.proxydir)
dscfg.set_doe_mode(DOE_MODE_OFF) # a proxy does not use other proxies for downloading data in the current stage
# Start new download
if DEBUG:
print >>sys.stderr, "proxy: new_download: Starting a new download"
self.session.add_observer(self.proxydownloader_started, NTFY_PROXYDOWNLOADER, [NTFY_STARTED])
d = self.session.start_download(tdef, dscfg)
d.set_state_callback(self.state_callback, getpeerlist=False)