Changeset 8bcc7e
- Timestamp:
- 02/09/2009 11:23:26 PM (16 years ago)
- Branches:
- 2.0.x, develop, extjs4-port, master
- Children:
- 9175ac
- Parents:
- db23f6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libtorrent/src/torrent.cpp
rdb23f6 r8bcc7e 102 102 , tor(t) 103 103 { TORRENT_ASSERT(t != 0); } 104 104 105 105 bool operator()(session_impl::connection_map::value_type const& c) const 106 106 { … … 118 118 { 119 119 peer_by_id(const peer_id& i): pid(i) {} 120 120 121 121 bool operator()(session_impl::connection_map::value_type const& p) const 122 122 { … … 353 353 if (m_torrent_file->is_valid() && m_torrent_file->priv()) return false; 354 354 if (m_trackers.empty()) return true; 355 355 356 356 return m_failed_trackers > 0 || !m_ses.settings().use_dht_as_fallback; 357 357 } … … 364 364 // reset, which means that all its peers already have an 365 365 // invalidated torrent pointer (so it cannot be verified to be correct) 366 366 367 367 // i.e. the invariant can only be maintained if all connections have 368 368 // been closed by the time the torrent is destructed. And they are … … 370 370 371 371 TORRENT_ASSERT(m_connections.empty()); 372 372 373 373 INVARIANT_CHECK; 374 374 … … 422 422 423 423 add_extension(tp); 424 424 425 425 for (peer_iterator i = m_connections.begin(); 426 426 i != m_connections.end(); ++i) … … 479 479 if (m_resume_entry.dict_find_string_value("file-format") != "libtorrent resume file") 480 480 error = "invalid file format tag"; 481 481 482 482 std::string info_hash = m_resume_entry.dict_find_string_value("info-hash"); 483 483 if (!error && info_hash.empty()) … … 507 507 } 508 508 } 509 509 510 510 m_storage->async_check_fastresume(&m_resume_entry 511 511 , bind(&torrent::on_resume_data_checked … … 563 563 { 564 564 peer_id id(0); 565 565 566 566 for (int i = 0; i < banned_peers_entry->list_size(); ++i) 567 567 { … … 581 581 582 582 bool fastresume_rejected = !j.str.empty(); 583 583 584 584 if (fastresume_rejected && m_ses.m_alerts.should_post<fastresume_rejected_alert>()) 585 585 { … … 748 748 , shared_from_this(), _1, _2)); 749 749 } 750 750 751 751 void torrent::on_piece_checked(int ret, disk_io_job const& j) 752 752 { … … 813 813 { 814 814 session_impl::mutex_t::scoped_lock l(m_ses.m_mutex); 815 815 816 816 if (m_abort) return; 817 817 announce_with_tracker(); … … 954 954 TORRENT_ASSERT(m_currently_trying_tracker >= 0); 955 955 TORRENT_ASSERT(m_currently_trying_tracker < int(m_trackers.size())); 956 956 957 957 tracker_request req; 958 958 req.info_hash = m_torrent_file->info_hash(); … … 974 974 m_ses.m_alerts.post_alert(tracker_warning_alert(get_handle(), req.url, msg)); 975 975 } 976 976 977 977 void torrent::tracker_scrape_response(tracker_request const& req 978 978 , int complete, int incomplete, int downloaded) 979 979 { 980 980 session_impl::mutex_t::scoped_lock l(m_ses.m_mutex); 981 981 982 982 INVARIANT_CHECK; 983 983 TORRENT_ASSERT(req.kind == tracker_request::scrape_request); 984 984 985 985 if (complete >= 0) m_complete = complete; 986 986 if (incomplete >= 0) m_incomplete = incomplete; 987 987 988 988 if (m_ses.m_alerts.should_post<scrape_reply_alert>()) 989 989 { … … 992 992 } 993 993 } 994 994 995 995 void torrent::tracker_response( 996 996 tracker_request const& r … … 1104 1104 return; 1105 1105 } 1106 1106 1107 1107 m_policy.peer_from_tracker(*host, pid, peer_info::tracker, 0); 1108 1108 } … … 1166 1166 * piece_size; 1167 1167 TORRENT_ASSERT(wanted_done >= 0); 1168 1168 1169 1169 size_type total_done 1170 1170 = size_type(num_have()) * piece_size; … … 1295 1295 // but not yet verified against the hash 1296 1296 std::cerr << "num_have: " << num_have() << std::endl; 1297 1297 1298 1298 std::cerr << "unfinished:" << std::endl; 1299 1299 1300 1300 for (std::vector<piece_picker::downloading_piece>::const_iterator i = 1301 1301 dl_queue.begin(); i != dl_queue.end(); ++i) … … 1308 1308 std::cerr << std::endl; 1309 1309 } 1310 1310 1311 1311 std::cerr << "downloading pieces:" << std::endl; 1312 1312 … … 1635 1635 m_storage->abort_disk_io(); 1636 1636 } 1637 1637 1638 1638 dequeue_torrent_check(); 1639 1640 if (m_state == torrent_status::checking_files) 1641 set_state(torrent_status::queued_for_checking); 1639 1642 1640 1643 m_owning_storage = 0; … … 1691 1694 { 1692 1695 session_impl::mutex_t::scoped_lock l(m_ses.m_mutex); 1693 1696 1694 1697 { 1695 1698 if (ret == 0) … … 1827 1830 // in the torrent 1828 1831 TORRENT_ASSERT(int(files.size()) == m_torrent_file->num_files()); 1829 1832 1830 1833 if (m_torrent_file->num_pieces() == 0) return; 1831 1834 … … 1843 1846 update_piece_priorities(); 1844 1847 } 1845 1848 1846 1849 int torrent::file_priority(int index) const 1847 1850 { … … 1965 1968 TORRENT_ASSERT(valid_metadata()); 1966 1969 if (is_seed()) return false; 1967 1970 1968 1971 TORRENT_ASSERT(m_picker.get()); 1969 1972 TORRENT_ASSERT(index >= 0); … … 2000 2003 // in the torrent 2001 2004 TORRENT_ASSERT((int)bitmask.size() == m_torrent_file->num_files()); 2002 2005 2003 2006 size_type position = 0; 2004 2007 … … 2015 2018 // is the file selected for download? 2016 2019 if (!bitmask[i]) 2017 { 2020 { 2018 2021 // mark all pieces of the file as downloadable 2019 2022 int start_piece = int(start / piece_length); … … 2048 2051 --m_num_uploads; 2049 2052 } 2050 2053 2051 2054 bool torrent::unchoke_peer(peer_connection& c) 2052 2055 { … … 2161 2164 return; 2162 2165 } 2163 2166 2164 2167 #ifdef TORRENT_USE_OPENSSL 2165 2168 if (protocol != "http" && protocol != "https") … … 2340 2343 return; 2341 2344 } 2342 2345 2343 2346 boost::shared_ptr<socket_type> s(new (std::nothrow) socket_type(m_ses.m_io_service)); 2344 2347 if (!s) return; 2345 2348 2346 2349 bool ret = instantiate_connection(m_ses.m_io_service, m_ses.web_seed_proxy(), *s); 2347 2350 (void)ret; … … 2359 2362 m_ses, shared_from_this(), s, a, url, 0)); 2360 2363 if (!c) return; 2361 2364 2362 2365 #ifdef TORRENT_DEBUG 2363 2366 c->m_in_constructor = false; … … 2410 2413 } 2411 2414 } 2412 2415 2413 2416 void torrent::resolve_peer_country(boost::intrusive_ptr<peer_connection> const& p) const 2414 2417 { … … 2448 2451 2449 2452 INVARIANT_CHECK; 2450 2453 2451 2454 m_resolving_country = false; 2452 2455 … … 2520 2523 // country is an ISO 3166 country code 2521 2524 int country = i->endpoint().address().to_v4().to_ulong() & 0xffff; 2522 2525 2523 2526 // look up the country code in the map 2524 2527 const int size = sizeof(country_map)/sizeof(country_map[0]); … … 2537 2540 return; 2538 2541 } 2539 2542 2540 2543 p->set_country(i->name); 2541 2544 } … … 2613 2616 std::string new_filename = mapped_files->list_string_value_at(i); 2614 2617 if (new_filename.empty()) continue; 2615 m_torrent_file->rename_file(i, new_filename);2618 rename_file(i, new_filename); 2616 2619 } 2617 2620 } … … 2628 2631 } 2629 2632 } 2630 2633 2631 2634 void torrent::write_resume_data(entry& ret) const 2632 2635 { … … 2651 2654 2652 2655 ret["sequential_download"] = m_sequential_download; 2653 2656 2654 2657 const sha1_hash& info_hash = torrent_file().info_hash(); 2655 2658 ret["info-hash"] = std::string((char*)info_hash.begin(), (char*)info_hash.end()); … … 2752 2755 entry::list_type& peer_list = ret["peers"].list(); 2753 2756 entry::list_type& banned_peer_list = ret["banned_peers"].list(); 2754 2757 2755 2758 int max_failcount = m_ses.m_settings.max_failcount; 2756 2759 … … 2845 2848 v.push_back(peer_info()); 2846 2849 peer_info& p = v.back(); 2847 2850 2848 2851 peer->get_peer_info(p); 2849 2852 #ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES … … 2923 2926 queue.push_back(pi); 2924 2927 } 2925 2926 } 2927 2928 2929 } 2930 2928 2931 bool torrent::connect_to_peer(policy::peer* peerinfo) 2929 2932 { … … 3051 3054 return false; 3052 3055 } 3053 3056 3054 3057 if (m_ses.m_connections.find(p) == m_ses.m_connections.end()) 3055 3058 { … … 3181 3184 double lhs_rate = double(lhs_transferred) / (lhs_time_connected + 1); 3182 3185 double rhs_rate = double(rhs_transferred) / (rhs_time_connected + 1); 3183 3186 3184 3187 return lhs_rate < rhs_rate; 3185 3188 } … … 3263 3266 3264 3267 INVARIANT_CHECK; 3265 3268 3266 3269 TORRENT_ASSERT(amount > 0); 3267 3270 m_bandwidth_limit[channel].expire(amount); … … 3357 3360 3358 3361 // 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 3360 3363 void torrent::resume_download() 3361 3364 { 3362 3365 INVARIANT_CHECK; 3363 3366 3364 3367 TORRENT_ASSERT(!is_finished()); 3365 3368 set_state(torrent_status::downloading); … … 3442 3445 { 3443 3446 session_impl::mutex_t::scoped_lock l(m_ses.m_mutex); 3444 3447 3445 3448 TORRENT_ASSERT(m_torrent_file->is_valid()); 3446 3449 … … 3459 3462 get_handle())); 3460 3463 } 3461 3464 3462 3465 if (!is_seed()) 3463 3466 { … … 3590 3593 else 3591 3594 TORRENT_ASSERT(m_queued_for_checking); 3592 3595 3593 3596 if (!m_ses.m_queued_for_checking.empty()) 3594 3597 { … … 3715 3718 } 3716 3719 } 3717 3720 3718 3721 // This check is very expensive. 3719 3722 TORRENT_ASSERT(!valid_metadata() || m_block_size > 0); … … 3766 3769 torrent* t = i->second.get(); 3767 3770 if (t == this) continue; 3768 if (t->m_sequence_number >= p 3771 if (t->m_sequence_number >= p 3769 3772 && t->m_sequence_number < m_sequence_number 3770 3773 && t->m_sequence_number != -1) … … 3987 3990 } 3988 3991 3989 // this is an async operation triggered by the client 3992 // this is an async operation triggered by the client 3990 3993 void torrent::save_resume_data() 3991 3994 { 3992 3995 INVARIANT_CHECK; 3993 3996 3994 3997 if (m_owning_storage.get()) 3995 3998 { … … 4264 4267 , bind(&torrent::connect_to_url_seed, this, _1)); 4265 4268 } 4266 4269 4267 4270 for (peer_iterator i = m_connections.begin(); 4268 4271 i != m_connections.end();) … … 4397 4400 { 4398 4401 TORRENT_ASSERT(valid_metadata()); 4399 4402 4400 4403 fp.resize(m_torrent_file->num_files(), 0); 4401 4404 … … 4406 4409 return; 4407 4410 } 4408 4411 4409 4412 TORRENT_ASSERT(has_picker()); 4410 4413 … … 4526 4529 } 4527 4530 } 4528 4531 4529 4532 void torrent::set_state(torrent_status::state_t s) 4530 4533 { … … 4664 4667 --num_filtered_pieces; 4665 4668 } 4666 4669 4667 4670 st.total_wanted -= size_type(num_filtered_pieces) * m_torrent_file->piece_length(); 4668 4671 } … … 4788 4791 4789 4792 } 4793
Note:
See TracChangeset
for help on using the changeset viewer.