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
* separate anonymous mode and force-proxy mode, and tighten it up a bit
* 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;
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<char>(out), *rd->resume_data);

View File

@ -983,7 +983,8 @@ bool handle_alert(libtorrent::session& ses, libtorrent::alert* a
{
std::vector<char> 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<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 == '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<char> 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);
}
}

View File

@ -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);

View File

@ -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

View File

@ -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();