lt sync 2642

This commit is contained in:
Andrew Resch 2008-08-28 03:56:28 +00:00
parent b3d5a8a808
commit aebd6e2f29
4 changed files with 30 additions and 3 deletions

View File

@ -46,6 +46,7 @@ namespace libtorrent
struct torrent_handle;
std::string TORRENT_EXPORT make_magnet_uri(torrent_handle const& handle);
std::string TORRENT_EXPORT make_magnet_uri(torrent_info const& info);
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 0.14

View File

@ -69,6 +69,26 @@ namespace libtorrent
return ret.str();
}
std::string make_magnet_uri(torrent_info const& info)
{
std::stringstream ret;
if (!info.is_valid()) return ret.str();
std::string name = info.name();
ret << "magnet:?xt=urn:btih:" << base32encode(
std::string((char*)info.info_hash().begin(), 20));
if (!name.empty())
ret << "&dn=" << escape_string(name.c_str(), name.length());
std::vector<announce_entry> const& tr = info.trackers();
if (!tr.empty())
{
ret << "&tr=" << escape_string(tr[0].url.c_str()
, tr[0].url.length());
}
return ret.str();
}
#ifndef TORRENT_NO_DEPRECATE
torrent_handle add_magnet_uri(session& ses, std::string const& uri
, fs::path const& save_path

View File

@ -1706,9 +1706,8 @@ namespace libtorrent
}
if (t->alerts().should_post<file_error_alert>())
{
t->alerts().post_alert(file_error_alert(j.error_file, t->get_handle(), j.str));
}
t->set_error(j.str);
t->pause();
return;
}

View File

@ -330,7 +330,11 @@ namespace libtorrent
void torrent::start()
{
// we need to start announcing since we don't have any
// metadata. To receive peers to ask for it.
if (m_torrent_file->is_valid()) init();
else if (!m_trackers.empty()) start_announcing();
if (m_abort) return;
}
@ -3919,7 +3923,10 @@ namespace libtorrent
void torrent::start_announcing()
{
if (is_paused()) return;
if (!m_files_checked) return;
// if we don't have metadata, we need to announce
// before checking files, to get peers to
// request the metadata from
if (!m_files_checked && valid_metadata()) return;
if (m_announcing) return;
m_announcing = true;