diff --git a/libtorrent/include/libtorrent/magnet_uri.hpp b/libtorrent/include/libtorrent/magnet_uri.hpp index a77880d16..88675dfe8 100644 --- a/libtorrent/include/libtorrent/magnet_uri.hpp +++ b/libtorrent/include/libtorrent/magnet_uri.hpp @@ -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 diff --git a/libtorrent/src/magnet_uri.cpp b/libtorrent/src/magnet_uri.cpp index af54de9e0..2570afc83 100644 --- a/libtorrent/src/magnet_uri.cpp +++ b/libtorrent/src/magnet_uri.cpp @@ -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 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 diff --git a/libtorrent/src/peer_connection.cpp b/libtorrent/src/peer_connection.cpp index e72239abc..d2a41f5e8 100755 --- a/libtorrent/src/peer_connection.cpp +++ b/libtorrent/src/peer_connection.cpp @@ -1706,9 +1706,8 @@ namespace libtorrent } if (t->alerts().should_post()) - { t->alerts().post_alert(file_error_alert(j.error_file, t->get_handle(), j.str)); - } + t->set_error(j.str); t->pause(); return; } diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index 137f93103..7c0ed22f9 100755 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -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;