bdecode_node - add const

This commit is contained in:
pavel.pimenov 2017-02-27 23:52:46 +03:00 committed by Arvid Norberg
parent 3764ee62cb
commit 78442e9a2c
14 changed files with 78 additions and 78 deletions

View File

@ -299,9 +299,9 @@ struct TORRENT_EXPORT bdecode_node
// size of the list. ``size()`` returns the size of the list. // size of the list. ``size()`` returns the size of the list.
bdecode_node list_at(int i) const; bdecode_node list_at(int i) const;
string_view list_string_value_at(int i string_view list_string_value_at(int i
, string_view default_val = string_view()); , string_view default_val = string_view()) const;
std::int64_t list_int_value_at(int i std::int64_t list_int_value_at(int i
, std::int64_t default_val = 0); , std::int64_t default_val = 0) const;
int list_size() const; int list_size() const;
// Functions with the ``dict_`` prefix operates on dictionaries. They are // Functions with the ``dict_`` prefix operates on dictionaries. They are

View File

@ -332,17 +332,17 @@ namespace libtorrent
} }
string_view bdecode_node::list_string_value_at(int i string_view bdecode_node::list_string_value_at(int i
, string_view default_val) , string_view default_val) const
{ {
bdecode_node n = list_at(i); bdecode_node const n = list_at(i);
if (n.type() != bdecode_node::string_t) return default_val; if (n.type() != bdecode_node::string_t) return default_val;
return n.string_value(); return n.string_value();
} }
std::int64_t bdecode_node::list_int_value_at(int i std::int64_t bdecode_node::list_int_value_at(int i
, std::int64_t default_val) , std::int64_t default_val) const
{ {
bdecode_node n = list_at(i); bdecode_node const n = list_at(i);
if (n.type() != bdecode_node::int_t) return default_val; if (n.type() != bdecode_node::int_t) return default_val;
return n.int_value(); return n.int_value();
} }

View File

@ -1240,7 +1240,7 @@ namespace libtorrent
std::map<int, sha1_hash> nodes; std::map<int, sha1_hash> nodes;
for (int i = 0; i < hash_list.list_size(); ++i) for (int i = 0; i < hash_list.list_size(); ++i)
{ {
bdecode_node e = hash_list.list_at(i); bdecode_node const e = hash_list.list_at(i);
if (e.type() != bdecode_node::list_t if (e.type() != bdecode_node::list_t
|| e.list_size() != 2 || e.list_size() != 2
|| e.list_at(0).type() != bdecode_node::int_t || e.list_at(0).type() != bdecode_node::int_t
@ -1795,7 +1795,7 @@ namespace libtorrent
if (is_disconnecting()) return; if (is_disconnecting()) return;
// upload_only // upload_only
if (bdecode_node m = root.dict_find_dict("m")) if (bdecode_node const m = root.dict_find_dict("m"))
{ {
m_upload_only_id = std::uint8_t(m.dict_find_int_value("upload_only", 0)); m_upload_only_id = std::uint8_t(m.dict_find_int_value("upload_only", 0));
m_holepunch_id = std::uint8_t(m.dict_find_int_value("ut_holepunch", 0)); m_holepunch_id = std::uint8_t(m.dict_find_int_value("ut_holepunch", 0));

View File

@ -434,12 +434,12 @@ namespace libtorrent
resp.interval = interval; resp.interval = interval;
resp.min_interval = min_interval; resp.min_interval = min_interval;
bdecode_node tracker_id = e.dict_find_string("tracker id"); bdecode_node const tracker_id = e.dict_find_string("tracker id");
if (tracker_id) if (tracker_id)
resp.trackerid = tracker_id.string_value().to_string(); resp.trackerid = tracker_id.string_value().to_string();
// parse the response // parse the response
bdecode_node failure = e.dict_find_string("failure reason"); bdecode_node const failure = e.dict_find_string("failure reason");
if (failure) if (failure)
{ {
resp.failure_reason = failure.string_value().to_string(); resp.failure_reason = failure.string_value().to_string();
@ -447,20 +447,20 @@ namespace libtorrent
return resp; return resp;
} }
bdecode_node warning = e.dict_find_string("warning message"); bdecode_node const warning = e.dict_find_string("warning message");
if (warning) if (warning)
resp.warning_message = warning.string_value().to_string(); resp.warning_message = warning.string_value().to_string();
if (0 != (flags & tracker_request::scrape_request)) if (0 != (flags & tracker_request::scrape_request))
{ {
bdecode_node files = e.dict_find_dict("files"); bdecode_node const files = e.dict_find_dict("files");
if (!files) if (!files)
{ {
ec = errors::invalid_files_entry; ec = errors::invalid_files_entry;
return resp; return resp;
} }
bdecode_node scrape_data = files.dict_find_dict( bdecode_node const scrape_data = files.dict_find_dict(
scrape_ih.to_string()); scrape_ih.to_string());
if (!scrape_data) if (!scrape_data)
@ -573,7 +573,7 @@ namespace libtorrent
return resp; return resp;
} }
*/ */
bdecode_node ip_ent = e.dict_find_string("external ip"); bdecode_node const ip_ent = e.dict_find_string("external ip");
if (ip_ent) if (ip_ent)
{ {
char const* p = ip_ent.string_ptr(); char const* p = ip_ent.string_ptr();

View File

@ -57,7 +57,7 @@ void find_data_observer::reply(msg const& m)
return; return;
} }
bdecode_node id = r.dict_find_string("id"); bdecode_node const id = r.dict_find_string("id");
if (!id || id.string_length() != 20) if (!id || id.string_length() != 20)
{ {
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
@ -67,7 +67,7 @@ void find_data_observer::reply(msg const& m)
timeout(); timeout();
return; return;
} }
bdecode_node token = r.dict_find_string("token"); bdecode_node const token = r.dict_find_string("token");
if (token) if (token)
{ {
static_cast<find_data*>(algorithm())->got_write_token( static_cast<find_data*>(algorithm())->got_write_token(

View File

@ -187,15 +187,15 @@ void get_item_observer::reply(msg const& m)
return; return;
} }
bdecode_node k = r.dict_find_string("k"); bdecode_node const k = r.dict_find_string("k");
if (k && k.string_length() == public_key::len) if (k && k.string_length() == public_key::len)
std::memcpy(pk.bytes.data(), k.string_ptr(), public_key::len); std::memcpy(pk.bytes.data(), k.string_ptr(), public_key::len);
bdecode_node s = r.dict_find_string("sig"); bdecode_node const s = r.dict_find_string("sig");
if (s && s.string_length() == signature::len) if (s && s.string_length() == signature::len)
std::memcpy(sig.bytes.data(), s.string_ptr(), signature::len); std::memcpy(sig.bytes.data(), s.string_ptr(), signature::len);
bdecode_node q = r.dict_find_int("seq"); bdecode_node const q = r.dict_find_int("seq");
if (q) if (q)
{ {
seq = sequence_number(q.int_value()); seq = sequence_number(q.int_value());

View File

@ -57,7 +57,7 @@ void get_peers_observer::reply(msg const& m)
} }
// look for peers // look for peers
bdecode_node n = r.dict_find_list("values"); bdecode_node const n = r.dict_find_list("values");
if (n) if (n)
{ {
std::vector<tcp::endpoint> peer_list; std::vector<tcp::endpoint> peer_list;
@ -297,7 +297,7 @@ void obfuscated_get_peers::done()
void obfuscated_get_peers_observer::reply(msg const& m) void obfuscated_get_peers_observer::reply(msg const& m)
{ {
bdecode_node r = m.message.dict_find_dict("r"); bdecode_node const r = m.message.dict_find_dict("r");
if (!r) if (!r)
{ {
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
@ -308,7 +308,7 @@ void obfuscated_get_peers_observer::reply(msg const& m)
return; return;
} }
bdecode_node id = r.dict_find_string("id"); bdecode_node const id = r.dict_find_string("id");
if (!id || id.string_length() != 20) if (!id || id.string_length() != 20)
{ {
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING

View File

@ -256,7 +256,7 @@ void node::unreachable(udp::endpoint const& ep)
void node::incoming(msg const& m) void node::incoming(msg const& m)
{ {
// is this a reply? // is this a reply?
bdecode_node y_ent = m.message.dict_find_string("y"); bdecode_node const y_ent = m.message.dict_find_string("y");
if (!y_ent || y_ent.string_length() == 0) if (!y_ent || y_ent.string_length() == 0)
{ {
// don't respond to this obviously broken messages. We don't // don't respond to this obviously broken messages. We don't
@ -274,7 +274,7 @@ void node::incoming(msg const& m)
// backwards compatibility // backwards compatibility
if (!ext_ip) if (!ext_ip)
{ {
bdecode_node r = m.message.dict_find_dict("r"); bdecode_node const r = m.message.dict_find_dict("r");
if (r) if (r)
ext_ip = r.dict_find_string("ip"); ext_ip = r.dict_find_string("ip");
} }
@ -332,7 +332,7 @@ void node::incoming(msg const& m)
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
if (m_observer != nullptr && m_observer->should_log(dht_logger::node)) if (m_observer != nullptr && m_observer->should_log(dht_logger::node))
{ {
bdecode_node err = m.message.dict_find_list("e"); bdecode_node const err = m.message.dict_find_list("e");
if (err && err.list_size() >= 2 if (err && err.list_size() >= 2
&& err.list_at(0).type() == bdecode_node::int_t && err.list_at(0).type() == bdecode_node::int_t
&& err.list_at(1).type() == bdecode_node::string_t) && err.list_at(1).type() == bdecode_node::string_t)
@ -577,7 +577,7 @@ struct ping_observer : observer
{ {
flags |= flag_done; flags |= flag_done;
bdecode_node r = m.message.dict_find_dict("r"); bdecode_node const r = m.message.dict_find_dict("r");
if (!r) if (!r)
{ {
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
@ -595,7 +595,7 @@ struct ping_observer : observer
udp const protocol = algorithm()->get_node().protocol(); udp const protocol = algorithm()->get_node().protocol();
int const protocol_size = int(detail::address_size(protocol)); int const protocol_size = int(detail::address_size(protocol));
char const* nodes_key = algorithm()->get_node().protocol_nodes_key(); char const* nodes_key = algorithm()->get_node().protocol_nodes_key();
bdecode_node n = r.dict_find_string(nodes_key); bdecode_node const n = r.dict_find_string(nodes_key);
if (n) if (n)
{ {
char const* nodes = n.string_ptr(); char const* nodes = n.string_ptr();

View File

@ -332,14 +332,14 @@ bool rpc_manager::incoming(msg const& m, node_id* id)
return false; return false;
} }
bdecode_node ret_ent = m.message.dict_find_dict("r"); bdecode_node const ret_ent = m.message.dict_find_dict("r");
if (!ret_ent) if (!ret_ent)
{ {
o->timeout(); o->timeout();
return false; return false;
} }
bdecode_node node_id_ent = ret_ent.dict_find_string("id"); bdecode_node const node_id_ent = ret_ent.dict_find_string("id");
if (!node_id_ent || node_id_ent.string_length() != 20) if (!node_id_ent || node_id_ent.string_length() != 20)
{ {
o->timeout(); o->timeout();

View File

@ -548,7 +548,7 @@ void traversal_algorithm::status(dht_lookup& l)
void traversal_observer::reply(msg const& m) void traversal_observer::reply(msg const& m)
{ {
bdecode_node r = m.message.dict_find_dict("r"); bdecode_node const r = m.message.dict_find_dict("r");
if (!r) if (!r)
{ {
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
@ -566,7 +566,7 @@ void traversal_observer::reply(msg const& m)
dht_observer* logger = get_observer(); dht_observer* logger = get_observer();
if (logger != nullptr && logger->should_log(dht_logger::traversal)) if (logger != nullptr && logger->should_log(dht_logger::traversal))
{ {
bdecode_node nid = r.dict_find_string("id"); bdecode_node const nid = r.dict_find_string("id");
char hex_id[41]; char hex_id[41];
aux::to_hex({nid.string_ptr(), 20}, hex_id); aux::to_hex({nid.string_ptr(), 20}, hex_id);
logger->log(dht_logger::traversal logger->log(dht_logger::traversal
@ -580,7 +580,7 @@ void traversal_observer::reply(msg const& m)
udp const protocol = algorithm()->get_node().protocol(); udp const protocol = algorithm()->get_node().protocol();
int const protocol_size = int(detail::address_size(protocol)); int const protocol_size = int(detail::address_size(protocol));
char const* nodes_key = algorithm()->get_node().protocol_nodes_key(); char const* nodes_key = algorithm()->get_node().protocol_nodes_key();
bdecode_node n = r.dict_find_string(nodes_key); bdecode_node const n = r.dict_find_string(nodes_key);
if (n) if (n)
{ {
char const* nodes = n.string_ptr(); char const* nodes = n.string_ptr();
@ -593,7 +593,7 @@ void traversal_observer::reply(msg const& m)
} }
} }
bdecode_node id = r.dict_find_string("id"); bdecode_node const id = r.dict_find_string("id");
if (!id || id.string_length() != 20) if (!id || id.string_length() != 20)
{ {
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING

View File

@ -64,7 +64,7 @@ namespace libtorrent
add_torrent_params read_resume_data(bdecode_node const& rd, error_code& ec) add_torrent_params read_resume_data(bdecode_node const& rd, error_code& ec)
{ {
add_torrent_params ret; add_torrent_params ret;
if (bdecode_node alloc = rd.dict_find_string("allocation")) if (bdecode_node const alloc = rd.dict_find_string("allocation"))
{ {
ret.storage_mode = (alloc.string_value() == "allocate" ret.storage_mode = (alloc.string_value() == "allocate"
|| alloc.string_value() == "full") || alloc.string_value() == "full")
@ -90,7 +90,7 @@ namespace libtorrent
ret.info_hash.assign(info_hash.data()); ret.info_hash.assign(info_hash.data());
// TODO: 4 add unit test for this, and all other fields of the resume data // TODO: 4 add unit test for this, and all other fields of the resume data
bdecode_node info = rd.dict_find_dict("info"); bdecode_node const info = rd.dict_find_dict("info");
if (info) if (info)
{ {
// verify the info-hash of the metadata stored in the resume file matches // verify the info-hash of the metadata stored in the resume file matches
@ -147,7 +147,7 @@ namespace libtorrent
ret.uuid = rd.dict_find_string_value("uuid").to_string(); ret.uuid = rd.dict_find_string_value("uuid").to_string();
#endif #endif
bdecode_node mapped_files = rd.dict_find_list("mapped_files"); bdecode_node const mapped_files = rd.dict_find_list("mapped_files");
if (mapped_files) if (mapped_files)
{ {
for (int i = 0; i < mapped_files.list_size(); ++i) for (int i = 0; i < mapped_files.list_size(); ++i)
@ -163,7 +163,7 @@ namespace libtorrent
// load file priorities except if the add_torrent_param file was set to // load file priorities except if the add_torrent_param file was set to
// override resume data // override resume data
bdecode_node file_priority = rd.dict_find_list("file_priority"); bdecode_node const file_priority = rd.dict_find_list("file_priority");
if (file_priority) if (file_priority)
{ {
int const num_files = file_priority.list_size(); int const num_files = file_priority.list_size();
@ -182,7 +182,7 @@ namespace libtorrent
} }
} }
bdecode_node trackers = rd.dict_find_list("trackers"); bdecode_node const trackers = rd.dict_find_list("trackers");
if (trackers) if (trackers)
{ {
// it's possible to delete the trackers from a torrent and then save // it's possible to delete the trackers from a torrent and then save
@ -194,7 +194,7 @@ namespace libtorrent
int tier = 0; int tier = 0;
for (int i = 0; i < trackers.list_size(); ++i) for (int i = 0; i < trackers.list_size(); ++i)
{ {
bdecode_node tier_list = trackers.list_at(i); bdecode_node const tier_list = trackers.list_at(i);
if (!tier_list || tier_list.type() != bdecode_node::list_t) if (!tier_list || tier_list.type() != bdecode_node::list_t)
continue; continue;
@ -211,8 +211,8 @@ namespace libtorrent
// seeds we loaded from the .torrent file, because we want whatever's in // seeds we loaded from the .torrent file, because we want whatever's in
// the resume file to take precedence. If there aren't even any fields in // the resume file to take precedence. If there aren't even any fields in
// the resume data though, keep the ones from the torrent // the resume data though, keep the ones from the torrent
bdecode_node url_list = rd.dict_find_list("url-list"); bdecode_node const url_list = rd.dict_find_list("url-list");
bdecode_node httpseeds = rd.dict_find_list("httpseeds"); bdecode_node const httpseeds = rd.dict_find_list("httpseeds");
if (url_list || httpseeds) if (url_list || httpseeds)
{ {
// since we found http seeds in the resume data, they should replace // since we found http seeds in the resume data, they should replace
@ -240,7 +240,7 @@ namespace libtorrent
} }
} }
bdecode_node mt = rd.dict_find_string("merkle tree"); bdecode_node const mt = rd.dict_find_string("merkle tree");
if (mt) if (mt)
{ {
ret.merkle_tree.resize(aux::numeric_cast<std::size_t>(mt.string_length() / 20)); ret.merkle_tree.resize(aux::numeric_cast<std::size_t>(mt.string_length() / 20));
@ -249,7 +249,7 @@ namespace libtorrent
} }
// some sanity checking. Maybe we shouldn't be in seed mode anymore // some sanity checking. Maybe we shouldn't be in seed mode anymore
if (bdecode_node pieces = rd.dict_find_string("pieces")) if (bdecode_node const pieces = rd.dict_find_string("pieces"))
{ {
char const* pieces_str = pieces.string_ptr(); char const* pieces_str = pieces.string_ptr();
int const pieces_len = pieces.string_length(); int const pieces_len = pieces.string_length();
@ -267,7 +267,7 @@ namespace libtorrent
} }
} }
if (bdecode_node piece_priority = rd.dict_find_string("piece_priority")) if (bdecode_node const piece_priority = rd.dict_find_string("piece_priority"))
{ {
char const* prio_str = piece_priority.string_ptr(); char const* prio_str = piece_priority.string_ptr();
ret.piece_priorities.resize(aux::numeric_cast<std::size_t>(piece_priority.string_length())); ret.piece_priorities.resize(aux::numeric_cast<std::size_t>(piece_priority.string_length()));
@ -278,7 +278,7 @@ namespace libtorrent
} }
using namespace libtorrent::detail; // for read_*_endpoint() using namespace libtorrent::detail; // for read_*_endpoint()
if (bdecode_node peers_entry = rd.dict_find_string("peers")) if (bdecode_node const peers_entry = rd.dict_find_string("peers"))
{ {
char const* ptr = peers_entry.string_ptr(); char const* ptr = peers_entry.string_ptr();
for (int i = 0; i < peers_entry.string_length(); i += 6) for (int i = 0; i < peers_entry.string_length(); i += 6)
@ -286,7 +286,7 @@ namespace libtorrent
} }
#if TORRENT_USE_IPV6 #if TORRENT_USE_IPV6
if (bdecode_node peers_entry = rd.dict_find_string("peers6")) if (bdecode_node const peers_entry = rd.dict_find_string("peers6"))
{ {
char const* ptr = peers_entry.string_ptr(); char const* ptr = peers_entry.string_ptr();
for (int i = 0; i < peers_entry.string_length(); i += 18) for (int i = 0; i < peers_entry.string_length(); i += 18)
@ -294,7 +294,7 @@ namespace libtorrent
} }
#endif #endif
if (bdecode_node peers_entry = rd.dict_find_string("banned_peers")) if (bdecode_node const peers_entry = rd.dict_find_string("banned_peers"))
{ {
char const* ptr = peers_entry.string_ptr(); char const* ptr = peers_entry.string_ptr();
for (int i = 0; i < peers_entry.string_length(); i += 6) for (int i = 0; i < peers_entry.string_length(); i += 6)
@ -302,7 +302,7 @@ namespace libtorrent
} }
#if TORRENT_USE_IPV6 #if TORRENT_USE_IPV6
if (bdecode_node peers_entry = rd.dict_find_string("banned_peers6")) if (bdecode_node const peers_entry = rd.dict_find_string("banned_peers6"))
{ {
char const* ptr = peers_entry.string_ptr(); char const* ptr = peers_entry.string_ptr();
for (int i = 0; i < peers_entry.string_length(); i += 18) for (int i = 0; i < peers_entry.string_length(); i += 18)
@ -311,16 +311,16 @@ namespace libtorrent
#endif #endif
// parse unfinished pieces // parse unfinished pieces
if (bdecode_node unfinished_entry = rd.dict_find_list("unfinished")) if (bdecode_node const unfinished_entry = rd.dict_find_list("unfinished"))
{ {
for (int i = 0; i < unfinished_entry.list_size(); ++i) for (int i = 0; i < unfinished_entry.list_size(); ++i)
{ {
bdecode_node e = unfinished_entry.list_at(i); bdecode_node const e = unfinished_entry.list_at(i);
if (e.type() != bdecode_node::dict_t) continue; if (e.type() != bdecode_node::dict_t) continue;
piece_index_t const piece = piece_index_t(int(e.dict_find_int_value("piece", -1))); piece_index_t const piece = piece_index_t(int(e.dict_find_int_value("piece", -1)));
if (piece < piece_index_t(0)) continue; if (piece < piece_index_t(0)) continue;
bdecode_node bitmask = e.dict_find_string("bitmask"); bdecode_node const bitmask = e.dict_find_string("bitmask");
if (bitmask || bitmask.string_length() == 0) continue; if (bitmask || bitmask.string_length() == 0) continue;
bitfield& bf = ret.unfinished_pieces[piece]; bitfield& bf = ret.unfinished_pieces[piece];
bf.assign(bitmask.string_ptr(), bitmask.string_length()); bf.assign(bitmask.string_ptr(), bitmask.string_length());

View File

@ -381,7 +381,7 @@ namespace libtorrent
std::uint32_t get_file_attributes(bdecode_node const& dict) std::uint32_t get_file_attributes(bdecode_node const& dict)
{ {
std::uint32_t file_flags = 0; std::uint32_t file_flags = 0;
bdecode_node attr = dict.dict_find_string("attr"); bdecode_node const attr = dict.dict_find_string("attr");
if (attr) if (attr)
{ {
for (int i = 0; i < attr.string_length(); ++i) for (int i = 0; i < attr.string_length(); ++i)
@ -407,7 +407,7 @@ namespace libtorrent
int const len = p.list_size(); int const len = p.list_size();
for (int i = 0; i < len; ++i) for (int i = 0; i < len; ++i)
{ {
bdecode_node e = p.list_at(i); bdecode_node const e = p.list_at(i);
if (e.type() != bdecode_node::string_t) if (e.type() != bdecode_node::string_t)
{ {
ec = errors::torrent_invalid_name; ec = errors::torrent_invalid_name;
@ -477,7 +477,7 @@ namespace libtorrent
for (int i = 0, end(p.list_size()); i < end; ++i) for (int i = 0, end(p.list_size()); i < end; ++i)
{ {
bdecode_node e = p.list_at(i); bdecode_node const e = p.list_at(i);
if (i == end - 1) if (i == end - 1)
{ {
filename = e.string_ptr() + info_ptr_diff; filename = e.string_ptr() + info_ptr_diff;
@ -506,7 +506,7 @@ namespace libtorrent
if (path.find("_____padding_file_") != std::string::npos) if (path.find("_____padding_file_") != std::string::npos)
file_flags = file_storage::flag_pad_file; file_flags = file_storage::flag_pad_file;
bdecode_node fh = dict.dict_find_string("sha1"); bdecode_node const fh = dict.dict_find_string("sha1");
char const* filehash = nullptr; char const* filehash = nullptr;
if (fh && fh.string_length() == 20) if (fh && fh.string_length() == 20)
filehash = fh.string_ptr() + info_ptr_diff; filehash = fh.string_ptr() + info_ptr_diff;
@ -514,7 +514,7 @@ namespace libtorrent
std::string symlink_path; std::string symlink_path;
if (file_flags & file_storage::flag_symlink) if (file_flags & file_storage::flag_symlink)
{ {
if (bdecode_node s_p = dict.dict_find_list("symlink path")) if (bdecode_node const s_p = dict.dict_find_list("symlink path"))
{ {
std::size_t const preallocate = std::size_t(path_length(s_p, ec)); std::size_t const preallocate = std::size_t(path_length(s_p, ec));
if (ec) return false; if (ec) return false;
@ -1124,8 +1124,8 @@ namespace libtorrent
files.set_num_pieces(int((files.total_size() + files.piece_length() - 1) files.set_num_pieces(int((files.total_size() + files.piece_length() - 1)
/ files.piece_length())); / files.piece_length()));
bdecode_node pieces = info.dict_find_string("pieces"); bdecode_node const pieces = info.dict_find_string("pieces");
bdecode_node root_hash = info.dict_find_string("root hash"); bdecode_node const root_hash = info.dict_find_string("root hash");
if (!pieces && !root_hash) if (!pieces && !root_hash)
{ {
ec = errors::torrent_missing_pieces; ec = errors::torrent_missing_pieces;
@ -1177,7 +1177,7 @@ namespace libtorrent
? private_torrent : 0; ? private_torrent : 0;
#ifndef TORRENT_DISABLE_MUTABLE_TORRENTS #ifndef TORRENT_DISABLE_MUTABLE_TORRENTS
bdecode_node similar = info.dict_find_list("similar"); bdecode_node const similar = info.dict_find_list("similar");
if (similar) if (similar)
{ {
for (int i = 0; i < similar.list_size(); ++i) for (int i = 0; i < similar.list_size(); ++i)
@ -1193,12 +1193,12 @@ namespace libtorrent
} }
} }
bdecode_node collections = info.dict_find_list("collections"); bdecode_node const collections = info.dict_find_list("collections");
if (collections) if (collections)
{ {
for (int i = 0; i < collections.list_size(); ++i) for (int i = 0; i < collections.list_size(); ++i)
{ {
bdecode_node str = collections.list_at(i); bdecode_node const str = collections.list_at(i);
if (str.type() != bdecode_node::string_t) continue; if (str.type() != bdecode_node::string_t) continue;
@ -1309,7 +1309,7 @@ namespace libtorrent
return false; return false;
} }
bdecode_node info = torrent_file.dict_find_dict("info"); bdecode_node const info = torrent_file.dict_find_dict("info");
if (!info) if (!info)
{ {
bdecode_node link = torrent_file.dict_find_string("magnet-uri"); bdecode_node link = torrent_file.dict_find_string("magnet-uri");
@ -1336,7 +1336,7 @@ namespace libtorrent
resolve_duplicate_filenames(); resolve_duplicate_filenames();
#ifndef TORRENT_DISABLE_MUTABLE_TORRENTS #ifndef TORRENT_DISABLE_MUTABLE_TORRENTS
bdecode_node similar = torrent_file.dict_find_list("similar"); bdecode_node const similar = torrent_file.dict_find_list("similar");
if (similar) if (similar)
{ {
for (int i = 0; i < similar.list_size(); ++i) for (int i = 0; i < similar.list_size(); ++i)
@ -1352,12 +1352,12 @@ namespace libtorrent
} }
} }
bdecode_node collections = torrent_file.dict_find_list("collections"); bdecode_node const collections = torrent_file.dict_find_list("collections");
if (collections) if (collections)
{ {
for (int i = 0; i < collections.list_size(); ++i) for (int i = 0; i < collections.list_size(); ++i)
{ {
bdecode_node str = collections.list_at(i); bdecode_node const str = collections.list_at(i);
if (str.type() != bdecode_node::string_t) continue; if (str.type() != bdecode_node::string_t) continue;
@ -1368,13 +1368,13 @@ namespace libtorrent
#endif // TORRENT_DISABLE_MUTABLE_TORRENTS #endif // TORRENT_DISABLE_MUTABLE_TORRENTS
// extract the url of the tracker // extract the url of the tracker
bdecode_node announce_node = torrent_file.dict_find_list("announce-list"); bdecode_node const announce_node = torrent_file.dict_find_list("announce-list");
if (announce_node) if (announce_node)
{ {
m_urls.reserve(announce_node.list_size()); m_urls.reserve(announce_node.list_size());
for (int j = 0, end(announce_node.list_size()); j < end; ++j) for (int j = 0, end(announce_node.list_size()); j < end; ++j)
{ {
bdecode_node tier = announce_node.list_at(j); bdecode_node const tier = announce_node.list_at(j);
if (tier.type() != bdecode_node::list_t) continue; if (tier.type() != bdecode_node::list_t) continue;
for (int k = 0, end2(tier.list_size()); k < end2; ++k) for (int k = 0, end2(tier.list_size()); k < end2; ++k)
{ {
@ -1422,12 +1422,12 @@ namespace libtorrent
if (!e.url.empty()) m_urls.push_back(e); if (!e.url.empty()) m_urls.push_back(e);
} }
bdecode_node nodes = torrent_file.dict_find_list("nodes"); bdecode_node const nodes = torrent_file.dict_find_list("nodes");
if (nodes) if (nodes)
{ {
for (int i = 0, end(nodes.list_size()); i < end; ++i) for (int i = 0, end(nodes.list_size()); i < end; ++i)
{ {
bdecode_node n = nodes.list_at(i); bdecode_node const n = nodes.list_at(i);
if (n.type() != bdecode_node::list_t if (n.type() != bdecode_node::list_t
|| n.list_size() < 2 || n.list_size() < 2
|| n.list_at(0).type() != bdecode_node::string_t || n.list_at(0).type() != bdecode_node::string_t
@ -1440,14 +1440,14 @@ namespace libtorrent
} }
// extract creation date // extract creation date
std::int64_t cd = torrent_file.dict_find_int_value("creation date", -1); std::int64_t const cd = torrent_file.dict_find_int_value("creation date", -1);
if (cd >= 0) if (cd >= 0)
{ {
m_creation_date = std::time_t(cd); m_creation_date = std::time_t(cd);
} }
// if there are any url-seeds, extract them // if there are any url-seeds, extract them
bdecode_node url_seeds = torrent_file.dict_find("url-list"); bdecode_node const url_seeds = torrent_file.dict_find("url-list");
if (url_seeds && url_seeds.type() == bdecode_node::string_t if (url_seeds && url_seeds.type() == bdecode_node::string_t
&& url_seeds.string_length() > 0) && url_seeds.string_length() > 0)
{ {
@ -1462,7 +1462,7 @@ namespace libtorrent
std::set<std::string> unique; std::set<std::string> unique;
for (int i = 0, end(url_seeds.list_size()); i < end; ++i) for (int i = 0, end(url_seeds.list_size()); i < end; ++i)
{ {
bdecode_node url = url_seeds.list_at(i); bdecode_node const url = url_seeds.list_at(i);
if (url.type() != bdecode_node::string_t) continue; if (url.type() != bdecode_node::string_t) continue;
if (url.string_length() == 0) continue; if (url.string_length() == 0) continue;
web_seed_entry ent(maybe_url_encode(url.string_value().to_string()) web_seed_entry ent(maybe_url_encode(url.string_value().to_string())
@ -1475,7 +1475,7 @@ namespace libtorrent
} }
// if there are any http-seeds, extract them // if there are any http-seeds, extract them
bdecode_node http_seeds = torrent_file.dict_find("httpseeds"); bdecode_node const http_seeds = torrent_file.dict_find("httpseeds");
if (http_seeds && http_seeds.type() == bdecode_node::string_t if (http_seeds && http_seeds.type() == bdecode_node::string_t
&& http_seeds.string_length() > 0) && http_seeds.string_length() > 0)
{ {
@ -1488,7 +1488,7 @@ namespace libtorrent
std::set<std::string> unique; std::set<std::string> unique;
for (int i = 0, end(http_seeds.list_size()); i < end; ++i) for (int i = 0, end(http_seeds.list_size()); i < end; ++i)
{ {
bdecode_node url = http_seeds.list_at(i); bdecode_node const url = http_seeds.list_at(i);
if (url.type() != bdecode_node::string_t || url.string_length() == 0) continue; if (url.type() != bdecode_node::string_t || url.string_length() == 0) continue;
std::string u = maybe_url_encode(url.string_value().to_string()); std::string u = maybe_url_encode(url.string_value().to_string());
if (unique.count(u)) continue; if (unique.count(u)) continue;

View File

@ -209,7 +209,7 @@ namespace libtorrent { namespace
{ {
m_message_index = 0; m_message_index = 0;
if (h.type() != bdecode_node::dict_t) return false; if (h.type() != bdecode_node::dict_t) return false;
bdecode_node messages = h.dict_find_dict("m"); bdecode_node const messages = h.dict_find_dict("m");
if (!messages) return false; if (!messages) return false;
int index = int(messages.dict_find_int_value("ut_metadata", -1)); int index = int(messages.dict_find_int_value("ut_metadata", -1));

View File

@ -256,7 +256,7 @@ namespace libtorrent { namespace
{ {
m_message_index = 0; m_message_index = 0;
if (h.type() != bdecode_node::dict_t) return false; if (h.type() != bdecode_node::dict_t) return false;
bdecode_node messages = h.dict_find_dict("m"); bdecode_node const messages = h.dict_find_dict("m");
if (!messages) return false; if (!messages) return false;
int index = int(messages.dict_find_int_value(extension_name, -1)); int index = int(messages.dict_find_int_value(extension_name, -1));
@ -323,7 +323,7 @@ namespace libtorrent { namespace
} }
p = pex_msg.dict_find_string("added"); p = pex_msg.dict_find_string("added");
bdecode_node pf = pex_msg.dict_find_string("added.f"); bdecode_node const pf = pex_msg.dict_find_string("added.f");
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
if (p) num_added += p.string_length() / 6; if (p) num_added += p.string_length() / 6;
@ -378,7 +378,7 @@ namespace libtorrent { namespace
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
if (p6) num_added += p6.string_length() / 18; if (p6) num_added += p6.string_length() / 18;
#endif #endif
bdecode_node p6f = pex_msg.dict_find("added6.f"); bdecode_node const p6f = pex_msg.dict_find("added6.f");
if (p6.type() == bdecode_node::string_t if (p6.type() == bdecode_node::string_t
&& p6f.type() == bdecode_node::string_t && p6f.type() == bdecode_node::string_t
&& p6f.string_length() == p6.string_length() / 18) && p6f.string_length() == p6.string_length() / 18)