Changeset 3740

Show
Ignore:
Timestamp:
08/23/08 08:09:52 (5 months ago)
Author:
andar
Message:

lt sync 2626

Location:
branches/1.0.0_RC/libtorrent
Files:
16 modified

Legend:

Unmodified
Added
Removed
  • branches/1.0.0_RC/libtorrent/bindings/python/src/torrent_handle.cpp

    r3439 r3740  
    55#include <libtorrent/torrent_handle.hpp> 
    66#include <boost/python.hpp> 
     7#include <boost/python/tuple.hpp> 
    78#include <boost/lexical_cast.hpp> 
    89#include "gil.hpp" 
     
    171172list get_download_queue(torrent_handle& handle) 
    172173{ 
     174    using boost::python::make_tuple; 
     175 
    173176    list ret; 
    174177 
     
    194197            block_info["bytes_progress"] = i->blocks[k].bytes_progress; 
    195198            block_info["block_size"] = i->blocks[k].block_size; 
    196             block_info["peer"] = std::make_pair( 
     199            block_info["peer"] = make_tuple( 
    197200                boost::lexical_cast<std::string>(i->blocks[k].peer.address()), i->blocks[k].peer.port()); 
    198201            block_list.append(block_info); 
  • branches/1.0.0_RC/libtorrent/include/libtorrent/alert.hpp

    r3675 r3740  
    8383                        progress_notification = 0x80, 
    8484                        ip_block_notification = 0x100, 
     85                        performance_warning = 0x200, 
    8586 
    8687                        all_categories = 0xffffffff 
  • branches/1.0.0_RC/libtorrent/include/libtorrent/alert_types.hpp

    r3732 r3740  
    152152        }; 
    153153 
     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 
    154190        struct TORRENT_EXPORT state_changed_alert: torrent_alert 
    155191        { 
  • branches/1.0.0_RC/libtorrent/include/libtorrent/bencode.hpp

    r3330 r3740  
    106106                int write_string(OutIt& out, const std::string& val) 
    107107                { 
    108                         int ret = val.length(); 
    109                         std::string::const_iterator end = val.begin() + ret; 
    110108                        for (std::string::const_iterator i = val.begin() 
    111                                 , end(val.begin() + ret); i != end; ++i) 
     109                                , end(val.end()); i != end; ++i) 
    112110                                *out++ = *i; 
    113                         return ret; 
     111                        return val.length(); 
    114112                } 
    115113 
  • branches/1.0.0_RC/libtorrent/include/libtorrent/pe_crypto.hpp

    r3330 r3740  
    5959                int compute_secret(const char* remote_pubkey); 
    6060 
    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; } 
    6264                 
    6365        private: 
     
    7274                char m_dh_local_key[96]; 
    7375                char m_dh_secret[96]; 
     76                sha1_hash m_xor_mask; 
    7477        }; 
    7578         
  • branches/1.0.0_RC/libtorrent/include/libtorrent/torrent.hpp

    r3512 r3740  
    132132 
    133133                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(); } 
    134142 
    135143                // starts the announce timer 
     
    822830                boost::scoped_ptr<std::string> m_name; 
    823831 
     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 
    824837                session_settings const& m_settings; 
    825838 
  • branches/1.0.0_RC/libtorrent/src/bt_peer_connection.cpp

    r3712 r3740  
    18421842                                } 
    18431843 
    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)); 
    18451846 
    18461847                                TORRENT_ASSERT(!packet_finished()); 
     
    18731874                        recv_buffer = receive_buffer(); 
    18741875 
    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(); 
    19011883                                obfs_hash ^= skey_hash; 
    19021884 
    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])) 
    19051887                                { 
    19061888                                        if (!t) 
    19071889                                        { 
    1908                                                 attach_to_torrent(info_hash); 
     1890                                                attach_to_torrent(ti.info_hash()); 
    19091891                                                if (is_disconnecting()) return; 
    19101892 
     
    19131895                                        } 
    19141896 
    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()); 
    19161898#ifdef TORRENT_VERBOSE_LOGGING 
    19171899                                        (*m_logger) << " stream key found, torrent located.\n"; 
    19181900#endif 
    1919                                         continue; // TODO Check flow control with multiple torrents 
     1901                                        break; 
    19201902                                } 
    19211903                        } 
  • branches/1.0.0_RC/libtorrent/src/identify_client.cpp

    r3675 r3740  
    6060        } 
    6161 
     62        bool isprint(char c) 
     63        { 
     64                return c >= 32 && c < 127; 
     65        } 
     66 
    6267        // takes a peer id and returns a valid boost::optional 
    6368        // object if the peer id matched the azureus style encoding 
     
    6873                fingerprint ret("..", 0, 0, 0, 0); 
    6974 
    70                 if (id[0] != '-' || !std::isprint(id[1]) || (id[2] < '0') 
     75                if (id[0] != '-' || !isprint(id[1]) || (id[2] < '0') 
    7176                        || (id[3] < '0') || (id[4] < '0') 
    7277                        || (id[5] < '0') || (id[6] < '0') 
     
    130135                if (sscanf(ids, "%c%d-%d-%d--", &ret.name[0], &ret.major_version, &ret.minor_version 
    131136                        , &ret.revision_version) != 4 
    132                         || !std::isprint(ret.name[0])) 
     137                        || !isprint(ret.name[0])) 
    133138                        return boost::optional<fingerprint>(); 
    134139 
     
    374379                for (peer_id::const_iterator i = p.begin(); i != p.end(); ++i) 
    375380                { 
    376                         unknown += std::isprint(*i)?*i:'.'; 
     381                        unknown += isprint(*i)?*i:'.'; 
    377382                } 
    378383                unknown += "]"; 
  • branches/1.0.0_RC/libtorrent/src/kademlia/dht_tracker.cpp

    r3276 r3740  
    449449#ifdef TORRENT_DHT_VERBOSE_LOGGING 
    450450                                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"; 
    453452#endif 
    454453                                return; 
  • branches/1.0.0_RC/libtorrent/src/lazy_bdecode.cpp

    r3712 r3740  
    377377                                { 
    378378                                        using namespace std; 
    379                                         if (isprint(str[i])) continue; 
     379                                        if (isprint((unsigned char)str[i])) continue; 
    380380                                        printable = false; 
    381381                                        break; 
  • branches/1.0.0_RC/libtorrent/src/natpmp.cpp

    r3675 r3740  
    106106        } 
    107107 
     108        m_socket.async_receive_from(asio::buffer(&m_response_buffer, 16) 
     109                , m_remote, bind(&natpmp::on_reply, self(), _1, _2)); 
     110 
    108111        for (std::vector<mapping_t>::iterator i = m_mappings.begin() 
    109112                , end(m_mappings.end()); i != end; ++i) 
     
    238241                m_retry_count = 0; 
    239242                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)); 
    242243        } 
    243244} 
     
    282283{ 
    283284        if (e) return; 
    284         if (m_abort) return; 
    285  
    286285        mutex_t::scoped_lock l(m_mutex); 
    287286        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) 
    289291        { 
    290292                m_currently_mapping = -1; 
     
    302304{ 
    303305        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)); 
    305318 
    306319        if (m_remote != m_nat_endpoint) 
    307320        { 
    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 
    310326                return; 
    311327        } 
  • branches/1.0.0_RC/libtorrent/src/pe_crypto.cpp

    r3321 r3740  
    3939 
    4040#include "libtorrent/pe_crypto.hpp" 
     41#include "libtorrent/hasher.hpp" 
    4142#include "libtorrent/assert.hpp" 
    4243 
     
    145146                std::copy(dh_secret, dh_secret + secret_size, m_dh_secret + 96 - secret_size); 
    146147                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 
    147155                return 0; 
    148         } 
    149  
    150         char const* dh_key_exchange::get_secret() const 
    151         { 
    152                 return m_dh_secret; 
    153156        } 
    154157 
  • branches/1.0.0_RC/libtorrent/src/peer_connection.cpp

    r3712 r3740  
    16441644                m_download_queue.erase(b); 
    16451645 
     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 
    16461653                if (!m_download_queue.empty()) 
    16471654                { 
     
    27662773                        if (m_desired_queue_size < min_request_queue) 
    27672774                                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                        } 
    27682782                } 
    27692783 
     
    36333647                } 
    36343648 
     3649/* 
     3650                // this assertion correct most of the time, but sometimes right when the 
     3651                // limit is changed it might break 
    36353652                for (int i = 0; i < 2; ++i) 
    36363653                { 
     
    36403657                                || m_bandwidth_limit[i].throttle() == bandwidth_limit::inf); 
    36413658                } 
     3659*/ 
    36423660 
    36433661                if (m_channel_state[download_channel] == peer_info::bw_torrent 
  • branches/1.0.0_RC/libtorrent/src/storage.cpp

    r3712 r3740  
    529529                        // don't allocate files with priority 0 
    530530                        int file_index = file_iter - files().begin(); 
    531                         if (allocate_files && (m_file_priority.size() <= file_index 
     531                        if (allocate_files && (int(m_file_priority.size()) <= file_index 
    532532                                || m_file_priority[file_index] > 0)) 
    533533                        { 
     
    21702170                                (file_offset - current_offset + m_files.piece_length() - 1) 
    21712171                                / m_files.piece_length()); 
     2172                        TORRENT_ASSERT(skip_blocks >= 1); 
    21722173 
    21732174                        if (m_storage_mode == storage_mode_compact) 
  • branches/1.0.0_RC/libtorrent/src/torrent.cpp

    r3732 r3740  
    207207        { 
    208208                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 
    209216        } 
    210217 
     
    281288        { 
    282289                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 
    283298#ifndef NDEBUG 
    284299                m_files_checked = false; 
     
    14721487                                if (m_ses.m_alerts.should_post<peer_ban_alert>()) 
    14731488                                { 
    1474                                         peer_id pid; 
     1489                                        peer_id pid(0); 
    14751490                                        if (p->connection) pid = p->connection->pid(); 
    14761491                                        m_ses.m_alerts.post_alert(peer_ban_alert( 
     
    22622277         
    22632278                bool ret = instantiate_connection(m_ses.m_io_service, m_ses.web_seed_proxy(), *s); 
     2279                (void)ret; 
    22642280                TORRENT_ASSERT(ret); 
    22652281 
     
    27762792 
    27772793                bool ret = instantiate_connection(m_ses.m_io_service, m_ses.peer_proxy(), *s); 
     2794                (void)ret; 
    27782795                TORRENT_ASSERT(ret); 
    27792796                std::pair<int, int> const& out_ports = m_ses.settings().outgoing_ports; 
     
    35243541        void torrent::set_sequential_download(bool sd) 
    35253542        { 
     3543                m_sequential_download = sd; 
    35263544                if (has_picker()) 
    35273545                { 
    35283546                        picker().sequential_download(sd); 
    3529                 } 
    3530                 else 
    3531                 { 
    3532                         m_sequential_download = sd; 
    35333547                } 
    35343548        } 
  • branches/1.0.0_RC/libtorrent/src/torrent_handle.cpp

    r3675 r3740  
    251251        { 
    252252                INVARIANT_CHECK; 
    253                 TORRENT_FORWARD_RETURN(is_paused(), false); 
     253                TORRENT_FORWARD_RETURN(is_torrent_paused(), false); 
    254254        } 
    255255