Changeset 2e3a9c


Ignore:
Timestamp:
09/19/2008 10:57:05 PM (16 years ago)
Author:
Andrew Resch <andrewresch@gmail.com>
Children:
fb23f2
Parents:
a0f90ac
Message:

lt sync 2690

Location:
libtorrent
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • libtorrent/include/libtorrent/udp_socket.hpp

    ra0f90ac r2e3a9c  
    3939#include <vector>
    4040#include <boost/function.hpp>
     41#include <boost/thread/mutex.hpp>
    4142
    4243namespace libtorrent
     
    8485                void unwrap(error_code const& e, char const* buf, int size);
    8586
     87                typedef boost::mutex mutex_t;
     88                mutable mutex_t m_mutex;
     89
    8690                udp::socket m_ipv4_sock;
    8791                udp::socket m_ipv6_sock;
  • libtorrent/src/disk_io_thread.cpp

    ra0f90ac r2e3a9c  
    10621062                                                        free_buffer(k->blocks[j]);
    10631063                                                        k->blocks[j] = 0;
     1064                                                        --m_cache_stats.cache_size;
    10641065                                                }
    10651066                                        }
  • libtorrent/src/peer_connection.cpp

    ra0f90ac r2e3a9c  
    338338                TORRENT_ASSERT(t);
    339339
     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
    340346                bool interested = false;
    341347                if (!t->is_finished())
     
    362368                catch (std::exception&) {}
    363369
    364                 TORRENT_ASSERT(is_interesting() == interested);
     370                TORRENT_ASSERT(in_handshake() || is_interesting() == interested);
    365371        }
    366372
  • libtorrent/src/piece_picker.cpp

    ra0f90ac r2e3a9c  
    15181518                {
    15191519                        if (!pieces[i->index]) continue;
     1520                        if (piece_priority(i->index) == 0) continue;
    15201521
    15211522                        int num_blocks_in_piece = blocks_in_piece(i->index);
     
    15411542                {
    15421543                        if (!pieces[i->index]) continue;
     1544                        if (piece_priority(i->index) == 0) continue;
    15431545                               
    15441546                        int num_blocks_in_piece = blocks_in_piece(i->index);
  • libtorrent/src/storage.cpp

    ra0f90ac r2e3a9c  
    6969#include "libtorrent/aux_/session_impl.hpp"
    7070#include "libtorrent/disk_buffer_holder.hpp"
     71
     72//#define TORRENT_PARTIAL_HASH_LOG
    7173
    7274#ifndef NDEBUG
     
    454456        sha1_hash storage::hash_for_slot(int slot, partial_hash& ph, int piece_size)
    455457        {
     458                TORRENT_ASSERT(!error());
    456459#ifndef NDEBUG
    457460                hasher partial;
     
    459462                int slot_size1 = piece_size;
    460463                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);
    462466                if (ph.offset > 0)
    463467                        partial.update(&m_scratch_buffer[0], ph.offset);
     
    470474                {
    471475                        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);
    473478                        ph.h.update(&m_scratch_buffer[0], slot_size);
    474479                }
     
    15391544                if (ret != size) return ret;
    15401545
    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
    15421549
    15431550                if (offset == 0)
     
    15471554                        ph.offset = size;
    15481555                        ph.h.update(buf, size);
    1549 /*
     1556#ifdef TORRENT_PARTIAL_HASH_LOG
    15501557                        out << time_now_string() << " NEW ["
    15511558                                " s: " << this
     
    15551562                                << " entries: " << m_piece_hasher.size()
    15561563                                << " ]" << std::endl;
    1557 */
     1564#endif
    15581565                }
    15591566                else
     
    15691576                                if (offset == i->second.offset)
    15701577                                {
    1571 /*
     1578#ifdef TORRENT_PARTIAL_HASH_LOG
    15721579                                        out << time_now_string() << " UPDATING ["
    15731580                                                " s: " << this
     
    15771584                                                << " entries: " << m_piece_hasher.size()
    15781585                                                << " ]" << std::endl;
    1579 */
     1586#endif
    15801587                                        i->second.offset += size;
    15811588                                        i->second.h.update(buf, size);
    15821589                                }
    1583 /*                              else
     1590#ifdef TORRENT_PARTIAL_HASH_LOG
     1591                                else
    15841592                                {
    15851593                                        out << time_now_string() << " SKIPPING (out of order) ["
     
    15911599                                                << " ]" << std::endl;
    15921600                                }
    1593 */                      }
    1594 /*                      else
     1601#endif
     1602                        }
     1603#ifdef TORRENT_PARTIAL_HASH_LOG
     1604                        else
    15951605                        {
    15961606                                out << time_now_string() << " SKIPPING (no entry) ["
     
    16021612                                        << " ]" << std::endl;
    16031613                        }
    1604 */
     1614#endif
    16051615                }
    16061616               
  • libtorrent/src/torrent.cpp

    ra0f90ac r2e3a9c  
    13981398                // become uninterested in some peers where this
    13991399                // 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();)
    14021402                {
    14031403                        peer_connection* p = *i;
     1404                        // update_interest may disconnect the peer and
     1405                        // invalidate the iterator
     1406                        ++i;
    14041407                        // if we're not interested already, no need to check
    14051408                        if (!p->is_interesting()) continue;
     
    18361839                        if (size == 0) continue;
    18371840                        position += size;
     1841                        if (m_file_priority[i] == 0) continue;
     1842
    18381843                        // mark all pieces of the file with this file's priority
    18391844                        // but only if the priority is higher than the pieces
     
    18551860        void torrent::update_peer_interest(bool was_finished)
    18561861        {
    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                }
    18591870
    18601871                // the torrent just became finished
  • libtorrent/src/udp_socket.cpp

    ra0f90ac r2e3a9c  
    3131        if (ec == asio::error::operation_aborted) return;
    3232
     33        mutex_t::scoped_lock l(m_mutex);       
     34
    3335        if (m_tunnel_packets)
    3436        {
     
    4850        if (e == asio::error::operation_aborted) return;
    4951
     52        mutex_t::scoped_lock l(m_mutex);       
     53
    5054        if (!m_callback) return;
    5155
     
    5660#endif
    5761                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));
    5963                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));
    6165#ifndef BOOST_NO_EXCEPTIONS
    6266                } catch(std::exception&) {}
     
    9195                        unwrap(e, m_v4_buf, bytes_transferred);
    9296                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));
    9498
    9599#ifndef BOOST_NO_EXCEPTIONS
     
    108112                        unwrap(e, m_v6_buf, bytes_transferred);
    109113                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));
    111115
    112116#ifndef BOOST_NO_EXCEPTIONS
     
    174178        }
    175179
    176         m_callback(e, sender, p, size - (p - buf));
     180        get_io_service().post(boost::bind(m_callback, e, sender, p, size - (p - buf)));
    177181}
    178182
    179183void udp_socket::close()
    180184{
     185        mutex_t::scoped_lock l(m_mutex);       
     186
    181187        error_code ec;
    182188        m_ipv4_sock.close(ec);
     
    193199void udp_socket::bind(udp::endpoint const& ep, error_code& ec)
    194200{
     201        mutex_t::scoped_lock l(m_mutex);       
     202
    195203        if (m_ipv4_sock.is_open()) m_ipv4_sock.close(ec);
    196204        if (m_ipv6_sock.is_open()) m_ipv6_sock.close(ec);
     
    219227void udp_socket::bind(int port)
    220228{
     229        mutex_t::scoped_lock l(m_mutex);       
     230
    221231        error_code ec;
    222232
     
    244254void udp_socket::set_proxy_settings(proxy_settings const& ps)
    245255{
     256        mutex_t::scoped_lock l(m_mutex);       
     257
    246258        error_code ec;
    247259        m_socks5_sock.close(ec);
     
    264276{
    265277        if (e) return;
     278
     279        mutex_t::scoped_lock l(m_mutex);       
     280
    266281        m_proxy_addr.address(i->endpoint().address());
    267282        m_proxy_addr.port(i->endpoint().port());
     
    272287void udp_socket::on_timeout()
    273288{
     289        mutex_t::scoped_lock l(m_mutex);       
     290
    274291        error_code ec;
    275292        m_socks5_sock.close(ec);
     
    279296void udp_socket::on_connect(int ticket)
    280297{
     298        mutex_t::scoped_lock l(m_mutex);       
     299
    281300        m_connection_ticket = ticket;
    282301        error_code ec;
     
    292311        if (e) return;
    293312
     313        mutex_t::scoped_lock l(m_mutex);       
     314
    294315        using namespace libtorrent::detail;
    295316
     
    317338        if (e) return;
    318339
     340        mutex_t::scoped_lock l(m_mutex);       
     341
    319342        asio::async_read(m_socks5_sock, asio::buffer(m_tmp_buf, 2)
    320343                , boost::bind(&udp_socket::handshake2, this, _1));
     
    326349
    327350        using namespace libtorrent::detail;
     351
     352        mutex_t::scoped_lock l(m_mutex);       
    328353
    329354        char* p = &m_tmp_buf[0];
     
    368393        if (e) return;
    369394
     395        mutex_t::scoped_lock l(m_mutex);       
     396
    370397        asio::async_read(m_socks5_sock, asio::buffer(m_tmp_buf, 2)
    371398                , boost::bind(&udp_socket::handshake4, this, _1));
     
    375402{
    376403        if (e) return;
     404
     405        mutex_t::scoped_lock l(m_mutex);       
    377406
    378407        using namespace libtorrent::detail;
     
    391420{
    392421        using namespace libtorrent::detail;
     422
     423        mutex_t::scoped_lock l(m_mutex);       
    393424
    394425        // send SOCKS5 UDP command
     
    409440        if (e) return;
    410441
     442        mutex_t::scoped_lock l(m_mutex);       
     443
    411444        asio::async_read(m_socks5_sock, asio::buffer(m_tmp_buf, 10)
    412445                , boost::bind(&udp_socket::connect2, this, _1));
     
    416449{
    417450        if (e) return;
    418        
     451
     452        mutex_t::scoped_lock l(m_mutex);       
     453
    419454        using namespace libtorrent::detail;
    420455
Note: See TracChangeset for help on using the changeset viewer.