• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ torrent_handle类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中torrent_handle的典型用法代码示例。如果您正苦于以下问题:C++ torrent_handle类的具体用法?C++ torrent_handle怎么用?C++ torrent_handle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了torrent_handle类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: make_magnet_uri

	std::string make_magnet_uri(torrent_handle const& handle)
	{
		if (!handle.is_valid()) return "";

		std::string ret;
		sha1_hash const& ih = handle.info_hash();
		ret += "magnet:?xt=urn:btih:";
		ret += to_hex(ih.to_string());

		torrent_status st = handle.status(torrent_handle::query_name);
		if (!st.name.empty())
		{
			ret += "&dn=";
			ret += escape_string(st.name.c_str(), st.name.length());
		}

		std::vector<announce_entry> const& tr = handle.trackers();
		for (std::vector<announce_entry>::const_iterator i = tr.begin(), end(tr.end()); i != end; ++i)
		{
			ret += "&tr=";
			ret += escape_string(i->url.c_str(), i->url.length());
		}

		std::set<std::string> seeds = handle.url_seeds();
		for (std::set<std::string>::iterator i = seeds.begin()
			, end(seeds.end()); i != end; ++i)
		{
			ret += "&ws=";
			ret += escape_string(i->c_str(), i->length());
		}

		return ret;
	}
开发者ID:ycopy,项目名称:libtorrent,代码行数:33,代码来源:magnet_uri.cpp


示例2: make_magnet_uri

	std::string make_magnet_uri(torrent_handle const& handle)
	{
		if (!handle.is_valid()) return "";

		std::string ret;
		sha1_hash const& ih = handle.info_hash();
		ret += "magnet:?xt=urn:btih:";
		ret += aux::to_hex(ih);

		torrent_status st = handle.status(torrent_handle::query_name);
		if (!st.name.empty())
		{
			ret += "&dn=";
			ret += escape_string(st.name);
		}

		for (auto const& tr : handle.trackers())
		{
			ret += "&tr=";
			ret += escape_string(tr.url);
		}

		for (auto const& s : handle.url_seeds())
		{
			ret += "&ws=";
			ret += escape_string(s);
		}

		return ret;
	}
开发者ID:Chocobo1,项目名称:libtorrent,代码行数:30,代码来源:magnet_uri.cpp


示例3: make_magnet_uri

	std::string make_magnet_uri(torrent_handle const& handle)
	{
		if (!handle.is_valid()) return "";

		char ret[1024];
		sha1_hash const& ih = handle.info_hash();
		int num_chars = snprintf(ret, sizeof(ret), "magnet:?xt=urn:btih:%s"
			, base32encode(std::string((char const*)&ih[0], 20)).c_str());

		std::string name = handle.name();

		if (!name.empty())
			num_chars += snprintf(ret + num_chars, sizeof(ret) - num_chars, "&dn=%s"
				, escape_string(name.c_str(), name.length()).c_str());

		std::string tracker;
		torrent_status st = handle.status();
		if (!st.current_tracker.empty())
		{
			tracker = st.current_tracker;
		}
		else
		{
			std::vector<announce_entry> const& tr = handle.trackers();
			if (!tr.empty()) tracker = tr[0].url;
		}
		if (!tracker.empty())
			num_chars += snprintf(ret + num_chars, sizeof(ret) - num_chars, "&tr=%s"
				, escape_string(tracker.c_str(), tracker.size()).c_str());

		return ret;
	}
开发者ID:bird1015,项目名称:avplayer,代码行数:32,代码来源:magnet_uri.cpp


示例4: if

	torrent_alert::torrent_alert(aux::stack_allocator& alloc
		, torrent_handle const& h)
		: handle(h)
		, m_alloc(alloc)
	{
		std::string name_str;
		if (h.native_handle())
		{
			m_name_idx = alloc.copy_string(h.native_handle()->name());
		}
		else if (h.is_valid())
		{
			char msg[41];
			to_hex(h.native_handle()->info_hash().data(), 20, msg);
			m_name_idx = alloc.copy_string(msg);
		}
		else
		{
			m_name_idx = alloc.copy_string("");
		}

#ifndef TORRENT_NO_DEPRECATE
		name = torrent_name();
#endif
	}
开发者ID:kevindhawkins,项目名称:libtorrent,代码行数:25,代码来源:alert.cpp


示例5: make_magnet_uri

	std::string make_magnet_uri(torrent_handle const& handle)
	{
		std::stringstream ret;
		if (!handle.is_valid()) return ret.str();

		std::string name = handle.name();

		ret << "magnet:?xt=urn:btih:" << base32encode(
			std::string((char*)handle.info_hash().begin(), 20));
		if (!name.empty())
			ret << "&dn=" << escape_string(name.c_str(), name.length());
		torrent_status st = handle.status();
		if (!st.current_tracker.empty())
		{
			ret << "&tr=" << escape_string(st.current_tracker.c_str()
				, st.current_tracker.length());
		}
		else
		{
			std::vector<announce_entry> const& tr = handle.trackers();
			if (!tr.empty())
			{
				ret << "&tr=" << escape_string(tr[0].url.c_str()
					, tr[0].url.length());
			}
		}
		return ret.str();
	}
开发者ID:huyang819,项目名称:cdn-partner,代码行数:28,代码来源:magnet_uri.cpp


示例6: handle

	torrent_alert::torrent_alert(aux::stack_allocator& alloc
		, torrent_handle const& h)
		: handle(h)
		, m_alloc(alloc)
	{
		boost::shared_ptr<torrent> t = h.native_handle();
		if (t)
		{
			std::string name_str = t->name();
			if (!name_str.empty()) {
				m_name_idx = alloc.copy_string(name_str);
			}
			else
			{
				char msg[41];
				to_hex(t->info_hash().data(), 20, msg);
				m_name_idx = alloc.copy_string(msg);
			}
		}
		else
		{
			m_name_idx = alloc.copy_string("");
		}

#ifndef TORRENT_NO_DEPRECATE
		name = torrent_name();
#endif
	}
开发者ID:microIBM,项目名称:libtorrent,代码行数:28,代码来源:alert.cpp


示例7: die

void MainWindow::realAddTorrent(QString torrentFile, QString torrentPath, QString mountPath) {
    if (!QFile::exists(torrentFile) && !isMagnet(torrentFile))
        die("torrent file not found");

    standartText = ("Torrent file: " + torrentFile + "\nDownload path: " + torrentPath + "\nMount path: " + mountPath + "\n").toLocal8Bit();
    standartTextLen = standartText.size();
    updateStandartText();

    if (torrentPath[torrentPath.length() - 1] != QChar('/'))
        torrentPath += "/";
    if (mountPath[mountPath.length() - 1] != QChar('/'))
        mountPath += "/";

    resumeSavePath = torrentPath;

    add_torrent_params p;
    p.storage_mode = libtorrent::storage_mode_allocate;

    if (isMagnet(torrentFile)) {
        int i;
        for (i = 1; torrentFile[i] != '='; i++);
        for (i = i + 1; torrentFile[i] != '='; i++);

        QString url;
        for (i = i + 1; torrentFile[i] != '&'; i++)
            url += torrentFile[i];

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
        QString name = QUrl(url).toString().replace("+", " ");
#else
        QString name = QUrl(url).toString(QUrl::PreferLocalFile).replace("+", " ");
#endif
        p.save_path = (torrentPath + name + "/").toStdString();

        const torrent_handle h = libtorrent::add_magnet_uri(*session, torrentFile.toStdString(), p);
        main = new Torrent(torrentPath + QString::fromStdString(h.name()), mountPath + QString::fromStdString(h.name()), h, this);
    } else {
        torrent_info *inf = new libtorrent::torrent_info(torrentFile.toStdString());
        p.ti = inf;
        p.save_path = (torrentPath + QString::fromStdString(inf->name()) + "/").toStdString();
        main = new Torrent(torrentPath + QString::fromStdString(inf->name()), mountPath + QString::fromStdString(inf->name()), session->add_torrent(p), this);
    }

    setupTimers();
}
开发者ID:vitlav,项目名称:QLiveBittorrent,代码行数:45,代码来源:mainwindow.cpp


示例8: on_torrent_added

	virtual void on_torrent_added(int idx, torrent_handle h) override
	{
		if (idx == 0) return;

		if (m_flags & upload_only)
		{
			h.set_upload_mode(true);
		}
	}
开发者ID:randy-waterhouse,项目名称:libtorrent,代码行数:9,代码来源:test_metadata_extension.cpp


示例9: remove_torrent

	void session::remove_torrent(const torrent_handle& h, int options)
	{
		if (!h.is_valid())
#ifdef BOOST_NO_EXCEPTIONS
			return;
#else
			throw_invalid_handle();
#endif
		TORRENT_ASYNC_CALL2(remove_torrent, h, options);
	}
开发者ID:pedia,项目名称:raidget,代码行数:10,代码来源:session.cpp


示例10: create_ut_pex_plugin

	boost::shared_ptr<torrent_plugin> create_ut_pex_plugin(torrent_handle const& th, void*)
	{
		torrent* t = th.native_handle().get();
		if (t->torrent_file().priv() || (t->torrent_file().is_i2p()
			&& !t->settings().get_bool(settings_pack::allow_i2p_mixed)))
		{
			return boost::shared_ptr<torrent_plugin>();
		}
		return boost::shared_ptr<torrent_plugin>(new ut_pex_plugin(*t));
	}
开发者ID:majestrate,项目名称:libtorrent,代码行数:10,代码来源:ut_pex.cpp


示例11: remove_torrent

	void session_handle::remove_torrent(const torrent_handle& h, int options)
	{
		if (!h.is_valid())
#ifdef BOOST_NO_EXCEPTIONS
			return;
#else
			throw_invalid_handle();
#endif
		async_call(&session_impl::remove_torrent, h, options);
	}
开发者ID:krattai,项目名称:AEBL,代码行数:10,代码来源:session_handle.cpp


示例12: UnregisterHandle

void TorrentDownloadManager::UnregisterHandle(torrent_handle h){
	this->dlmutex.Lock();
	if(!this->handle_map.erase(h)){
		try{
			syslog(LOG_ERR,"Erase of handle %s failed",h.name().c_str());
		}catch(libtorrent::invalid_handle& err){
			syslog(LOG_ERR,"Erase of invalid handle");
		}
	}
	this->dlmutex.Unlock();
}
开发者ID:Excito,项目名称:filetransferdaemon,代码行数:11,代码来源:TorrentDownloader.cpp


示例13: wait_for_complete

void wait_for_complete(lt::session& ses, torrent_handle h)
{
	for (int i = 0; i < 70; ++i)
	{
		print_alerts(ses, "ses1");
		torrent_status st = h.status();
		fprintf(stderr, "%f %%\n", st.progress_ppm / 10000.f);
		if (st.progress_ppm == 1000000) return;
		test_sleep(500);
	}
	TEST_ERROR("torrent did not finish");
}
开发者ID:Sukumi,项目名称:libtorrent,代码行数:12,代码来源:test_recheck.cpp


示例14: wait_for_complete

void wait_for_complete(lt::session& ses, torrent_handle h)
{
	int last_progress = 0;
	clock_type::time_point last_change = clock_type::now();
	for (int i = 0; i < 400; ++i)
	{
		print_alerts(ses, "ses1");
		torrent_status st = h.status();
		fprintf(stderr, "%f %%\n", st.progress_ppm / 10000.f);
		if (st.progress_ppm == 1000000) return;
		if (st.progress_ppm != last_progress)
		{
			last_progress = st.progress_ppm;
			last_change = clock_type::now();
		}
		if (clock_type::now() - last_change > seconds(10)) break;
		test_sleep(500);
	}
	TEST_ERROR("torrent did not finish");
}
开发者ID:Meonardo,项目名称:libtorrent,代码行数:20,代码来源:test_recheck.cpp



注:本文中的torrent_handle类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ torrent_info类代码示例发布时间:2022-05-31
下一篇:
C++ tokenizer类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap