diff --git a/include/libtorrent/alert.hpp b/include/libtorrent/alert.hpp index b5f841f54..b0b56945d 100644 --- a/include/libtorrent/alert.hpp +++ b/include/libtorrent/alert.hpp @@ -127,8 +127,8 @@ namespace libtorrent { // Enables alerts for port mapping events. For NAT-PMP and UPnP. port_mapping_notification = 0x4, - // Enables alerts for events related to the storage. File errors and - // synchronization events for moving the storage, renaming files etc. + // Enables alerts for events related to the storage. File errors and + // synchronization events for moving the storage, renaming files etc. storage_notification = 0x8, // Enables all tracker events. Includes announcing to trackers, @@ -145,10 +145,10 @@ namespace libtorrent { // pieces are completed. progress_notification = 0x80, - // Alerts when a peer is blocked by the ip blocker or port blocker. + // Alerts when a peer is blocked by the ip blocker or port blocker. ip_block_notification = 0x100, - // Alerts when some limit is reached that might limit the download + // Alerts when some limit is reached that might limit the download // or upload rate. performance_warning = 0x200, @@ -163,8 +163,8 @@ namespace libtorrent { stats_notification = 0x800, #ifndef TORRENT_NO_DEPRECATE - // Alerts on RSS related events, like feeds being updated, feed error - // conditions and successful RSS feed updates. Enabling this categoty + // Alerts on RSS related events, like feeds being updated, feed error + // conditions and successful RSS feed updates. Enabling this categoty // will make you receive rss_alert alerts. rss_notification = 0x1000, #endif diff --git a/include/libtorrent/enum_net.hpp b/include/libtorrent/enum_net.hpp index b37eac44f..e0e9d6903 100644 --- a/include/libtorrent/enum_net.hpp +++ b/include/libtorrent/enum_net.hpp @@ -77,7 +77,7 @@ namespace libtorrent TORRENT_EXTRA_EXPORT std::vector enum_net_interfaces(io_service& ios , error_code& ec); - TORRENT_EXTRA_EXPORT std::vector enum_routes(io_service& ios, error_code& ec); + TORRENT_EXTRA_EXPORT std::vector enum_routes(error_code& ec); // return (a1 & mask) == (a2 & mask) TORRENT_EXTRA_EXPORT bool match_addr_mask(address const& a1 @@ -90,8 +90,7 @@ namespace libtorrent TORRENT_EXTRA_EXPORT bool in_local_network(std::vector const& net , address const& addr); - TORRENT_EXTRA_EXPORT address get_default_gateway(io_service& ios - , error_code& ec); + TORRENT_EXTRA_EXPORT address get_default_gateway(error_code& ec); #ifdef SO_BINDTODEVICE struct bind_to_device_opt diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 8e199c7bd..fee285180 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -756,8 +756,6 @@ namespace libtorrent void recalc_share_mode(); - void update_sparse_piece_prio(int piece, int cursor, int reverse_cursor); - struct suggest_piece_t { int piece_index; @@ -773,7 +771,7 @@ namespace libtorrent // we're not super seeding if we're not a seed return m_super_seeding && is_seed(); } - + void super_seeding(bool on); int get_piece_to_super_seed(bitfield const&); @@ -870,7 +868,7 @@ namespace libtorrent void on_name_lookup(error_code const& e , std::vector
const& addrs , int port - , std::list::iterator web, tcp::endpoint proxy); + , std::list::iterator web); void connect_web_seed(std::list::iterator web, tcp::endpoint a); @@ -1149,6 +1147,8 @@ namespace libtorrent private: + void update_sparse_piece_prio(int piece, int start, int end); + void ip_filter_updated(); void inc_stats_counter(int c, int value = 1); diff --git a/include/libtorrent/udp_socket.hpp b/include/libtorrent/udp_socket.hpp index 4f155d637..996cb7eb9 100644 --- a/include/libtorrent/udp_socket.hpp +++ b/include/libtorrent/udp_socket.hpp @@ -185,7 +185,7 @@ namespace libtorrent void setup_read(udp::socket* s); void on_read(error_code const& ec, udp::socket* s); - void on_read_impl(udp::socket* sock, udp::endpoint const& ep + void on_read_impl(udp::endpoint const& ep , error_code const& e, std::size_t bytes_transferred); void on_name_lookup(error_code const& e, tcp::resolver::iterator i); void on_connect_timeout(error_code const& ec); diff --git a/src/enum_net.cpp b/src/enum_net.cpp index aa8b99b5c..987722454 100644 --- a/src/enum_net.cpp +++ b/src/enum_net.cpp @@ -280,7 +280,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl #endif #if TORRENT_USE_IFADDRS - bool iface_from_ifaddrs(ifaddrs *ifa, ip_interface &rv, error_code& ec) + bool iface_from_ifaddrs(ifaddrs *ifa, ip_interface &rv) { int family = ifa->ifa_addr->sa_family; @@ -311,7 +311,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl namespace libtorrent { - + // return (a1 & mask) == (a2 & mask) bool match_addr_mask(address const& a1, address const& a2, address const& mask) { @@ -403,9 +403,10 @@ namespace libtorrent } } #endif - + std::vector enum_net_interfaces(io_service& ios, error_code& ec) { + TORRENT_UNUSED(ios); // this may be unused depending on configuration std::vector ret; #if TORRENT_USE_IFADDRS int s = socket(AF_INET, SOCK_DGRAM, 0); @@ -436,7 +437,7 @@ namespace libtorrent ) { ip_interface iface; - if (iface_from_ifaddrs(ifa, iface, ec)) + if (iface_from_ifaddrs(ifa, iface)) { ifreq req; memset(&req, 0, sizeof(req)); @@ -618,7 +619,7 @@ namespace libtorrent INTERFACE_INFO buffer[30]; DWORD size; - + if (WSAIoctl(s, SIO_GET_INTERFACE_LIST, 0, 0, buffer, sizeof(buffer), &size, 0, 0) != 0) { @@ -667,9 +668,9 @@ namespace libtorrent return ret; } - address get_default_gateway(io_service& ios, error_code& ec) + address get_default_gateway(error_code& ec) { - std::vector ret = enum_routes(ios, ec); + std::vector ret = enum_routes(ec); #if defined TORRENT_WINDOWS || defined TORRENT_MINGW std::vector::iterator i = std::find_if(ret.begin(), ret.end() , boost::bind(&is_loopback, boost::bind(&ip_route::destination, _1))); @@ -681,10 +682,10 @@ namespace libtorrent return i->gateway; } - std::vector enum_routes(io_service& ios, error_code& ec) + std::vector enum_routes(error_code& ec) { std::vector ret; - + #if TORRENT_USE_SYSCTL /* struct rt_msg @@ -835,12 +836,12 @@ namespace libtorrent rtm = (rt_msghdr*)next; if (rtm->rtm_version != RTM_VERSION) continue; - + ip_route r; if (parse_route(s, rtm, &r)) ret.push_back(r); } close(s); - + #elif TORRENT_USE_GETIPFORWARDTABLE /* move this to enum_net_interfaces @@ -925,7 +926,7 @@ namespace libtorrent typedef DWORD (WINAPI *GetIpForwardTable2_t)( ADDRESS_FAMILY, PMIB_IPFORWARD_TABLE2*); typedef void (WINAPI *FreeMibTable_t)(PVOID Memory); - + GetIpForwardTable2_t GetIpForwardTable2 = (GetIpForwardTable2_t)GetProcAddress( iphlp, "GetIpForwardTable2"); FreeMibTable_t FreeMibTable = (FreeMibTable_t)GetProcAddress( @@ -962,7 +963,7 @@ namespace libtorrent // Get GetIpForwardTable() pointer typedef DWORD (WINAPI *GetIpForwardTable_t)(PMIB_IPFORWARDTABLE pIpForwardTable,PULONG pdwSize,BOOL bOrder); - + GetIpForwardTable_t GetIpForwardTable = (GetIpForwardTable_t)GetProcAddress( iphlp, "GetIpForwardTable"); if (!GetIpForwardTable) diff --git a/src/natpmp.cpp b/src/natpmp.cpp index cd60451e0..6d4bce268 100644 --- a/src/natpmp.cpp +++ b/src/natpmp.cpp @@ -88,7 +88,7 @@ void natpmp::start() mutex::scoped_lock l(m_mutex); error_code ec; - address gateway = get_default_gateway(m_socket.get_io_service(), ec); + address gateway = get_default_gateway(ec); if (ec) { char msg[200]; diff --git a/src/peer_list.cpp b/src/peer_list.cpp index d8916b6d9..bba339db4 100644 --- a/src/peer_list.cpp +++ b/src/peer_list.cpp @@ -159,7 +159,7 @@ namespace libtorrent ++i; continue; } - + int current = i - m_peers.begin(); TORRENT_ASSERT(current >= 0); TORRENT_ASSERT(m_peers.size() > 0); @@ -171,7 +171,7 @@ namespace libtorrent // peer_info_struct. If that is the case, just continue size_t count = m_peers.size(); peer_connection_interface* p = (*i)->connection; - + banned.push_back(p->remote().address()); p->disconnect(errors::banned_by_ip_filter @@ -221,7 +221,7 @@ namespace libtorrent ++i; continue; } - + int current = i - m_peers.begin(); TORRENT_ASSERT(current >= 0); TORRENT_ASSERT(m_peers.size() > 0); @@ -233,7 +233,7 @@ namespace libtorrent // peer_info_struct. If that is the case, just continue int count = m_peers.size(); peer_connection_interface* p = (*i)->connection; - + banned.push_back(p->remote().address()); p->disconnect(errors::banned_by_port_filter, op_bittorrent); @@ -389,7 +389,7 @@ namespace libtorrent ++round_robin; } - + if (erase_candidate > -1) { TORRENT_ASSERT(erase_candidate >= 0 && erase_candidate < int(m_peers.size())); @@ -467,7 +467,7 @@ namespace libtorrent || (p.seed && m_finished) || int(p.failcount) >= m_max_failcount) return false; - + return true; } @@ -554,7 +554,7 @@ namespace libtorrent peers.insert(i, &pe); } - + if (erase_candidate > -1) { erase_peer(m_peers.begin() + erase_candidate, state); @@ -581,7 +581,7 @@ namespace libtorrent tcp::endpoint remote = c.remote(); std::pair range = find_peers(remote.address()); iter = std::find_if(range.first, range.second, match_peer_endpoint(remote)); - + if (iter != range.second) { TORRENT_ASSERT((*iter)->in_use); @@ -766,10 +766,10 @@ namespace libtorrent if (m_round_robin >= iter - m_peers.begin()) ++m_round_robin; i = *iter; - + i->source = peer_info::incoming; } - + TORRENT_ASSERT(i); c.set_peer_info(i); TORRENT_ASSERT(i->connection == 0); diff --git a/src/torrent.cpp b/src/torrent.cpp index 2895aa799..d550e79c4 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -4027,8 +4027,8 @@ namespace libtorrent TORRENT_ASSERT(m_picker); if (m_picker->have_piece(i) || m_picker->piece_priority(i) == 0) return; - bool have_before = i == 0 || m_picker->have_piece(i - 1); - bool have_after = i == end - 1 || m_picker->have_piece(i + 1); + bool have_before = i < start || m_picker->have_piece(i - 1); + bool have_after = i >= end || m_picker->have_piece(i + 1); if (have_after && have_before) m_picker->set_piece_priority(i, 7); else if (have_after || have_before) @@ -4281,7 +4281,7 @@ namespace libtorrent std::vector::iterator i = std::lower_bound(m_predictive_pieces.begin() , m_predictive_pieces.end(), index); if (i != m_predictive_pieces.end() && *i == index) return; - + for (peer_iterator p = m_connections.begin() , end(m_connections.end()); p != end; ++p) { @@ -4307,7 +4307,7 @@ namespace libtorrent TORRENT_ASSERT(m_picker.get()); TORRENT_ASSERT(index >= 0); - TORRENT_ASSERT(index < m_torrent_file->num_pieces()); + TORRENT_ASSERT(index < m_torrent_file->num_pieces()); inc_stats_counter(counters::num_piece_failed); @@ -6145,7 +6145,7 @@ namespace libtorrent web->resolving = true; m_ses.async_resolve(hostname, resolver_interface::abort_on_shutdown , boost::bind(&torrent::on_name_lookup, shared_from_this(), _1, _2 - , port, web, tcp::endpoint())); + , port, web)); } } @@ -6228,14 +6228,13 @@ namespace libtorrent web->resolving = true; m_ses.async_resolve(hostname, resolver_interface::abort_on_shutdown , boost::bind(&torrent::on_name_lookup, shared_from_this(), _1, _2 - , port, web, a)); + , port, web)); } void torrent::on_name_lookup(error_code const& e , std::vector
const& addrs , int port - , std::list::iterator web - , tcp::endpoint proxy) + , std::list::iterator web) { TORRENT_ASSERT(is_single_thread()); @@ -6303,7 +6302,7 @@ namespace libtorrent , a.address(), peer_blocked_alert::ip_filter); return; } - + TORRENT_ASSERT(web->resolving == false); TORRENT_ASSERT(web->peer_info.connection == 0); @@ -6319,7 +6318,7 @@ namespace libtorrent boost::shared_ptr s = boost::make_shared(boost::ref(m_ses.get_io_service())); if (!s) return; - + void* userdata = 0; #ifdef TORRENT_USE_OPENSSL bool ssl = string_begins_no_case("https://", web->url.c_str()); @@ -9962,7 +9961,6 @@ namespace libtorrent int num_pieces = m_torrent_file->num_pieces(); int rarest_rarity = INT_MAX; - bool prio_updated = false; for (int i = 0; i < num_pieces; ++i) { piece_picker::piece_stats_t ps = m_picker->piece_stats(i); @@ -9970,7 +9968,6 @@ namespace libtorrent if (ps.priority == 0 && (ps.have || ps.downloading)) { m_picker->set_piece_priority(i, 1); - prio_updated = true; continue; } // don't count pieces we already have or are trying to download @@ -10859,7 +10856,7 @@ namespace libtorrent need_policy(); torrent_state st = get_policy_state(); - torrent_peer* p = m_peer_list->add_peer(adr, source, 0, &st); + torrent_peer* p = m_peer_list->add_peer(adr, source, flags, &st); peers_erased(st.erased); if (p) { @@ -11123,7 +11120,7 @@ namespace libtorrent fp.resize(m_torrent_file->num_files(), 0); return; } - + int num_files = m_torrent_file->num_files(); if (m_file_progress.empty()) { diff --git a/src/udp_socket.cpp b/src/udp_socket.cpp index 9f79b6d60..a09957de1 100644 --- a/src/udp_socket.cpp +++ b/src/udp_socket.cpp @@ -302,7 +302,7 @@ void udp_socket::on_read(error_code const& ec, udp::socket* s) #endif if (ec == asio::error::would_block || ec == asio::error::try_again) break; - on_read_impl(s, ep, ec, bytes_transferred); + on_read_impl(ep, ec, bytes_transferred); } call_drained_handler(); setup_read(s); @@ -419,7 +419,7 @@ void udp_socket::unsubscribe(udp_socket_observer* o) m_observers.erase(i); } -void udp_socket::on_read_impl(udp::socket* s, udp::endpoint const& ep +void udp_socket::on_read_impl(udp::endpoint const& ep , error_code const& e, std::size_t bytes_transferred) { TORRENT_ASSERT(m_magic == 0x1337); diff --git a/src/upnp.cpp b/src/upnp.cpp index 8bbcbb637..1c567e4ee 100644 --- a/src/upnp.cpp +++ b/src/upnp.cpp @@ -401,12 +401,12 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer } log(msg, l); return; - } + } bool non_router = false; if (m_ignore_non_routers) { - std::vector routes = enum_routes(m_io_service, ec); + std::vector routes = enum_routes(ec); if (std::find_if(routes.begin(), routes.end() , boost::bind(&ip_route::gateway, _1) == from.address()) == routes.end()) { diff --git a/src/utp_socket_manager.cpp b/src/utp_socket_manager.cpp index ac92072b5..434572188 100644 --- a/src/utp_socket_manager.cpp +++ b/src/utp_socket_manager.cpp @@ -94,7 +94,7 @@ namespace libtorrent { m_last_route_update = aux::time_now(); error_code ec; - m_routes = enum_routes(m_sock.get_io_service(), ec); + m_routes = enum_routes(ec); } int mtu = 0; @@ -206,7 +206,7 @@ namespace libtorrent { m_last_route_update = aux::time_now(); error_code ec; - m_routes = enum_routes(m_sock.get_io_service(), ec); + m_routes = enum_routes(ec); if (ec) return socket_ep; } diff --git a/test/test_torrent.cpp b/test/test_torrent.cpp index 76152fd4b..78a13af2e 100644 --- a/test/test_torrent.cpp +++ b/test/test_torrent.cpp @@ -169,7 +169,7 @@ int test_main() std::vector piece(128 * 1024); for (int i = 0; i < int(piece.size()); ++i) piece[i] = (i % 26) + 'A'; - + // calculate the hash for all pieces sha1_hash ph = hasher(&piece[0], piece.size()).final(); int num = t.num_pieces(); @@ -229,7 +229,7 @@ int test_main() initialize_file_progress(fp, picker, fs); boost::uint64_t sum = 0; - for (int i = 0; i < fp.size(); ++i) + for (int i = 0; i < int(fp.size()); ++i) sum += fp[i]; TEST_EQUAL(sum, fs.piece_size(idx));