make libtorrent and examples build with deprecated functions disabled (with some slight performance improvements). use hex encoding instead of base32 in create_magnet_uri

This commit is contained in:
Arvid Norberg 2013-03-04 03:24:53 +00:00
parent 431efc6157
commit 0682272661
6 changed files with 27 additions and 48 deletions

View File

@ -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 * 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 * separate anonymous mode and force-proxy mode, and tighten it up a bit
* add per-tracker scrape information to announce_entry * add per-tracker scrape information to announce_entry

View File

@ -2351,8 +2351,6 @@ Its declaration looks like this::
boost::intrusive_ptr<torrent_info> torrent_file() const; boost::intrusive_ptr<torrent_info> torrent_file() const;
bool is_valid() const; bool is_valid() const;
std::string name() const;
enum save_resume_flags_t { flush_disk_cache = 1, save_info_dict = 2 }; enum save_resume_flags_t { flush_disk_cache = 1, save_info_dict = 2 };
void save_resume_data(int flags = 0) const; void save_resume_data(int flags = 0) const;
bool need_save_resume_data() 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; 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); , std::ios_base::binary);
out.unsetf(std::ios_base::skipws); out.unsetf(std::ios_base::skipws);
bencode(std::ostream_iterator<char>(out), *rd->resume_data); bencode(std::ostream_iterator<char>(out), *rd->resume_data);

View File

@ -983,7 +983,8 @@ bool handle_alert(libtorrent::session& ses, libtorrent::alert* a
{ {
std::vector<char> out; std::vector<char> out;
bencode(std::back_inserter(out), *p->resume_data); 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() if (h.is_valid()
&& non_files.find(h) == non_files.end() && non_files.find(h) == non_files.end()
&& std::find_if(files.begin(), files.end() && std::find_if(files.begin(), files.end()
@ -1646,48 +1647,22 @@ int main(int argc, char* argv[])
ses.async_add_torrent(p); ses.async_add_torrent(p);
} }
if (c == 'M')
{
printf("saving peers for torrents\n");
std::vector<peer_list_entry> peers;
std::vector<torrent_handle> torrents = ses.get_torrents();
for (std::vector<torrent_handle>::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<peer_list_entry>::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 == 'q') break;
if (c == 'D') if (c == 'D')
{ {
torrent_handle h = get_active_torrent(filtered_handles).handle; torrent_status const& st = get_active_torrent(filtered_handles);
if (h.is_valid()) 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)" 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'; char response = 'n';
scanf("%c", &response); scanf("%c", &response);
if (response == 'y') if (response == 'y')
{ {
// also delete the .torrent file from the torrent directory // also delete the .torrent file from the torrent directory
handles_t::iterator i = std::find_if(files.begin(), files.end() 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()) if (i != files.end())
{ {
error_code ec; 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()); if (ec) printf("failed to delete .torrent file: %s\n", ec.message().c_str());
files.erase(i); files.erase(i);
} }
if (h.is_valid()) if (st.handle.is_valid())
ses.remove_torrent(h, session::delete_files); ses.remove_torrent(st.handle, session::delete_files);
} }
} }
} }
@ -2011,7 +1986,7 @@ int main(int argc, char* argv[])
if (s.paused) out += esc("34"); if (s.paused) out += esc("34");
else out += esc("37"); else out += esc("37");
std::string name = s.handle.name(); std::string name = s.name;
if (name.size() > 40) name.resize(40); if (name.size() > 40) name.resize(40);
snprintf(str, sizeof(str), "%-40s %s ", name.c_str(), term); snprintf(str, sizeof(str), "%-40s %s ", name.c_str(), term);
out += str; out += str;
@ -2218,7 +2193,7 @@ int main(int argc, char* argv[])
h.get_peer_info(peers); h.get_peer_info(peers);
out += "====== "; out += "====== ";
out += h.name(); out += st->name;
out += " ======\n"; out += " ======\n";
if (print_peers && !peers.empty()) if (print_peers && !peers.empty())
@ -2363,12 +2338,12 @@ int main(int argc, char* argv[])
} }
if (!st.has_metadata) 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; continue;
} }
if (!st.need_save_resume) 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; continue;
} }
@ -2420,9 +2395,10 @@ int main(int argc, char* argv[])
if (!rd->resume_data) continue; if (!rd->resume_data) continue;
torrent_handle h = rd->handle; torrent_handle h = rd->handle;
torrent_status st = h.status(torrent_handle::query_save_path);
std::vector<char> out; std::vector<char> out;
bencode(std::back_inserter(out), *rd->resume_data); 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);
} }
} }

View File

@ -165,7 +165,7 @@ int main(int argc, char* argv[])
{ {
torrent_status st = i->status(); torrent_status st = i->status();
std::string const& progress = progress_bar(st.progress_ppm / 1000, 40); 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); if (name.size() > 70) name.resize(70);
std::string error = st.error; std::string error = st.error;
if (error.size() > 40) error.resize(40); if (error.size() > 40) error.resize(40);

View File

@ -55,13 +55,14 @@ namespace libtorrent {
std::string torrent_alert::message() const std::string torrent_alert::message() const
{ {
if (!handle.is_valid()) return " - "; 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]; 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 msg;
} }
return handle.name(); return st.name;
} }
std::string peer_alert::message() const std::string peer_alert::message() const

View File

@ -47,9 +47,10 @@ namespace libtorrent
char ret[1024]; char ret[1024];
sha1_hash const& ih = handle.info_hash(); sha1_hash const& ih = handle.info_hash();
int num_chars = snprintf(ret, sizeof(ret), "magnet:?xt=urn:btih:%s" 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()) if (!name.empty())
num_chars += snprintf(ret + num_chars, sizeof(ret) - num_chars, "&dn=%s" num_chars += snprintf(ret + num_chars, sizeof(ret) - num_chars, "&dn=%s"
@ -71,7 +72,7 @@ namespace libtorrent
char ret[1024]; char ret[1024];
sha1_hash const& ih = info.info_hash(); sha1_hash const& ih = info.info_hash();
int num_chars = snprintf(ret, sizeof(ret), "magnet:?xt=urn:btih:%s" 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(); std::string const& name = info.name();