当前位置: 首页>>代码示例>>C++>>正文


C++ libtorrent::session类代码示例

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


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

示例1: load_dht_state

void load_dht_state(lt::session& s)
{
	FILE* f = fopen(".dht", "rb");
	if (f == NULL) return;

	fseek(f, 0, SEEK_END);
	int size = ftell(f);
	fseek(f, 0, SEEK_SET);

	if (size > 0)
	{
		std::vector<char> state;
		state.resize(size);
		fread(&state[0], 1, state.size(), f);

		bdecode_node e;
		error_code ec;
		bdecode(&state[0], &state[0] + state.size(), e, ec);
		if (ec)
			fprintf(stderr, "failed to parse .dht file: (%d) %s\n"
				, ec.value(), ec.message().c_str());
		else
		{
			printf("load dht state from .dht\n");
			s.load_state(e);
		}
	}
	fclose(f);
}
开发者ID:MikaelSmith,项目名称:libtorrent,代码行数:29,代码来源:dht_put.cpp

示例2: on_alert

	bool on_alert(libtorrent::alert const* alert
		, int session_idx
		, std::vector<libtorrent::torrent_handle> const& handles
		, libtorrent::session& ses) override
	{
		if (alert_cast<metadata_received_alert>(alert))
		{
			m_metadata_alerts += 1;
		}

		// make sure this function can be called on
		// torrents without metadata
		if ((m_flags & disconnect) == 0)
		{
			handles[session_idx].status();
		}

		if ((m_flags & disconnect)
			&& session_idx == 1
			&& alert_cast<metadata_received_alert>(alert))
		{
			ses.remove_torrent(handles[session_idx]);
			return true;
		}
		return false;
	}
开发者ID:randy-waterhouse,项目名称:libtorrent,代码行数:26,代码来源:test_metadata_extension.cpp

示例3: filter_ips

void filter_ips(lt::session& ses)
{
	using namespace libtorrent;
	ip_filter filter;
	filter.add_rule(asio::ip::address_v4::from_string("50.0.0.1")
		, asio::ip::address_v4::from_string("50.0.0.2"), ip_filter::blocked);
	ses.set_ip_filter(filter);
}
开发者ID:RavenB,项目名称:libtorrent,代码行数:8,代码来源:test_transfer.cpp

示例4: catch

//-----------------------------------------------------------------------------
JNIEXPORT jboolean JNICALL Java_com_softwarrior_libtorrent_LibTorrent_ResumeSession
	(JNIEnv *, jobject)
{
	jboolean result = JNI_FALSE;
	try {
		if(gSessionState){
			gSession.resume();
			bool paused = gSession.is_paused();
			if(!paused) result = JNI_TRUE;
		}
	} catch(...){
		LOG_ERR("Exception: failed to resume session");
		gSessionState=false;
	}
	if(!gSessionState) LOG_ERR("LibTorrent.ResumeSession SessionState==false");
	gSessionState==true ? result=JNI_TRUE : result=JNI_FALSE;
	return result;
}
开发者ID:kknet,项目名称:PopcornTV,代码行数:19,代码来源:libtorrent.cpp

示例5: enable_enc

void enable_enc(lt::session& ses)
{
	using namespace libtorrent;
	settings_pack p;
	p.set_bool(settings_pack::prefer_rc4, true);
	p.set_int(settings_pack::in_enc_policy, settings_pack::pe_forced);
	p.set_int(settings_pack::out_enc_policy, settings_pack::pe_forced);
	p.set_int(settings_pack::allowed_enc_level, settings_pack::pe_both);
	ses.apply_settings(p);
}
开发者ID:RavenB,项目名称:libtorrent,代码行数:10,代码来源:test_transfer.cpp

示例6: enable_utp

void enable_utp(lt::session& ses)
{
	using namespace libtorrent;
	settings_pack p;
	p.set_bool(settings_pack::enable_outgoing_tcp, false);
	p.set_bool(settings_pack::enable_incoming_tcp, false);
	p.set_bool(settings_pack::enable_outgoing_utp, true);
	p.set_bool(settings_pack::enable_incoming_utp, true);
	ses.apply_settings(p);
}
开发者ID:RavenB,项目名称:libtorrent,代码行数:10,代码来源:test_transfer.cpp

示例7:

//-----------------------------------------------------------------------------
JNIEXPORT jboolean JNICALL Java_com_softwarrior_libtorrent_LibTorrent_SetSession
	(JNIEnv *env, jobject obj, jint ListenPort, jint UploadLimit, jint DownloadLimit)
{
	jboolean result = JNI_FALSE;
	try{
		gSession.set_alert_mask(libtorrent::alert::all_categories
			& ~(libtorrent::alert::dht_notification
			+ libtorrent::alert::progress_notification
			+ libtorrent::alert::debug_notification
			+ libtorrent::alert::stats_notification));

		int listenPort = 54321;
		if(ListenPort > 0)
			listenPort = ListenPort;
			gSession.listen_on(std::make_pair(listenPort, listenPort+10));

		int uploadLimit = UploadLimit;
		if(uploadLimit > 0){
			gSession.set_upload_rate_limit(uploadLimit * 1000);
		}
		else{
			gSession.set_upload_rate_limit(0);
		}
		int downloadLimit = DownloadLimit;
		if(downloadLimit > 0){
			gSession.set_download_rate_limit(downloadLimit * 1000);
		}
		else{
			gSession.set_download_rate_limit(0);
		}

		libtorrent::session_settings sets = gSession.settings();

		sets.announce_to_all_trackers = true;
		sets.announce_to_all_tiers = true;
		sets.prefer_udp_trackers = false;
		sets.max_peerlist_size = 0;

		gSession.set_settings(sets);

		LOG_INFO("ListenPort: %d\n", listenPort);
		LOG_INFO("DownloadLimit: %d\n", downloadLimit);
		LOG_INFO("UploadLimit: %d\n", uploadLimit);

		gSessionState=true;
	}catch(...){
		LOG_ERR("Exception: failed to set session");
		gSessionState=false;
	}
	if(!gSessionState) LOG_ERR("LibTorrent.SetSession SessionState==false");
	gSessionState==true ? result=JNI_TRUE : result=JNI_FALSE;
	return result;
}
开发者ID:kknet,项目名称:PopcornTV,代码行数:54,代码来源:libtorrent.cpp

示例8: bootstrap_session

void bootstrap_session(std::vector<dht_network*> networks, lt::session& ses)
{
	lt::dht_settings sett;
	sett.ignore_dark_internet = false;
	ses.set_dht_settings(sett);

	lt::entry state;

	for (auto dht : networks)
	{
		// bootstrap off of 8 of the nodes
		auto router_nodes = dht->router_nodes();

		char const* nodes_key;
		if (router_nodes.front().address().is_v6())
			nodes_key = "nodes6";
		else
			nodes_key = "nodes";

		lt::entry::list_type& nodes = state["dht state"][nodes_key].list();
		for (auto const& n : router_nodes)
		{
			std::string node;
			std::back_insert_iterator<std::string> out(node);
			lt::detail::write_endpoint(n, out);
			nodes.push_back(lt::entry(node));
		}
	}

	std::vector<char> buf;
	lt::bencode(std::back_inserter(buf), state);
	lt::bdecode_node e;
	lt::error_code ec;
	lt::bdecode(&buf[0], &buf[0] + buf.size(), e, ec);

	ses.load_state(e);
	lt::settings_pack pack;
	pack.set_bool(lt::settings_pack::enable_dht, true);
	ses.apply_settings(pack);
}
开发者ID:Chocobo1,项目名称:libtorrent,代码行数:40,代码来源:test_dht.cpp

示例9: save_dht_state

int save_dht_state(lt::session& s)
{
	entry e;
	s.save_state(e, session::save_dht_state);
	std::vector<char> state;
	bencode(std::back_inserter(state), e);
	FILE* f = fopen(".dht", "wb+");
	if (f == NULL)
	{
		fprintf(stderr, "failed to open file .dht for writing");
		return 1;
	}
	fwrite(&state[0], 1, state.size(), f);
	fclose(f);

	return 0;
}
开发者ID:MikaelSmith,项目名称:libtorrent,代码行数:17,代码来源:dht_put.cpp

示例10: set_proxy

void set_proxy(lt::session& ses, int proxy_type, int flags = 0, bool proxy_peer_connections = true)
{
	// apply the proxy settings to session 0
	using namespace libtorrent;
	settings_pack p;
	p.set_int(settings_pack::proxy_type, proxy_type);
	if (proxy_type == settings_pack::socks4)
		p.set_int(settings_pack::proxy_port, 4444);
	else
		p.set_int(settings_pack::proxy_port, 5555);
	if (flags & ipv6)
		p.set_str(settings_pack::proxy_hostname, "2001::2");
	else
		p.set_str(settings_pack::proxy_hostname, "50.50.50.50");
	p.set_bool(settings_pack::proxy_hostnames, true);
	p.set_bool(settings_pack::proxy_peer_connections, proxy_peer_connections);
	p.set_bool(settings_pack::proxy_tracker_connections, true);

	ses.apply_settings(p);
}
开发者ID:RavenB,项目名称:libtorrent,代码行数:20,代码来源:test_transfer.cpp

示例11: memset

//-----------------------------------------------------------------------------
JNIEXPORT jstring JNICALL Java_com_softwarrior_libtorrent_LibTorrent_GetSessionStatusText
	(JNIEnv *env, jobject obj)
{
	jstring result = NULL;
	try {
		if(gSessionState){
			std::string out;
			char str[500]; memset(str,0,500);
			libtorrent::session_status s_s = gSession.status();
			snprintf(str, sizeof(str),
					  "%25s%20d\n"
					  "%22s%20s/%s\n"
					  "%25s%20s/%s\n"
					  "%18s%20s/%s\n"
					  "%15s%20s/%s\n"
					  "%19s%20s/%s\n"
				,"conns:"
				, s_s.num_peers
				, "down/rate:"
				, add_suffix(s_s.total_download).c_str(), add_suffix(s_s.download_rate, "/s").c_str()
				, "up/rate:"
				, add_suffix(s_s.total_upload).c_str(), add_suffix(s_s.upload_rate, "/s").c_str()
				, "ip rate down/up:"
				, add_suffix(s_s.ip_overhead_download_rate, "/s").c_str(), add_suffix(s_s.ip_overhead_upload_rate, "/s").c_str()
				, "dht rate down/up:"
				, add_suffix(s_s.dht_download_rate, "/s").c_str(), add_suffix(s_s.dht_upload_rate, "/s").c_str()
				, "tr rate down/up:"
				, add_suffix(s_s.tracker_download_rate, "/s").c_str(), add_suffix(s_s.tracker_upload_rate, "/s").c_str());
			out += str;
			result = env->NewStringUTF(out.c_str());
		}
	} catch(...){
		LOG_ERR("Exception: failed to get session status");
	}
	return result;
}
开发者ID:kknet,项目名称:PopcornTV,代码行数:37,代码来源:libtorrent.cpp

示例12: test_resume_flags

torrent_handle test_resume_flags(libtorrent::session& ses, int flags
	, char const* file_priorities = "1111", char const* resume_file_prio = "")
{
	boost::shared_ptr<torrent_info> ti = generate_torrent();

	add_torrent_params p;

	p.ti = ti;
	p.flags = flags;
#ifdef TORRENT_WINDOWS
	p.save_path = "c:\\add_torrent_params save_path";
#else
	p.save_path = "/add_torrent_params save_path";
#endif
	p.trackers.push_back("http://add_torrent_params_tracker.com/announce");
	p.url_seeds.push_back("http://add_torrent_params_url_seed.com");

	std::vector<char> rd = generate_resume_data(ti.get(), resume_file_prio);
	p.resume_data.swap(rd);

	p.max_uploads = 1;
	p.max_connections = 2;
	p.upload_limit = 3;
	p.download_limit = 4;

	std::vector<boost::uint8_t> priorities_vector;
	for (int i = 0; file_priorities[i]; ++i)
		priorities_vector.push_back(file_priorities[i] - '0');

	p.file_priorities = priorities_vector;

	torrent_handle h = ses.add_torrent(p);
	torrent_status s = h.status();
	TEST_EQUAL(s.info_hash, ti->info_hash());
	return h;
}
开发者ID:redchief,项目名称:libtorrent,代码行数:36,代码来源:test_resume.cpp

示例13: main

int main(int argc, char* argv[])
{       
        if (argc == 1) {
            printhelp(argv[0]);
        }
        int tmp;
        char torrentfile[255];
        int usrpid = 0;
        int mypid;
        char pidfilename[255];
        char ip[16];
        int delay = 10;
        strcpy(ip, "0.0.0.0");
        strcpy(pidfilename, argv[0]);
        strcat(pidfilename, ".pid");

        while((tmp=getopt(argc,argv,"ht:p:f:b:d:"))!=-1) {
             switch(tmp) {
                case 'h':
                    printhelp(argv[0]);
                    break;
                case 't':
                    strcpy(torrentfile, optarg);
                    break;
                case 'p':
                    usrpid = atoi(optarg);
                    break;
                case 'f':
                    strcpy(pidfilename, optarg);
                    break;
                case 'b':
                    strcpy(ip, optarg);
                    break;
                case 'd':
                    delay = atoi(optarg);
                    break;
                default:
                    printhelp(argv[0]);
                    break;
             }
        }
        if (usrpid == 0) {
            printhelp(argv[0]);
        }
        mypid = ::getpid();
        std::signal(SIGINT, exit_signalHandler);
        std::signal(SIGTERM, exit_signalHandler);

        using namespace libtorrent;

        // set peer_id to nodename
        char hostname[HOST_NAME_MAX];
        gethostname(hostname, HOST_NAME_MAX);
        char buff[21];
        snprintf(buff, sizeof(buff), "%20s", hostname);
        peer_id my_peer_id = sha1_hash(buff);
        s.set_peer_id(my_peer_id);
        error_code ec;

        // set up torrent session
        s.listen_on(std::make_pair(6881, 6889), ec, ip);
        if (ec)
        {
                fprintf(stderr, "failed to open listen socket: %s\n", ec.message().c_str());
                return 1;
        }

        // create torrent object
        add_torrent_params p;
        p.save_path = "./";
        p.ti = new torrent_info(torrentfile, ec);
        if (ec)
        {
                fprintf(stderr, "%s\n", ec.message().c_str());
                return 1;
        }

        // start downloading torrent
        torrent_handle torrent = s.add_torrent(p, ec);
        if (ec)
        {
                fprintf(stderr, "%s\n", ec.message().c_str());
                return 1;
        }

        // create pidfile
        std::ofstream pidfile;
        pidfile.open(pidfilename);
        pidfile << mypid;
        pidfile << "\n";
        pidfile.close();

        std::vector<torrent_status> vts;
        s.get_torrent_status(&vts, &yes, 0);
        torrent_status& st = vts[0];
        boost::int64_t remains = st.total_wanted - st.total_wanted_done;
        fprintf(stdout, "Remains: %i\n", remains);
        //fprintf(stdout, "Torrent: %i\n", torrent);

        while( remains > 0 && run ) {
//.........这里部分代码省略.........
开发者ID:dchirikov,项目名称:luna,代码行数:101,代码来源:ltorrent-client.cpp

示例14: is_seed

bool is_seed(lt::session& ses)
{
	lt::torrent_handle h = ses.get_torrents()[0];
	return h.status().is_seeding;
}
开发者ID:RavenB,项目名称:libtorrent,代码行数:5,代码来源:test_transfer.cpp

示例15: test_transfer

// proxy: 0=none, 1=socks4, 2=socks5, 3=socks5_pw 4=http 5=http_pw
void test_transfer(lt::session& ses, boost::shared_ptr<torrent_info> torrent_file
	, int proxy, int port, char const* protocol, bool url_seed
	, bool chunked_encoding, bool test_ban, bool keepalive, bool proxy_peers)
{
	using namespace libtorrent;

	TORRENT_ASSERT(torrent_file->web_seeds().size() > 0);

	std::string save_path = "tmp2_web_seed";
	save_path += proxy_name[proxy];

	error_code ec;
	remove_all(save_path, ec);

	static char const* test_name[] = {"no", "SOCKS4", "SOCKS5", "SOCKS5 password", "HTTP", "HTTP password"};

	fprintf(stderr, "\n\n  ==== TESTING === proxy: %s ==== protocol: %s "
		"==== seed: %s === transfer-encoding: %s === corruption: %s "
		"==== keepalive: %s\n\n\n"
		, test_name[proxy], protocol, url_seed ? "URL seed" : "HTTP seed"
		, chunked_encoding ? "chunked": "none", test_ban ? "yes" : "no"
		, keepalive ? "yes" : "no");

	int proxy_port = 0;
	if (proxy)
	{
		proxy_port = start_proxy(proxy);
		if (proxy_port < 0)
		{
			fprintf(stderr, "failed to start proxy");
			return;
		}
		settings_pack pack;
		pack.set_str(settings_pack::proxy_hostname, "127.0.0.1");
		pack.set_str(settings_pack::proxy_username, "testuser");
		pack.set_str(settings_pack::proxy_password, "testpass");
		pack.set_int(settings_pack::proxy_type, (settings_pack::proxy_type_t)proxy);
		pack.set_int(settings_pack::proxy_port, proxy_port);
		pack.set_bool(settings_pack::proxy_peer_connections, proxy_peers);
		ses.apply_settings(pack);
	}
	else
	{
		settings_pack pack;
		pack.set_str(settings_pack::proxy_hostname, "");
		pack.set_str(settings_pack::proxy_username, "");
		pack.set_str(settings_pack::proxy_password, "");
		pack.set_int(settings_pack::proxy_type, settings_pack::none);
		pack.set_int(settings_pack::proxy_port, 0);
		pack.set_bool(settings_pack::proxy_peer_connections, proxy_peers);
		ses.apply_settings(pack);
	}

	add_torrent_params p;
	p.flags &= ~add_torrent_params::flag_paused;
	p.flags &= ~add_torrent_params::flag_auto_managed;
	p.ti = torrent_file;
	p.save_path = save_path;
#ifndef TORRENT_NO_DEPRECATE
	p.storage_mode = storage_mode_compact;
#endif
	torrent_handle th = ses.add_torrent(p, ec);
	printf("adding torrent, save_path = \"%s\" cwd = \"%s\" torrent = \"%s\"\n"
		, save_path.c_str(), current_working_directory().c_str()
		, torrent_file->name().c_str());

	std::vector<announce_entry> empty;
	th.replace_trackers(empty);

	const boost::int64_t total_size = torrent_file->total_size();

	file_storage const& fs = torrent_file->files();
	int pad_file_size = 0;
	for (int i = 0; i < fs.num_files(); ++i)
	{
		if (fs.file_flags(i) & file_storage::flag_pad_file)
			pad_file_size += fs.file_size(i);
	}

	peer_disconnects = 0;
	std::map<std::string, boost::int64_t> cnt = get_counters(ses);

	for (int i = 0; i < 40; ++i)
	{
		torrent_status s = th.status();

		cnt = get_counters(ses);

		print_ses_rate(i / 10.f, &s, NULL);
		print_alerts(ses, "  >>  ses", test_ban, false, false, &on_alert);

		if (test_ban && th.url_seeds().empty() && th.http_seeds().empty())
		{
			fprintf(stderr, "testing ban: URL seed removed\n");
			// when we don't have any web seeds left, we know we successfully banned it
			break;
		}

		if (s.is_seeding)
//.........这里部分代码省略.........
开发者ID:aresch,项目名称:libtorrent,代码行数:101,代码来源:web_seed_suite.cpp


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