Changeset 8bcc7e


Ignore:
Timestamp:
02/09/2009 11:23:26 PM (16 years ago)
Author:
Andrew Resch <andrewresch@gmail.com>
Branches:
2.0.x, develop, extjs4-port, master
Children:
9175ac
Parents:
db23f6
Message:

lt sync 3243

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libtorrent/src/torrent.cpp

    rdb23f6 r8bcc7e  
    102102                        , tor(t)
    103103                { TORRENT_ASSERT(t != 0); }
    104 
     104               
    105105                bool operator()(session_impl::connection_map::value_type const& c) const
    106106                {
     
    118118        {
    119119                peer_by_id(const peer_id& i): pid(i) {}
    120 
     120               
    121121                bool operator()(session_impl::connection_map::value_type const& p) const
    122122                {
     
    353353                if (m_torrent_file->is_valid() && m_torrent_file->priv()) return false;
    354354                if (m_trackers.empty()) return true;
    355 
     355                       
    356356                return m_failed_trackers > 0 || !m_ses.settings().use_dht_as_fallback;
    357357        }
     
    364364                // reset, which means that all its peers already have an
    365365                // invalidated torrent pointer (so it cannot be verified to be correct)
    366 
     366               
    367367                // i.e. the invariant can only be maintained if all connections have
    368368                // been closed by the time the torrent is destructed. And they are
     
    370370
    371371                TORRENT_ASSERT(m_connections.empty());
    372 
     372               
    373373                INVARIANT_CHECK;
    374374
     
    422422
    423423                add_extension(tp);
    424 
     424               
    425425                for (peer_iterator i = m_connections.begin();
    426426                        i != m_connections.end(); ++i)
     
    479479                        if (m_resume_entry.dict_find_string_value("file-format") != "libtorrent resume file")
    480480                                error = "invalid file format tag";
    481 
     481       
    482482                        std::string info_hash = m_resume_entry.dict_find_string_value("info-hash");
    483483                        if (!error && info_hash.empty())
     
    507507                        }
    508508                }
    509 
     509       
    510510                m_storage->async_check_fastresume(&m_resume_entry
    511511                        , bind(&torrent::on_resume_data_checked
     
    563563                        {
    564564                                peer_id id(0);
    565 
     565       
    566566                                for (int i = 0; i < banned_peers_entry->list_size(); ++i)
    567567                                {
     
    581581
    582582                bool fastresume_rejected = !j.str.empty();
    583 
     583               
    584584                if (fastresume_rejected && m_ses.m_alerts.should_post<fastresume_rejected_alert>())
    585585                {
     
    748748                        , shared_from_this(), _1, _2));
    749749        }
    750 
     750       
    751751        void torrent::on_piece_checked(int ret, disk_io_job const& j)
    752752        {
     
    813813        {
    814814                session_impl::mutex_t::scoped_lock l(m_ses.m_mutex);
    815 
     815       
    816816                if (m_abort) return;
    817817                announce_with_tracker();
     
    954954                TORRENT_ASSERT(m_currently_trying_tracker >= 0);
    955955                TORRENT_ASSERT(m_currently_trying_tracker < int(m_trackers.size()));
    956 
     956               
    957957                tracker_request req;
    958958                req.info_hash = m_torrent_file->info_hash();
     
    974974                        m_ses.m_alerts.post_alert(tracker_warning_alert(get_handle(), req.url, msg));
    975975        }
    976 
     976       
    977977        void torrent::tracker_scrape_response(tracker_request const& req
    978978                , int complete, int incomplete, int downloaded)
    979979        {
    980980                session_impl::mutex_t::scoped_lock l(m_ses.m_mutex);
    981 
     981 
    982982                INVARIANT_CHECK;
    983983                TORRENT_ASSERT(req.kind == tracker_request::scrape_request);
    984 
     984 
    985985                if (complete >= 0) m_complete = complete;
    986986                if (incomplete >= 0) m_incomplete = incomplete;
    987 
     987 
    988988                if (m_ses.m_alerts.should_post<scrape_reply_alert>())
    989989                {
     
    992992                }
    993993        }
    994 
     994 
    995995        void torrent::tracker_response(
    996996                tracker_request const& r
     
    11041104                        return;
    11051105                }
    1106 
     1106                       
    11071107                m_policy.peer_from_tracker(*host, pid, peer_info::tracker, 0);
    11081108        }
     
    11661166                        * piece_size;
    11671167                TORRENT_ASSERT(wanted_done >= 0);
    1168 
     1168               
    11691169                size_type total_done
    11701170                        = size_type(num_have()) * piece_size;
     
    12951295                        // but not yet verified against the hash
    12961296                        std::cerr << "num_have: " << num_have() << std::endl;
    1297 
     1297                       
    12981298                        std::cerr << "unfinished:" << std::endl;
    1299 
     1299                       
    13001300                        for (std::vector<piece_picker::downloading_piece>::const_iterator i =
    13011301                                dl_queue.begin(); i != dl_queue.end(); ++i)
     
    13081308                                std::cerr << std::endl;
    13091309                        }
    1310 
     1310                       
    13111311                        std::cerr << "downloading pieces:" << std::endl;
    13121312
     
    16351635                        m_storage->abort_disk_io();
    16361636                }
    1637 
     1637               
    16381638                dequeue_torrent_check();
     1639               
     1640                if (m_state == torrent_status::checking_files)
     1641                        set_state(torrent_status::queued_for_checking);
    16391642
    16401643                m_owning_storage = 0;
     
    16911694        {
    16921695                session_impl::mutex_t::scoped_lock l(m_ses.m_mutex);
    1693 
     1696               
    16941697                {
    16951698                        if (ret == 0)
     
    18271830                // in the torrent
    18281831                TORRENT_ASSERT(int(files.size()) == m_torrent_file->num_files());
    1829 
     1832               
    18301833                if (m_torrent_file->num_pieces() == 0) return;
    18311834
     
    18431846                update_piece_priorities();
    18441847        }
    1845 
     1848       
    18461849        int torrent::file_priority(int index) const
    18471850        {
     
    19651968                TORRENT_ASSERT(valid_metadata());
    19661969                if (is_seed()) return false;
    1967 
     1970               
    19681971                TORRENT_ASSERT(m_picker.get());
    19691972                TORRENT_ASSERT(index >= 0);
     
    20002003                // in the torrent
    20012004                TORRENT_ASSERT((int)bitmask.size() == m_torrent_file->num_files());
    2002 
     2005               
    20032006                size_type position = 0;
    20042007
     
    20152018                                // is the file selected for download?
    20162019                                if (!bitmask[i])
    2017                                 {
     2020                                {           
    20182021                                        // mark all pieces of the file as downloadable
    20192022                                        int start_piece = int(start / piece_length);
     
    20482051                --m_num_uploads;
    20492052        }
    2050 
     2053       
    20512054        bool torrent::unchoke_peer(peer_connection& c)
    20522055        {
     
    21612164                        return;
    21622165                }
    2163 
     2166               
    21642167#ifdef TORRENT_USE_OPENSSL
    21652168                if (protocol != "http" && protocol != "https")
     
    23402343                        return;
    23412344                }
    2342 
     2345               
    23432346                boost::shared_ptr<socket_type> s(new (std::nothrow) socket_type(m_ses.m_io_service));
    23442347                if (!s) return;
    2345 
     2348       
    23462349                bool ret = instantiate_connection(m_ses.m_io_service, m_ses.web_seed_proxy(), *s);
    23472350                (void)ret;
     
    23592362                        m_ses, shared_from_this(), s, a, url, 0));
    23602363                if (!c) return;
    2361 
     2364                       
    23622365#ifdef TORRENT_DEBUG
    23632366                c->m_in_constructor = false;
     
    24102413                }
    24112414        }
    2412 
     2415       
    24132416        void torrent::resolve_peer_country(boost::intrusive_ptr<peer_connection> const& p) const
    24142417        {
     
    24482451
    24492452                INVARIANT_CHECK;
    2450 
     2453               
    24512454                m_resolving_country = false;
    24522455
     
    25202523                        // country is an ISO 3166 country code
    25212524                        int country = i->endpoint().address().to_v4().to_ulong() & 0xffff;
    2522 
     2525                       
    25232526                        // look up the country code in the map
    25242527                        const int size = sizeof(country_map)/sizeof(country_map[0]);
     
    25372540                                return;
    25382541                        }
    2539 
     2542                       
    25402543                        p->set_country(i->name);
    25412544                }
     
    26132616                                std::string new_filename = mapped_files->list_string_value_at(i);
    26142617                                if (new_filename.empty()) continue;
    2615                                 m_torrent_file->rename_file(i, new_filename);
     2618                                rename_file(i, new_filename);
    26162619                        }
    26172620                }
     
    26282631                }
    26292632        }
    2630 
     2633       
    26312634        void torrent::write_resume_data(entry& ret) const
    26322635        {
     
    26512654
    26522655                ret["sequential_download"] = m_sequential_download;
    2653 
     2656               
    26542657                const sha1_hash& info_hash = torrent_file().info_hash();
    26552658                ret["info-hash"] = std::string((char*)info_hash.begin(), (char*)info_hash.end());
     
    27522755                entry::list_type& peer_list = ret["peers"].list();
    27532756                entry::list_type& banned_peer_list = ret["banned_peers"].list();
    2754 
     2757               
    27552758                int max_failcount = m_ses.m_settings.max_failcount;
    27562759
     
    28452848                        v.push_back(peer_info());
    28462849                        peer_info& p = v.back();
    2847 
     2850                       
    28482851                        peer->get_peer_info(p);
    28492852#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
     
    29232926                        queue.push_back(pi);
    29242927                }
    2925 
    2926         }
    2927 
     2928       
     2929        }
     2930       
    29282931        bool torrent::connect_to_peer(policy::peer* peerinfo)
    29292932        {
     
    30513054                        return false;
    30523055                }
    3053 
     3056               
    30543057                if (m_ses.m_connections.find(p) == m_ses.m_connections.end())
    30553058                {
     
    31813184                                double lhs_rate = double(lhs_transferred) / (lhs_time_connected + 1);
    31823185                                double rhs_rate = double(rhs_transferred) / (rhs_time_connected + 1);
    3183 
     3186                       
    31843187                                return lhs_rate < rhs_rate;
    31853188                        }
     
    32633266
    32643267                INVARIANT_CHECK;
    3265 
     3268               
    32663269                TORRENT_ASSERT(amount > 0);
    32673270                m_bandwidth_limit[channel].expire(amount);
     
    33573360
    33583361        // this is called when we were finished, but some files were
    3359         // marked for downloading, and we are no longer finished
     3362        // marked for downloading, and we are no longer finished       
    33603363        void torrent::resume_download()
    33613364        {
    33623365                INVARIANT_CHECK;
    3363 
     3366       
    33643367                TORRENT_ASSERT(!is_finished());
    33653368                set_state(torrent_status::downloading);
     
    34423445        {
    34433446                session_impl::mutex_t::scoped_lock l(m_ses.m_mutex);
    3444 
     3447               
    34453448                TORRENT_ASSERT(m_torrent_file->is_valid());
    34463449
     
    34593462                                get_handle()));
    34603463                }
    3461 
     3464               
    34623465                if (!is_seed())
    34633466                {
     
    35903593                else
    35913594                        TORRENT_ASSERT(m_queued_for_checking);
    3592 
     3595 
    35933596                if (!m_ses.m_queued_for_checking.empty())
    35943597                {
     
    37153718                        }
    37163719                }
    3717 
     3720                       
    37183721// This check is very expensive.
    37193722                TORRENT_ASSERT(!valid_metadata() || m_block_size > 0);
     
    37663769                                torrent* t = i->second.get();
    37673770                                if (t == this) continue;
    3768                                 if (t->m_sequence_number >= p
     3771                                if (t->m_sequence_number >= p 
    37693772                                        && t->m_sequence_number < m_sequence_number
    37703773                                        && t->m_sequence_number != -1)
     
    39873990        }
    39883991
    3989         // this is an async operation triggered by the client
     3992        // this is an async operation triggered by the client   
    39903993        void torrent::save_resume_data()
    39913994        {
    39923995                INVARIANT_CHECK;
    3993 
     3996       
    39943997                if (m_owning_storage.get())
    39953998                {
     
    42644267                                , bind(&torrent::connect_to_url_seed, this, _1));
    42654268                }
    4266 
     4269               
    42674270                for (peer_iterator i = m_connections.begin();
    42684271                        i != m_connections.end();)
     
    43974400        {
    43984401                TORRENT_ASSERT(valid_metadata());
    4399 
     4402       
    44004403                fp.resize(m_torrent_file->num_files(), 0);
    44014404
     
    44064409                        return;
    44074410                }
    4408 
     4411               
    44094412                TORRENT_ASSERT(has_picker());
    44104413
     
    45264529                }
    45274530        }
    4528 
     4531       
    45294532        void torrent::set_state(torrent_status::state_t s)
    45304533        {
     
    46644667                                --num_filtered_pieces;
    46654668                        }
    4666 
     4669                       
    46674670                        st.total_wanted -= size_type(num_filtered_pieces) * m_torrent_file->piece_length();
    46684671                }
     
    47884791
    47894792}
     4793
Note: See TracChangeset for help on using the changeset viewer.