Changeset 3768

Show
Ignore:
Timestamp:
08/28/08 03:56:28 (4 months ago)
Author:
andar
Message:

lt sync 2642

Files:
8 modified

Legend:

Unmodified
Added
Removed
  • branches/1.0.0_RC/libtorrent/include/libtorrent/magnet_uri.hpp

    r3675 r3768  
    4747 
    4848        std::string TORRENT_EXPORT make_magnet_uri(torrent_handle const& handle); 
     49        std::string TORRENT_EXPORT make_magnet_uri(torrent_info const& info); 
    4950 
    5051#ifndef TORRENT_NO_DEPRECATE 
  • branches/1.0.0_RC/libtorrent/src/magnet_uri.cpp

    r3675 r3768  
    7070        } 
    7171 
     72        std::string make_magnet_uri(torrent_info const& info) 
     73        { 
     74                std::stringstream ret; 
     75                if (!info.is_valid()) return ret.str(); 
     76 
     77                std::string name = info.name(); 
     78 
     79                ret << "magnet:?xt=urn:btih:" << base32encode( 
     80                        std::string((char*)info.info_hash().begin(), 20)); 
     81                if (!name.empty()) 
     82                        ret << "&dn=" << escape_string(name.c_str(), name.length()); 
     83                std::vector<announce_entry> const& tr = info.trackers(); 
     84                if (!tr.empty()) 
     85                { 
     86                        ret << "&tr=" << escape_string(tr[0].url.c_str() 
     87                                , tr[0].url.length()); 
     88                } 
     89                return ret.str(); 
     90        } 
     91 
    7292#ifndef TORRENT_NO_DEPRECATE 
    7393        torrent_handle add_magnet_uri(session& ses, std::string const& uri 
  • branches/1.0.0_RC/libtorrent/src/peer_connection.cpp

    r3758 r3768  
    17071707                 
    17081708                        if (t->alerts().should_post<file_error_alert>()) 
    1709                         { 
    17101709                                t->alerts().post_alert(file_error_alert(j.error_file, t->get_handle(), j.str)); 
    1711                         } 
     1710                        t->set_error(j.str); 
    17121711                        t->pause(); 
    17131712                        return; 
  • branches/1.0.0_RC/libtorrent/src/torrent.cpp

    r3759 r3768  
    331331        void torrent::start() 
    332332        { 
     333                // we need to start announcing since we don't have any 
     334                // metadata. To receive peers to ask for it. 
    333335                if (m_torrent_file->is_valid()) init(); 
     336                else if (!m_trackers.empty()) start_announcing(); 
     337 
    334338                if (m_abort) return; 
    335339        } 
     
    39203924        { 
    39213925                if (is_paused()) return; 
    3922                 if (!m_files_checked) return; 
     3926                // if we don't have metadata, we need to announce 
     3927                // before checking files, to get peers to 
     3928                // request the metadata from 
     3929                if (!m_files_checked && valid_metadata()) return; 
    39233930                if (m_announcing) return; 
    39243931 
  • trunk/libtorrent/include/libtorrent/magnet_uri.hpp

    r3640 r3768  
    4747 
    4848        std::string TORRENT_EXPORT make_magnet_uri(torrent_handle const& handle); 
     49        std::string TORRENT_EXPORT make_magnet_uri(torrent_info const& info); 
    4950 
    5051#ifndef TORRENT_NO_DEPRECATE 
  • trunk/libtorrent/src/magnet_uri.cpp

    r3640 r3768  
    7070        } 
    7171 
     72        std::string make_magnet_uri(torrent_info const& info) 
     73        { 
     74                std::stringstream ret; 
     75                if (!info.is_valid()) return ret.str(); 
     76 
     77                std::string name = info.name(); 
     78 
     79                ret << "magnet:?xt=urn:btih:" << base32encode( 
     80                        std::string((char*)info.info_hash().begin(), 20)); 
     81                if (!name.empty()) 
     82                        ret << "&dn=" << escape_string(name.c_str(), name.length()); 
     83                std::vector<announce_entry> const& tr = info.trackers(); 
     84                if (!tr.empty()) 
     85                { 
     86                        ret << "&tr=" << escape_string(tr[0].url.c_str() 
     87                                , tr[0].url.length()); 
     88                } 
     89                return ret.str(); 
     90        } 
     91 
    7292#ifndef TORRENT_NO_DEPRECATE 
    7393        torrent_handle add_magnet_uri(session& ses, std::string const& uri 
  • trunk/libtorrent/src/peer_connection.cpp

    r3758 r3768  
    17071707                 
    17081708                        if (t->alerts().should_post<file_error_alert>()) 
    1709                         { 
    17101709                                t->alerts().post_alert(file_error_alert(j.error_file, t->get_handle(), j.str)); 
    1711                         } 
     1710                        t->set_error(j.str); 
    17121711                        t->pause(); 
    17131712                        return; 
  • trunk/libtorrent/src/torrent.cpp

    r3759 r3768  
    331331        void torrent::start() 
    332332        { 
     333                // we need to start announcing since we don't have any 
     334                // metadata. To receive peers to ask for it. 
    333335                if (m_torrent_file->is_valid()) init(); 
     336                else if (!m_trackers.empty()) start_announcing(); 
     337 
    334338                if (m_abort) return; 
    335339        } 
     
    39203924        { 
    39213925                if (is_paused()) return; 
    3922                 if (!m_files_checked) return; 
     3926                // if we don't have metadata, we need to announce 
     3927                // before checking files, to get peers to 
     3928                // request the metadata from 
     3929                if (!m_files_checked && valid_metadata()) return; 
    39233930                if (m_announcing) return; 
    39243931