Changeset 3740
- Timestamp:
- 08/23/08 08:09:52 (5 months ago)
- Location:
- branches/1.0.0_RC/libtorrent
- Files:
-
- 16 modified
-
bindings/python/src/torrent_handle.cpp (modified) (3 diffs)
-
include/libtorrent/alert.hpp (modified) (1 diff)
-
include/libtorrent/alert_types.hpp (modified) (1 diff)
-
include/libtorrent/bencode.hpp (modified) (1 diff)
-
include/libtorrent/pe_crypto.hpp (modified) (2 diffs)
-
include/libtorrent/torrent.hpp (modified) (2 diffs)
-
src/bt_peer_connection.cpp (modified) (3 diffs)
-
src/identify_client.cpp (modified) (4 diffs)
-
src/kademlia/dht_tracker.cpp (modified) (1 diff)
-
src/lazy_bdecode.cpp (modified) (1 diff)
-
src/natpmp.cpp (modified) (4 diffs)
-
src/pe_crypto.cpp (modified) (2 diffs)
-
src/peer_connection.cpp (modified) (4 diffs)
-
src/storage.cpp (modified) (2 diffs)
-
src/torrent.cpp (modified) (6 diffs)
-
src/torrent_handle.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/1.0.0_RC/libtorrent/bindings/python/src/torrent_handle.cpp
r3439 r3740 5 5 #include <libtorrent/torrent_handle.hpp> 6 6 #include <boost/python.hpp> 7 #include <boost/python/tuple.hpp> 7 8 #include <boost/lexical_cast.hpp> 8 9 #include "gil.hpp" … … 171 172 list get_download_queue(torrent_handle& handle) 172 173 { 174 using boost::python::make_tuple; 175 173 176 list ret; 174 177 … … 194 197 block_info["bytes_progress"] = i->blocks[k].bytes_progress; 195 198 block_info["block_size"] = i->blocks[k].block_size; 196 block_info["peer"] = std::make_pair(199 block_info["peer"] = make_tuple( 197 200 boost::lexical_cast<std::string>(i->blocks[k].peer.address()), i->blocks[k].peer.port()); 198 201 block_list.append(block_info); -
branches/1.0.0_RC/libtorrent/include/libtorrent/alert.hpp
r3675 r3740 83 83 progress_notification = 0x80, 84 84 ip_block_notification = 0x100, 85 performance_warning = 0x200, 85 86 86 87 all_categories = 0xffffffff -
branches/1.0.0_RC/libtorrent/include/libtorrent/alert_types.hpp
r3732 r3740 152 152 }; 153 153 154 struct TORRENT_EXPORT performance_alert: torrent_alert 155 { 156 enum performance_warning_t 157 { 158 outstanding_disk_buffer_limit_reached, 159 outstanding_request_limit_reached, 160 }; 161 162 performance_alert(torrent_handle const& h 163 , performance_warning_t w) 164 : torrent_alert(h) 165 , warning_code(w) 166 {} 167 168 virtual std::auto_ptr<alert> clone() const 169 { return std::auto_ptr<alert>(new performance_alert(*this)); } 170 171 virtual char const* what() const { return "performance warning"; } 172 virtual std::string message() const 173 { 174 static char const* warning_str[] = 175 { 176 "max outstanding disk writes reached", 177 "max outstanding piece requests reached", 178 }; 179 180 return torrent_alert::message() + ": performance warning: " 181 + warning_str[warning_code]; 182 } 183 184 const static int static_category = alert::performance_warning; 185 virtual int category() const { return static_category; } 186 187 performance_warning_t warning_code; 188 }; 189 154 190 struct TORRENT_EXPORT state_changed_alert: torrent_alert 155 191 { -
branches/1.0.0_RC/libtorrent/include/libtorrent/bencode.hpp
r3330 r3740 106 106 int write_string(OutIt& out, const std::string& val) 107 107 { 108 int ret = val.length();109 std::string::const_iterator end = val.begin() + ret;110 108 for (std::string::const_iterator i = val.begin() 111 , end(val. begin() + ret); i != end; ++i)109 , end(val.end()); i != end; ++i) 112 110 *out++ = *i; 113 return ret;111 return val.length(); 114 112 } 115 113 -
branches/1.0.0_RC/libtorrent/include/libtorrent/pe_crypto.hpp
r3330 r3740 59 59 int compute_secret(const char* remote_pubkey); 60 60 61 const char* get_secret() const; 61 char const* get_secret() const { return m_dh_secret; } 62 63 sha1_hash const& get_hash_xor_mask() const { return m_xor_mask; } 62 64 63 65 private: … … 72 74 char m_dh_local_key[96]; 73 75 char m_dh_secret[96]; 76 sha1_hash m_xor_mask; 74 77 }; 75 78 -
branches/1.0.0_RC/libtorrent/include/libtorrent/torrent.hpp
r3512 r3740 132 132 133 133 void parse_resume_data(std::vector<char>* resume_data); 134 135 #ifndef TORRENT_DISABLE_ENCRYPTION 136 sha1_hash const& obfuscated_hash() const 137 { return m_obfuscated_hash; } 138 #endif 139 140 sha1_hash const& info_hash() const 141 { return m_torrent_file->info_hash(); } 134 142 135 143 // starts the announce timer … … 822 830 boost::scoped_ptr<std::string> m_name; 823 831 832 #ifndef TORRENT_DISABLE_ENCRYPTION 833 // this is SHA1("req2" + info-hash), used for 834 // encrypted hand shakes 835 sha1_hash m_obfuscated_hash; 836 #endif 824 837 session_settings const& m_settings; 825 838 -
branches/1.0.0_RC/libtorrent/src/bt_peer_connection.cpp
r3712 r3740 1842 1842 } 1843 1843 1844 cut_receive_buffer(bytes_processed, (std::min)(packet_size(), (512+20) - m_sync_bytes_read)); 1844 cut_receive_buffer(bytes_processed, (std::min)(packet_size() 1845 , (512+20) - m_sync_bytes_read)); 1845 1846 1846 1847 TORRENT_ASSERT(!packet_finished()); … … 1873 1874 recv_buffer = receive_buffer(); 1874 1875 1875 // only calls info_hash() on the torrent_handle's, which 1876 // never throws. 1877 session_impl::mutex_t::scoped_lock l(m_ses.m_mutex); 1878 1879 std::vector<torrent_handle> active_torrents = m_ses.get_torrents(); 1880 std::vector<torrent_handle>::const_iterator i; 1881 hasher h; 1882 sha1_hash skey_hash, obfs_hash; 1883 1884 for (i = active_torrents.begin(); i != active_torrents.end(); ++i) 1885 { 1886 torrent_handle const& t_h = *i; // TODO possible errors 1887 sha1_hash const& info_hash = t_h.info_hash(); 1888 // TODO Does info_hash need to be checked for validity? 1889 1890 h.reset(); 1891 h.update("req2", 4); 1892 h.update((char*)info_hash.begin(), 20); 1893 1894 skey_hash = h.final(); 1895 1896 h.reset(); 1897 h.update("req3", 4); 1898 h.update(m_dh_key_exchange->get_secret(), dh_key_len); 1899 1900 obfs_hash = h.final(); 1876 aux::session_impl::torrent_map::const_iterator i; 1877 1878 for (i = m_ses.m_torrents.begin(); i != m_ses.m_torrents.end(); ++i) 1879 { 1880 torrent const& ti = *i->second; 1881 sha1_hash const& skey_hash = ti.obfuscated_hash(); 1882 sha1_hash obfs_hash = m_dh_key_exchange->get_hash_xor_mask(); 1901 1883 obfs_hash ^= skey_hash; 1902 1884 1903 if (std::equal (recv_buffer.begin, recv_buffer.begin + 20,1904 (char*) obfs_hash.begin()))1885 if (std::equal(recv_buffer.begin, recv_buffer.begin + 20, 1886 (char*)&obfs_hash[0])) 1905 1887 { 1906 1888 if (!t) 1907 1889 { 1908 attach_to_torrent( info_hash);1890 attach_to_torrent(ti.info_hash()); 1909 1891 if (is_disconnecting()) return; 1910 1892 … … 1913 1895 } 1914 1896 1915 init_pe_RC4_handler(m_dh_key_exchange->get_secret(), info_hash);1897 init_pe_RC4_handler(m_dh_key_exchange->get_secret(), ti.info_hash()); 1916 1898 #ifdef TORRENT_VERBOSE_LOGGING 1917 1899 (*m_logger) << " stream key found, torrent located.\n"; 1918 1900 #endif 1919 continue; // TODO Check flow control with multiple torrents1901 break; 1920 1902 } 1921 1903 } -
branches/1.0.0_RC/libtorrent/src/identify_client.cpp
r3675 r3740 60 60 } 61 61 62 bool isprint(char c) 63 { 64 return c >= 32 && c < 127; 65 } 66 62 67 // takes a peer id and returns a valid boost::optional 63 68 // object if the peer id matched the azureus style encoding … … 68 73 fingerprint ret("..", 0, 0, 0, 0); 69 74 70 if (id[0] != '-' || ! std::isprint(id[1]) || (id[2] < '0')75 if (id[0] != '-' || !isprint(id[1]) || (id[2] < '0') 71 76 || (id[3] < '0') || (id[4] < '0') 72 77 || (id[5] < '0') || (id[6] < '0') … … 130 135 if (sscanf(ids, "%c%d-%d-%d--", &ret.name[0], &ret.major_version, &ret.minor_version 131 136 , &ret.revision_version) != 4 132 || ! std::isprint(ret.name[0]))137 || !isprint(ret.name[0])) 133 138 return boost::optional<fingerprint>(); 134 139 … … 374 379 for (peer_id::const_iterator i = p.begin(); i != p.end(); ++i) 375 380 { 376 unknown += std::isprint(*i)?*i:'.';381 unknown += isprint(*i)?*i:'.'; 377 382 } 378 383 unknown += "]"; -
branches/1.0.0_RC/libtorrent/src/kademlia/dht_tracker.cpp
r3276 r3740 449 449 #ifdef TORRENT_DHT_VERBOSE_LOGGING 450 450 std::string msg(buf, buf + bytes_transferred); 451 TORRENT_LOG(dht_tracker) << "invalid incoming packet: " 452 << e.what() << "\n" << msg << "\n"; 451 TORRENT_LOG(dht_tracker) << "invalid incoming packet\n"; 453 452 #endif 454 453 return; -
branches/1.0.0_RC/libtorrent/src/lazy_bdecode.cpp
r3712 r3740 377 377 { 378 378 using namespace std; 379 if (isprint( str[i])) continue;379 if (isprint((unsigned char)str[i])) continue; 380 380 printable = false; 381 381 break; -
branches/1.0.0_RC/libtorrent/src/natpmp.cpp
r3675 r3740 106 106 } 107 107 108 m_socket.async_receive_from(asio::buffer(&m_response_buffer, 16) 109 , m_remote, bind(&natpmp::on_reply, self(), _1, _2)); 110 108 111 for (std::vector<mapping_t>::iterator i = m_mappings.begin() 109 112 , end(m_mappings.end()); i != end; ++i) … … 238 241 m_retry_count = 0; 239 242 send_map_request(i); 240 m_socket.async_receive_from(asio::buffer(&m_response_buffer, 16)241 , m_remote, bind(&natpmp::on_reply, self(), _1, _2));242 243 } 243 244 } … … 282 283 { 283 284 if (e) return; 284 if (m_abort) return;285 286 285 mutex_t::scoped_lock l(m_mutex); 287 286 if (m_currently_mapping != i) return; 288 if (m_retry_count >= 9) 287 288 // if we're shutting down, don't retry, just move on 289 // to the next mapping 290 if (m_retry_count >= 9 || m_abort) 289 291 { 290 292 m_currently_mapping = -1; … … 302 304 { 303 305 using namespace libtorrent::detail; 304 if (e) return; 306 if (e) 307 { 308 #if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING) 309 m_log << time_now_string() 310 << " <== on_receive [" 311 " error: " << e.message() << " ]" << std::endl; 312 #endif 313 return; 314 } 315 316 m_socket.async_receive_from(asio::buffer(&m_response_buffer, 16) 317 , m_remote, bind(&natpmp::on_reply, self(), _1, _2)); 305 318 306 319 if (m_remote != m_nat_endpoint) 307 320 { 308 m_socket.async_receive_from(asio::buffer(&m_response_buffer, 16) 309 , m_remote, bind(&natpmp::on_reply, self(), _1, _2)); 321 #if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING) 322 m_log << time_now_string() 323 << " <== received packet from the wrong IP [" 324 " ip: " << m_remote << " ]" << std::endl; 325 #endif 310 326 return; 311 327 } -
branches/1.0.0_RC/libtorrent/src/pe_crypto.cpp
r3321 r3740 39 39 40 40 #include "libtorrent/pe_crypto.hpp" 41 #include "libtorrent/hasher.hpp" 41 42 #include "libtorrent/assert.hpp" 42 43 … … 145 146 std::copy(dh_secret, dh_secret + secret_size, m_dh_secret + 96 - secret_size); 146 147 BN_free(bn_remote_pubkey); 148 149 // calculate the xor mask for the obfuscated hash 150 hasher h; 151 h.update("req3", 4); 152 h.update(m_dh_secret, 96); 153 m_xor_mask = h.final(); 154 147 155 return 0; 148 }149 150 char const* dh_key_exchange::get_secret() const151 {152 return m_dh_secret;153 156 } 154 157 -
branches/1.0.0_RC/libtorrent/src/peer_connection.cpp
r3712 r3740 1644 1644 m_download_queue.erase(b); 1645 1645 1646 if (m_outstanding_writing_bytes >= m_ses.settings().max_outstanding_disk_bytes_per_connection 1647 && t->alerts().should_post<performance_alert>()) 1648 { 1649 t->alerts().post_alert(performance_alert(t->get_handle() 1650 , performance_alert::outstanding_disk_buffer_limit_reached)); 1651 } 1652 1646 1653 if (!m_download_queue.empty()) 1647 1654 { … … 2766 2773 if (m_desired_queue_size < min_request_queue) 2767 2774 m_desired_queue_size = min_request_queue; 2775 2776 if (m_desired_queue_size == m_max_out_request_queue 2777 && t->alerts().should_post<performance_alert>()) 2778 { 2779 t->alerts().post_alert(performance_alert(t->get_handle() 2780 , performance_alert::outstanding_request_limit_reached)); 2781 } 2768 2782 } 2769 2783 … … 3633 3647 } 3634 3648 3649 /* 3650 // this assertion correct most of the time, but sometimes right when the 3651 // limit is changed it might break 3635 3652 for (int i = 0; i < 2; ++i) 3636 3653 { … … 3640 3657 || m_bandwidth_limit[i].throttle() == bandwidth_limit::inf); 3641 3658 } 3659 */ 3642 3660 3643 3661 if (m_channel_state[download_channel] == peer_info::bw_torrent -
branches/1.0.0_RC/libtorrent/src/storage.cpp
r3712 r3740 529 529 // don't allocate files with priority 0 530 530 int file_index = file_iter - files().begin(); 531 if (allocate_files && ( m_file_priority.size() <= file_index531 if (allocate_files && (int(m_file_priority.size()) <= file_index 532 532 || m_file_priority[file_index] > 0)) 533 533 { … … 2170 2170 (file_offset - current_offset + m_files.piece_length() - 1) 2171 2171 / m_files.piece_length()); 2172 TORRENT_ASSERT(skip_blocks >= 1); 2172 2173 2173 2174 if (m_storage_mode == storage_mode_compact) -
branches/1.0.0_RC/libtorrent/src/torrent.cpp
r3732 r3740 207 207 { 208 208 parse_resume_data(resume_data); 209 210 #ifndef TORRENT_DISABLE_ENCRYPTION 211 hasher h; 212 h.update("req2", 4); 213 h.update((char*)&tf->info_hash()[0], 20); 214 m_obfuscated_hash = h.final(); 215 #endif 209 216 } 210 217 … … 281 288 { 282 289 parse_resume_data(resume_data); 290 291 #ifndef TORRENT_DISABLE_ENCRYPTION 292 hasher h; 293 h.update("req2", 4); 294 h.update((char*)&info_hash[0], 20); 295 m_obfuscated_hash = h.final(); 296 #endif 297 283 298 #ifndef NDEBUG 284 299 m_files_checked = false; … … 1472 1487 if (m_ses.m_alerts.should_post<peer_ban_alert>()) 1473 1488 { 1474 peer_id pid ;1489 peer_id pid(0); 1475 1490 if (p->connection) pid = p->connection->pid(); 1476 1491 m_ses.m_alerts.post_alert(peer_ban_alert( … … 2262 2277 2263 2278 bool ret = instantiate_connection(m_ses.m_io_service, m_ses.web_seed_proxy(), *s); 2279 (void)ret; 2264 2280 TORRENT_ASSERT(ret); 2265 2281 … … 2776 2792 2777 2793 bool ret = instantiate_connection(m_ses.m_io_service, m_ses.peer_proxy(), *s); 2794 (void)ret; 2778 2795 TORRENT_ASSERT(ret); 2779 2796 std::pair<int, int> const& out_ports = m_ses.settings().outgoing_ports; … … 3524 3541 void torrent::set_sequential_download(bool sd) 3525 3542 { 3543 m_sequential_download = sd; 3526 3544 if (has_picker()) 3527 3545 { 3528 3546 picker().sequential_download(sd); 3529 }3530 else3531 {3532 m_sequential_download = sd;3533 3547 } 3534 3548 } -
branches/1.0.0_RC/libtorrent/src/torrent_handle.cpp
r3675 r3740 251 251 { 252 252 INVARIANT_CHECK; 253 TORRENT_FORWARD_RETURN(is_ paused(), false);253 TORRENT_FORWARD_RETURN(is_torrent_paused(), false); 254 254 } 255 255
