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


C++ bdecode_node::dict_find_string方法代码示例

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


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

示例1: reply

void get_item_observer::reply(msg const& m)
{
	public_key pk;
	signature sig;
	sequence_number seq{0};

	bdecode_node const r = m.message.dict_find_dict("r");
	if (!r)
	{
#ifndef TORRENT_DISABLE_LOGGING
		get_observer()->log(dht_logger::traversal, "[%p] missing response dict"
			, static_cast<void*>(algorithm()));
#endif
		timeout();
		return;
	}

	bdecode_node const k = r.dict_find_string("k");
	if (k && k.string_length() == public_key::len)
		std::memcpy(pk.bytes.data(), k.string_ptr(), public_key::len);

	bdecode_node const s = r.dict_find_string("sig");
	if (s && s.string_length() == signature::len)
		std::memcpy(sig.bytes.data(), s.string_ptr(), signature::len);

	bdecode_node const q = r.dict_find_int("seq");
	if (q)
	{
		seq = sequence_number(q.int_value());
	}
	else if (k && s)
	{
		timeout();
		return;
	}

	bdecode_node v = r.dict_find("v");
	if (v)
	{
		static_cast<get_item*>(algorithm())->got_data(v, pk, seq, sig);
	}

	find_data_observer::reply(m);
}
开发者ID:pavel-pimenov,项目名称:flylinkdc-r5xx,代码行数:44,代码来源:get_item.cpp

示例2: extract_peer_info

// TODO: 2 returning a bool here is redundant. Instead this function should
// return the peer_entry
bool extract_peer_info(bdecode_node const& info, peer_entry& ret, error_code& ec)
{
    // extract peer id (if any)
    if (info.type() != bdecode_node::dict_t)
    {
        ec.assign(errors::invalid_peer_dict, get_libtorrent_category());
        return false;
    }
    bdecode_node i = info.dict_find_string("peer id");
    if (i && i.string_length() == 20)
    {
        std::copy(i.string_ptr(), i.string_ptr()+20, ret.pid.begin());
    }
    else
    {
        // if there's no peer_id, just initialize it to a bunch of zeroes
        std::fill_n(ret.pid.begin(), 20, 0);
    }

    // extract ip
    i = info.dict_find_string("ip");
    if (i == 0)
    {
        ec.assign(errors::invalid_tracker_response, get_libtorrent_category());
        return false;
    }
    ret.hostname = i.string_value();

    // extract port
    i = info.dict_find_int("port");
    if (i == 0)
    {
        ec.assign(errors::invalid_tracker_response, get_libtorrent_category());
        return false;
    }
    ret.port = boost::uint16_t(i.int_value());

    return true;
}
开发者ID:RavenB,项目名称:libtorrent,代码行数:41,代码来源:http_tracker_connection.cpp

示例3: extract_single_file

	// 'top_level' is extracting the file for a single-file torrent. The
	// distinction is that the filename is found in "name" rather than
	// "path"
	// root_dir is the name of the torrent, unless this is a single file
	// torrent, in which case it's empty.
	bool extract_single_file(bdecode_node const& dict, file_storage& files
		, std::string const& root_dir, ptrdiff_t info_ptr_diff, bool top_level
		, int& pad_file_cnt, error_code& ec)
	{
		if (dict.type() != bdecode_node::dict_t) return false;

		boost::uint32_t file_flags = get_file_attributes(dict);

		// symlinks have an implied "size" of zero. i.e. they use up 0 bytes of
		// the torrent payload space
		boost::int64_t const file_size = (file_flags & file_storage::flag_symlink)
			? 0
			: dict.dict_find_int_value("length", -1);
		if (file_size < 0 )
		{
			ec = errors::torrent_invalid_length;
			return false;
		}

		boost::int64_t const mtime = dict.dict_find_int_value("mtime", 0);

		std::string path = root_dir;
		std::string path_element;
		char const* filename = NULL;
		int filename_len = 0;

		if (top_level)
		{
			// prefer the name.utf-8 because if it exists, it is more likely to be
			// correctly encoded
			bdecode_node p = dict.dict_find_string("name.utf-8");
			if (!p) p = dict.dict_find_string("name");
			if (!p || p.string_length() == 0)
			{
				ec = errors::torrent_missing_name;
				return false;
			}

			filename = p.string_ptr() + info_ptr_diff;
			filename_len = p.string_length();
			while (filename_len > 0 && filename[0] == TORRENT_SEPARATOR)
			{
				filename += 1;
				filename_len -= 1;
			}
			sanitize_append_path_element(path, p.string_ptr(), p.string_length());
		}
		else
		{
			bdecode_node p = dict.dict_find_list("path.utf-8");
			if (!p) p = dict.dict_find_list("path");

			if (p && p.list_size() > 0)
			{
				std::size_t const orig_path_len = path.size();
				int const preallocate = path.size() + path_length(p, ec);
				if (ec) return false;
				path.reserve(preallocate);

				for (int i = 0, end(p.list_size()); i < end; ++i)
				{
					bdecode_node e = p.list_at(i);
					if (i == end - 1)
					{
						filename = e.string_ptr() + info_ptr_diff;
						filename_len = e.string_length();
					}
					while (filename_len > 0 && filename[0] == TORRENT_SEPARATOR)
					{
						filename += 1;
						filename_len -= 1;
					}
					sanitize_append_path_element(path, e.string_ptr(), e.string_length());
				}

				// if all path elements were sanitized away, we need to use another
				// name instead
				if (path.size() == orig_path_len)
				{
					path += TORRENT_SEPARATOR;
					path += "_";
				}
			}
			else if (file_flags & file_storage::flag_pad_file)
			{
				// pad files don't need a path element, we'll just store them
				// under the .pad directory
				char cnt[10];
				snprintf(cnt, sizeof(cnt), "%d", pad_file_cnt);
				path = combine_path(".pad", cnt);
				++pad_file_cnt;
			}
			else
			{
				ec = errors::torrent_missing_name;
//.........这里部分代码省略.........
开发者ID:PopcornTimeTV,项目名称:PopcornTorrent,代码行数:101,代码来源:torrent_info.cpp


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