Changeset 2319

Show
Ignore:
Timestamp:
11/26/07 00:26:45 (14 months ago)
Author:
markybob
Message:

small lsd, dht, webseed, and socks fixes

Location:
tags/deluge-0.5.6.96/libtorrent/src
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • tags/deluge-0.5.6.96/libtorrent/src/kademlia/dht_tracker.cpp

    r2189 r2319  
    274274                m_socket.open(ep.protocol()); 
    275275                m_socket.bind(ep); 
     276                m_socket.async_receive_from(asio::buffer(&m_in_buf[m_buffer][0] 
     277                        , m_in_buf[m_buffer].size()), m_remote_endpoint[m_buffer] 
     278                        , m_strand.wrap(bind(&dht_tracker::on_receive, self(), _1, _2))); 
    276279        } 
    277280 
  • tags/deluge-0.5.6.96/libtorrent/src/socks4_stream.cpp

    r634 r2319  
    4444                { 
    4545                        (*h)(e); 
    46                         close(); 
     46                        asio::error_code ec; 
     47                        close(ec); 
    4748                        return; 
    4849                } 
     
    5556                { 
    5657                        asio::error_code ec = asio::error::operation_not_supported; 
    57                         (*h)(e); 
    58                         close(); 
     58                        (*h)(ec); 
     59                        close(ec); 
    5960                        return; 
    6061                } 
     
    6970                { 
    7071                        (*h)(e); 
    71                         close(); 
     72                        asio::error_code ec; 
     73                        close(ec); 
    7274                        return; 
    7375                } 
     
    9496                { 
    9597                        (*h)(e); 
    96                         close(); 
     98                        asio::error_code ec; 
     99                        close(ec); 
    97100                        return; 
    98101                } 
     
    108111                { 
    109112                        (*h)(e); 
    110                         close(); 
     113                        asio::error_code ec; 
     114                        close(ec); 
    111115                        return; 
    112116                } 
     
    120124                if (reply_version != 0) 
    121125                { 
    122                         (*h)(asio::error::operation_not_supported); 
    123                         close(); 
     126                        asio::error_code ec = asio::error::operation_not_supported; 
     127                        (*h)(ec); 
     128                        close(ec); 
    124129                        return; 
    125130                } 
     
    141146                } 
    142147                (*h)(ec); 
    143                 close(); 
     148                close(ec); 
    144149        } 
    145150 
  • tags/deluge-0.5.6.96/libtorrent/src/socks5_stream.cpp

    r1919 r2319  
    4545                { 
    4646                        (*h)(e); 
    47                         close(); 
     47                        asio::error_code ec; 
     48                        close(ec); 
    4849                        return; 
    4950                } 
     
    5859                { 
    5960                        (*h)(e); 
    60                         close(); 
     61                        asio::error_code ec; 
     62                        close(ec); 
    6163                        return; 
    6264                } 
     
    8789                { 
    8890                        (*h)(e); 
    89                         close(); 
     91                        asio::error_code ec; 
     92                        close(ec); 
    9093                        return; 
    9194                } 
     
    101104                { 
    102105                        (*h)(e); 
    103                         close(); 
     106                        asio::error_code ec; 
     107                        close(ec); 
    104108                        return; 
    105109                } 
     
    114118                { 
    115119                        (*h)(asio::error::operation_not_supported); 
    116                         close(); 
     120                        asio::error_code ec; 
     121                        close(ec); 
    117122                        return; 
    118123                } 
     
    127132                        { 
    128133                                (*h)(asio::error::operation_not_supported); 
    129                                 close(); 
     134                                asio::error_code ec; 
     135                                close(ec); 
    130136                                return; 
    131137                        } 
     
    145151                { 
    146152                        (*h)(asio::error::operation_not_supported); 
    147                         close(); 
     153                        asio::error_code ec; 
     154                        close(ec); 
    148155                        return; 
    149156                } 
     
    156163                { 
    157164                        (*h)(e); 
    158                         close(); 
     165                        asio::error_code ec; 
     166                        close(ec); 
    159167                        return; 
    160168                } 
     
    171179                { 
    172180                        (*h)(e); 
    173                         close(); 
     181                        asio::error_code ec; 
     182                        close(ec); 
    174183                        return; 
    175184                } 
     
    184193                { 
    185194                        (*h)(asio::error::operation_not_supported); 
    186                         close(); 
     195                        asio::error_code ec; 
     196                        close(ec); 
    187197                        return; 
    188198                } 
     
    191201                { 
    192202                        (*h)(asio::error::operation_not_supported); 
    193                         close(); 
     203                        asio::error_code ec; 
     204                        close(ec); 
    194205                        return; 
    195206                } 
     
    223234                { 
    224235                        (*h)(e); 
    225                         close(); 
     236                        asio::error_code ec; 
     237                        close(ec); 
    226238                        return; 
    227239                } 
     
    237249                { 
    238250                        (*h)(e); 
    239                         close(); 
     251                        asio::error_code ec; 
     252                        close(ec); 
    240253                        return; 
    241254                } 
     
    249262                { 
    250263                        (*h)(asio::error::operation_not_supported); 
    251                         close(); 
     264                        asio::error_code ec; 
     265                        close(ec); 
    252266                        return; 
    253267                } 
     
    268282                        } 
    269283                        (*h)(e); 
    270                         close(); 
     284                        asio::error_code ec; 
     285                        close(ec); 
    271286                        return; 
    272287                } 
     
    292307                { 
    293308                        (*h)(asio::error::operation_not_supported); 
    294                         close(); 
     309                        asio::error_code ec; 
     310                        close(ec); 
    295311                        return; 
    296312                } 
     
    306322                { 
    307323                        (*h)(e); 
    308                         close(); 
     324                        asio::error_code ec; 
     325                        close(ec); 
    309326                        return; 
    310327                } 
  • tags/deluge-0.5.6.96/libtorrent/src/torrent.cpp

    r2272 r2319  
    288288        bool torrent::should_announce_dht() const 
    289289        { 
     290                if (m_ses.m_listen_sockets.empty()) return false; 
     291 
     292                if (!m_ses.m_dht) return false; 
    290293                // don't announce private torrents 
    291294                if (m_torrent_file->is_valid() && m_torrent_file->priv()) return false; 
     
    435438 
    436439                        // announce with the local discovery service 
    437                         m_ses.announce_lsd(m_torrent_file->info_hash()); 
     440                        if (!m_paused) 
     441                                m_ses.announce_lsd(m_torrent_file->info_hash()); 
    438442                } 
    439443                else 
     
    445449 
    446450#ifndef TORRENT_DISABLE_DHT 
     451                if (m_paused) return; 
    447452                if (!m_ses.m_dht) return; 
    448453                ptime now = time_now(); 
     
    450455                { 
    451456                        m_last_dht_announce = now; 
    452                         // TODO: There should be a way to abort an announce operation on the dht. 
    453                         // when the torrent is destructed 
    454457                        if (m_ses.m_listen_sockets.empty()) return; 
    455458                        m_ses.m_dht->announce(m_torrent_file->info_hash() 
     
    22512254#ifndef TORRENT_DISABLE_DHT 
    22522255                        // only start the announce if we want to announce with the dht 
    2253                         if (should_announce_dht()) 
    2254                         { 
    2255                                 if (m_abort) return; 
     2256                        ptime now = time_now(); 
     2257                        if (should_announce_dht() && now - m_last_dht_announce > minutes(14)) 
     2258                        { 
    22562259                                // force the DHT to reannounce 
    2257                                 m_last_dht_announce = time_now() - minutes(15); 
     2260                                m_last_dht_announce = now; 
    22582261                                boost::weak_ptr<torrent> self(shared_from_this()); 
    2259                                 m_announce_timer.expires_from_now(seconds(1)); 
    2260                                 m_announce_timer.async_wait(m_ses.m_strand.wrap( 
    2261                                         bind(&torrent::on_announce_disp, self, _1))); 
     2262                                m_ses.m_dht->announce(m_torrent_file->info_hash() 
     2263                                        , m_ses.m_listen_sockets.front().external_port 
     2264                                        , m_ses.m_strand.wrap(bind(&torrent::on_dht_announce_response_disp, self, _1))); 
    22622265                        } 
    22632266#endif 
  • tags/deluge-0.5.6.96/libtorrent/src/web_peer_connection.cpp

    r1919 r2319  
    307307        namespace 
    308308        { 
    309                 bool range_contains(peer_request const& range, peer_request const& req) 
    310                 { 
    311                         return range.start <= req.start 
    312                                 && range.start + range.length >= req.start + req.length; 
     309                bool range_contains(peer_request const& range, peer_request const& req, int piece_size) 
     310                { 
     311                        size_type range_start = size_type(range.piece) * piece_size + range.start; 
     312                        size_type req_start = size_type(req.piece) * piece_size + req.start; 
     313                        return range_start <= req_start 
     314                                && range_start + range.length >= req_start + req.length; 
    313315                } 
    314316        } 
     
    471473                        } 
    472474 
     475//                      std::cerr << "REQUESTS: m_requests: " << m_requests.size() 
     476//                              << " file_requests: " << m_file_requests.size() << std::endl; 
     477 
    473478                        torrent_info const& info = t->torrent_file(); 
    474479 
     
    481486 
    482487                        peer_request front_request = m_requests.front(); 
    483  
     488/* 
    484489                        size_type rs = size_type(in_range.piece) * info.piece_length() + in_range.start; 
    485490                        size_type re = rs + in_range.length; 
    486491                        size_type fs = size_type(front_request.piece) * info.piece_length() + front_request.start; 
    487492                        size_type fe = fs + front_request.length; 
    488                         if (fs < rs || fe > re) 
    489                         { 
    490                                 throw std::runtime_error("invalid range in HTTP response"); 
    491                         } 
    492  
     493 
     494                        std::cerr << "RANGE: r = (" << rs << ", " << re << " ) " 
     495                                "f = (" << fs << ", " << fe << ") " 
     496                                "file_index = " << file_index << " received_body = " << m_received_body << std::endl; 
     497*/ 
    493498                        // skip the http header and the blocks we've already read. The 
    494499                        // http_body.begin is now in sync with the request at the front 
     
    505510                                > front_request.start + int(m_piece.size()); 
    506511 
     512                        if (!range_overlaps_request) 
     513                        { 
     514                                throw std::runtime_error("invalid range in HTTP response"); 
     515                        } 
     516 
    507517                        // if the request is contained in the range (i.e. the entire request 
    508518                        // fits in the range) we should not start a partial piece, since we soon 
    509519                        // will receive enough to call incoming_piece() and pass the read buffer 
    510520                        // directly (in the next loop below). 
    511                         if (range_overlaps_request && !range_contains(in_range, front_request)) 
     521                        if (range_overlaps_request && !range_contains(in_range, front_request, info.piece_length())) 
    512522                        { 
    513523                                // the start of the next block to receive is stored 
     
    550560                        // report all received blocks to the bittorrent engine 
    551561                        while (!m_requests.empty() 
    552                                 && range_contains(in_range, m_requests.front()) 
     562                                && range_contains(in_range, m_requests.front(), info.piece_length()) 
    553563                                && recv_buffer.left() >= m_requests.front().length) 
    554564                        {