diff --git a/ChangeLog b/ChangeLog index 9bed3b5d9..a26cf6dfe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * use hex encoding instead of base32 in create_magnet_uri * include name, save_path and torrent_file in torrent_status, for improved performance * separate anonymous mode and force-proxy mode, and tighten it up a bit * add per-tracker scrape information to announce_entry diff --git a/docs/manual.rst b/docs/manual.rst index 72974dc59..6ace67167 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -2351,8 +2351,6 @@ Its declaration looks like this:: boost::intrusive_ptr torrent_file() const; bool is_valid() const; - std::string name() const; - enum save_resume_flags_t { flush_disk_cache = 1, save_info_dict = 2 }; void save_resume_data(int flags = 0) const; bool need_save_resume_data() const; @@ -3228,7 +3226,9 @@ Example code to pause and save resume data for all torrents and wait for the ale } torrent_handle h = rd->handle; - std::ofstream out((h.status().save_path + "/" + h.torrent_file()->name() + ".fastresume").c_str() + torrent_status st = h.status(torrent_handle::query_save_path | torrent_handle::query_name); + std::ofstream out((st.save_path + + "/" + st.name + ".fastresume").c_str() , std::ios_base::binary); out.unsetf(std::ios_base::skipws); bencode(std::ostream_iterator(out), *rd->resume_data); diff --git a/examples/client_test.cpp b/examples/client_test.cpp index e156f7105..da1681881 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -983,7 +983,8 @@ bool handle_alert(libtorrent::session& ses, libtorrent::alert* a { std::vector out; bencode(std::back_inserter(out), *p->resume_data); - save_file(combine_path(h.save_path(), combine_path(".resume", to_hex(h.info_hash().to_string()) + ".resume")), out); + torrent_status st = h.status(torrent_handle::query_save_path); + save_file(combine_path(st.save_path, combine_path(".resume", to_hex(st.info_hash.to_string()) + ".resume")), out); if (h.is_valid() && non_files.find(h) == non_files.end() && std::find_if(files.begin(), files.end() @@ -1646,48 +1647,22 @@ int main(int argc, char* argv[]) ses.async_add_torrent(p); } - if (c == 'M') - { - printf("saving peers for torrents\n"); - - std::vector peers; - std::vector torrents = ses.get_torrents(); - for (std::vector::iterator i = torrents.begin(); - i != torrents.end(); ++i) - { - i->get_full_peer_list(peers); - FILE* f = fopen(("peers_" + i->name()).c_str(), "w+"); - if (!f) break; - for (std::vector::iterator k = peers.begin() - , end(peers.end()); k != end; ++k) - { - fprintf(f, "%s\t%d\n", print_address(k->ip.address()).c_str() -#ifndef TORRENT_DISABLE_GEO_IP - , ses.as_for_ip(k->ip.address()) -#else - , 0 -#endif - ); - } - } - } - if (c == 'q') break; if (c == 'D') { - torrent_handle h = get_active_torrent(filtered_handles).handle; - if (h.is_valid()) + torrent_status const& st = get_active_torrent(filtered_handles); + if (st.handle.is_valid()) { printf("\n\nARE YOU SURE YOU WANT TO DELETE THE FILES FOR '%s'. THIS OPERATION CANNOT BE UNDONE. (y/N)" - , h.name().c_str()); + , st.name.c_str()); char response = 'n'; scanf("%c", &response); if (response == 'y') { // also delete the .torrent file from the torrent directory handles_t::iterator i = std::find_if(files.begin(), files.end() - , boost::bind(&handles_t::value_type::second, _1) == h); + , boost::bind(&handles_t::value_type::second, _1) == st.handle); if (i != files.end()) { error_code ec; @@ -1698,8 +1673,8 @@ int main(int argc, char* argv[]) if (ec) printf("failed to delete .torrent file: %s\n", ec.message().c_str()); files.erase(i); } - if (h.is_valid()) - ses.remove_torrent(h, session::delete_files); + if (st.handle.is_valid()) + ses.remove_torrent(st.handle, session::delete_files); } } } @@ -2011,7 +1986,7 @@ int main(int argc, char* argv[]) if (s.paused) out += esc("34"); else out += esc("37"); - std::string name = s.handle.name(); + std::string name = s.name; if (name.size() > 40) name.resize(40); snprintf(str, sizeof(str), "%-40s %s ", name.c_str(), term); out += str; @@ -2218,7 +2193,7 @@ int main(int argc, char* argv[]) h.get_peer_info(peers); out += "====== "; - out += h.name(); + out += st->name; out += " ======\n"; if (print_peers && !peers.empty()) @@ -2363,12 +2338,12 @@ int main(int argc, char* argv[]) } if (!st.has_metadata) { - printf(" skipping %s, no metadata\n", st.handle.name().c_str()); + printf(" skipping %s, no metadata\n", st.name.c_str()); continue; } if (!st.need_save_resume) { - printf(" skipping %s, resume file up-to-date\n", st.handle.name().c_str()); + printf(" skipping %s, resume file up-to-date\n", st.name.c_str()); continue; } @@ -2420,9 +2395,10 @@ int main(int argc, char* argv[]) if (!rd->resume_data) continue; torrent_handle h = rd->handle; + torrent_status st = h.status(torrent_handle::query_save_path); std::vector out; bencode(std::back_inserter(out), *rd->resume_data); - save_file(combine_path(h.save_path(), combine_path(".resume", to_hex(h.info_hash().to_string()) + ".resume")), out); + save_file(combine_path(st.save_path, combine_path(".resume", to_hex(st.info_hash.to_string()) + ".resume")), out); } } diff --git a/examples/rss_reader.cpp b/examples/rss_reader.cpp index 4b56b4740..ee7b32c28 100644 --- a/examples/rss_reader.cpp +++ b/examples/rss_reader.cpp @@ -165,7 +165,7 @@ int main(int argc, char* argv[]) { torrent_status st = i->status(); std::string const& progress = progress_bar(st.progress_ppm / 1000, 40); - std::string name = i->name(); + std::string name = st.name; if (name.size() > 70) name.resize(70); std::string error = st.error; if (error.size() > 40) error.resize(40); diff --git a/src/alert.cpp b/src/alert.cpp index 2ada5ce0c..507b8a770 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -55,13 +55,14 @@ namespace libtorrent { std::string torrent_alert::message() const { if (!handle.is_valid()) return " - "; - if (handle.name().empty()) + torrent_status st = handle.status(torrent_handle::query_name); + if (st.name.empty()) { char msg[41]; - to_hex((char const*)&handle.info_hash()[0], 20, msg); + to_hex((char const*)&st.info_hash[0], 20, msg); return msg; } - return handle.name(); + return st.name; } std::string peer_alert::message() const diff --git a/src/magnet_uri.cpp b/src/magnet_uri.cpp index 246d90c35..32a92145d 100644 --- a/src/magnet_uri.cpp +++ b/src/magnet_uri.cpp @@ -47,9 +47,10 @@ namespace libtorrent 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()); + , to_hex(ih.to_string()).c_str()); - std::string name = handle.name(); + torrent_status st = handle.status(torrent_handle::query_name); + std::string name = st.name; if (!name.empty()) num_chars += snprintf(ret + num_chars, sizeof(ret) - num_chars, "&dn=%s" @@ -71,7 +72,7 @@ namespace libtorrent char ret[1024]; sha1_hash const& ih = info.info_hash(); int num_chars = snprintf(ret, sizeof(ret), "magnet:?xt=urn:btih:%s" - , base32encode(std::string((char*)&ih[0], 20)).c_str()); + , to_hex(ih.to_string()).c_str()); std::string const& name = info.name();