Changeset 2e3a9c
- Timestamp:
- 09/19/2008 10:57:05 PM (16 years ago)
- Children:
- fb23f2
- Parents:
- a0f90ac
- Location:
- libtorrent
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
libtorrent/include/libtorrent/udp_socket.hpp
ra0f90ac r2e3a9c 39 39 #include <vector> 40 40 #include <boost/function.hpp> 41 #include <boost/thread/mutex.hpp> 41 42 42 43 namespace libtorrent … … 84 85 void unwrap(error_code const& e, char const* buf, int size); 85 86 87 typedef boost::mutex mutex_t; 88 mutable mutex_t m_mutex; 89 86 90 udp::socket m_ipv4_sock; 87 91 udp::socket m_ipv6_sock; -
libtorrent/src/disk_io_thread.cpp
ra0f90ac r2e3a9c 1062 1062 free_buffer(k->blocks[j]); 1063 1063 k->blocks[j] = 0; 1064 --m_cache_stats.cache_size; 1064 1065 } 1065 1066 } -
libtorrent/src/peer_connection.cpp
ra0f90ac r2e3a9c 338 338 TORRENT_ASSERT(t); 339 339 340 // if m_have_piece is 0, it means the connections 341 // have not been initialized yet. The interested 342 // flag will be updated once they are. 343 if (m_have_piece.size() == 0) return; 344 if (!t->ready_for_connections()) return; 345 340 346 bool interested = false; 341 347 if (!t->is_finished()) … … 362 368 catch (std::exception&) {} 363 369 364 TORRENT_ASSERT(i s_interesting() == interested);370 TORRENT_ASSERT(in_handshake() || is_interesting() == interested); 365 371 } 366 372 -
libtorrent/src/piece_picker.cpp
ra0f90ac r2e3a9c 1518 1518 { 1519 1519 if (!pieces[i->index]) continue; 1520 if (piece_priority(i->index) == 0) continue; 1520 1521 1521 1522 int num_blocks_in_piece = blocks_in_piece(i->index); … … 1541 1542 { 1542 1543 if (!pieces[i->index]) continue; 1544 if (piece_priority(i->index) == 0) continue; 1543 1545 1544 1546 int num_blocks_in_piece = blocks_in_piece(i->index); -
libtorrent/src/storage.cpp
ra0f90ac r2e3a9c 69 69 #include "libtorrent/aux_/session_impl.hpp" 70 70 #include "libtorrent/disk_buffer_holder.hpp" 71 72 //#define TORRENT_PARTIAL_HASH_LOG 71 73 72 74 #ifndef NDEBUG … … 454 456 sha1_hash storage::hash_for_slot(int slot, partial_hash& ph, int piece_size) 455 457 { 458 TORRENT_ASSERT(!error()); 456 459 #ifndef NDEBUG 457 460 hasher partial; … … 459 462 int slot_size1 = piece_size; 460 463 m_scratch_buffer.resize(slot_size1); 461 read_impl(&m_scratch_buffer[0], slot, 0, slot_size1, true); 464 read_impl(&m_scratch_buffer[0], slot, 0, slot_size1, false); 465 if (error()) return sha1_hash(0); 462 466 if (ph.offset > 0) 463 467 partial.update(&m_scratch_buffer[0], ph.offset); … … 470 474 { 471 475 m_scratch_buffer.resize(slot_size); 472 read_impl(&m_scratch_buffer[0], slot, ph.offset, slot_size, true); 476 read_impl(&m_scratch_buffer[0], slot, ph.offset, slot_size, false); 477 if (error()) return sha1_hash(0); 473 478 ph.h.update(&m_scratch_buffer[0], slot_size); 474 479 } … … 1539 1544 if (ret != size) return ret; 1540 1545 1541 // std::ofstream out("partial_hash.log", std::ios::app); 1546 #ifdef TORRENT_PARTIAL_HASH_LOG 1547 std::ofstream out("partial_hash.log", std::ios::app); 1548 #endif 1542 1549 1543 1550 if (offset == 0) … … 1547 1554 ph.offset = size; 1548 1555 ph.h.update(buf, size); 1549 /* 1556 #ifdef TORRENT_PARTIAL_HASH_LOG 1550 1557 out << time_now_string() << " NEW [" 1551 1558 " s: " << this … … 1555 1562 << " entries: " << m_piece_hasher.size() 1556 1563 << " ]" << std::endl; 1557 */ 1564 #endif 1558 1565 } 1559 1566 else … … 1569 1576 if (offset == i->second.offset) 1570 1577 { 1571 /* 1578 #ifdef TORRENT_PARTIAL_HASH_LOG 1572 1579 out << time_now_string() << " UPDATING [" 1573 1580 " s: " << this … … 1577 1584 << " entries: " << m_piece_hasher.size() 1578 1585 << " ]" << std::endl; 1579 */ 1586 #endif 1580 1587 i->second.offset += size; 1581 1588 i->second.h.update(buf, size); 1582 1589 } 1583 /* else 1590 #ifdef TORRENT_PARTIAL_HASH_LOG 1591 else 1584 1592 { 1585 1593 out << time_now_string() << " SKIPPING (out of order) [" … … 1591 1599 << " ]" << std::endl; 1592 1600 } 1593 */ } 1594 /* else 1601 #endif 1602 } 1603 #ifdef TORRENT_PARTIAL_HASH_LOG 1604 else 1595 1605 { 1596 1606 out << time_now_string() << " SKIPPING (no entry) [" … … 1602 1612 << " ]" << std::endl; 1603 1613 } 1604 */ 1614 #endif 1605 1615 } 1606 1616 -
libtorrent/src/torrent.cpp
ra0f90ac r2e3a9c 1398 1398 // become uninterested in some peers where this 1399 1399 // was the last piece we were interested in 1400 for (peer_iterator i = m_connections.begin() 1401 , end(m_connections.end()); i != end; ++i)1400 for (peer_iterator i = m_connections.begin(); 1401 i != m_connections.end();) 1402 1402 { 1403 1403 peer_connection* p = *i; 1404 // update_interest may disconnect the peer and 1405 // invalidate the iterator 1406 ++i; 1404 1407 // if we're not interested already, no need to check 1405 1408 if (!p->is_interesting()) continue; … … 1836 1839 if (size == 0) continue; 1837 1840 position += size; 1841 if (m_file_priority[i] == 0) continue; 1842 1838 1843 // mark all pieces of the file with this file's priority 1839 1844 // but only if the priority is higher than the pieces … … 1855 1860 void torrent::update_peer_interest(bool was_finished) 1856 1861 { 1857 for (peer_iterator i = begin(); i != end(); ++i) 1858 (*i)->update_interest(); 1862 for (peer_iterator i = begin(); i != end();) 1863 { 1864 peer_connection* p = *i; 1865 // update_interest may disconnect the peer and 1866 // invalidate the iterator 1867 ++i; 1868 p->update_interest(); 1869 } 1859 1870 1860 1871 // the torrent just became finished -
libtorrent/src/udp_socket.cpp
ra0f90ac r2e3a9c 31 31 if (ec == asio::error::operation_aborted) return; 32 32 33 mutex_t::scoped_lock l(m_mutex); 34 33 35 if (m_tunnel_packets) 34 36 { … … 48 50 if (e == asio::error::operation_aborted) return; 49 51 52 mutex_t::scoped_lock l(m_mutex); 53 50 54 if (!m_callback) return; 51 55 … … 56 60 #endif 57 61 if (s == &m_ipv4_sock) 58 m_callback(e, m_v4_ep, 0, 0);62 get_io_service().post(boost::bind(m_callback, e, m_v4_ep, (char*)0, 0)); 59 63 else 60 m_callback(e, m_v6_ep, 0, 0);64 get_io_service().post(boost::bind(m_callback, e, m_v6_ep, (char*)0, 0)); 61 65 #ifndef BOOST_NO_EXCEPTIONS 62 66 } catch(std::exception&) {} … … 91 95 unwrap(e, m_v4_buf, bytes_transferred); 92 96 else 93 m_callback(e, m_v4_ep, m_v4_buf, bytes_transferred);97 get_io_service().post(boost::bind(m_callback, e, m_v4_ep, m_v4_buf, bytes_transferred)); 94 98 95 99 #ifndef BOOST_NO_EXCEPTIONS … … 108 112 unwrap(e, m_v6_buf, bytes_transferred); 109 113 else 110 m_callback(e, m_v6_ep, m_v6_buf, bytes_transferred);114 get_io_service().post(boost::bind(m_callback, e, m_v6_ep, m_v6_buf, bytes_transferred)); 111 115 112 116 #ifndef BOOST_NO_EXCEPTIONS … … 174 178 } 175 179 176 m_callback(e, sender, p, size - (p - buf));180 get_io_service().post(boost::bind(m_callback, e, sender, p, size - (p - buf))); 177 181 } 178 182 179 183 void udp_socket::close() 180 184 { 185 mutex_t::scoped_lock l(m_mutex); 186 181 187 error_code ec; 182 188 m_ipv4_sock.close(ec); … … 193 199 void udp_socket::bind(udp::endpoint const& ep, error_code& ec) 194 200 { 201 mutex_t::scoped_lock l(m_mutex); 202 195 203 if (m_ipv4_sock.is_open()) m_ipv4_sock.close(ec); 196 204 if (m_ipv6_sock.is_open()) m_ipv6_sock.close(ec); … … 219 227 void udp_socket::bind(int port) 220 228 { 229 mutex_t::scoped_lock l(m_mutex); 230 221 231 error_code ec; 222 232 … … 244 254 void udp_socket::set_proxy_settings(proxy_settings const& ps) 245 255 { 256 mutex_t::scoped_lock l(m_mutex); 257 246 258 error_code ec; 247 259 m_socks5_sock.close(ec); … … 264 276 { 265 277 if (e) return; 278 279 mutex_t::scoped_lock l(m_mutex); 280 266 281 m_proxy_addr.address(i->endpoint().address()); 267 282 m_proxy_addr.port(i->endpoint().port()); … … 272 287 void udp_socket::on_timeout() 273 288 { 289 mutex_t::scoped_lock l(m_mutex); 290 274 291 error_code ec; 275 292 m_socks5_sock.close(ec); … … 279 296 void udp_socket::on_connect(int ticket) 280 297 { 298 mutex_t::scoped_lock l(m_mutex); 299 281 300 m_connection_ticket = ticket; 282 301 error_code ec; … … 292 311 if (e) return; 293 312 313 mutex_t::scoped_lock l(m_mutex); 314 294 315 using namespace libtorrent::detail; 295 316 … … 317 338 if (e) return; 318 339 340 mutex_t::scoped_lock l(m_mutex); 341 319 342 asio::async_read(m_socks5_sock, asio::buffer(m_tmp_buf, 2) 320 343 , boost::bind(&udp_socket::handshake2, this, _1)); … … 326 349 327 350 using namespace libtorrent::detail; 351 352 mutex_t::scoped_lock l(m_mutex); 328 353 329 354 char* p = &m_tmp_buf[0]; … … 368 393 if (e) return; 369 394 395 mutex_t::scoped_lock l(m_mutex); 396 370 397 asio::async_read(m_socks5_sock, asio::buffer(m_tmp_buf, 2) 371 398 , boost::bind(&udp_socket::handshake4, this, _1)); … … 375 402 { 376 403 if (e) return; 404 405 mutex_t::scoped_lock l(m_mutex); 377 406 378 407 using namespace libtorrent::detail; … … 391 420 { 392 421 using namespace libtorrent::detail; 422 423 mutex_t::scoped_lock l(m_mutex); 393 424 394 425 // send SOCKS5 UDP command … … 409 440 if (e) return; 410 441 442 mutex_t::scoped_lock l(m_mutex); 443 411 444 asio::async_read(m_socks5_sock, asio::buffer(m_tmp_buf, 10) 412 445 , boost::bind(&udp_socket::connect2, this, _1)); … … 416 449 { 417 450 if (e) return; 418 451 452 mutex_t::scoped_lock l(m_mutex); 453 419 454 using namespace libtorrent::detail; 420 455
Note:
See TracChangeset
for help on using the changeset viewer.