relevance 3 | src/alert.cpp:370 | change this to use a timed wait on a condition variable problem is, that's not necessarily portable. But it should be used where available. This implementation can be left the way it is for more primitive platforms |
change this to use a timed wait on a condition variable
problem is, that's not necessarily portable. But it should be used
where available. This implementation can be left the way it is for
more primitive platformssrc/alert.cpp:370 delete m_alerts.front();
@@ -75,7 +79,7 @@ more primitive platformssrc/alert.cpp:370src/storage.cpp:989 | use binary search to find the file entry | |
use binary search to find the file entrysrc/storage.cpp:989 size_type ret = 0;
+ | ||
relevance 3 | src/storage.cpp:989 | use binary search to find the file entry |
use binary search to find the file entrysrc/storage.cpp:989 size_type ret = 0;
if (f && !ec) ret = f->phys_offset(file_offset);
if (ret == 0)
@@ -126,7 +130,7 @@ more primitive platformssrc/alert.cpp:370src/storage.cpp:1095 | use binary search to find the file entry | |
use binary search to find the file entrysrc/storage.cpp:1095 TORRENT_ASSERT(offset >= 0);
+ | ||
relevance 3 | src/storage.cpp:1095 | use binary search to find the file entry |
use binary search to find the file entrysrc/storage.cpp:1095 TORRENT_ASSERT(offset >= 0);
TORRENT_ASSERT(offset < m_files.piece_size(slot));
TORRENT_ASSERT(num_bufs > 0);
@@ -177,7 +181,162 @@ more primitive platformssrc/alert.cpp:370src/utp_stream.cpp:412 | remove the read timeout concept. This should not be necessary | |
remove the read timeout concept. This should not be necessarysrc/utp_stream.cpp:412 // these are the callbacks made into the utp_stream object
+ | ||
relevance 3 | src/torrent.cpp:1505 | filter out peers that are disconnecting |
filter out peers that are disconnectingsrc/torrent.cpp:1505 snprintf(filename, sizeof(filename), "/tmp/%d.pem", rand());
+ FILE* f = fopen(filename, "w+");
+ fwrite(cert.c_str(), cert.size(), 1, f);
+ fclose(f);
+ ctx->load_verify_file(filename);
+#endif
+ // if all went well, set the torrent ssl context to this one
+ m_ssl_ctx = ctx;
+ // tell the client we need a cert for this torrent
+ alerts().post_alert(torrent_need_cert_alert(get_handle()));
+#else
+ set_error(asio::error::operation_not_supported, "x.509 certificate");
+ pause();
+#endif
+ }
+
+#endif // TORRENT_OPENSSL
+
+ peer_connection* torrent::find_lowest_ranking_peer() const
+ {
+ const_peer_iterator lowest_rank = std::min_element(begin(), end()
+ , boost::bind(&peer_connection::peer_rank, _1)
+ < boost::bind(&peer_connection::peer_rank, _2));
+
+ if (lowest_rank == end()) return NULL;
+ return *lowest_rank;
+ }
+
+ // this may not be called from a constructor because of the call to
+ // shared_from_this()
+ void torrent::init()
+ {
+ TORRENT_ASSERT(m_ses.is_network_thread());
+ TORRENT_ASSERT(m_torrent_file->is_valid());
+ TORRENT_ASSERT(m_torrent_file->num_files() > 0);
+ TORRENT_ASSERT(m_torrent_file->total_size() >= 0);
+
+#ifdef TORRENT_USE_OPENSSL
+ std::string cert = m_torrent_file->ssl_cert();
+ if (!cert.empty()) init_ssl(cert);
+#endif
+
+ m_file_priority.resize(m_torrent_file->num_files(), 1);
+ m_file_progress.resize(m_torrent_file->num_files(), 0);
+
+ m_block_size_shift = root2((std::min)(int(block_size()), m_torrent_file->piece_length()));
+
+ if (m_torrent_file->num_pieces() > piece_picker::max_pieces)
+ {
+ set_error(errors::too_many_pieces_in_torrent, "");
+ pause();
+ | ||
relevance 3 | src/torrent.cpp:6004 | if peer is a really good peer, maybe we shouldn't disconnect it |
if peer is a really good peer, maybe we shouldn't disconnect itsrc/torrent.cpp:6004 return false;
+ }
+ TORRENT_ASSERT(m_connections.find(p) == m_connections.end());
+ m_connections.insert(p);
+#ifdef TORRENT_DEBUG
+ error_code ec;
+ TORRENT_ASSERT(p->remote() == p->get_socket()->remote_endpoint(ec) || ec);
+#endif
+
+ TORRENT_ASSERT(p->peer_info_struct() != NULL);
+
+ // we need to do this after we've added the peer to the policy
+ // since that's when the peer is assigned its peer_info object,
+ // which holds the rank
+ if (maybe_replace_peer)
+ {
+ // now, find the lowest rank peer and disconnect that
+ // if it's lower rank than the incoming connection
+ peer_connection* peer = find_lowest_ranking_peer();
+
+ if (peer && peer->peer_rank() < p->peer_rank())
+ {
+ peer->disconnect(errors::too_many_connections);
+ p->peer_disconnected_other();
+ }
+ else
+ {
+ p->disconnect(errors::too_many_connections);
+ // we have to do this here because from the peer's point of
+ // it wasn't really attached to the torrent, but we do need
+ // to let policy know we're removing it
+ remove_peer(p);
+ return false;
+ }
+ }
+
+#if defined TORRENT_DEBUG && !defined TORRENT_DISABLE_INVARIANT_CHECKS
+ m_policy.check_invariant();
+#endif
+
+ if (m_share_mode)
+ recalc_share_mode();
+
+ return true;
+ }
+
+ bool torrent::want_more_peers() const
+ {
+ return m_connections.size() < m_max_connections
+ && !is_paused()
+ && ((m_state != torrent_status::checking_files
+ | ||
relevance 3 | src/torrent.cpp:8718 | with 110 as response codes, we should just consider the tracker as a failure and not retry it anymore |
with 110 as response codes, we should just consider
+the tracker as a failure and not retry
+it anymoresrc/torrent.cpp:8718 TORRENT_ASSERT(m_ses.is_network_thread());
+ TORRENT_ASSERT(b > 0);
+ m_total_failed_bytes += b;
+ m_ses.add_failed_bytes(b);
+// TORRENT_ASSERT(m_total_redundant_bytes + m_total_failed_bytes
+// <= m_stat.total_payload_download());
+ }
+
+ int torrent::num_seeds() const
+ {
+ TORRENT_ASSERT(m_ses.is_network_thread());
+ INVARIANT_CHECK;
+
+ int ret = 0;
+ for (std::set<peer_connection*>::const_iterator i = m_connections.begin()
+ , end(m_connections.end()); i != end; ++i)
+ if ((*i)->is_seed()) ++ret;
+ return ret;
+ }
+
+ void torrent::tracker_request_error(tracker_request const& r
+ , int response_code, error_code const& ec, const std::string& msg
+ , int retry_interval)
+ {
+ TORRENT_ASSERT(m_ses.is_network_thread());
+
+ INVARIANT_CHECK;
+
+#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
+ debug_log("*** tracker error: (%d) %s %s", ec.value(), ec.message().c_str(), msg.c_str());
+#endif
+ if (r.kind == tracker_request::announce_request)
+ {
+ announce_entry* ae = find_tracker(r);
+ if (ae)
+ {
+ ae->failed(settings(), retry_interval);
+ ae->last_error = ec;
+ ae->message = msg;
+ int tracker_index = ae - &m_trackers[0];
+#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
+ debug_log("*** increment tracker fail count [%d]", ae->fails);
+#endif
+ deprioritize_tracker(tracker_index);
+ }
+ if (m_ses.m_alerts.should_post<tracker_error_alert>())
+ {
+ m_ses.m_alerts.post_alert(tracker_error_alert(get_handle()
+ , ae?ae->fails:0, response_code, r.url, ec, msg));
+ }
+ }
+ | ||
relevance 3 | src/utp_stream.cpp:412 | remove the read timeout concept. This should not be necessary |
remove the read timeout concept. This should not be necessarysrc/utp_stream.cpp:412 // these are the callbacks made into the utp_stream object
// on read/write/connect events
utp_stream::handler_t m_read_handler;
utp_stream::handler_t m_write_handler;
@@ -199,7 +358,7 @@ more primitive platformssrc/alert.cpp:370 ptime m_read_timeout;
- | ||
relevance 3 | src/utp_stream.cpp:415 | remove the write timeout concept. This should not be necessary |
remove the write timeout concept. This should not be necessarysrc/utp_stream.cpp:415 // these are the callbacks made into the utp_stream object
+ | ||
relevance 3 | src/utp_stream.cpp:415 | remove the write timeout concept. This should not be necessary |
remove the write timeout concept. This should not be necessarysrc/utp_stream.cpp:415 // these are the callbacks made into the utp_stream object
// on read/write/connect events
utp_stream::handler_t m_read_handler;
utp_stream::handler_t m_write_handler;
@@ -250,7 +409,7 @@ more primitive platformssrc/alert.cpp:370src/kademlia/rpc_manager.cpp:36 | remove this dependency by having the dht observer have its own flags | |
remove this dependency by having the dht observer
+ | ||
relevance 3 | src/kademlia/rpc_manager.cpp:36 | remove this dependency by having the dht observer have its own flags |
remove this dependency by having the dht observer
have its own flagssrc/kademlia/rpc_manager.cpp:36 contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
@@ -302,7 +461,58 @@ namespace io = libtorrent::detail;
#ifdef TORRENT_DHT_VERBOSE_LOGGING
TORRENT_DEFINE_LOG(rpc)
- | ||
relevance 3 | include/libtorrent/kademlia/find_data.hpp:60 | rename this class to find_peers, since that's what it does find_data is an unnecessarily generic name |
rename this class to find_peers, since that's what it does
+ | ||
relevance 3 | include/libtorrent/kademlia/dht_tracker.hpp:79 | take a udp_socket_interface here instead. Move udp_socket_interface down into libtorrent core |
take a udp_socket_interface here instead. Move udp_socket_interface down into libtorrent coreinclude/libtorrent/kademlia/dht_tracker.hpp:79 struct lazy_entry;
+}
+
+namespace libtorrent { namespace dht
+{
+
+#ifdef TORRENT_DHT_VERBOSE_LOGGING
+ TORRENT_DECLARE_LOG(dht_tracker);
+#endif
+
+ struct dht_tracker;
+
+ TORRENT_EXTRA_EXPORT void intrusive_ptr_add_ref(dht_tracker const*);
+ TORRENT_EXTRA_EXPORT void intrusive_ptr_release(dht_tracker const*);
+
+ struct dht_tracker : udp_socket_interface, udp_socket_observer
+ {
+ friend void intrusive_ptr_add_ref(dht_tracker const*);
+ friend void intrusive_ptr_release(dht_tracker const*);
+
+ dht_tracker(libtorrent::aux::session_impl& ses, rate_limited_udp_socket& sock
+ , dht_settings const& settings, entry const* state = 0);
+ virtual ~dht_tracker();
+
+ void start(entry const& bootstrap);
+ void stop();
+
+ void add_node(udp::endpoint node);
+ void add_node(std::pair<std::string, int> const& node);
+ void add_router_node(udp::endpoint const& node);
+
+ entry state() const;
+
+ void announce(sha1_hash const& ih, int listen_port, bool seed
+ , boost::function<void(std::vector<tcp::endpoint> const&)> f);
+
+ void dht_status(session_status& s);
+ void network_stats(int& sent, int& received);
+
+ // translate bittorrent kademlia message into the generic kademlia message
+ // used by the library
+ virtual bool incoming_packet(error_code const& ec
+ , udp::endpoint const&, char const* buf, int size);
+
+ private:
+
+ boost::intrusive_ptr<dht_tracker> self()
+ { return boost::intrusive_ptr<dht_tracker>(this); }
+
+ void on_name_lookup(error_code const& e
+ , udp::resolver::iterator host);
+ | ||
relevance 3 | include/libtorrent/kademlia/find_data.hpp:60 | rename this class to find_peers, since that's what it does find_data is an unnecessarily generic name |
rename this class to find_peers, since that's what it does
find_data is an unnecessarily generic nameinclude/libtorrent/kademlia/find_data.hpp:60#include <libtorrent/kademlia/node_id.hpp>
#include <libtorrent/kademlia/routing_table.hpp>
#include <libtorrent/kademlia/rpc_manager.hpp>
@@ -354,7 +564,58 @@ private:
nodes_callback m_nodes_callback;
std::map<node_id, std::string> m_write_tokens;
node_id const m_target;
- | ||
relevance 2 | src/torrent.cpp:5790 | pass in ec along with the alert |
pass in ec along with the alertsrc/torrent.cpp:5790
+ | ||
relevance 2 | src/session_impl.cpp:5113 | if we still can't find the torrent, we should probably look for it by url here |
if we still can't find the torrent, we should probably look for it by url heresrc/session_impl.cpp:5113 }
+ }
+#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
+ else
+ {
+ session_log("metadata info-hash failed");
+ }
+#endif
+ }
+#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
+ else
+ {
+ session_log("no metadata found");
+ }
+#endif
+ }
+
+ // is the torrent already active?
+ boost::shared_ptr<torrent> torrent_ptr = find_torrent(*ih).lock();
+ if (!torrent_ptr && !params.uuid.empty()) torrent_ptr = find_torrent(params.uuid).lock();
+
+ if (torrent_ptr)
+ {
+ if ((params.flags & add_torrent_params::flag_duplicate_is_error) == 0)
+ {
+ if (!params.uuid.empty() && torrent_ptr->uuid().empty())
+ torrent_ptr->set_uuid(params.uuid);
+ if (!params.url.empty() && torrent_ptr->url().empty())
+ torrent_ptr->set_url(params.url);
+ if (!params.source_feed_url.empty() && torrent_ptr->source_feed_url().empty())
+ torrent_ptr->set_source_feed_url(params.source_feed_url);
+ return torrent_handle(torrent_ptr);
+ }
+
+ ec = errors::duplicate_torrent;
+ return torrent_handle();
+ }
+
+ int queue_pos = 0;
+ for (torrent_map::const_iterator i = m_torrents.begin()
+ , end(m_torrents.end()); i != end; ++i)
+ {
+ int pos = i->second->queue_position();
+ if (pos >= queue_pos) queue_pos = pos + 1;
+ }
+
+ torrent_ptr.reset(new torrent(*this, m_listen_interface
+ , 16 * 1024, queue_pos, params, *ih));
+ torrent_ptr->start();
+
+#ifndef TORRENT_DISABLE_EXTENSIONS
+ | ||
relevance 2 | src/torrent.cpp:5789 | pass in ec along with the alert |
pass in ec along with the alertsrc/torrent.cpp:5789
if (info_hash != m_torrent_file->info_hash())
{
if (alerts().should_post<metadata_failed_alert>())
@@ -405,7 +666,7 @@ private:
{
std::set<peer_connection*>::iterator p = i++;
(*p)->disconnect_if_redundant();
- | ||
relevance 2 | src/utp_stream.cpp:617 | support the option to turn it off |
support the option to turn it offsrc/utp_stream.cpp:617 UTP_STATE_ERROR_WAIT,
+ | ||
relevance 2 | src/utp_stream.cpp:617 | support the option to turn it off |
support the option to turn it offsrc/utp_stream.cpp:617 UTP_STATE_ERROR_WAIT,
// there are no more references to this socket
// and we can delete it
@@ -456,7 +717,155 @@ private:
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
int socket_impl_size() { return sizeof(utp_socket_impl); }
#endif
- | ||
relevance 2 | include/libtorrent/torrent.hpp:1038 | this should be a deque, since time critical pieces are expected to be popped in the same order as they are sorted. The expectation is that new items are pushed back and items are popped from the front |
this should be a deque, since time critical
+ | ||
relevance 2 | src/utp_stream.cpp:1846 | we might want to do something else here as well, to resend the packet immediately without it being an MTU probe |
we might want to do something else here
+as well, to resend the packet immediately without
+it being an MTU probesrc/utp_stream.cpp:1846 , boost::uint32_t(h->timestamp_difference_microseconds), int(p->mtu_probe)
+ , h->extension);
+#endif
+
+ error_code ec;
+#ifdef TORRENT_DEBUG
+ // simulate 1% packet loss
+// if ((rand() % 100) > 0)
+#endif
+ m_sm->send_packet(udp::endpoint(m_remote_address, m_port)
+ , (char const*)h, p->size, ec
+ , p->mtu_probe ? utp_socket_manager::dont_fragment : 0);
+
+ ++m_out_packets;
+
+ if (ec == error::message_size)
+ {
+ m_mtu_ceiling = p->size - 1;
+ if (m_mtu_floor > m_mtu_ceiling) m_mtu_floor = m_mtu_ceiling;
+ update_mtu_limits();
+ }
+ else if (ec == error::would_block || ec == error::try_again)
+ {
+#if TORRENT_UTP_LOG
+ UTP_LOGV("%8p: socket stalled\n", this);
+#endif
+ if (!m_stalled)
+ {
+ m_stalled = true;
+ m_sm->subscribe_writable(this);
+ }
+ }
+ else if (ec)
+ {
+ TORRENT_ASSERT(stack_alloced != bool(payload_size));
+ if (payload_size) free(p);
+ m_error = ec;
+ m_state = UTP_STATE_ERROR_WAIT;
+ test_socket_state();
+ return false;
+ }
+
+ if (!m_stalled)
+ ++p->num_transmissions;
+
+ // if we have payload, we need to save the packet until it's acked
+ // and progress m_seq_nr
+ if (p->size > p->header_size)
+ {
+ // if we're sending a payload packet, there should not
+ // be a nagle packet waiting for more data
+ | ||
relevance 2 | src/kademlia/dht_tracker.cpp:641 | fix this stats logging. For instance, the stats counters could be factored out into its own class, and dht_tracker could take an optional reference to it ++m_replies_sent[e["r"]]; m_replies_bytes_sent[e["r"]] += int(m_send_buf.size()); |
fix this stats logging. For instance,
+the stats counters could be factored out into its own
+class, and dht_tracker could take an optional reference to it
+++m_replies_sent[e["r"]];
+m_replies_bytes_sent[e["r"]] += int(m_send_buf.size());src/kademlia/dht_tracker.cpp:641#ifdef TORRENT_DHT_VERBOSE_LOGGING
+ std::stringstream log_line;
+ lazy_entry print;
+ int ret = lazy_bdecode(&m_send_buf[0], &m_send_buf[0] + m_send_buf.size(), print, ec);
+ TORRENT_ASSERT(ret == 0);
+ log_line << print_entry(print, true);
+#endif
+
+ if (m_sock.send(addr, &m_send_buf[0], (int)m_send_buf.size(), ec, send_flags))
+ {
+ if (ec) return false;
+
+ // account for IP and UDP overhead
+ m_sent_bytes += m_send_buf.size() + (addr.address().is_v6() ? 48 : 28);
+
+#ifdef TORRENT_DHT_VERBOSE_LOGGING
+ m_total_out_bytes += m_send_buf.size();
+
+ if (e["y"].string() == "r")
+ {
+ }
+ else if (e["y"].string() == "q")
+ {
+ m_queries_out_bytes += m_send_buf.size();
+ }
+ TORRENT_LOG(dht_tracker) << "==> " << addr << " " << log_line.str();
+#endif
+ return true;
+ }
+ else
+ {
+#ifdef TORRENT_DHT_VERBOSE_LOGGING
+ TORRENT_LOG(dht_tracker) << "==> " << addr << " DROPPED " << log_line.str();
+#endif
+ return false;
+ }
+ }
+
+}}
+
+ | ||
relevance 2 | src/kademlia/node.cpp:63 | make this configurable in dht_settings |
make this configurable in dht_settingssrc/kademlia/node.cpp:63#include "libtorrent/alert.hpp"
+#include "libtorrent/socket.hpp"
+#include "libtorrent/random.hpp"
+#include "libtorrent/aux_/session_impl.hpp"
+#include "libtorrent/kademlia/node_id.hpp"
+#include "libtorrent/kademlia/rpc_manager.hpp"
+#include "libtorrent/kademlia/routing_table.hpp"
+#include "libtorrent/kademlia/node.hpp"
+
+#include "libtorrent/kademlia/refresh.hpp"
+#include "libtorrent/kademlia/find_data.hpp"
+#include "libtorrent/rsa.hpp"
+
+namespace libtorrent { namespace dht
+{
+
+void incoming_error(entry& e, char const* msg);
+
+using detail::write_endpoint;
+
+enum { announce_interval = 30 };
+
+#ifdef TORRENT_DHT_VERBOSE_LOGGING
+TORRENT_DEFINE_LOG(node)
+#endif
+
+// remove peers that have timed out
+void purge_peers(std::set<peer_entry>& peers)
+{
+ for (std::set<peer_entry>::iterator i = peers.begin()
+ , end(peers.end()); i != end;)
+ {
+ // the peer has timed out
+ if (i->added + minutes(int(announce_interval * 1.5f)) < time_now())
+ {
+#ifdef TORRENT_DHT_VERBOSE_LOGGING
+ TORRENT_LOG(node) << "peer timed out at: " << i->addr;
+#endif
+ peers.erase(i++);
+ }
+ else
+ ++i;
+ }
+}
+
+void nop() {}
+
+node_impl::node_impl(alert_dispatcher* alert_disp
+ , udp_socket_interface* sock
+ , dht_settings const& settings, node_id nid, address const& external_address
+ , dht_observer* observer)
+ | ||
relevance 2 | include/libtorrent/torrent.hpp:1038 | this should be a deque, since time critical pieces are expected to be popped in the same order as they are sorted. The expectation is that new items are pushed back and items are popped from the front |
this should be a deque, since time critical
pieces are expected to be popped in the same order
as they are sorted. The expectation is that new items
are pushed back and items are popped from the frontinclude/libtorrent/torrent.hpp:1038
@@ -510,7 +919,58 @@ are pushed back and items are popped from the frontinclude/libtorrent/t
// each bit represents a piece. a set bit means
// the piece has had its hash verified. This
- | ||
relevance 2 | include/libtorrent/kademlia/node_entry.hpp:92 | replace with a union of address_v4 and address_v6 to not waste space. This struct is instantiated hundreds of times for the routing table |
replace with a union of address_v4 and address_v6
+ | ||
relevance 2 | include/libtorrent/torrent_info.hpp:450 | these strings (m_comment, m_created_by, m_ssl_root_cert) could be lazy_entry* to save memory |
these strings (m_comment, m_created_by, m_ssl_root_cert) could be lazy_entry* to save memoryinclude/libtorrent/torrent_info.hpp:450 std::vector<announce_entry> m_urls;
+ std::vector<web_seed_entry> m_web_seeds;
+ nodes_t m_nodes;
+
+ // if this is a merkle torrent, this is the merkle
+ // tree. It has space for merkle_num_nodes(merkle_num_leafs(num_pieces))
+ // hashes
+ std::vector<sha1_hash> m_merkle_tree;
+
+ // this is a copy of the info section from the torrent.
+ // it use maintained in this flat format in order to
+ // make it available through the metadata extension
+ boost::shared_array<char> m_info_section;
+
+ // this is a pointer into the m_info_section buffer
+ // pointing to the first byte of the first sha-1 hash
+ char const* m_piece_hashes;
+
+ // if a comment is found in the torrent file
+ // this will be set to that comment
+ std::string m_comment;
+
+ // an optional string naming the software used
+ // to create the torrent file
+ std::string m_created_by;
+
+#ifdef TORRENT_USE_OPENSSL
+ // for ssl-torrens, this contains the root
+ // certificate, in .pem format (i.e. ascii
+ // base64 encoded with head and tails)
+ std::string m_ssl_root_cert;
+#endif
+
+ // the info section parsed. points into m_info_section
+ // parsed lazily
+ mutable lazy_entry m_info_dict;
+
+ // if a creation date is found in the torrent file
+ // this will be set to that, otherwise it'll be
+ // 1970, Jan 1
+ time_t m_creation_date;
+
+ // the hash that identifies this torrent
+ sha1_hash m_info_hash;
+
+ // the number of bytes in m_info_section
+ boost::uint32_t m_info_section_size:24;
+
+ // this is used when creating a torrent. If there's
+ // only one file there are cases where it's impossible
+ // to know if it should be written as a multifile torrent
+ | ||
relevance 2 | include/libtorrent/kademlia/node_entry.hpp:92 | replace with a union of address_v4 and address_v6 to not waste space. This struct is instantiated hundreds of times for the routing table |
replace with a union of address_v4 and address_v6
to not waste space. This struct is instantiated hundreds of times
for the routing tableinclude/libtorrent/kademlia/node_entry.hpp:92 , id(0)
{
@@ -549,7 +1009,7 @@ for the routing tableinclude/libtorrent/kademlia/node_entry.hpp:92
#endif
- | ||
relevance 1 | src/http_seed_connection.cpp:120 | in chunked encoding mode, this assert won't hold. the chunk headers should be subtracted from the receive_buffer_size |
in chunked encoding mode, this assert won't hold.
+ | ||
relevance 1 | src/http_seed_connection.cpp:120 | in chunked encoding mode, this assert won't hold. the chunk headers should be subtracted from the receive_buffer_size |
in chunked encoding mode, this assert won't hold.
the chunk headers should be subtracted from the receive_buffer_sizesrc/http_seed_connection.cpp:120 boost::optional<piece_block_progress>
http_seed_connection::downloading_piece_progress() const
{
@@ -601,7 +1061,7 @@ the chunk headers should be subtracted from the receive_buffer_sizesrc/
std::string request;
request.reserve(400);
- | ||
relevance 1 | src/peer_connection.cpp:2488 | peers should really be corked/uncorked outside of all completed disk operations |
peers should really be corked/uncorked outside of
+ | ||
relevance 1 | src/peer_connection.cpp:2488 | peers should really be corked/uncorked outside of all completed disk operations |
peers should really be corked/uncorked outside of
all completed disk operationssrc/peer_connection.cpp:2488 }
if (is_disconnecting()) return;
@@ -653,1174 +1113,8 @@ all completed disk operationssrc/peer_connection.cpp:2488 | ||
relevance 1 | src/session_impl.cpp:6135 | we only need to do this if our global IPv4 address has changed since the DHT (currently) only supports IPv4. Since restarting the DHT is kind of expensive, it would be nice to not do it unnecessarily |
we only need to do this if our global IPv4 address has changed
-since the DHT (currently) only supports IPv4. Since restarting the DHT
-is kind of expensive, it would be nice to not do it unnecessarilysrc/session_impl.cpp:6135 void session_impl::set_external_address(address const& ip
- , int source_type, address const& source)
- {
-#if defined TORRENT_VERBOSE_LOGGING
- session_log(": set_external_address(%s, %d, %s)", print_address(ip).c_str()
- , source_type, print_address(source).c_str());
-#endif
-
- if (!m_external_ip.cast_vote(ip, source_type, source)) return;
-
-#if defined TORRENT_VERBOSE_LOGGING
- session_log(" external IP updated");
-#endif
-
- if (m_alerts.should_post<external_ip_alert>())
- m_alerts.post_alert(external_ip_alert(ip));
-
- // since we have a new external IP now, we need to
- // restart the DHT with a new node ID
-#ifndef TORRENT_DISABLE_DHT
- if (m_dht)
- {
- entry s = m_dht->state();
- int cur_state = 0;
- int prev_state = 0;
- entry* nodes1 = s.find_key("nodes");
- if (nodes1 && nodes1->type() == entry::list_t) cur_state = nodes1->list().size();
- entry* nodes2 = m_dht_state.find_key("nodes");
- if (nodes2 && nodes2->type() == entry::list_t) prev_state = nodes2->list().size();
- if (cur_state > prev_state) m_dht_state = s;
- start_dht(m_dht_state);
- }
-#endif
- }
-
- void session_impl::free_disk_buffer(char* buf)
- {
- m_disk_thread.free_buffer(buf);
- }
-
- char* session_impl::allocate_disk_buffer(char const* category)
- {
- return m_disk_thread.allocate_buffer(category);
- }
-
- char* session_impl::allocate_buffer()
- {
- TORRENT_ASSERT(is_network_thread());
-
-#ifdef TORRENT_DISK_STATS
- TORRENT_ASSERT(m_buffer_allocations >= 0);
- | ||
relevance 1 | src/torrent.cpp:5294 | save the send_stats state instead of throwing them away it may pose an issue when downgrading though |
save the send_stats state instead of throwing them away
-it may pose an issue when downgrading thoughsrc/torrent.cpp:5294 ? (1 << k) : 0;
- bitmask.append(1, v);
- TORRENT_ASSERT(bits == 8 || j == num_bitmask_bytes - 1);
- }
- piece_struct["bitmask"] = bitmask;
- // push the struct onto the unfinished-piece list
- up.push_back(piece_struct);
- }
- }
-
- // save trackers
- if (!m_trackers.empty())
- {
- entry::list_type& tr_list = ret["trackers"].list();
- tr_list.push_back(entry::list_type());
- int tier = 0;
- for (std::vector<announce_entry>::const_iterator i = m_trackers.begin()
- , end(m_trackers.end()); i != end; ++i)
- {
- // don't save trackers we can't trust
- if (i->send_stats == false) continue;
- if (i->tier == tier)
- {
- tr_list.back().list().push_back(i->url);
- }
- else
- {
- tr_list.push_back(entry::list_t);
- tr_list.back().list().push_back(i->url);
- tier = i->tier;
- }
- }
- }
-
- // save web seeds
- if (!m_web_seeds.empty())
- {
- entry::list_type& url_list = ret["url-list"].list();
- entry::list_type& httpseed_list = ret["httpseeds"].list();
- for (std::list<web_seed_entry>::const_iterator i = m_web_seeds.begin()
- , end(m_web_seeds.end()); i != end; ++i)
- {
- if (i->type == web_seed_entry::url_seed)
- url_list.push_back(i->url);
- else if (i->type == web_seed_entry::http_seed)
- httpseed_list.push_back(i->url);
- }
- }
-
- // write have bitmask
- // the pieces string has one byte per piece. Each
- | ||
relevance 0 | src/bt_peer_connection.cpp:660 | this could be optimized using knuth morris pratt |
this could be optimized using knuth morris prattsrc/bt_peer_connection.cpp:660 if (m_encrypted && m_rc4_encrypted)
- {
- fun = encrypt;
- userdata = m_enc_handler.get();
- }
-#endif
-
- peer_connection::send_buffer(buf, size, flags, fun, userdata);
- }
-
- int bt_peer_connection::get_syncoffset(char const* src, int src_size,
- char const* target, int target_size) const
- {
- TORRENT_ASSERT(target_size >= src_size);
- TORRENT_ASSERT(src_size > 0);
- TORRENT_ASSERT(src);
- TORRENT_ASSERT(target);
-
- int traverse_limit = target_size - src_size;
-
- for (int i = 0; i < traverse_limit; ++i)
- {
- char const* target_ptr = target + i;
- if (std::equal(src, src+src_size, target_ptr))
- return i;
- }
-
-// // Partial sync
-// for (int i = 0; i < target_size; ++i)
-// {
-// // first is iterator in src[] at which mismatch occurs
-// // second is iterator in target[] at which mismatch occurs
-// std::pair<const char*, const char*> ret;
-// int src_sync_size;
-// if (i > traverse_limit) // partial sync test
-// {
-// ret = std::mismatch(src, src + src_size - (i - traverse_limit), &target[i]);
-// src_sync_size = ret.first - src;
-// if (src_sync_size == (src_size - (i - traverse_limit)))
-// return i;
-// }
-// else // complete sync test
-// {
-// ret = std::mismatch(src, src + src_size, &target[i]);
-// src_sync_size = ret.first - src;
-// if (src_sync_size == src_size)
-// return i;
-// }
-// }
-
- // no complete sync
- | ||
relevance 0 | src/bt_peer_connection.cpp:1755 | don't trust this blindly |
don't trust this blindlysrc/bt_peer_connection.cpp:1755 // but where do we put that info?
-
- int last_seen_complete = boost::uint8_t(root.dict_find_int_value("complete_ago", -1));
- if (last_seen_complete >= 0) set_last_seen_complete(last_seen_complete);
-
- std::string client_info = root.dict_find_string_value("v");
- if (!client_info.empty()) m_client_version = client_info;
-
- int reqq = int(root.dict_find_int_value("reqq"));
- if (reqq > 0) m_max_out_request_queue = reqq;
-
- if (root.dict_find_int_value("upload_only", 0))
- set_upload_only(true);
-
- if (root.dict_find_int_value("share_mode", 0))
- set_share_mode(true);
-
- std::string myip = root.dict_find_string_value("yourip");
- if (!myip.empty())
- {
- if (myip.size() == address_v4::bytes_type().size())
- {
- address_v4::bytes_type bytes;
- std::copy(myip.begin(), myip.end(), bytes.begin());
- m_ses.set_external_address(address_v4(bytes)
- , aux::session_impl::source_peer, remote().address());
- }
-#if TORRENT_USE_IPV6
- else if (myip.size() == address_v6::bytes_type().size())
- {
- address_v6::bytes_type bytes;
- std::copy(myip.begin(), myip.end(), bytes.begin());
- address_v6 ipv6_address(bytes);
- if (ipv6_address.is_v4_mapped())
- m_ses.set_external_address(ipv6_address.to_v4()
- , aux::session_impl::source_peer, remote().address());
- else
- m_ses.set_external_address(ipv6_address
- , aux::session_impl::source_peer, remote().address());
- }
-#endif
- }
-
- // if we're finished and this peer is uploading only
- // disconnect it
- if (t->is_finished() && upload_only()
- && t->settings().close_redundant_connections
- && !t->share_mode())
- disconnect(errors::upload_upload_connection);
- }
-
- | ||
relevance 0 | src/bt_peer_connection.cpp:2069 | if we're finished, send upload_only message |
if we're finished, send upload_only messagesrc/bt_peer_connection.cpp:2069 if (msg[5 + k / 8] & (0x80 >> (k % 8))) bitfield_string[k] = '1';
- else bitfield_string[k] = '0';
- }
- peer_log("==> BITFIELD [ %s ]", bitfield_string.c_str());
-#endif
-#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
- m_sent_bitfield = true;
-#endif
-
- send_buffer(msg, packet_size);
-
- if (num_lazy_pieces > 0)
- {
- for (int i = 0; i < num_lazy_pieces; ++i)
- {
-#ifdef TORRENT_VERBOSE_LOGGING
- peer_log("==> HAVE [ piece: %d ]", lazy_pieces[i]);
-#endif
- write_have(lazy_pieces[i]);
- }
- }
-
- if (m_supports_fast)
- send_allowed_set();
- }
-
-#ifndef TORRENT_DISABLE_EXTENSIONS
- void bt_peer_connection::write_extensions()
- {
- INVARIANT_CHECK;
-
- TORRENT_ASSERT(m_supports_extensions);
- TORRENT_ASSERT(m_sent_handshake);
-
- entry handshake;
- entry::dictionary_type& m = handshake["m"].dict();
-
- // only send the port in case we bade the connection
- // on incoming connections the other end already knows
- // our listen port
- if (!m_ses.m_settings.anonymous_mode)
- {
- if (is_outgoing()) handshake["p"] = m_ses.listen_port();
- handshake["v"] = m_ses.settings().user_agent;
- }
-
- std::string remote_address;
- std::back_insert_iterator<std::string> out(remote_address);
- detail::write_address(remote().address(), out);
- handshake["yourip"] = remote_address;
- handshake["reqq"] = m_ses.settings().max_allowed_in_request_queue;
- | ||
relevance 0 | src/bt_peer_connection.cpp:3308 | move the erasing into the loop above remove all payload ranges that has been sent |
move the erasing into the loop above
-remove all payload ranges that has been sentsrc/bt_peer_connection.cpp:3308 for (std::vector<range>::iterator i = m_payloads.begin();
- i != m_payloads.end(); ++i)
- {
- i->start -= bytes_transferred;
- if (i->start < 0)
- {
- if (i->start + i->length <= 0)
- {
- amount_payload += i->length;
- }
- else
- {
- amount_payload += -i->start;
- i->length -= -i->start;
- i->start = 0;
- }
- }
- }
- }
-
- m_payloads.erase(
- std::remove_if(m_payloads.begin(), m_payloads.end(), range_below_zero)
- , m_payloads.end());
-
- TORRENT_ASSERT(amount_payload <= (int)bytes_transferred);
- m_statistics.sent_bytes(amount_payload, bytes_transferred - amount_payload);
-
- if (amount_payload > 0)
- {
- boost::shared_ptr<torrent> t = associated_torrent().lock();
- TORRENT_ASSERT(t);
- if (t) t->update_last_upload();
- }
- }
-
-#ifdef TORRENT_DEBUG
- void bt_peer_connection::check_invariant() const
- {
- boost::shared_ptr<torrent> t = associated_torrent().lock();
-
-#ifndef TORRENT_DISABLE_ENCRYPTION
- TORRENT_ASSERT( (bool(m_state != read_pe_dhkey) || m_dh_key_exchange.get())
- || !is_outgoing());
-
- TORRENT_ASSERT(!m_rc4_encrypted || m_enc_handler.get());
-#endif
- if (!in_handshake())
- {
- TORRENT_ASSERT(m_sent_handshake);
- }
-
- | ||
relevance 0 | src/file.cpp:1205 | is there any way to pre-fetch data from a file on windows? |
is there any way to pre-fetch data from a file on windows?src/file.cpp:1205
- void file::init_file()
- {
- if (m_page_size != 0) return;
-
- m_page_size = page_size();
- }
-
-#endif
-
- void file::hint_read(size_type file_offset, int len)
- {
-#if defined POSIX_FADV_WILLNEED
- posix_fadvise(m_fd, file_offset, len, POSIX_FADV_WILLNEED);
-#elif defined F_RDADVISE
- radvisory r;
- r.ra_offset = file_offset;
- r.ra_count = len;
- fcntl(m_fd, F_RDADVISE, &r);
-#else
-#endif
- }
-
- size_type file::readv(size_type file_offset, iovec_t const* bufs, int num_bufs, error_code& ec)
- {
-#ifdef TORRENT_WINDOWS
- if (m_file_handle == INVALID_HANDLE_VALUE)
- {
- ec = error_code(ERROR_INVALID_HANDLE, get_system_category());
- return -1;
- }
-#else
- if (m_fd == -1)
- {
- ec = error_code(EBADF, get_system_category());
- return -1;
- }
-#endif
- TORRENT_ASSERT((m_open_mode & rw_mask) == read_only || (m_open_mode & rw_mask) == read_write);
- TORRENT_ASSERT(bufs);
- TORRENT_ASSERT(num_bufs > 0);
- TORRENT_ASSERT(is_open());
-
-#if defined TORRENT_WINDOWS || defined TORRENT_LINUX || defined TORRENT_DEBUG
- // make sure m_page_size is initialized
- init_file();
-#endif
-
-#ifdef TORRENT_DEBUG
- if (m_open_mode & no_buffer)
- {
- | ||
relevance 0 | src/http_tracker_connection.cpp:99 | support authentication (i.e. user name and password) in the URL |
support authentication (i.e. user name and password) in the URLsrc/http_tracker_connection.cpp:99 , aux::session_impl const& ses
- , proxy_settings const& ps
- , std::string const& auth
-#if TORRENT_USE_I2P
- , i2p_connection* i2p_conn
-#endif
- )
- : tracker_connection(man, req, ios, c)
- , m_man(man)
- , m_ses(ses)
- , m_ps(ps)
- , m_cc(cc)
- , m_ios(ios)
-#if TORRENT_USE_I2P
- , m_i2p_conn(i2p_conn)
-#endif
- {}
-
- void http_tracker_connection::start()
- {
- std::string url = tracker_req().url;
-
- if (tracker_req().kind == tracker_request::scrape_request)
- {
- // find and replace "announce" with "scrape"
- // in request
-
- std::size_t pos = url.find("announce");
- if (pos == std::string::npos)
- {
- m_ios.post(boost::bind(&http_tracker_connection::fail_disp, self()
- , error_code(errors::scrape_not_available)));
- return;
- }
- url.replace(pos, 8, "scrape");
- }
-
-#if TORRENT_USE_I2P
- bool i2p = is_i2p_url(url);
-#else
- static const bool i2p = false;
-#endif
-
- session_settings const& settings = m_ses.settings();
-
- // if request-string already contains
- // some parameters, append an ampersand instead
- // of a question mark
- size_t arguments_start = url.find('?');
- if (arguments_start != std::string::npos)
- url += "&";
- | ||
relevance 0 | src/i2p_stream.cpp:172 | move this to proxy_base and use it in all proxies |
move this to proxy_base and use it in all proxiessrc/i2p_stream.cpp:172 {
- m_state = sam_idle;
-
- std::string name = m_sam_socket->name_lookup();
- if (!m_name_lookup.empty())
- {
- std::pair<std::string, name_lookup_handler>& nl = m_name_lookup.front();
- do_name_lookup(nl.first, nl.second);
- m_name_lookup.pop_front();
- }
-
- if (ec)
- {
- handler(ec, 0);
- return;
- }
-
- handler(ec, name.c_str());
- }
-
- bool i2p_stream::handle_error(error_code const& e, boost::shared_ptr<handler_type> const& h)
- {
- if (!e) return false;
-// fprintf(stderr, "i2p error \"%s\"\n", e.message().c_str());
- (*h)(e);
- error_code ec;
- close(ec);
- return true;
- }
-
- void i2p_stream::do_connect(error_code const& e, tcp::resolver::iterator i
- , boost::shared_ptr<handler_type> h)
- {
- if (e || i == tcp::resolver::iterator())
- {
- (*h)(e);
- error_code ec;
- close(ec);
- return;
- }
-
- m_sock.async_connect(i->endpoint(), boost::bind(
- &i2p_stream::connected, this, _1, h));
- }
-
- void i2p_stream::connected(error_code const& e, boost::shared_ptr<handler_type> h)
- {
- if (handle_error(e, h)) return;
-
- // send hello command
- m_state = read_hello_response;
- | ||
relevance 0 | src/packet_buffer.cpp:176 | use compare_less_wrap for this comparison as well |
use compare_less_wrap for this comparison as wellsrc/packet_buffer.cpp:176 while (new_size < size)
- new_size <<= 1;
-
- void** new_storage = (void**)malloc(sizeof(void*) * new_size);
-
- for (index_type i = 0; i < new_size; ++i)
- new_storage[i] = 0;
-
- for (index_type i = m_first; i < (m_first + m_capacity); ++i)
- new_storage[i & (new_size - 1)] = m_storage[i & (m_capacity - 1)];
-
- free(m_storage);
-
- m_storage = new_storage;
- m_capacity = new_size;
- }
-
- void* packet_buffer::remove(index_type idx)
- {
- INVARIANT_CHECK;
- if (idx >= m_first + m_capacity)
- return 0;
-
- if (compare_less_wrap(idx, m_first, 0xffff))
- return 0;
-
- const int mask = (m_capacity - 1);
- void* old_value = m_storage[idx & mask];
- m_storage[idx & mask] = 0;
-
- if (old_value)
- {
- --m_size;
- if (m_size == 0) m_last = m_first;
- }
-
- if (idx == m_first && m_size != 0)
- {
- ++m_first;
- for (boost::uint32_t i = 0; i < m_capacity; ++i, ++m_first)
- if (m_storage[m_first & mask]) break;
- m_first &= 0xffff;
- }
-
- if (((idx + 1) & 0xffff) == m_last && m_size != 0)
- {
- --m_last;
- for (boost::uint32_t i = 0; i < m_capacity; ++i, --m_last)
- if (m_storage[m_last & mask]) break;
- ++m_last;
- m_last &= 0xffff;
- | ||
relevance 0 | src/peer_connection.cpp:2651 | this might need something more so that once we have the metadata we can construct a full bitfield |
this might need something more
-so that once we have the metadata
-we can construct a full bitfieldsrc/peer_connection.cpp:2651
-#ifdef TORRENT_VERBOSE_LOGGING
- peer_log("*** THIS IS A SEED [ p: %p ]", m_peer_info);
-#endif
-
- t->get_policy().set_seed(m_peer_info, true);
- m_upload_only = true;
- m_bitfield_received = true;
-
- // if we don't have metadata yet
- // just remember the bitmask
- // don't update the piecepicker
- // (since it doesn't exist yet)
- if (!t->ready_for_connections())
- {
- // assume seeds are interesting when we
- // don't even have the metadata
- t->get_policy().peer_is_interesting(*this);
-
- disconnect_if_redundant();
- return;
- }
-
- TORRENT_ASSERT(!m_have_piece.empty());
- m_have_piece.set_all();
- m_num_pieces = m_have_piece.size();
-
- t->peer_has_all(this);
-
- // if we're finished, we're not interested
- if (t->is_upload_only()) send_not_interested();
- else t->get_policy().peer_is_interesting(*this);
-
- disconnect_if_redundant();
- }
-
- // -----------------------------
- // --------- HAVE NONE ---------
- // -----------------------------
-
- void peer_connection::incoming_have_none()
- {
- INVARIANT_CHECK;
-
-#ifdef TORRENT_VERBOSE_LOGGING
- peer_log("<== HAVE_NONE");
-#endif
-
- boost::shared_ptr<torrent> t = m_torrent.lock();
- TORRENT_ASSERT(t);
-
- | ||
relevance 0 | src/peer_connection.cpp:2782 | sort the allowed fast set in priority order |
sort the allowed fast set in priority ordersrc/peer_connection.cpp:2782 // this piece index later
- m_allowed_fast.push_back(index);
-
- // if the peer has the piece and we want
- // to download it, request it
- if (int(m_have_piece.size()) > index
- && m_have_piece[index]
- && t->valid_metadata()
- && t->has_picker()
- && t->picker().piece_priority(index) > 0)
- {
- t->get_policy().peer_is_interesting(*this);
- }
- }
-
- std::vector<int> const& peer_connection::allowed_fast()
- {
- boost::shared_ptr<torrent> t = m_torrent.lock();
- TORRENT_ASSERT(t);
-
- return m_allowed_fast;
- }
-
- bool peer_connection::can_request_time_critical() const
- {
- if (has_peer_choked() || !is_interesting()) return false;
- if ((int)m_download_queue.size() + (int)m_request_queue.size()
- > m_desired_queue_size * 2) return false;
- if (on_parole()) return false;
- if (m_disconnecting) return false;
- boost::shared_ptr<torrent> t = m_torrent.lock();
- TORRENT_ASSERT(t);
- if (t->upload_mode()) return false;
- return true;
- }
-
- void peer_connection::make_time_critical(piece_block const& block)
- {
- std::vector<pending_block>::iterator rit = std::find_if(m_request_queue.begin()
- , m_request_queue.end(), has_block(block));
- if (rit == m_request_queue.end()) return;
-#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
- boost::shared_ptr<torrent> t = m_torrent.lock();
- TORRENT_ASSERT(t);
- TORRENT_ASSERT(t->has_picker());
- TORRENT_ASSERT(t->picker().is_requested(block));
-#endif
- // ignore it if it's already time critical
- if (rit - m_request_queue.begin() < m_queued_time_critical) return;
- pending_block b = *rit;
- m_request_queue.erase(rit);
- | ||
relevance 0 | src/peer_connection.cpp:3892 | we should probably just send a HAVE_ALL here |
we should probably just send a HAVE_ALL heresrc/peer_connection.cpp:3892 std::fill(m_recv_buffer.begin() + m_recv_pos, m_recv_buffer.end(), 0);
-#endif
-
- m_packet_size = packet_size;
- }
-
- void peer_connection::superseed_piece(int replace_piece, int new_piece)
- {
- if (new_piece == -1)
- {
- if (m_superseed_piece[0] == -1) return;
- m_superseed_piece[0] = -1;
- m_superseed_piece[1] = -1;
-
-#ifdef TORRENT_VERBOSE_LOGGING
- peer_log("*** ending super seed mode");
-#endif
- boost::shared_ptr<torrent> t = m_torrent.lock();
- assert(t);
-
- for (int i = 0; i < int(m_have_piece.size()); ++i)
- {
- if (m_have_piece[i] || !t->have_piece(i)) continue;
-#ifdef TORRENT_VERBOSE_LOGGING
- peer_log("==> HAVE [ piece: %d] (ending super seed)", i);
-#endif
- write_have(i);
- }
-
- return;
- }
-
- assert(!has_piece(new_piece));
-
-#ifdef TORRENT_VERBOSE_LOGGING
- peer_log("==> HAVE [ piece: %d ] (super seed)", new_piece);
-#endif
- write_have(new_piece);
-
- if (replace_piece >= 0)
- {
- // move the piece we're replacing to the tail
- if (m_superseed_piece[0] == replace_piece)
- std::swap(m_superseed_piece[0], m_superseed_piece[1]);
- }
-
- m_superseed_piece[1] = m_superseed_piece[0];
- m_superseed_piece[0] = new_piece;
- }
-
- void peer_connection::update_desired_queue_size()
- | ||
relevance 0 | src/peer_connection.cpp:4475 | peers should really be corked/uncorked outside of all completed disk operations |
peers should really be corked/uncorked outside of
-all completed disk operationssrc/peer_connection.cpp:4475 // this means we're in seed mode and we haven't yet
- // verified this piece (r.piece)
- t->filesystem().async_read_and_hash(r, boost::bind(&peer_connection::on_disk_read_complete
- , self(), _1, _2, r), cache.second);
- t->verified(r.piece);
- }
-
- m_reading_bytes += r.length;
-
- m_requests.erase(m_requests.begin());
- sent_a_piece = true;
- }
-
- if (t->share_mode() && sent_a_piece)
- t->recalc_share_mode();
- }
-
- void peer_connection::on_disk_read_complete(int ret, disk_io_job const& j, peer_request r)
- {
- // flush send buffer at the end of this scope
- cork _c(*this);
-
-#ifdef TORRENT_STATS
- ++m_ses.m_num_messages[aux::session_impl::on_disk_read_counter];
-#endif
- TORRENT_ASSERT(m_ses.is_network_thread());
-
- m_reading_bytes -= r.length;
-
- disk_buffer_holder buffer(m_ses, j.buffer);
-#if TORRENT_DISK_STATS
- if (j.buffer) m_ses.m_disk_thread.rename_buffer(j.buffer, "received send buffer");
-#endif
-
- boost::shared_ptr<torrent> t = m_torrent.lock();
- if (!t)
- {
- disconnect(j.error);
- return;
- }
-
- if (ret != r.length)
- {
- if (ret == -3)
- {
-#if defined TORRENT_VERBOSE_LOGGING
- peer_log("==> REJECT_PIECE [ piece: %d s: %d l: %d ]"
- , r.piece , r.start , r.length);
-#endif
- write_reject_request(r);
- if (t->seed_mode()) t->leave_seed_mode(false);
- | ||
relevance 0 | src/policy.cpp:857 | only allow _one_ connection to use this override at a time |
only allow _one_ connection to use this
-override at a timesrc/policy.cpp:857 " external: " << external.external_address(m_peers[candidate]->address()) <<
- " t: " << (session_time - m_peers[candidate]->last_connected) <<
- " ]\n";
- }
-#endif
-
- if (candidate == -1) return m_peers.end();
- return m_peers.begin() + candidate;
- }
-
- bool policy::new_connection(peer_connection& c, int session_time)
- {
- TORRENT_ASSERT(!c.is_outgoing());
-
- INVARIANT_CHECK;
-
- // if the connection comes from the tracker,
- // it's probably just a NAT-check. Ignore the
- // num connections constraint then.
-
- error_code ec;
- TORRENT_ASSERT(c.remote() == c.get_socket()->remote_endpoint(ec) || ec);
- TORRENT_ASSERT(!m_torrent->is_paused());
-
-#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING
- if (c.remote().address() == m_torrent->current_tracker().address())
- {
- m_torrent->debug_log("overriding connection limit for tracker NAT-check");
- }
-#endif
-
- iterator iter;
- peer* i = 0;
-
- bool found = false;
- if (m_torrent->settings().allow_multiple_connections_per_ip)
- {
- tcp::endpoint remote = c.remote();
- std::pair<iterator, iterator> 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);
- found = true;
- }
- }
- else
- {
- iter = std::lower_bound(
- m_peers.begin(), m_peers.end()
- | ||
relevance 0 | src/policy.cpp:1889 | how do we deal with our external address changing? Pass in a force-update maybe? and keep a version number in policy |
how do we deal with our external address changing? Pass in a force-update maybe? and keep a version number in policysrc/policy.cpp:1889#endif
- , on_parole(false)
- , banned(false)
-#ifndef TORRENT_DISABLE_DHT
- , added_to_dht(false)
-#endif
- , supports_utp(true) // assume peers support utp
- , confirmed_supports_utp(false)
- , supports_holepunch(false)
- , web_seed(false)
-#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
- , in_use(false)
-#endif
- {
- TORRENT_ASSERT((src & 0xff) == src);
- }
-
- // TOOD: pass in both an IPv6 and IPv4 address here
- boost::uint32_t policy::peer::rank(external_ip const& external, int external_port) const
- {
- if (peer_rank == 0)
- peer_rank = peer_priority(
- tcp::endpoint(external.external_address(this->address()), external_port)
- , tcp::endpoint(this->address(), this->port));
- return peer_rank;
- }
-
- size_type policy::peer::total_download() const
- {
- if (connection != 0)
- {
- TORRENT_ASSERT(prev_amount_download == 0);
- return connection->statistics().total_payload_download();
- }
- else
- {
- return size_type(prev_amount_download) << 10;
- }
- }
-
- size_type policy::peer::total_upload() const
- {
- if (connection != 0)
- {
- TORRENT_ASSERT(prev_amount_upload == 0);
- return connection->statistics().total_payload_upload();
- }
- else
- {
- return size_type(prev_amount_upload) << 10;
- }
- | ||
relevance 0 | src/session_impl.cpp:1887 | recalculate all connect candidates for all torrents |
recalculate all connect candidates for all torrentssrc/session_impl.cpp:1887 m_upload_rate.close();
-
- // #error closing the udp socket here means that
- // the uTP connections cannot be closed gracefully
- m_udp_socket.close();
- m_external_udp_port = 0;
-
-#ifndef TORRENT_DISABLE_GEO_IP
- if (m_asnum_db) GeoIP_delete(m_asnum_db);
- if (m_country_db) GeoIP_delete(m_country_db);
- m_asnum_db = 0;
- m_country_db = 0;
-#endif
-
- m_disk_thread.abort();
- }
-
- void session_impl::set_port_filter(port_filter const& f)
- {
- m_port_filter = f;
- }
-
- void session_impl::set_ip_filter(ip_filter const& f)
- {
- INVARIANT_CHECK;
-
- m_ip_filter = f;
-
- // Close connections whose endpoint is filtered
- // by the new ip-filter
- for (torrent_map::iterator i = m_torrents.begin()
- , end(m_torrents.end()); i != end; ++i)
- i->second->ip_filter_updated();
- }
-
- ip_filter const& session_impl::get_ip_filter() const
- {
- return m_ip_filter;
- }
-
- void session_impl::update_disk_thread_settings()
- {
- disk_io_job j;
- j.buffer = (char*)new session_settings(m_settings);
- j.action = disk_io_job::update_settings;
- m_disk_thread.add_job(j);
- }
-
- void session_impl::set_settings(session_settings const& s)
- {
- INVARIANT_CHECK;
- | ||
relevance 0 | src/session_impl.cpp:4267 | allow extensions to sort torrents for queuing |
allow extensions to sort torrents for queuingsrc/session_impl.cpp:4267 else if (!t->is_paused())
- {
- TORRENT_ASSERT(t->m_resume_data_loaded || !t->valid_metadata());
- --hard_limit;
- if (is_active(t, settings()))
- {
- // this is not an auto managed torrent,
- // if it's running and active, decrease the
- // counters.
- if (t->is_finished())
- --num_seeds;
- else
- --num_downloaders;
- }
- }
- }
-
- bool handled_by_extension = false;
-
-#ifndef TORRENT_DISABLE_EXTENSIONS
-#endif
-
- if (!handled_by_extension)
- {
- std::sort(downloaders.begin(), downloaders.end()
- , boost::bind(&torrent::sequence_number, _1) < boost::bind(&torrent::sequence_number, _2));
-
- std::sort(seeds.begin(), seeds.end()
- , boost::bind(&torrent::seed_rank, _1, boost::ref(m_settings))
- > boost::bind(&torrent::seed_rank, _2, boost::ref(m_settings)));
- }
-
- if (settings().auto_manage_prefer_seeds)
- {
- auto_manage_torrents(seeds, dht_limit, tracker_limit, lsd_limit
- , hard_limit, num_seeds);
- auto_manage_torrents(downloaders, dht_limit, tracker_limit, lsd_limit
- , hard_limit, num_downloaders);
- }
- else
- {
- auto_manage_torrents(downloaders, dht_limit, tracker_limit, lsd_limit
- , hard_limit, num_downloaders);
- auto_manage_torrents(seeds, dht_limit, tracker_limit, lsd_limit
- , hard_limit, num_seeds);
- }
- }
-
- void session_impl::recalculate_optimistic_unchoke_slots()
- {
- TORRENT_ASSERT(is_network_thread());
- | ||
relevance 0 | src/session_impl.cpp:4423 | use a lower limit than m_settings.connections_limit to allocate the to 10% or so of connection slots for incoming connections |
use a lower limit than m_settings.connections_limit
-to allocate the to 10% or so of connection slots for incoming
-connectionssrc/session_impl.cpp:4423 {
- if (m_boost_connections > max_connections)
- {
- m_boost_connections -= max_connections;
- max_connections = 0;
- }
- else
- {
- max_connections -= m_boost_connections;
- m_boost_connections = 0;
- }
- }
-
- // this logic is here to smooth out the number of new connection
- // attempts over time, to prevent connecting a large number of
- // sockets, wait 10 seconds, and then try again
- int limit = (std::min)(m_settings.connections_limit - num_connections(), free_slots);
- if (m_settings.smooth_connects && max_connections > (limit+1) / 2)
- max_connections = (limit+1) / 2;
-
- if (!m_torrents.empty()
- && free_slots > -m_half_open.limit()
- && num_connections() < m_settings.connections_limit
- && !m_abort
- && m_settings.connection_speed > 0
- && max_connections > 0)
- {
- // this is the maximum number of connections we will
- // attempt this tick
- int average_peers = 0;
- if (num_downloads > 0)
- average_peers = num_downloads_peers / num_downloads;
-
- if (m_next_connect_torrent == m_torrents.end())
- m_next_connect_torrent = m_torrents.begin();
-
- int steps_since_last_connect = 0;
- int num_torrents = int(m_torrents.size());
- for (;;)
- {
- torrent& t = *m_next_connect_torrent->second;
- if (t.want_more_peers())
- {
- TORRENT_ASSERT(t.allows_peers());
- // have a bias to give more connection attempts
- // to downloading torrents than seed, and even
- // more to downloading torrents with less than
- // average number of connections
- int num_attempts = 1;
- if (!t.is_finished())
- {
- | ||
relevance 0 | src/session_impl.cpp:4457 | make this bias configurable |
make this bias configurablesrc/session_impl.cpp:4457 | ||
relevance 0 | src/session_impl.cpp:4458 | also take average_peers into account, to create a bias for downloading torrents with < average peers |
also take average_peers into account, to create a bias for downloading torrents with < average peerssrc/session_impl.cpp:4458 {
- if (m_boost_connections > max_connections)
- {
- m_boost_connections -= max_connections;
- max_connections = 0;
- }
- else
- {
- max_connections -= m_boost_connections;
- m_boost_connections = 0;
- }
- }
-
- // this logic is here to smooth out the number of new connection
- // attempts over time, to prevent connecting a large number of
- // sockets, wait 10 seconds, and then try again
- int limit = (std::min)(m_settings.connections_limit - num_connections(), free_slots);
- if (m_settings.smooth_connects && max_connections > (limit+1) / 2)
- max_connections = (limit+1) / 2;
-
- TORRENT_ASSERT(m_num_active_downloading > 0);
- num_attempts += m_num_active_finished / m_num_active_downloading;
- }
- while (m_current_connect_attempts < num_attempts)
- {
- TORRENT_TRY
- {
- ++m_current_connect_attempts;
- if (t.try_connect_peer())
- {
- --max_connections;
- --free_slots;
- steps_since_last_connect = 0;
-#ifdef TORRENT_STATS
- ++m_connection_attempts;
-#endif
- }
- }
- TORRENT_CATCH(std::bad_alloc&)
- {
- // we ran out of memory trying to connect to a peer
- // lower the global limit to the number of peers
- // we already have
- m_settings.connections_limit = num_connections();
- if (m_settings.connections_limit < 2) m_settings.connections_limit = 2;
- }
- if (!t.want_more_peers()) break;
- if (free_slots <= -m_half_open.limit()) return;
- if (max_connections == 0) return;
- if (num_connections() >= m_settings.connections_limit) return;
- }
- | ||
relevance 0 | src/session_impl.cpp:4602 | make configurable |
make configurablesrc/session_impl.cpp:4602
-#ifdef TORRENT_DEBUG
- for (std::vector<peer_connection*>::const_iterator i = peers.begin()
- , end(peers.end()), prev(peers.end()); i != end; ++i)
- {
- if (prev != end)
- {
- boost::shared_ptr<torrent> t1 = (*prev)->associated_torrent().lock();
- TORRENT_ASSERT(t1);
- boost::shared_ptr<torrent> t2 = (*i)->associated_torrent().lock();
- TORRENT_ASSERT(t2);
- TORRENT_ASSERT((*prev)->uploaded_since_unchoke() * 1000
- * (1 + t1->priority()) / total_milliseconds(unchoke_interval)
- >= (*i)->uploaded_since_unchoke() * 1000
- * (1 + t2->priority()) / total_milliseconds(unchoke_interval));
- }
- prev = i;
- }
-#endif
-
- int rate_threshold = 1024;
-
- for (std::vector<peer_connection*>::const_iterator i = peers.begin()
- , end(peers.end()); i != end; ++i)
- {
- peer_connection const& p = **i;
- int rate = int(p.uploaded_since_unchoke()
- * 1000 / total_milliseconds(unchoke_interval));
-
- if (rate < rate_threshold) break;
-
- ++m_allowed_upload_slots;
-
- | ||
relevance 0 | src/session_impl.cpp:4616 | make configurable |
make configurablesrc/session_impl.cpp:4616
-#ifdef TORRENT_DEBUG
- for (std::vector<peer_connection*>::const_iterator i = peers.begin()
- , end(peers.end()), prev(peers.end()); i != end; ++i)
- {
- if (prev != end)
- {
- boost::shared_ptr<torrent> t1 = (*prev)->associated_torrent().lock();
- TORRENT_ASSERT(t1);
- boost::shared_ptr<torrent> t2 = (*i)->associated_torrent().lock();
- TORRENT_ASSERT(t2);
- TORRENT_ASSERT((*prev)->uploaded_since_unchoke() * 1000
- * (1 + t1->priority()) / total_milliseconds(unchoke_interval)
- >= (*i)->uploaded_since_unchoke() * 1000
- * (1 + t2->priority()) / total_milliseconds(unchoke_interval));
- }
- prev = i;
- }
-#endif
-
- rate_threshold += 1024;
- }
- // allow one optimistic unchoke
- ++m_allowed_upload_slots;
- }
-
- if (m_settings.choking_algorithm == session_settings::bittyrant_choker)
- {
- // if we're using the bittyrant choker, sort peers by their return
- // on investment. i.e. download rate / upload rate
- std::sort(peers.begin(), peers.end()
- , boost::bind(&peer_connection::bittyrant_unchoke_compare, _1, _2));
- }
- else
- {
- // sorts the peers that are eligible for unchoke by download rate and secondary
- // by total upload. The reason for this is, if all torrents are being seeded,
- // the download rate will be 0, and the peers we have sent the least to should
- // be unchoked
- std::sort(peers.begin(), peers.end()
- , boost::bind(&peer_connection::unchoke_compare, _1, _2));
- }
-
- // auto unchoke
- int upload_limit = m_bandwidth_channel[peer_connection::upload_channel]->throttle();
- if (m_settings.choking_algorithm == session_settings::auto_expand_choker
- && upload_limit > 0)
- {
- // if our current upload rate is less than 90% of our
- // limit AND most torrents are not "congested", i.e.
- // they are not holding back because of a per-torrent
- | ||
relevance 0 | src/session_impl.cpp:5113 | find by url? |
find by url?src/session_impl.cpp:5113 }
- }
-#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
- else
- {
- session_log("metadata info-hash failed");
- }
-#endif
- }
-#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
- else
- {
- session_log("no metadata found");
- }
-#endif
- }
-
- // is the torrent already active?
- boost::shared_ptr<torrent> torrent_ptr = find_torrent(*ih).lock();
- if (!torrent_ptr && !params.uuid.empty()) torrent_ptr = find_torrent(params.uuid).lock();
-
- if (torrent_ptr)
- {
- if ((params.flags & add_torrent_params::flag_duplicate_is_error) == 0)
- {
- if (!params.uuid.empty() && torrent_ptr->uuid().empty())
- torrent_ptr->set_uuid(params.uuid);
- if (!params.url.empty() && torrent_ptr->url().empty())
- torrent_ptr->set_url(params.url);
- if (!params.source_feed_url.empty() && torrent_ptr->source_feed_url().empty())
- torrent_ptr->set_source_feed_url(params.source_feed_url);
- return torrent_handle(torrent_ptr);
- }
-
- ec = errors::duplicate_torrent;
- return torrent_handle();
- }
-
- int queue_pos = 0;
- for (torrent_map::const_iterator i = m_torrents.begin()
- , end(m_torrents.end()); i != end; ++i)
- {
- int pos = i->second->queue_position();
- if (pos >= queue_pos) queue_pos = pos + 1;
- }
-
- torrent_ptr.reset(new torrent(*this, m_listen_interface
- , 16 * 1024, queue_pos, params, *ih));
- torrent_ptr->start();
-
-#ifndef TORRENT_DISABLE_EXTENSIONS
- | ||
relevance 0 | src/session_impl.cpp:5469 | report the proper address of the router |
report the proper address of the routersrc/session_impl.cpp:5469 }
-
- void session_impl::on_port_mapping(int mapping, address const& ip, int port
+ | ||
relevance 1 | src/session_impl.cpp:5471 | report the proper address of the router as the source IP of this understanding of our external address, instead of the empty address |
report the proper address of the router as the source IP of
+this understanding of our external address, instead of the empty addresssrc/session_impl.cpp:5471 void session_impl::on_port_mapping(int mapping, address const& ip, int port
, error_code const& ec, int map_transport)
{
TORRENT_ASSERT(is_network_thread());
@@ -1838,8 +1132,10 @@ connectionssrc/session_impl.cpp:4423 if (ip != address()) set_external_address(ip, source_router
- , address());
+ if (ip != address())
+ {
+ set_external_address(ip, source_router, address());
+ }
if (!m_listen_sockets.empty()) {
m_listen_sockets.front().external_address = ip;
@@ -1869,7 +1165,7 @@ connectionssrc/session_impl.cpp:4423src/session_impl.cpp:5673 | report errors as alerts | |
report errors as alertssrc/session_impl.cpp:5673 }
+ | ||
relevance 1 | src/session_impl.cpp:5676 | report errors as alerts |
report errors as alertssrc/session_impl.cpp:5676 }
void session_impl::add_dht_router(std::pair<std::string, int> const& node)
{
@@ -1920,215 +1216,60 @@ connectionssrc/session_impl.cpp:4423src/storage.cpp:325 | if the read fails, set error and exit immediately | |
if the read fails, set error and exit immediatelysrc/storage.cpp:325 int block_size = 16 * 1024;
- if (m_storage->disk_pool()) block_size = m_storage->disk_pool()->block_size();
- int size = slot_size;
- int num_blocks = (size + block_size - 1) / block_size;
-
- // when we optimize for speed we allocate all the buffers we
- // need for the rest of the piece, and read it all in one call
- // and then hash it. When optimizing for memory usage, we read
- // one block at a time and hash it. This ends up only using a
- // single buffer
- if (m_storage->settings().optimize_hashing_for_speed)
- {
- file::iovec_t* bufs = TORRENT_ALLOCA(file::iovec_t, num_blocks);
- for (int i = 0; i < num_blocks; ++i)
- {
- bufs[i].iov_base = m_storage->disk_pool()->allocate_buffer("hash temp");
- bufs[i].iov_len = (std::min)(block_size, size);
- size -= bufs[i].iov_len;
- }
- num_read = m_storage->readv(bufs, slot, ph.offset, num_blocks);
-
- for (int i = 0; i < num_blocks; ++i)
- {
- if (small_hash && small_piece_size <= block_size)
- {
- ph.h.update((char const*)bufs[i].iov_base, small_piece_size);
- *small_hash = hasher(ph.h).final();
- small_hash = 0; // avoid this case again
- if (int(bufs[i].iov_len) > small_piece_size)
- ph.h.update((char const*)bufs[i].iov_base + small_piece_size
- , bufs[i].iov_len - small_piece_size);
- }
- else
- {
- ph.h.update((char const*)bufs[i].iov_base, bufs[i].iov_len);
- small_piece_size -= bufs[i].iov_len;
- }
- ph.offset += bufs[i].iov_len;
- m_storage->disk_pool()->free_buffer((char*)bufs[i].iov_base);
- }
- }
- else
- {
- file::iovec_t buf;
- disk_buffer_holder holder(*m_storage->disk_pool()
- , m_storage->disk_pool()->allocate_buffer("hash temp"));
- buf.iov_base = holder.get();
- for (int i = 0; i < num_blocks; ++i)
- {
- buf.iov_len = (std::min)(block_size, size);
- int ret = m_storage->readv(&buf, slot, ph.offset, 1);
- | ||
relevance 0 | src/storage.cpp:358 | if the read fails, set error and exit immediately |
if the read fails, set error and exit immediatelysrc/storage.cpp:358 if (m_storage->disk_pool()) block_size = m_storage->disk_pool()->block_size();
- int size = slot_size;
- int num_blocks = (size + block_size - 1) / block_size;
-
- // when we optimize for speed we allocate all the buffers we
- // need for the rest of the piece, and read it all in one call
- // and then hash it. When optimizing for memory usage, we read
- // one block at a time and hash it. This ends up only using a
- // single buffer
- if (m_storage->settings().optimize_hashing_for_speed)
- {
- file::iovec_t* bufs = TORRENT_ALLOCA(file::iovec_t, num_blocks);
- for (int i = 0; i < num_blocks; ++i)
- {
- bufs[i].iov_base = m_storage->disk_pool()->allocate_buffer("hash temp");
- bufs[i].iov_len = (std::min)(block_size, size);
- size -= bufs[i].iov_len;
- }
- num_read = m_storage->readv(bufs, slot, ph.offset, num_blocks);
- if (ret > 0) num_read += ret;
-
- if (small_hash && small_piece_size <= block_size)
- {
- if (small_piece_size > 0) ph.h.update((char const*)buf.iov_base, small_piece_size);
- *small_hash = hasher(ph.h).final();
- small_hash = 0; // avoid this case again
- if (int(buf.iov_len) > small_piece_size)
- ph.h.update((char const*)buf.iov_base + small_piece_size
- , buf.iov_len - small_piece_size);
- }
- else
- {
- ph.h.update((char const*)buf.iov_base, buf.iov_len);
- small_piece_size -= buf.iov_len;
- }
-
- ph.offset += buf.iov_len;
- size -= buf.iov_len;
- }
- }
- if (error()) return 0;
- }
- return num_read;
- }
-
- default_storage::default_storage(file_storage const& fs, file_storage const* mapped, std::string const& path
- , file_pool& fp, std::vector<boost::uint8_t> const& file_prio)
- : m_files(fs)
- , m_file_priority(file_prio)
- , m_pool(fp)
- , m_page_size(page_size())
- | ||
relevance 0 | src/storage.cpp:623 | make this more generic to not just work if files have been renamed, but also if they have been merged into a single file for instance maybe use the same format as .torrent files and reuse some code from torrent_info |
make this more generic to not just work if files have been
-renamed, but also if they have been merged into a single file for instance
-maybe use the same format as .torrent files and reuse some code from torrent_infosrc/storage.cpp:623 for (file_iter = files().begin();;)
- {
- if (file_offset < file_iter->size)
- break;
-
- file_offset -= file_iter->size;
- ++file_iter;
- TORRENT_ASSERT(file_iter != files().end());
- }
-
- error_code ec;
- boost::intrusive_ptr<file> file_handle = open_file(file_iter, file::read_only, ec);
- if (!file_handle || ec) return slot;
-
- size_type data_start = file_handle->sparse_end(file_offset);
- return int((data_start + m_files.piece_length() - 1) / m_files.piece_length());
- }
-
- bool default_storage::verify_resume_data(lazy_entry const& rd, error_code& error)
+ | ||
relevance 1 | src/session_impl.cpp:6138 | we only need to do this if our global IPv4 address has changed since the DHT (currently) only supports IPv4. Since restarting the DHT is kind of expensive, it would be nice to not do it unnecessarily |
we only need to do this if our global IPv4 address has changed
+since the DHT (currently) only supports IPv4. Since restarting the DHT
+is kind of expensive, it would be nice to not do it unnecessarilysrc/session_impl.cpp:6138 void session_impl::set_external_address(address const& ip
+ , int source_type, address const& source)
{
- lazy_entry const* mapped_files = rd.dict_find_list("mapped_files");
- if (mapped_files && mapped_files->list_size() == m_files.num_files())
- {
- m_mapped_files.reset(new file_storage(m_files));
- for (int i = 0; i < m_files.num_files(); ++i)
- {
- std::string new_filename = mapped_files->list_string_value_at(i);
- if (new_filename.empty()) continue;
- m_mapped_files->rename_file(i, new_filename);
- }
+#if defined TORRENT_VERBOSE_LOGGING
+ session_log(": set_external_address(%s, %d, %s)", print_address(ip).c_str()
+ , source_type, print_address(source).c_str());
+#endif
+
+ if (!m_external_ip.cast_vote(ip, source_type, source)) return;
+
+#if defined TORRENT_VERBOSE_LOGGING
+ session_log(" external IP updated");
+#endif
+
+ if (m_alerts.should_post<external_ip_alert>())
+ m_alerts.post_alert(external_ip_alert(ip));
+
+ // since we have a new external IP now, we need to
+ // restart the DHT with a new node ID
+#ifndef TORRENT_DISABLE_DHT
+ if (m_dht)
+ {
+ entry s = m_dht->state();
+ int cur_state = 0;
+ int prev_state = 0;
+ entry* nodes1 = s.find_key("nodes");
+ if (nodes1 && nodes1->type() == entry::list_t) cur_state = nodes1->list().size();
+ entry* nodes2 = m_dht_state.find_key("nodes");
+ if (nodes2 && nodes2->type() == entry::list_t) prev_state = nodes2->list().size();
+ if (cur_state > prev_state) m_dht_state = s;
+ start_dht(m_dht_state);
}
-
- lazy_entry const* file_priority = rd.dict_find_list("file_priority");
- if (file_priority && file_priority->list_size()
- == files().num_files())
- {
- m_file_priority.resize(file_priority->list_size());
- for (int i = 0; i < file_priority->list_size(); ++i)
- m_file_priority[i] = boost::uint8_t(file_priority->list_int_value_at(i, 1));
- }
-
- std::vector<std::pair<size_type, std::time_t> > file_sizes;
- lazy_entry const* file_sizes_ent = rd.dict_find_list("file sizes");
- if (file_sizes_ent == 0)
- {
- error = errors::missing_file_sizes;
- return false;
- }
-
- for (int i = 0; i < file_sizes_ent->list_size(); ++i)
- {
- | ||
relevance 0 | src/storage.cpp:1208 | what if file_base is used to merge several virtual files into a single physical file? We should probably disable this if file_base is used. This is not a widely used feature though |
what if file_base is used to merge several virtual files
-into a single physical file? We should probably disable this
-if file_base is used. This is not a widely used feature thoughsrc/storage.cpp:1208 int bytes_transferred = 0;
- // if the file is opened in no_buffer mode, and the
- // read is unaligned, we need to fall back on a slow
- // special read that reads aligned buffers and copies
- // it into the one supplied
- size_type adjusted_offset = files().file_base(*file_iter) + file_offset;
- if ((file_handle->open_mode() & file::no_buffer)
- && ((adjusted_offset & (file_handle->pos_alignment()-1)) != 0
- || (uintptr_t(tmp_bufs->iov_base) & (file_handle->buf_alignment()-1)) != 0))
- {
- bytes_transferred = (int)(this->*op.unaligned_op)(file_handle, adjusted_offset
- , tmp_bufs, num_tmp_bufs, ec);
- if (op.mode == file::read_write
- && adjusted_offset + bytes_transferred >= file_iter->size
- && (file_handle->pos_alignment() > 0 || file_handle->size_alignment() > 0))
- {
- // we were writing, and we just wrote the last block of the file
- // we likely wrote a bit too much, since we're restricted to
- // a specific alignment for writes. Make sure to truncate the size
-
- file_handle->set_size(file_iter->size, ec);
- }
- }
- else
- {
- bytes_transferred = (int)((*file_handle).*op.regular_op)(adjusted_offset
- , tmp_bufs, num_tmp_bufs, ec);
- TORRENT_ASSERT(bytes_transferred <= bufs_size(tmp_bufs, num_tmp_bufs));
- }
- file_offset = 0;
-
- if (ec)
- {
- set_error(combine_path(m_save_path, files().file_path(*file_iter)), ec);
- return -1;
- }
-
- if (file_bytes_left != bytes_transferred)
- return bytes_transferred;
-
- advance_bufs(current_buf, bytes_transferred);
- TORRENT_ASSERT(count_bufs(current_buf, bytes_left - file_bytes_left) <= num_bufs);
- }
- return size;
+#endif
}
- // these functions are inefficient, but should be fairly uncommon. The read
- // case happens if unaligned files are opened in no_buffer mode or if clients
- // makes unaligned requests (and the disk cache is disabled or fully utilized
- // for write cache).
+ void session_impl::free_disk_buffer(char* buf)
+ {
+ m_disk_thread.free_buffer(buf);
+ }
- | ||
relevance 0 | src/torrent.cpp:1112 | make this depend on the error and on the filesystem the files are being downloaded to. If the error is no_space_left_on_device and the filesystem doesn't support sparse files, only zero the priorities of the pieces that are at the tails of all files, leaving everything up to the highest written piece in each file |
make this depend on the error and on the filesystem the
+ char* session_impl::allocate_disk_buffer(char const* category)
+ {
+ return m_disk_thread.allocate_buffer(category);
+ }
+
+ char* session_impl::allocate_buffer()
+ {
+ TORRENT_ASSERT(is_network_thread());
+
+#ifdef TORRENT_DISK_STATS
+ TORRENT_ASSERT(m_buffer_allocations >= 0);
+ | ||
relevance 1 | src/torrent.cpp:1112 | make this depend on the error and on the filesystem the files are being downloaded to. If the error is no_space_left_on_device and the filesystem doesn't support sparse files, only zero the priorities of the pieces that are at the tails of all files, leaving everything up to the highest written piece in each file |
make this depend on the error and on the filesystem the
files are being downloaded to. If the error is no_space_left_on_device
and the filesystem doesn't support sparse files, only zero the priorities
of the pieces that are at the tails of all files, leaving everything
@@ -2183,278 +1324,60 @@ up to the highest written piece in each filesrc/torrent.cpp:1112 | ||
relevance 0 | src/torrent.cpp:1505 | filter out peers that are disconnecting |
filter out peers that are disconnectingsrc/torrent.cpp:1505 snprintf(filename, sizeof(filename), "/tmp/%d.pem", rand());
- FILE* f = fopen(filename, "w+");
- fwrite(cert.c_str(), cert.size(), 1, f);
- fclose(f);
- ctx->load_verify_file(filename);
-#endif
- // if all went well, set the torrent ssl context to this one
- m_ssl_ctx = ctx;
- // tell the client we need a cert for this torrent
- alerts().post_alert(torrent_need_cert_alert(get_handle()));
-#else
- set_error(asio::error::operation_not_supported, "x.509 certificate");
- pause();
-#endif
- }
-
-#endif // TORRENT_OPENSSL
-
- peer_connection* torrent::find_lowest_ranking_peer() const
- {
- const_peer_iterator lowest_rank = std::min_element(begin(), end()
- , boost::bind(&peer_connection::peer_rank, _1)
- < boost::bind(&peer_connection::peer_rank, _2));
-
- if (lowest_rank == end()) return NULL;
- return *lowest_rank;
- }
-
- // this may not be called from a constructor because of the call to
- // shared_from_this()
- void torrent::init()
- {
- TORRENT_ASSERT(m_ses.is_network_thread());
- TORRENT_ASSERT(m_torrent_file->is_valid());
- TORRENT_ASSERT(m_torrent_file->num_files() > 0);
- TORRENT_ASSERT(m_torrent_file->total_size() >= 0);
-
-#ifdef TORRENT_USE_OPENSSL
- std::string cert = m_torrent_file->ssl_cert();
- if (!cert.empty()) init_ssl(cert);
-#endif
-
- m_file_priority.resize(m_torrent_file->num_files(), 1);
- m_file_progress.resize(m_torrent_file->num_files(), 0);
-
- m_block_size_shift = root2((std::min)(int(block_size()), m_torrent_file->piece_length()));
-
- if (m_torrent_file->num_pieces() > piece_picker::max_pieces)
- {
- set_error(errors::too_many_pieces_in_torrent, "");
- pause();
- | ||
relevance 0 | src/torrent.cpp:2289 | this pattern is repeated in a few places. Factor this into a function and generalize the concept of a torrent having a dedicated listen port |
this pattern is repeated in a few places. Factor this into
-a function and generalize the concept of a torrent having a
-dedicated listen portsrc/torrent.cpp:2289 req.downloaded -= m_total_redundant_bytes;
- if (req.downloaded < 0) req.downloaded = 0;
-
- req.event = e;
- error_code ec;
- if (!m_ses.m_settings.anonymous_mode)
- {
- tcp::endpoint ep;
- ep = m_ses.get_ipv6_interface();
- if (ep != tcp::endpoint()) req.ipv6 = ep.address().to_string(ec);
- ep = m_ses.get_ipv4_interface();
- if (ep != tcp::endpoint()) req.ipv4 = ep.address().to_string(ec);
- }
-
- // if we are aborting. we don't want any new peers
- req.num_want = (req.event == tracker_request::stopped)
- ?0:settings().num_want;
-
- // SSL torrents use their own listen socket
-#ifdef TORRENT_USE_OPENSSL
- if (is_ssl_torrent()) req.listen_port = m_ses.ssl_listen_port();
- else
-#endif
- req.listen_port = m_ses.listen_port();
- req.key = m_ses.m_key;
-
- ptime now = time_now_hires();
-
- // the tier is kept as INT_MAX until we find the first
- // tracker that works, then it's set to that tracker's
- // tier.
- int tier = INT_MAX;
-
- // have we sent an announce in this tier yet?
- bool sent_announce = false;
-
- for (int i = 0; i < int(m_trackers.size()); ++i)
- {
- announce_entry& ae = m_trackers[i];
-#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
- char msg[1000];
- snprintf(msg, sizeof(msg), "*** announce with tracker: considering \"%s\" "
- "[ announce_to_all_tiers: %d announce_to_all_trackers: %d"
- " i->tier: %d tier: %d "
- " is_working: %d fails: %d fail_limit: %d updating: %d"
- " can_announce: %d sent_announce: %d ]"
- , ae.url.c_str(), settings().announce_to_all_tiers
- , settings().announce_to_all_trackers
- , ae.tier, tier, ae.is_working(), ae.fails, ae.fail_limit
- , ae.updating, ae.can_announce(now, is_seed()), sent_announce);
- debug_log(msg);
- | ||
relevance 0 | src/torrent.cpp:5028 | make this more generic to not just work if files have been renamed, but also if they have been merged into a single file for instance maybe use the same format as .torrent files and reuse some code from torrent_info The mapped_files needs to be read both in the network thread and in the disk thread, since they both have their own mapped files structures which are kept in sync |
make this more generic to not just work if files have been
-renamed, but also if they have been merged into a single file for instance
-maybe use the same format as .torrent files and reuse some code from torrent_info
-The mapped_files needs to be read both in the network thread
-and in the disk thread, since they both have their own mapped files structures
-which are kept in syncsrc/torrent.cpp:5028 if (m_seed_mode) m_verified.resize(m_torrent_file->num_pieces(), false);
- super_seeding(rd.dict_find_int_value("super_seeding", 0));
-
- m_last_scrape = rd.dict_find_int_value("last_scrape", 0);
- m_last_download = rd.dict_find_int_value("last_download", 0);
- m_last_upload = rd.dict_find_int_value("last_upload", 0);
-
- m_url = rd.dict_find_string_value("url");
- m_uuid = rd.dict_find_string_value("uuid");
- m_source_feed_url = rd.dict_find_string_value("feed");
-
- if (!m_uuid.empty() || !m_url.empty())
- {
- boost::shared_ptr<torrent> me(shared_from_this());
-
- // insert this torrent in the uuid index
- m_ses.m_uuids.insert(std::make_pair(m_uuid.empty()
- ? m_url : m_uuid, me));
- }
-
- lazy_entry const* mapped_files = rd.dict_find_list("mapped_files");
- if (mapped_files && mapped_files->list_size() == m_torrent_file->num_files())
- {
- for (int i = 0; i < m_torrent_file->num_files(); ++i)
- {
- std::string new_filename = mapped_files->list_string_value_at(i);
- if (new_filename.empty()) continue;
- m_torrent_file->rename_file(i, new_filename);
- }
- }
-
- m_added_time = rd.dict_find_int_value("added_time", m_added_time);
- m_completed_time = rd.dict_find_int_value("completed_time", m_completed_time);
- if (m_completed_time != 0 && m_completed_time < m_added_time)
- m_completed_time = m_added_time;
-
- lazy_entry const* file_priority = rd.dict_find_list("file_priority");
- if (file_priority && file_priority->list_size()
- == m_torrent_file->num_files())
- {
- for (int i = 0; i < file_priority->list_size(); ++i)
- m_file_priority[i] = file_priority->list_int_value_at(i, 1);
- update_piece_priorities();
- }
-
- lazy_entry const* piece_priority = rd.dict_find_string("piece_priority");
- if (piece_priority && piece_priority->string_length()
- == m_torrent_file->num_pieces())
- {
- char const* p = piece_priority->string_ptr();
- for (int i = 0; i < piece_priority->string_length(); ++i)
- | ||
relevance 0 | src/torrent.cpp:5164 | if this is a merkle torrent and we can't restore the tree, we need to wipe all the bits in the have array, but not necessarily we might want to do a full check to see if we have all the pieces |
if this is a merkle torrent and we can't
-restore the tree, we need to wipe all the
-bits in the have array, but not necessarily
-we might want to do a full check to see if we have
-all the piecessrc/torrent.cpp:5164 add_web_seed(url, web_seed_entry::http_seed);
+ | ||
relevance 1 | src/torrent.cpp:5292 | save the send_stats state instead of throwing them away it may pose an issue when downgrading though |
save the send_stats state instead of throwing them away
+it may pose an issue when downgrading thoughsrc/torrent.cpp:5292 ? (1 << k) : 0;
+ bitmask.append(1, v);
+ TORRENT_ASSERT(bits == 8 || j == num_bitmask_bytes - 1);
+ }
+ piece_struct["bitmask"] = bitmask;
+ // push the struct onto the unfinished-piece list
+ up.push_back(piece_struct);
}
}
- if (m_torrent_file->is_merkle_torrent())
+ // save trackers
+ if (!m_trackers.empty())
{
- lazy_entry const* mt = rd.dict_find_string("merkle tree");
- if (mt)
+ entry::list_type& tr_list = ret["trackers"].list();
+ tr_list.push_back(entry::list_type());
+ int tier = 0;
+ for (std::vector<announce_entry>::const_iterator i = m_trackers.begin()
+ , end(m_trackers.end()); i != end; ++i)
{
- std::vector<sha1_hash> tree;
- tree.resize(m_torrent_file->merkle_tree().size());
- std::memcpy(&tree[0], mt->string_ptr()
- , (std::min)(mt->string_length(), int(tree.size()) * 20));
- if (mt->string_length() < int(tree.size()) * 20)
- std::memset(&tree[0] + mt->string_length() / 20, 0
- , tree.size() - mt->string_length() / 20);
- m_torrent_file->set_merkle_tree(tree);
- }
- else
- {
- TORRENT_ASSERT(false);
- }
- }
- }
-
- boost::intrusive_ptr<torrent_info> torrent::get_torrent_copy()
- {
- if (!m_torrent_file->is_valid()) return boost::intrusive_ptr<torrent_info>();
-
- // copy the torrent_info object
- return boost::intrusive_ptr<torrent_info>(new torrent_info(*m_torrent_file));
- }
-
- void torrent::write_resume_data(entry& ret) const
- {
- using namespace libtorrent::detail; // for write_*_endpoint()
- ret["file-format"] = "libtorrent resume file";
- ret["file-version"] = 1;
- ret["libtorrent-version"] = LIBTORRENT_VERSION;
-
- ret["total_uploaded"] = m_total_uploaded;
- ret["total_downloaded"] = m_total_downloaded;
-
- ret["active_time"] = m_active_time;
- ret["finished_time"] = m_finished_time;
- ret["seeding_time"] = m_seeding_time;
- ret["last_seen_complete"] = m_last_seen_complete;
-
- ret["num_seeds"] = m_complete;
- ret["num_incomplete"] = m_incomplete;
- ret["num_downloaders"] = m_downloaders;
- | ||
relevance 0 | src/torrent.cpp:5351 | make this more generic to not just work if files have been renamed, but also if they have been merged into a single file for instance |
make this more generic to not just work if files have been
-renamed, but also if they have been merged into a single file for instancesrc/torrent.cpp:5351 entry::string_type& pieces = ret["pieces"].string();
- pieces.resize(m_torrent_file->num_pieces());
- if (is_seed())
- {
- std::memset(&pieces[0], 1, pieces.size());
- }
- else
- {
- for (int i = 0, end(pieces.size()); i < end; ++i)
- pieces[i] = m_picker->have_piece(i) ? 1 : 0;
- }
-
- if (m_seed_mode)
- {
- TORRENT_ASSERT(m_verified.size() == pieces.size());
- for (int i = 0, end(pieces.size()); i < end; ++i)
- pieces[i] |= m_verified[i] ? 2 : 0;
- }
-
- // write renamed files
- if (&m_torrent_file->files() != &m_torrent_file->orig_files()
- && m_torrent_file->files().num_files() == m_torrent_file->orig_files().num_files())
- {
- entry::list_type& fl = ret["mapped_files"].list();
- for (torrent_info::file_iterator i = m_torrent_file->begin_files()
- , end(m_torrent_file->end_files()); i != end; ++i)
- {
- fl.push_back(m_torrent_file->files().file_path(*i));
+ // don't save trackers we can't trust
+ if (i->send_stats == false) continue;
+ if (i->tier == tier)
+ {
+ tr_list.back().list().push_back(i->url);
+ }
+ else
+ {
+ tr_list.push_back(entry::list_t);
+ tr_list.back().list().push_back(i->url);
+ tier = i->tier;
+ }
}
}
- // write local peers
-
- std::back_insert_iterator<entry::string_type> peers(ret["peers"].string());
- std::back_insert_iterator<entry::string_type> banned_peers(ret["banned_peers"].string());
-#if TORRENT_USE_IPV6
- std::back_insert_iterator<entry::string_type> peers6(ret["peers6"].string());
- std::back_insert_iterator<entry::string_type> banned_peers6(ret["banned_peers6"].string());
-#endif
-
- // failcount is a 5 bit value
- int max_failcount = (std::min)(settings().max_failcount, 31);
-
- int num_saved_peers = 0;
-
- for (policy::const_iterator i = m_policy.begin_peer()
- , end(m_policy.end_peer()); i != end; ++i)
+ // save web seeds
+ if (!m_web_seeds.empty())
{
- error_code ec;
- policy::peer const* p = *i;
- address addr = p->address();
- | ||
relevance 0 | src/torrent.cpp:5928 | ideally, we would disconnect the oldest connection i.e. the one that has waited the longest to connect. |
ideally, we would disconnect the oldest connection
-i.e. the one that has waited the longest to connect.src/torrent.cpp:5928 return false;
+ entry::list_type& url_list = ret["url-list"].list();
+ entry::list_type& httpseed_list = ret["httpseeds"].list();
+ for (std::list<web_seed_entry>::const_iterator i = m_web_seeds.begin()
+ , end(m_web_seeds.end()); i != end; ++i)
+ {
+ if (i->type == web_seed_entry::url_seed)
+ url_list.push_back(i->url);
+ else if (i->type == web_seed_entry::http_seed)
+ httpseed_list.push_back(i->url);
+ }
}
- if (m_ses.is_aborted())
+ // write have bitmask
+ // the pieces string has one byte per piece. Each
+ | ||
relevance 1 | src/torrent.cpp:5930 | ideally, we would disconnect the oldest connection i.e. the one that has waited the longest to connect. |
ideally, we would disconnect the oldest connection
+i.e. the one that has waited the longest to connect.src/torrent.cpp:5930 if (m_ses.is_aborted())
{
p->disconnect(errors::session_closing);
return false;
@@ -2471,11 +1394,11 @@ i.e. the one that has waited the longest to connect.src/torrent.cpp:592
if (m_num_connecting > m_max_connections / 10)
{
// find one of the connecting peers and disconnect it
-
- // find any peer that's connecting (i.e. a half-open TCP connection)
+ // find any peer that's connecting (i.e. a half-open TCP connection)
// that's also not disconnecting
- std::set<peer_connection*>::iterator i = std::find_if(begin(), end()
- , boost::bind(&peer_connection::is_connecting, _1)
+
+ std::set<peer_connection*>::iterator i = std::find_if(begin(), end()
+ , boost::bind(&peer_connection::is_connecting, _1)
&& !boost::bind(&peer_connection::is_disconnecting, _1));
if (i == end())
@@ -2502,59 +1425,12 @@ i.e. the one that has waited the longest to connect.src/torrent.cpp:592
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
- | ||
relevance 0 | src/torrent.cpp:6005 | if peer is a really good peer, maybe we shouldn't disconnect it |
if peer is a really good peer, maybe we shouldn't disconnect itsrc/torrent.cpp:6005 return false;
- }
- TORRENT_ASSERT(m_connections.find(p) == m_connections.end());
- m_connections.insert(p);
-#ifdef TORRENT_DEBUG
- error_code ec;
- TORRENT_ASSERT(p->remote() == p->get_socket()->remote_endpoint(ec) || ec);
-#endif
-
- TORRENT_ASSERT(p->peer_info_struct() != NULL);
-
- // we need to do this after we've added the peer to the policy
- // since that's when the peer is assigned its peer_info object,
- // which holds the rank
- if (maybe_replace_peer)
- {
- // now, find the lowest rank peer and disconnect that
- // if it's lower rank than the incoming connection
- peer_connection* peer = find_lowest_ranking_peer();
-
- if (peer && peer->peer_rank() < p->peer_rank())
- {
- peer->disconnect(errors::too_many_connections);
- p->peer_disconnected_other();
- }
- else
{
- p->disconnect(errors::too_many_connections);
- // we have to do this here because from the peer's point of
- // it wasn't really attached to the torrent, but we do need
- // to let policy know we're removing it
- remove_peer(p);
- return false;
- }
- }
-
-#if defined TORRENT_DEBUG && !defined TORRENT_DISABLE_INVARIANT_CHECKS
- m_policy.check_invariant();
-#endif
-
- if (m_share_mode)
- recalc_share_mode();
-
- return true;
- }
-
- bool torrent::want_more_peers() const
- {
- return m_connections.size() < m_max_connections
- && !is_paused()
- && ((m_state != torrent_status::checking_files
- | ||
relevance 0 | src/torrent.cpp:6180 | should disconnect all peers that have the pieces we have not just seeds |
should disconnect all peers that have the pieces we have
-not just seedssrc/torrent.cpp:6180 }
+ boost::shared_ptr<peer_plugin> pp((*i)->new_connection(p));
+ if (pp) p->add_extension(pp);
+ | ||
relevance 1 | src/torrent.cpp:6179 | should disconnect all peers that have the pieces we have not just seeds. It would be pretty expensive to check all pieces for all peers though |
should disconnect all peers that have the pieces we have
+not just seeds. It would be pretty expensive to check all pieces
+for all peers thoughsrc/torrent.cpp:6179 }
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
m_finished_alert_posted = true;
#endif
@@ -2605,7 +1481,1712 @@ not just seedssrc/torrent.cpp:6180src/torrent.cpp:7820 | go through the pieces we have and count the total number of downloaders we have. Only count peers that are interested in us since some peers might not send have messages for pieces we have it num_interested == 0, we need to pick a new piece | |
go through the pieces we have and count the total number
+ | ||
relevance 1 | src/torrent_info.cpp:187 | we might save constructing a std::String if this would take a char const* instead |
we might save constructing a std::String if this would take a char const* insteadsrc/torrent_info.cpp:187 {
+ tmp_path += i[0];
+ tmp_path += i[1];
+ tmp_path += i[2];
+ tmp_path += i[3];
+ i += 3;
+ continue;
+ }
+
+ convert_to_utf8(tmp_path, *i);
+ valid_encoding = false;
+ }
+ // the encoding was not valid utf-8
+ // save the original encoding and replace the
+ // commonly used path with the correctly
+ // encoded string
+ if (!valid_encoding) target = tmp_path;
+ return valid_encoding;
+ }
+
+ bool valid_path_element(std::string const& element)
+ {
+ if (element.empty()
+ || element == "." || element == ".."
+ || element[0] == '/' || element[0] == '\\'
+ || element[element.size()-1] == ':')
+ return false;
+ return true;
+ }
+
+ void trim_path_element(std::string& path_element)
+ {
+ const int max_path_len = TORRENT_MAX_PATH;
+ if (int(path_element.size()) > max_path_len)
+ {
+ // truncate filenames that are too long. But keep extensions!
+ std::string ext = extension(path_element);
+ if (ext.size() > 15)
+ {
+ path_element.resize(max_path_len);
+ }
+ else
+ {
+ path_element.resize(max_path_len - ext.size());
+ path_element += ext;
+ }
+ }
+ }
+
+ TORRENT_EXTRA_EXPORT std::string sanitize_path(std::string const& p)
+ {
+ | ||
relevance 1 | src/torrent_info.cpp:366 | this logic should be a separate step done once the torrent is loaded, and the original filenames should be preserved! |
this logic should be a separate step
+done once the torrent is loaded, and the original
+filenames should be preserved!src/torrent_info.cpp:366 }
+ return false;
+ }
+ };
+
+ bool extract_files(lazy_entry const& list, file_storage& target
+ , std::string const& root_dir, ptrdiff_t info_ptr_diff)
+ {
+ if (list.type() != lazy_entry::list_t) return false;
+ target.reserve(list.list_size());
+ for (int i = 0, end(list.list_size()); i < end; ++i)
+ {
+ lazy_entry const* file_hash = 0;
+ time_t mtime = 0;
+ file_entry e;
+ lazy_entry const* fee = 0;
+ if (!extract_single_file(*list.list_at(i), e, root_dir
+ , &file_hash, &fee, &mtime))
+ return false;
+
+ int cnt = 0;
+ std::set<std::string, string_less_no_case> files;
+
+ // as long as this file already exists
+ // increase the counter
+ while (!files.insert(e.path).second)
+ {
+ ++cnt;
+ char suffix[50];
+ snprintf(suffix, sizeof(suffix), ".%d%s", cnt, extension(e.path).c_str());
+ replace_extension(e.path, suffix);
+ }
+ target.add_file(e, file_hash ? file_hash->string_ptr() + info_ptr_diff : 0);
+
+ // This is a memory optimization! Instead of having
+ // each entry keep a string for its filename, make it
+ // simply point into the info-section buffer
+ internal_file_entry const& fe = *target.rbegin();
+ | ||
relevance 1 | src/torrent_info.cpp:387 | once the filename renaming is removed from here this check can be removed as well |
once the filename renaming is removed from here
+this check can be removed as wellsrc/torrent_info.cpp:387 }
+ return false;
+ }
+ };
+
+ bool extract_files(lazy_entry const& list, file_storage& target
+ , std::string const& root_dir, ptrdiff_t info_ptr_diff)
+ {
+ if (list.type() != lazy_entry::list_t) return false;
+ target.reserve(list.list_size());
+ for (int i = 0, end(list.list_size()); i < end; ++i)
+ {
+ lazy_entry const* file_hash = 0;
+ time_t mtime = 0;
+ file_entry e;
+ lazy_entry const* fee = 0;
+ if (!extract_single_file(*list.list_at(i), e, root_dir
+ , &file_hash, &fee, &mtime))
+ return false;
+
+ if (fee && fe.filename() == fee->string_value())
+ {
+ // this string pointer does not necessarily point into
+ // the m_info_section buffer.
+ char const* str_ptr = fee->string_ptr() + info_ptr_diff;
+ const_cast<internal_file_entry&>(fe).set_name(str_ptr, fee->string_length());
+ }
+ }
+ return true;
+ }
+
+ int merkle_get_parent(int tree_node)
+ {
+ // node 0 doesn't have a parent
+ TORRENT_ASSERT(tree_node > 0);
+ return (tree_node - 1) / 2;
+ }
+
+ int merkle_get_sibling(int tree_node)
+ {
+ // node 0 doesn't have a sibling
+ TORRENT_ASSERT(tree_node > 0);
+ // even numbers have their sibling to the left
+ // odd numbers have their sibling to the right
+ return tree_node + (tree_node&1?1:-1);
+ }
+
+ int merkle_num_nodes(int leafs)
+ {
+ TORRENT_ASSERT(leafs > 0);
+ return (leafs << 1) - 1;
+ | ||
relevance 1 | src/kademlia/node.cpp:690 | find_node should write directly to the response entry |
find_node should write directly to the response entrysrc/kademlia/node.cpp:690 {
+ TORRENT_LOG(node) << " values: " << reply["values"].list().size();
+ }
+#endif
+ }
+ else if (strcmp(query, "find_node") == 0)
+ {
+ key_desc_t msg_desc[] = {
+ {"target", lazy_entry::string_t, 20, 0},
+ };
+
+ lazy_entry const* msg_keys[1];
+ if (!verify_message(arg_ent, msg_desc, msg_keys, 1, error_string, sizeof(error_string)))
+ {
+ incoming_error(e, error_string);
+ return;
+ }
+
+ sha1_hash target(msg_keys[0]->string_ptr());
+
+ nodes_t n;
+ m_table.find_node(target, n, 0);
+ write_nodes_entry(reply, n);
+ }
+ else if (strcmp(query, "announce_peer") == 0)
+ {
+#ifdef TORRENT_DHT_VERBOSE_LOGGING
+ extern int g_failed_announces;
+#endif
+ key_desc_t msg_desc[] = {
+ {"info_hash", lazy_entry::string_t, 20, 0},
+ {"port", lazy_entry::int_t, 0, 0},
+ {"token", lazy_entry::string_t, 0, 0},
+ {"n", lazy_entry::string_t, 0, key_desc_t::optional},
+ {"seed", lazy_entry::int_t, 0, key_desc_t::optional},
+ };
+
+ lazy_entry const* msg_keys[5];
+ if (!verify_message(arg_ent, msg_desc, msg_keys, 5, error_string, sizeof(error_string)))
+ {
+#ifdef TORRENT_DHT_VERBOSE_LOGGING
+ ++g_failed_announces;
+#endif
+ incoming_error(e, error_string);
+ return;
+ }
+
+ int port = int(msg_keys[1]->int_value());
+ if (port < 0 || port >= 65536)
+ {
+#ifdef TORRENT_DHT_VERBOSE_LOGGING
+ | ||
relevance 1 | include/libtorrent/ip_voter.hpp:100 | instead, have one instance per possible subnet, global IPv4, global IPv6, loopback, 192.168.x.x, 10.x.x.x, etc. |
instead, have one instance per possible subnet, global IPv4, global IPv6, loopback, 192.168.x.x, 10.x.x.x, etc.include/libtorrent/ip_voter.hpp:100 bloom_filter<32> m_external_address_voters;
+ std::vector<external_ip_t> m_external_addresses;
+ address m_external_address;
+ };
+
+ // this keeps track of multiple external IPs (for now, just IPv6 and IPv4, but
+ // it could be extended to deal with loopback and local network addresses as well)
+ struct TORRENT_EXTRA_EXPORT external_ip
+ {
+ // returns true if a different IP is the top vote now
+ // i.e. we changed our idea of what our external IP is
+ bool cast_vote(address const& ip, int source_type, address const& source);
+
+ // the external IP as it would be observed from `ip`
+ address external_address(address const& ip) const;
+
+ private:
+
+ // for now, assume one external IPv4 and one external IPv6 address
+ // 0 = IPv4 1 = IPv6
+ ip_voter m_vote_group[2];
+ };
+
+}
+
+#endif
+
+ | ||
relevance 1 | include/libtorrent/utp_stream.hpp:350 | implement blocking write. Low priority since it's not used (yet) |
implement blocking write. Low priority since it's not used (yet)include/libtorrent/utp_stream.hpp:350 for (typename Mutable_Buffers::const_iterator i = buffers.begin()
+ , end(buffers.end()); i != end; ++i)
+ {
+ using asio::buffer_cast;
+ using asio::buffer_size;
+ add_read_buffer(buffer_cast<void*>(*i), buffer_size(*i));
+#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
+ buf_size += buffer_size(*i);
+#endif
+ }
+ std::size_t ret = read_some(true);
+ TORRENT_ASSERT(ret <= buf_size);
+ TORRENT_ASSERT(ret > 0);
+ return ret;
+ }
+
+ template <class Const_Buffers>
+ std::size_t write_some(Const_Buffers const& buffers, error_code& ec)
+ {
+ TORRENT_ASSERT(false && "not implemented!");
+ return 0;
+ }
+
+#ifndef BOOST_NO_EXCEPTIONS
+ template <class Mutable_Buffers>
+ std::size_t read_some(Mutable_Buffers const& buffers)
+ {
+ error_code ec;
+ std::size_t ret = read_some(buffers, ec);
+ if (ec)
+ boost::throw_exception(boost::system::system_error(ec));
+ return ret;
+ }
+
+ template <class Const_Buffers>
+ std::size_t write_some(Const_Buffers const& buffers)
+ {
+ error_code ec;
+ std::size_t ret = write_some(buffers, ec);
+ if (ec)
+ boost::throw_exception(boost::system::system_error(ec));
+ return ret;
+ }
+#endif
+
+ template <class Const_Buffers, class Handler>
+ void async_write_some(Const_Buffers const& buffers, Handler const& handler)
+ {
+ if (m_impl == 0)
+ {
+ m_io_service.post(boost::bind<void>(handler, asio::error::not_connected, 0));
+ | ||
relevance 1 | include/libtorrent/web_peer_connection.hpp:127 | if we make this be a disk_buffer_holder instead we would save a copy sometimes use allocate_disk_receive_buffer and release_disk_receive_buffer |
if we make this be a disk_buffer_holder instead
+we would save a copy sometimes
+use allocate_disk_receive_buffer and release_disk_receive_bufferinclude/libtorrent/web_peer_connection.hpp:127
+ private:
+
+ bool maybe_harvest_block();
+
+ // returns the block currently being
+ // downloaded. And the progress of that
+ // block. If the peer isn't downloading
+ // a piece for the moment, the boost::optional
+ // will be invalid.
+ boost::optional<piece_block_progress> downloading_piece_progress() const;
+
+ // this has one entry per http-request
+ // (might be more than the bt requests)
+ std::deque<int> m_file_requests;
+
+ std::string m_url;
+
+ // this is used for intermediate storage of pieces
+ // that are received in more than one HTTP response
+ std::vector<char> m_piece;
+
+ // the number of bytes received in the current HTTP
+ // response. used to know where in the buffer the
+ // next response starts
+ size_type m_received_body;
+
+ // position in the current range response
+ size_type m_range_pos;
+
+ // the position in the current block
+ int m_block_pos;
+
+ // this is the offset inside the current receive
+ // buffer where the next chunk header will be.
+ // this is updated for each chunk header that's
+ // parsed. It does not necessarily point to a valid
+ // offset in the receive buffer, if we haven't received
+ // it yet. This offset never includes the HTTP header
+ size_type m_chunk_pos;
+
+ // this is the number of bytes we've already received
+ // from the next chunk header we're waiting for
+ int m_partial_chunk_header;
+ };
+}
+
+#endif // TORRENT_WEB_PEER_CONNECTION_HPP_INCLUDED
+
+ | ||
relevance 0 | src/bt_peer_connection.cpp:660 | this could be optimized using knuth morris pratt |
this could be optimized using knuth morris prattsrc/bt_peer_connection.cpp:660 if (m_encrypted && m_rc4_encrypted)
+ {
+ fun = encrypt;
+ userdata = m_enc_handler.get();
+ }
+#endif
+
+ peer_connection::send_buffer(buf, size, flags, fun, userdata);
+ }
+
+ int bt_peer_connection::get_syncoffset(char const* src, int src_size,
+ char const* target, int target_size) const
+ {
+ TORRENT_ASSERT(target_size >= src_size);
+ TORRENT_ASSERT(src_size > 0);
+ TORRENT_ASSERT(src);
+ TORRENT_ASSERT(target);
+
+ int traverse_limit = target_size - src_size;
+
+ for (int i = 0; i < traverse_limit; ++i)
+ {
+ char const* target_ptr = target + i;
+ if (std::equal(src, src+src_size, target_ptr))
+ return i;
+ }
+
+// // Partial sync
+// for (int i = 0; i < target_size; ++i)
+// {
+// // first is iterator in src[] at which mismatch occurs
+// // second is iterator in target[] at which mismatch occurs
+// std::pair<const char*, const char*> ret;
+// int src_sync_size;
+// if (i > traverse_limit) // partial sync test
+// {
+// ret = std::mismatch(src, src + src_size - (i - traverse_limit), &target[i]);
+// src_sync_size = ret.first - src;
+// if (src_sync_size == (src_size - (i - traverse_limit)))
+// return i;
+// }
+// else // complete sync test
+// {
+// ret = std::mismatch(src, src + src_size, &target[i]);
+// src_sync_size = ret.first - src;
+// if (src_sync_size == src_size)
+// return i;
+// }
+// }
+
+ // no complete sync
+ | ||
relevance 0 | src/bt_peer_connection.cpp:1755 | don't trust this blindly |
don't trust this blindlysrc/bt_peer_connection.cpp:1755 // but where do we put that info?
+
+ int last_seen_complete = boost::uint8_t(root.dict_find_int_value("complete_ago", -1));
+ if (last_seen_complete >= 0) set_last_seen_complete(last_seen_complete);
+
+ std::string client_info = root.dict_find_string_value("v");
+ if (!client_info.empty()) m_client_version = client_info;
+
+ int reqq = int(root.dict_find_int_value("reqq"));
+ if (reqq > 0) m_max_out_request_queue = reqq;
+
+ if (root.dict_find_int_value("upload_only", 0))
+ set_upload_only(true);
+
+ if (root.dict_find_int_value("share_mode", 0))
+ set_share_mode(true);
+
+ std::string myip = root.dict_find_string_value("yourip");
+ if (!myip.empty())
+ {
+ if (myip.size() == address_v4::bytes_type().size())
+ {
+ address_v4::bytes_type bytes;
+ std::copy(myip.begin(), myip.end(), bytes.begin());
+ m_ses.set_external_address(address_v4(bytes)
+ , aux::session_impl::source_peer, remote().address());
+ }
+#if TORRENT_USE_IPV6
+ else if (myip.size() == address_v6::bytes_type().size())
+ {
+ address_v6::bytes_type bytes;
+ std::copy(myip.begin(), myip.end(), bytes.begin());
+ address_v6 ipv6_address(bytes);
+ if (ipv6_address.is_v4_mapped())
+ m_ses.set_external_address(ipv6_address.to_v4()
+ , aux::session_impl::source_peer, remote().address());
+ else
+ m_ses.set_external_address(ipv6_address
+ , aux::session_impl::source_peer, remote().address());
+ }
+#endif
+ }
+
+ // if we're finished and this peer is uploading only
+ // disconnect it
+ if (t->is_finished() && upload_only()
+ && t->settings().close_redundant_connections
+ && !t->share_mode())
+ disconnect(errors::upload_upload_connection);
+ }
+
+ | ||
relevance 0 | src/bt_peer_connection.cpp:2069 | if we're finished, send upload_only message |
if we're finished, send upload_only messagesrc/bt_peer_connection.cpp:2069 if (msg[5 + k / 8] & (0x80 >> (k % 8))) bitfield_string[k] = '1';
+ else bitfield_string[k] = '0';
+ }
+ peer_log("==> BITFIELD [ %s ]", bitfield_string.c_str());
+#endif
+#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
+ m_sent_bitfield = true;
+#endif
+
+ send_buffer(msg, packet_size);
+
+ if (num_lazy_pieces > 0)
+ {
+ for (int i = 0; i < num_lazy_pieces; ++i)
+ {
+#ifdef TORRENT_VERBOSE_LOGGING
+ peer_log("==> HAVE [ piece: %d ]", lazy_pieces[i]);
+#endif
+ write_have(lazy_pieces[i]);
+ }
+ }
+
+ if (m_supports_fast)
+ send_allowed_set();
+ }
+
+#ifndef TORRENT_DISABLE_EXTENSIONS
+ void bt_peer_connection::write_extensions()
+ {
+ INVARIANT_CHECK;
+
+ TORRENT_ASSERT(m_supports_extensions);
+ TORRENT_ASSERT(m_sent_handshake);
+
+ entry handshake;
+ entry::dictionary_type& m = handshake["m"].dict();
+
+ // only send the port in case we bade the connection
+ // on incoming connections the other end already knows
+ // our listen port
+ if (!m_ses.m_settings.anonymous_mode)
+ {
+ if (is_outgoing()) handshake["p"] = m_ses.listen_port();
+ handshake["v"] = m_ses.settings().user_agent;
+ }
+
+ std::string remote_address;
+ std::back_insert_iterator<std::string> out(remote_address);
+ detail::write_address(remote().address(), out);
+ handshake["yourip"] = remote_address;
+ handshake["reqq"] = m_ses.settings().max_allowed_in_request_queue;
+ | ||
relevance 0 | src/bt_peer_connection.cpp:3308 | move the erasing into the loop above remove all payload ranges that has been sent |
move the erasing into the loop above
+remove all payload ranges that has been sentsrc/bt_peer_connection.cpp:3308 for (std::vector<range>::iterator i = m_payloads.begin();
+ i != m_payloads.end(); ++i)
+ {
+ i->start -= bytes_transferred;
+ if (i->start < 0)
+ {
+ if (i->start + i->length <= 0)
+ {
+ amount_payload += i->length;
+ }
+ else
+ {
+ amount_payload += -i->start;
+ i->length -= -i->start;
+ i->start = 0;
+ }
+ }
+ }
+ }
+
+ m_payloads.erase(
+ std::remove_if(m_payloads.begin(), m_payloads.end(), range_below_zero)
+ , m_payloads.end());
+
+ TORRENT_ASSERT(amount_payload <= (int)bytes_transferred);
+ m_statistics.sent_bytes(amount_payload, bytes_transferred - amount_payload);
+
+ if (amount_payload > 0)
+ {
+ boost::shared_ptr<torrent> t = associated_torrent().lock();
+ TORRENT_ASSERT(t);
+ if (t) t->update_last_upload();
+ }
+ }
+
+#ifdef TORRENT_DEBUG
+ void bt_peer_connection::check_invariant() const
+ {
+ boost::shared_ptr<torrent> t = associated_torrent().lock();
+
+#ifndef TORRENT_DISABLE_ENCRYPTION
+ TORRENT_ASSERT( (bool(m_state != read_pe_dhkey) || m_dh_key_exchange.get())
+ || !is_outgoing());
+
+ TORRENT_ASSERT(!m_rc4_encrypted || m_enc_handler.get());
+#endif
+ if (!in_handshake())
+ {
+ TORRENT_ASSERT(m_sent_handshake);
+ }
+
+ | ||
relevance 0 | src/file.cpp:1205 | is there any way to pre-fetch data from a file on windows? |
is there any way to pre-fetch data from a file on windows?src/file.cpp:1205
+ void file::init_file()
+ {
+ if (m_page_size != 0) return;
+
+ m_page_size = page_size();
+ }
+
+#endif
+
+ void file::hint_read(size_type file_offset, int len)
+ {
+#if defined POSIX_FADV_WILLNEED
+ posix_fadvise(m_fd, file_offset, len, POSIX_FADV_WILLNEED);
+#elif defined F_RDADVISE
+ radvisory r;
+ r.ra_offset = file_offset;
+ r.ra_count = len;
+ fcntl(m_fd, F_RDADVISE, &r);
+#else
+#endif
+ }
+
+ size_type file::readv(size_type file_offset, iovec_t const* bufs, int num_bufs, error_code& ec)
+ {
+#ifdef TORRENT_WINDOWS
+ if (m_file_handle == INVALID_HANDLE_VALUE)
+ {
+ ec = error_code(ERROR_INVALID_HANDLE, get_system_category());
+ return -1;
+ }
+#else
+ if (m_fd == -1)
+ {
+ ec = error_code(EBADF, get_system_category());
+ return -1;
+ }
+#endif
+ TORRENT_ASSERT((m_open_mode & rw_mask) == read_only || (m_open_mode & rw_mask) == read_write);
+ TORRENT_ASSERT(bufs);
+ TORRENT_ASSERT(num_bufs > 0);
+ TORRENT_ASSERT(is_open());
+
+#if defined TORRENT_WINDOWS || defined TORRENT_LINUX || defined TORRENT_DEBUG
+ // make sure m_page_size is initialized
+ init_file();
+#endif
+
+#ifdef TORRENT_DEBUG
+ if (m_open_mode & no_buffer)
+ {
+ | ||
relevance 0 | src/http_tracker_connection.cpp:99 | support authentication (i.e. user name and password) in the URL |
support authentication (i.e. user name and password) in the URLsrc/http_tracker_connection.cpp:99 , aux::session_impl const& ses
+ , proxy_settings const& ps
+ , std::string const& auth
+#if TORRENT_USE_I2P
+ , i2p_connection* i2p_conn
+#endif
+ )
+ : tracker_connection(man, req, ios, c)
+ , m_man(man)
+ , m_ses(ses)
+ , m_ps(ps)
+ , m_cc(cc)
+ , m_ios(ios)
+#if TORRENT_USE_I2P
+ , m_i2p_conn(i2p_conn)
+#endif
+ {}
+
+ void http_tracker_connection::start()
+ {
+ std::string url = tracker_req().url;
+
+ if (tracker_req().kind == tracker_request::scrape_request)
+ {
+ // find and replace "announce" with "scrape"
+ // in request
+
+ std::size_t pos = url.find("announce");
+ if (pos == std::string::npos)
+ {
+ m_ios.post(boost::bind(&http_tracker_connection::fail_disp, self()
+ , error_code(errors::scrape_not_available)));
+ return;
+ }
+ url.replace(pos, 8, "scrape");
+ }
+
+#if TORRENT_USE_I2P
+ bool i2p = is_i2p_url(url);
+#else
+ static const bool i2p = false;
+#endif
+
+ session_settings const& settings = m_ses.settings();
+
+ // if request-string already contains
+ // some parameters, append an ampersand instead
+ // of a question mark
+ size_t arguments_start = url.find('?');
+ if (arguments_start != std::string::npos)
+ url += "&";
+ | ||
relevance 0 | src/i2p_stream.cpp:172 | move this to proxy_base and use it in all proxies |
move this to proxy_base and use it in all proxiessrc/i2p_stream.cpp:172 {
+ m_state = sam_idle;
+
+ std::string name = m_sam_socket->name_lookup();
+ if (!m_name_lookup.empty())
+ {
+ std::pair<std::string, name_lookup_handler>& nl = m_name_lookup.front();
+ do_name_lookup(nl.first, nl.second);
+ m_name_lookup.pop_front();
+ }
+
+ if (ec)
+ {
+ handler(ec, 0);
+ return;
+ }
+
+ handler(ec, name.c_str());
+ }
+
+ bool i2p_stream::handle_error(error_code const& e, boost::shared_ptr<handler_type> const& h)
+ {
+ if (!e) return false;
+// fprintf(stderr, "i2p error \"%s\"\n", e.message().c_str());
+ (*h)(e);
+ error_code ec;
+ close(ec);
+ return true;
+ }
+
+ void i2p_stream::do_connect(error_code const& e, tcp::resolver::iterator i
+ , boost::shared_ptr<handler_type> h)
+ {
+ if (e || i == tcp::resolver::iterator())
+ {
+ (*h)(e);
+ error_code ec;
+ close(ec);
+ return;
+ }
+
+ m_sock.async_connect(i->endpoint(), boost::bind(
+ &i2p_stream::connected, this, _1, h));
+ }
+
+ void i2p_stream::connected(error_code const& e, boost::shared_ptr<handler_type> h)
+ {
+ if (handle_error(e, h)) return;
+
+ // send hello command
+ m_state = read_hello_response;
+ | ||
relevance 0 | src/packet_buffer.cpp:176 | use compare_less_wrap for this comparison as well |
use compare_less_wrap for this comparison as wellsrc/packet_buffer.cpp:176 while (new_size < size)
+ new_size <<= 1;
+
+ void** new_storage = (void**)malloc(sizeof(void*) * new_size);
+
+ for (index_type i = 0; i < new_size; ++i)
+ new_storage[i] = 0;
+
+ for (index_type i = m_first; i < (m_first + m_capacity); ++i)
+ new_storage[i & (new_size - 1)] = m_storage[i & (m_capacity - 1)];
+
+ free(m_storage);
+
+ m_storage = new_storage;
+ m_capacity = new_size;
+ }
+
+ void* packet_buffer::remove(index_type idx)
+ {
+ INVARIANT_CHECK;
+ if (idx >= m_first + m_capacity)
+ return 0;
+
+ if (compare_less_wrap(idx, m_first, 0xffff))
+ return 0;
+
+ const int mask = (m_capacity - 1);
+ void* old_value = m_storage[idx & mask];
+ m_storage[idx & mask] = 0;
+
+ if (old_value)
+ {
+ --m_size;
+ if (m_size == 0) m_last = m_first;
+ }
+
+ if (idx == m_first && m_size != 0)
+ {
+ ++m_first;
+ for (boost::uint32_t i = 0; i < m_capacity; ++i, ++m_first)
+ if (m_storage[m_first & mask]) break;
+ m_first &= 0xffff;
+ }
+
+ if (((idx + 1) & 0xffff) == m_last && m_size != 0)
+ {
+ --m_last;
+ for (boost::uint32_t i = 0; i < m_capacity; ++i, --m_last)
+ if (m_storage[m_last & mask]) break;
+ ++m_last;
+ m_last &= 0xffff;
+ | ||
relevance 0 | src/peer_connection.cpp:2651 | this might need something more so that once we have the metadata we can construct a full bitfield |
this might need something more
+so that once we have the metadata
+we can construct a full bitfieldsrc/peer_connection.cpp:2651
+#ifdef TORRENT_VERBOSE_LOGGING
+ peer_log("*** THIS IS A SEED [ p: %p ]", m_peer_info);
+#endif
+
+ t->get_policy().set_seed(m_peer_info, true);
+ m_upload_only = true;
+ m_bitfield_received = true;
+
+ // if we don't have metadata yet
+ // just remember the bitmask
+ // don't update the piecepicker
+ // (since it doesn't exist yet)
+ if (!t->ready_for_connections())
+ {
+ // assume seeds are interesting when we
+ // don't even have the metadata
+ t->get_policy().peer_is_interesting(*this);
+
+ disconnect_if_redundant();
+ return;
+ }
+
+ TORRENT_ASSERT(!m_have_piece.empty());
+ m_have_piece.set_all();
+ m_num_pieces = m_have_piece.size();
+
+ t->peer_has_all(this);
+
+ // if we're finished, we're not interested
+ if (t->is_upload_only()) send_not_interested();
+ else t->get_policy().peer_is_interesting(*this);
+
+ disconnect_if_redundant();
+ }
+
+ // -----------------------------
+ // --------- HAVE NONE ---------
+ // -----------------------------
+
+ void peer_connection::incoming_have_none()
+ {
+ INVARIANT_CHECK;
+
+#ifdef TORRENT_VERBOSE_LOGGING
+ peer_log("<== HAVE_NONE");
+#endif
+
+ boost::shared_ptr<torrent> t = m_torrent.lock();
+ TORRENT_ASSERT(t);
+
+ | ||
relevance 0 | src/peer_connection.cpp:2782 | sort the allowed fast set in priority order |
sort the allowed fast set in priority ordersrc/peer_connection.cpp:2782 // this piece index later
+ m_allowed_fast.push_back(index);
+
+ // if the peer has the piece and we want
+ // to download it, request it
+ if (int(m_have_piece.size()) > index
+ && m_have_piece[index]
+ && t->valid_metadata()
+ && t->has_picker()
+ && t->picker().piece_priority(index) > 0)
+ {
+ t->get_policy().peer_is_interesting(*this);
+ }
+ }
+
+ std::vector<int> const& peer_connection::allowed_fast()
+ {
+ boost::shared_ptr<torrent> t = m_torrent.lock();
+ TORRENT_ASSERT(t);
+
+ return m_allowed_fast;
+ }
+
+ bool peer_connection::can_request_time_critical() const
+ {
+ if (has_peer_choked() || !is_interesting()) return false;
+ if ((int)m_download_queue.size() + (int)m_request_queue.size()
+ > m_desired_queue_size * 2) return false;
+ if (on_parole()) return false;
+ if (m_disconnecting) return false;
+ boost::shared_ptr<torrent> t = m_torrent.lock();
+ TORRENT_ASSERT(t);
+ if (t->upload_mode()) return false;
+ return true;
+ }
+
+ void peer_connection::make_time_critical(piece_block const& block)
+ {
+ std::vector<pending_block>::iterator rit = std::find_if(m_request_queue.begin()
+ , m_request_queue.end(), has_block(block));
+ if (rit == m_request_queue.end()) return;
+#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
+ boost::shared_ptr<torrent> t = m_torrent.lock();
+ TORRENT_ASSERT(t);
+ TORRENT_ASSERT(t->has_picker());
+ TORRENT_ASSERT(t->picker().is_requested(block));
+#endif
+ // ignore it if it's already time critical
+ if (rit - m_request_queue.begin() < m_queued_time_critical) return;
+ pending_block b = *rit;
+ m_request_queue.erase(rit);
+ | ||
relevance 0 | src/peer_connection.cpp:3892 | we should probably just send a HAVE_ALL here |
we should probably just send a HAVE_ALL heresrc/peer_connection.cpp:3892 std::fill(m_recv_buffer.begin() + m_recv_pos, m_recv_buffer.end(), 0);
+#endif
+
+ m_packet_size = packet_size;
+ }
+
+ void peer_connection::superseed_piece(int replace_piece, int new_piece)
+ {
+ if (new_piece == -1)
+ {
+ if (m_superseed_piece[0] == -1) return;
+ m_superseed_piece[0] = -1;
+ m_superseed_piece[1] = -1;
+
+#ifdef TORRENT_VERBOSE_LOGGING
+ peer_log("*** ending super seed mode");
+#endif
+ boost::shared_ptr<torrent> t = m_torrent.lock();
+ assert(t);
+
+ for (int i = 0; i < int(m_have_piece.size()); ++i)
+ {
+ if (m_have_piece[i] || !t->have_piece(i)) continue;
+#ifdef TORRENT_VERBOSE_LOGGING
+ peer_log("==> HAVE [ piece: %d] (ending super seed)", i);
+#endif
+ write_have(i);
+ }
+
+ return;
+ }
+
+ assert(!has_piece(new_piece));
+
+#ifdef TORRENT_VERBOSE_LOGGING
+ peer_log("==> HAVE [ piece: %d ] (super seed)", new_piece);
+#endif
+ write_have(new_piece);
+
+ if (replace_piece >= 0)
+ {
+ // move the piece we're replacing to the tail
+ if (m_superseed_piece[0] == replace_piece)
+ std::swap(m_superseed_piece[0], m_superseed_piece[1]);
+ }
+
+ m_superseed_piece[1] = m_superseed_piece[0];
+ m_superseed_piece[0] = new_piece;
+ }
+
+ void peer_connection::update_desired_queue_size()
+ | ||
relevance 0 | src/peer_connection.cpp:4475 | peers should really be corked/uncorked outside of all completed disk operations |
peers should really be corked/uncorked outside of
+all completed disk operationssrc/peer_connection.cpp:4475 // this means we're in seed mode and we haven't yet
+ // verified this piece (r.piece)
+ t->filesystem().async_read_and_hash(r, boost::bind(&peer_connection::on_disk_read_complete
+ , self(), _1, _2, r), cache.second);
+ t->verified(r.piece);
+ }
+
+ m_reading_bytes += r.length;
+
+ m_requests.erase(m_requests.begin());
+ sent_a_piece = true;
+ }
+
+ if (t->share_mode() && sent_a_piece)
+ t->recalc_share_mode();
+ }
+
+ void peer_connection::on_disk_read_complete(int ret, disk_io_job const& j, peer_request r)
+ {
+ // flush send buffer at the end of this scope
+ cork _c(*this);
+
+#ifdef TORRENT_STATS
+ ++m_ses.m_num_messages[aux::session_impl::on_disk_read_counter];
+#endif
+ TORRENT_ASSERT(m_ses.is_network_thread());
+
+ m_reading_bytes -= r.length;
+
+ disk_buffer_holder buffer(m_ses, j.buffer);
+#if TORRENT_DISK_STATS
+ if (j.buffer) m_ses.m_disk_thread.rename_buffer(j.buffer, "received send buffer");
+#endif
+
+ boost::shared_ptr<torrent> t = m_torrent.lock();
+ if (!t)
+ {
+ disconnect(j.error);
+ return;
+ }
+
+ if (ret != r.length)
+ {
+ if (ret == -3)
+ {
+#if defined TORRENT_VERBOSE_LOGGING
+ peer_log("==> REJECT_PIECE [ piece: %d s: %d l: %d ]"
+ , r.piece , r.start , r.length);
+#endif
+ write_reject_request(r);
+ if (t->seed_mode()) t->leave_seed_mode(false);
+ | ||
relevance 0 | src/policy.cpp:857 | only allow _one_ connection to use this override at a time |
only allow _one_ connection to use this
+override at a timesrc/policy.cpp:857 " external: " << external.external_address(m_peers[candidate]->address()) <<
+ " t: " << (session_time - m_peers[candidate]->last_connected) <<
+ " ]\n";
+ }
+#endif
+
+ if (candidate == -1) return m_peers.end();
+ return m_peers.begin() + candidate;
+ }
+
+ bool policy::new_connection(peer_connection& c, int session_time)
+ {
+ TORRENT_ASSERT(!c.is_outgoing());
+
+ INVARIANT_CHECK;
+
+ // if the connection comes from the tracker,
+ // it's probably just a NAT-check. Ignore the
+ // num connections constraint then.
+
+ error_code ec;
+ TORRENT_ASSERT(c.remote() == c.get_socket()->remote_endpoint(ec) || ec);
+ TORRENT_ASSERT(!m_torrent->is_paused());
+
+#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING
+ if (c.remote().address() == m_torrent->current_tracker().address())
+ {
+ m_torrent->debug_log("overriding connection limit for tracker NAT-check");
+ }
+#endif
+
+ iterator iter;
+ peer* i = 0;
+
+ bool found = false;
+ if (m_torrent->settings().allow_multiple_connections_per_ip)
+ {
+ tcp::endpoint remote = c.remote();
+ std::pair<iterator, iterator> 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);
+ found = true;
+ }
+ }
+ else
+ {
+ iter = std::lower_bound(
+ m_peers.begin(), m_peers.end()
+ | ||
relevance 0 | src/policy.cpp:1889 | how do we deal with our external address changing? Pass in a force-update maybe? and keep a version number in policy |
how do we deal with our external address changing? Pass in a force-update maybe? and keep a version number in policysrc/policy.cpp:1889#endif
+ , on_parole(false)
+ , banned(false)
+#ifndef TORRENT_DISABLE_DHT
+ , added_to_dht(false)
+#endif
+ , supports_utp(true) // assume peers support utp
+ , confirmed_supports_utp(false)
+ , supports_holepunch(false)
+ , web_seed(false)
+#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
+ , in_use(false)
+#endif
+ {
+ TORRENT_ASSERT((src & 0xff) == src);
+ }
+
+ // TOOD: pass in both an IPv6 and IPv4 address here
+ boost::uint32_t policy::peer::rank(external_ip const& external, int external_port) const
+ {
+ if (peer_rank == 0)
+ peer_rank = peer_priority(
+ tcp::endpoint(external.external_address(this->address()), external_port)
+ , tcp::endpoint(this->address(), this->port));
+ return peer_rank;
+ }
+
+ size_type policy::peer::total_download() const
+ {
+ if (connection != 0)
+ {
+ TORRENT_ASSERT(prev_amount_download == 0);
+ return connection->statistics().total_payload_download();
+ }
+ else
+ {
+ return size_type(prev_amount_download) << 10;
+ }
+ }
+
+ size_type policy::peer::total_upload() const
+ {
+ if (connection != 0)
+ {
+ TORRENT_ASSERT(prev_amount_upload == 0);
+ return connection->statistics().total_payload_upload();
+ }
+ else
+ {
+ return size_type(prev_amount_upload) << 10;
+ }
+ | ||
relevance 0 | src/session_impl.cpp:1887 | recalculate all connect candidates for all torrents |
recalculate all connect candidates for all torrentssrc/session_impl.cpp:1887 m_upload_rate.close();
+
+ // #error closing the udp socket here means that
+ // the uTP connections cannot be closed gracefully
+ m_udp_socket.close();
+ m_external_udp_port = 0;
+
+#ifndef TORRENT_DISABLE_GEO_IP
+ if (m_asnum_db) GeoIP_delete(m_asnum_db);
+ if (m_country_db) GeoIP_delete(m_country_db);
+ m_asnum_db = 0;
+ m_country_db = 0;
+#endif
+
+ m_disk_thread.abort();
+ }
+
+ void session_impl::set_port_filter(port_filter const& f)
+ {
+ m_port_filter = f;
+ }
+
+ void session_impl::set_ip_filter(ip_filter const& f)
+ {
+ INVARIANT_CHECK;
+
+ m_ip_filter = f;
+
+ // Close connections whose endpoint is filtered
+ // by the new ip-filter
+ for (torrent_map::iterator i = m_torrents.begin()
+ , end(m_torrents.end()); i != end; ++i)
+ i->second->ip_filter_updated();
+ }
+
+ ip_filter const& session_impl::get_ip_filter() const
+ {
+ return m_ip_filter;
+ }
+
+ void session_impl::update_disk_thread_settings()
+ {
+ disk_io_job j;
+ j.buffer = (char*)new session_settings(m_settings);
+ j.action = disk_io_job::update_settings;
+ m_disk_thread.add_job(j);
+ }
+
+ void session_impl::set_settings(session_settings const& s)
+ {
+ INVARIANT_CHECK;
+ | ||
relevance 0 | src/session_impl.cpp:4267 | allow extensions to sort torrents for queuing |
allow extensions to sort torrents for queuingsrc/session_impl.cpp:4267 else if (!t->is_paused())
+ {
+ TORRENT_ASSERT(t->m_resume_data_loaded || !t->valid_metadata());
+ --hard_limit;
+ if (is_active(t, settings()))
+ {
+ // this is not an auto managed torrent,
+ // if it's running and active, decrease the
+ // counters.
+ if (t->is_finished())
+ --num_seeds;
+ else
+ --num_downloaders;
+ }
+ }
+ }
+
+ bool handled_by_extension = false;
+
+#ifndef TORRENT_DISABLE_EXTENSIONS
+#endif
+
+ if (!handled_by_extension)
+ {
+ std::sort(downloaders.begin(), downloaders.end()
+ , boost::bind(&torrent::sequence_number, _1) < boost::bind(&torrent::sequence_number, _2));
+
+ std::sort(seeds.begin(), seeds.end()
+ , boost::bind(&torrent::seed_rank, _1, boost::ref(m_settings))
+ > boost::bind(&torrent::seed_rank, _2, boost::ref(m_settings)));
+ }
+
+ if (settings().auto_manage_prefer_seeds)
+ {
+ auto_manage_torrents(seeds, dht_limit, tracker_limit, lsd_limit
+ , hard_limit, num_seeds);
+ auto_manage_torrents(downloaders, dht_limit, tracker_limit, lsd_limit
+ , hard_limit, num_downloaders);
+ }
+ else
+ {
+ auto_manage_torrents(downloaders, dht_limit, tracker_limit, lsd_limit
+ , hard_limit, num_downloaders);
+ auto_manage_torrents(seeds, dht_limit, tracker_limit, lsd_limit
+ , hard_limit, num_seeds);
+ }
+ }
+
+ void session_impl::recalculate_optimistic_unchoke_slots()
+ {
+ TORRENT_ASSERT(is_network_thread());
+ | ||
relevance 0 | src/session_impl.cpp:4423 | use a lower limit than m_settings.connections_limit to allocate the to 10% or so of connection slots for incoming connections |
use a lower limit than m_settings.connections_limit
+to allocate the to 10% or so of connection slots for incoming
+connectionssrc/session_impl.cpp:4423 {
+ if (m_boost_connections > max_connections)
+ {
+ m_boost_connections -= max_connections;
+ max_connections = 0;
+ }
+ else
+ {
+ max_connections -= m_boost_connections;
+ m_boost_connections = 0;
+ }
+ }
+
+ // this logic is here to smooth out the number of new connection
+ // attempts over time, to prevent connecting a large number of
+ // sockets, wait 10 seconds, and then try again
+ int limit = (std::min)(m_settings.connections_limit - num_connections(), free_slots);
+ if (m_settings.smooth_connects && max_connections > (limit+1) / 2)
+ max_connections = (limit+1) / 2;
+
+ if (!m_torrents.empty()
+ && free_slots > -m_half_open.limit()
+ && num_connections() < m_settings.connections_limit
+ && !m_abort
+ && m_settings.connection_speed > 0
+ && max_connections > 0)
+ {
+ // this is the maximum number of connections we will
+ // attempt this tick
+ int average_peers = 0;
+ if (num_downloads > 0)
+ average_peers = num_downloads_peers / num_downloads;
+
+ if (m_next_connect_torrent == m_torrents.end())
+ m_next_connect_torrent = m_torrents.begin();
+
+ int steps_since_last_connect = 0;
+ int num_torrents = int(m_torrents.size());
+ for (;;)
+ {
+ torrent& t = *m_next_connect_torrent->second;
+ if (t.want_more_peers())
+ {
+ TORRENT_ASSERT(t.allows_peers());
+ // have a bias to give more connection attempts
+ // to downloading torrents than seed, and even
+ // more to downloading torrents with less than
+ // average number of connections
+ int num_attempts = 1;
+ if (!t.is_finished())
+ {
+ | ||
relevance 0 | src/session_impl.cpp:4457 | make this bias configurable |
make this bias configurablesrc/session_impl.cpp:4457 | ||
relevance 0 | src/session_impl.cpp:4458 | also take average_peers into account, to create a bias for downloading torrents with < average peers |
also take average_peers into account, to create a bias for downloading torrents with < average peerssrc/session_impl.cpp:4458 {
+ if (m_boost_connections > max_connections)
+ {
+ m_boost_connections -= max_connections;
+ max_connections = 0;
+ }
+ else
+ {
+ max_connections -= m_boost_connections;
+ m_boost_connections = 0;
+ }
+ }
+
+ // this logic is here to smooth out the number of new connection
+ // attempts over time, to prevent connecting a large number of
+ // sockets, wait 10 seconds, and then try again
+ int limit = (std::min)(m_settings.connections_limit - num_connections(), free_slots);
+ if (m_settings.smooth_connects && max_connections > (limit+1) / 2)
+ max_connections = (limit+1) / 2;
+
+ TORRENT_ASSERT(m_num_active_downloading > 0);
+ num_attempts += m_num_active_finished / m_num_active_downloading;
+ }
+ while (m_current_connect_attempts < num_attempts)
+ {
+ TORRENT_TRY
+ {
+ ++m_current_connect_attempts;
+ if (t.try_connect_peer())
+ {
+ --max_connections;
+ --free_slots;
+ steps_since_last_connect = 0;
+#ifdef TORRENT_STATS
+ ++m_connection_attempts;
+#endif
+ }
+ }
+ TORRENT_CATCH(std::bad_alloc&)
+ {
+ // we ran out of memory trying to connect to a peer
+ // lower the global limit to the number of peers
+ // we already have
+ m_settings.connections_limit = num_connections();
+ if (m_settings.connections_limit < 2) m_settings.connections_limit = 2;
+ }
+ if (!t.want_more_peers()) break;
+ if (free_slots <= -m_half_open.limit()) return;
+ if (max_connections == 0) return;
+ if (num_connections() >= m_settings.connections_limit) return;
+ }
+ | ||
relevance 0 | src/session_impl.cpp:4602 | make configurable |
make configurablesrc/session_impl.cpp:4602
+#ifdef TORRENT_DEBUG
+ for (std::vector<peer_connection*>::const_iterator i = peers.begin()
+ , end(peers.end()), prev(peers.end()); i != end; ++i)
+ {
+ if (prev != end)
+ {
+ boost::shared_ptr<torrent> t1 = (*prev)->associated_torrent().lock();
+ TORRENT_ASSERT(t1);
+ boost::shared_ptr<torrent> t2 = (*i)->associated_torrent().lock();
+ TORRENT_ASSERT(t2);
+ TORRENT_ASSERT((*prev)->uploaded_since_unchoke() * 1000
+ * (1 + t1->priority()) / total_milliseconds(unchoke_interval)
+ >= (*i)->uploaded_since_unchoke() * 1000
+ * (1 + t2->priority()) / total_milliseconds(unchoke_interval));
+ }
+ prev = i;
+ }
+#endif
+
+ int rate_threshold = 1024;
+
+ for (std::vector<peer_connection*>::const_iterator i = peers.begin()
+ , end(peers.end()); i != end; ++i)
+ {
+ peer_connection const& p = **i;
+ int rate = int(p.uploaded_since_unchoke()
+ * 1000 / total_milliseconds(unchoke_interval));
+
+ if (rate < rate_threshold) break;
+
+ ++m_allowed_upload_slots;
+
+ | ||
relevance 0 | src/session_impl.cpp:4616 | make configurable |
make configurablesrc/session_impl.cpp:4616
+#ifdef TORRENT_DEBUG
+ for (std::vector<peer_connection*>::const_iterator i = peers.begin()
+ , end(peers.end()), prev(peers.end()); i != end; ++i)
+ {
+ if (prev != end)
+ {
+ boost::shared_ptr<torrent> t1 = (*prev)->associated_torrent().lock();
+ TORRENT_ASSERT(t1);
+ boost::shared_ptr<torrent> t2 = (*i)->associated_torrent().lock();
+ TORRENT_ASSERT(t2);
+ TORRENT_ASSERT((*prev)->uploaded_since_unchoke() * 1000
+ * (1 + t1->priority()) / total_milliseconds(unchoke_interval)
+ >= (*i)->uploaded_since_unchoke() * 1000
+ * (1 + t2->priority()) / total_milliseconds(unchoke_interval));
+ }
+ prev = i;
+ }
+#endif
+
+ rate_threshold += 1024;
+ }
+ // allow one optimistic unchoke
+ ++m_allowed_upload_slots;
+ }
+
+ if (m_settings.choking_algorithm == session_settings::bittyrant_choker)
+ {
+ // if we're using the bittyrant choker, sort peers by their return
+ // on investment. i.e. download rate / upload rate
+ std::sort(peers.begin(), peers.end()
+ , boost::bind(&peer_connection::bittyrant_unchoke_compare, _1, _2));
+ }
+ else
+ {
+ // sorts the peers that are eligible for unchoke by download rate and secondary
+ // by total upload. The reason for this is, if all torrents are being seeded,
+ // the download rate will be 0, and the peers we have sent the least to should
+ // be unchoked
+ std::sort(peers.begin(), peers.end()
+ , boost::bind(&peer_connection::unchoke_compare, _1, _2));
+ }
+
+ // auto unchoke
+ int upload_limit = m_bandwidth_channel[peer_connection::upload_channel]->throttle();
+ if (m_settings.choking_algorithm == session_settings::auto_expand_choker
+ && upload_limit > 0)
+ {
+ // if our current upload rate is less than 90% of our
+ // limit AND most torrents are not "congested", i.e.
+ // they are not holding back because of a per-torrent
+ | ||
relevance 0 | src/storage.cpp:325 | if the read fails, set error and exit immediately |
if the read fails, set error and exit immediatelysrc/storage.cpp:325 int block_size = 16 * 1024;
+ if (m_storage->disk_pool()) block_size = m_storage->disk_pool()->block_size();
+ int size = slot_size;
+ int num_blocks = (size + block_size - 1) / block_size;
+
+ // when we optimize for speed we allocate all the buffers we
+ // need for the rest of the piece, and read it all in one call
+ // and then hash it. When optimizing for memory usage, we read
+ // one block at a time and hash it. This ends up only using a
+ // single buffer
+ if (m_storage->settings().optimize_hashing_for_speed)
+ {
+ file::iovec_t* bufs = TORRENT_ALLOCA(file::iovec_t, num_blocks);
+ for (int i = 0; i < num_blocks; ++i)
+ {
+ bufs[i].iov_base = m_storage->disk_pool()->allocate_buffer("hash temp");
+ bufs[i].iov_len = (std::min)(block_size, size);
+ size -= bufs[i].iov_len;
+ }
+ num_read = m_storage->readv(bufs, slot, ph.offset, num_blocks);
+
+ for (int i = 0; i < num_blocks; ++i)
+ {
+ if (small_hash && small_piece_size <= block_size)
+ {
+ ph.h.update((char const*)bufs[i].iov_base, small_piece_size);
+ *small_hash = hasher(ph.h).final();
+ small_hash = 0; // avoid this case again
+ if (int(bufs[i].iov_len) > small_piece_size)
+ ph.h.update((char const*)bufs[i].iov_base + small_piece_size
+ , bufs[i].iov_len - small_piece_size);
+ }
+ else
+ {
+ ph.h.update((char const*)bufs[i].iov_base, bufs[i].iov_len);
+ small_piece_size -= bufs[i].iov_len;
+ }
+ ph.offset += bufs[i].iov_len;
+ m_storage->disk_pool()->free_buffer((char*)bufs[i].iov_base);
+ }
+ }
+ else
+ {
+ file::iovec_t buf;
+ disk_buffer_holder holder(*m_storage->disk_pool()
+ , m_storage->disk_pool()->allocate_buffer("hash temp"));
+ buf.iov_base = holder.get();
+ for (int i = 0; i < num_blocks; ++i)
+ {
+ buf.iov_len = (std::min)(block_size, size);
+ int ret = m_storage->readv(&buf, slot, ph.offset, 1);
+ | ||
relevance 0 | src/storage.cpp:358 | if the read fails, set error and exit immediately |
if the read fails, set error and exit immediatelysrc/storage.cpp:358 if (m_storage->disk_pool()) block_size = m_storage->disk_pool()->block_size();
+ int size = slot_size;
+ int num_blocks = (size + block_size - 1) / block_size;
+
+ // when we optimize for speed we allocate all the buffers we
+ // need for the rest of the piece, and read it all in one call
+ // and then hash it. When optimizing for memory usage, we read
+ // one block at a time and hash it. This ends up only using a
+ // single buffer
+ if (m_storage->settings().optimize_hashing_for_speed)
+ {
+ file::iovec_t* bufs = TORRENT_ALLOCA(file::iovec_t, num_blocks);
+ for (int i = 0; i < num_blocks; ++i)
+ {
+ bufs[i].iov_base = m_storage->disk_pool()->allocate_buffer("hash temp");
+ bufs[i].iov_len = (std::min)(block_size, size);
+ size -= bufs[i].iov_len;
+ }
+ num_read = m_storage->readv(bufs, slot, ph.offset, num_blocks);
+ if (ret > 0) num_read += ret;
+
+ if (small_hash && small_piece_size <= block_size)
+ {
+ if (small_piece_size > 0) ph.h.update((char const*)buf.iov_base, small_piece_size);
+ *small_hash = hasher(ph.h).final();
+ small_hash = 0; // avoid this case again
+ if (int(buf.iov_len) > small_piece_size)
+ ph.h.update((char const*)buf.iov_base + small_piece_size
+ , buf.iov_len - small_piece_size);
+ }
+ else
+ {
+ ph.h.update((char const*)buf.iov_base, buf.iov_len);
+ small_piece_size -= buf.iov_len;
+ }
+
+ ph.offset += buf.iov_len;
+ size -= buf.iov_len;
+ }
+ }
+ if (error()) return 0;
+ }
+ return num_read;
+ }
+
+ default_storage::default_storage(file_storage const& fs, file_storage const* mapped, std::string const& path
+ , file_pool& fp, std::vector<boost::uint8_t> const& file_prio)
+ : m_files(fs)
+ , m_file_priority(file_prio)
+ , m_pool(fp)
+ , m_page_size(page_size())
+ | ||
relevance 0 | src/storage.cpp:623 | make this more generic to not just work if files have been renamed, but also if they have been merged into a single file for instance maybe use the same format as .torrent files and reuse some code from torrent_info |
make this more generic to not just work if files have been
+renamed, but also if they have been merged into a single file for instance
+maybe use the same format as .torrent files and reuse some code from torrent_infosrc/storage.cpp:623 for (file_iter = files().begin();;)
+ {
+ if (file_offset < file_iter->size)
+ break;
+
+ file_offset -= file_iter->size;
+ ++file_iter;
+ TORRENT_ASSERT(file_iter != files().end());
+ }
+
+ error_code ec;
+ boost::intrusive_ptr<file> file_handle = open_file(file_iter, file::read_only, ec);
+ if (!file_handle || ec) return slot;
+
+ size_type data_start = file_handle->sparse_end(file_offset);
+ return int((data_start + m_files.piece_length() - 1) / m_files.piece_length());
+ }
+
+ bool default_storage::verify_resume_data(lazy_entry const& rd, error_code& error)
+ {
+ lazy_entry const* mapped_files = rd.dict_find_list("mapped_files");
+ if (mapped_files && mapped_files->list_size() == m_files.num_files())
+ {
+ m_mapped_files.reset(new file_storage(m_files));
+ for (int i = 0; i < m_files.num_files(); ++i)
+ {
+ std::string new_filename = mapped_files->list_string_value_at(i);
+ if (new_filename.empty()) continue;
+ m_mapped_files->rename_file(i, new_filename);
+ }
+ }
+
+ lazy_entry const* file_priority = rd.dict_find_list("file_priority");
+ if (file_priority && file_priority->list_size()
+ == files().num_files())
+ {
+ m_file_priority.resize(file_priority->list_size());
+ for (int i = 0; i < file_priority->list_size(); ++i)
+ m_file_priority[i] = boost::uint8_t(file_priority->list_int_value_at(i, 1));
+ }
+
+ std::vector<std::pair<size_type, std::time_t> > file_sizes;
+ lazy_entry const* file_sizes_ent = rd.dict_find_list("file sizes");
+ if (file_sizes_ent == 0)
+ {
+ error = errors::missing_file_sizes;
+ return false;
+ }
+
+ for (int i = 0; i < file_sizes_ent->list_size(); ++i)
+ {
+ | ||
relevance 0 | src/storage.cpp:1208 | what if file_base is used to merge several virtual files into a single physical file? We should probably disable this if file_base is used. This is not a widely used feature though |
what if file_base is used to merge several virtual files
+into a single physical file? We should probably disable this
+if file_base is used. This is not a widely used feature thoughsrc/storage.cpp:1208 int bytes_transferred = 0;
+ // if the file is opened in no_buffer mode, and the
+ // read is unaligned, we need to fall back on a slow
+ // special read that reads aligned buffers and copies
+ // it into the one supplied
+ size_type adjusted_offset = files().file_base(*file_iter) + file_offset;
+ if ((file_handle->open_mode() & file::no_buffer)
+ && ((adjusted_offset & (file_handle->pos_alignment()-1)) != 0
+ || (uintptr_t(tmp_bufs->iov_base) & (file_handle->buf_alignment()-1)) != 0))
+ {
+ bytes_transferred = (int)(this->*op.unaligned_op)(file_handle, adjusted_offset
+ , tmp_bufs, num_tmp_bufs, ec);
+ if (op.mode == file::read_write
+ && adjusted_offset + bytes_transferred >= file_iter->size
+ && (file_handle->pos_alignment() > 0 || file_handle->size_alignment() > 0))
+ {
+ // we were writing, and we just wrote the last block of the file
+ // we likely wrote a bit too much, since we're restricted to
+ // a specific alignment for writes. Make sure to truncate the size
+
+ file_handle->set_size(file_iter->size, ec);
+ }
+ }
+ else
+ {
+ bytes_transferred = (int)((*file_handle).*op.regular_op)(adjusted_offset
+ , tmp_bufs, num_tmp_bufs, ec);
+ TORRENT_ASSERT(bytes_transferred <= bufs_size(tmp_bufs, num_tmp_bufs));
+ }
+ file_offset = 0;
+
+ if (ec)
+ {
+ set_error(combine_path(m_save_path, files().file_path(*file_iter)), ec);
+ return -1;
+ }
+
+ if (file_bytes_left != bytes_transferred)
+ return bytes_transferred;
+
+ advance_bufs(current_buf, bytes_transferred);
+ TORRENT_ASSERT(count_bufs(current_buf, bytes_left - file_bytes_left) <= num_bufs);
+ }
+ return size;
+ }
+
+ // these functions are inefficient, but should be fairly uncommon. The read
+ // case happens if unaligned files are opened in no_buffer mode or if clients
+ // makes unaligned requests (and the disk cache is disabled or fully utilized
+ // for write cache).
+
+ | ||
relevance 0 | src/torrent.cpp:5025 | make this more generic to not just work if files have been renamed, but also if they have been merged into a single file for instance maybe use the same format as .torrent files and reuse some code from torrent_info The mapped_files needs to be read both in the network thread and in the disk thread, since they both have their own mapped files structures which are kept in sync |
make this more generic to not just work if files have been
+renamed, but also if they have been merged into a single file for instance
+maybe use the same format as .torrent files and reuse some code from torrent_info
+The mapped_files needs to be read both in the network thread
+and in the disk thread, since they both have their own mapped files structures
+which are kept in syncsrc/torrent.cpp:5025 if (m_seed_mode) m_verified.resize(m_torrent_file->num_pieces(), false);
+ super_seeding(rd.dict_find_int_value("super_seeding", 0));
+
+ m_last_scrape = rd.dict_find_int_value("last_scrape", 0);
+ m_last_download = rd.dict_find_int_value("last_download", 0);
+ m_last_upload = rd.dict_find_int_value("last_upload", 0);
+
+ m_url = rd.dict_find_string_value("url");
+ m_uuid = rd.dict_find_string_value("uuid");
+ m_source_feed_url = rd.dict_find_string_value("feed");
+
+ if (!m_uuid.empty() || !m_url.empty())
+ {
+ boost::shared_ptr<torrent> me(shared_from_this());
+
+ // insert this torrent in the uuid index
+ m_ses.m_uuids.insert(std::make_pair(m_uuid.empty()
+ ? m_url : m_uuid, me));
+ }
+
+ lazy_entry const* mapped_files = rd.dict_find_list("mapped_files");
+ if (mapped_files && mapped_files->list_size() == m_torrent_file->num_files())
+ {
+ for (int i = 0; i < m_torrent_file->num_files(); ++i)
+ {
+ std::string new_filename = mapped_files->list_string_value_at(i);
+ if (new_filename.empty()) continue;
+ m_torrent_file->rename_file(i, new_filename);
+ }
+ }
+
+ m_added_time = rd.dict_find_int_value("added_time", m_added_time);
+ m_completed_time = rd.dict_find_int_value("completed_time", m_completed_time);
+ if (m_completed_time != 0 && m_completed_time < m_added_time)
+ m_completed_time = m_added_time;
+
+ lazy_entry const* file_priority = rd.dict_find_list("file_priority");
+ if (file_priority && file_priority->list_size()
+ == m_torrent_file->num_files())
+ {
+ for (int i = 0; i < file_priority->list_size(); ++i)
+ m_file_priority[i] = file_priority->list_int_value_at(i, 1);
+ update_piece_priorities();
+ }
+
+ lazy_entry const* piece_priority = rd.dict_find_string("piece_priority");
+ if (piece_priority && piece_priority->string_length()
+ == m_torrent_file->num_pieces())
+ {
+ char const* p = piece_priority->string_ptr();
+ for (int i = 0; i < piece_priority->string_length(); ++i)
+ | ||
relevance 0 | src/torrent.cpp:5161 | if this is a merkle torrent and we can't restore the tree, we need to wipe all the bits in the have array, but not necessarily we might want to do a full check to see if we have all the pieces. This is low priority since almost no one uses merkle torrents |
if this is a merkle torrent and we can't
+restore the tree, we need to wipe all the
+bits in the have array, but not necessarily
+we might want to do a full check to see if we have
+all the pieces. This is low priority since almost
+no one uses merkle torrentssrc/torrent.cpp:5161 add_web_seed(url, web_seed_entry::http_seed);
+ }
+ }
+
+ if (m_torrent_file->is_merkle_torrent())
+ {
+ lazy_entry const* mt = rd.dict_find_string("merkle tree");
+ if (mt)
+ {
+ std::vector<sha1_hash> tree;
+ tree.resize(m_torrent_file->merkle_tree().size());
+ std::memcpy(&tree[0], mt->string_ptr()
+ , (std::min)(mt->string_length(), int(tree.size()) * 20));
+ if (mt->string_length() < int(tree.size()) * 20)
+ std::memset(&tree[0] + mt->string_length() / 20, 0
+ , tree.size() - mt->string_length() / 20);
+ m_torrent_file->set_merkle_tree(tree);
+ }
+ else
+ {
+ TORRENT_ASSERT(false);
+ }
+ }
+ }
+
+ boost::intrusive_ptr<torrent_info> torrent::get_torrent_copy()
+ {
+ if (!m_torrent_file->is_valid()) return boost::intrusive_ptr<torrent_info>();
+
+ // copy the torrent_info object
+ return boost::intrusive_ptr<torrent_info>(new torrent_info(*m_torrent_file));
+ }
+
+ void torrent::write_resume_data(entry& ret) const
+ {
+ using namespace libtorrent::detail; // for write_*_endpoint()
+ ret["file-format"] = "libtorrent resume file";
+ ret["file-version"] = 1;
+ ret["libtorrent-version"] = LIBTORRENT_VERSION;
+
+ ret["total_uploaded"] = m_total_uploaded;
+ ret["total_downloaded"] = m_total_downloaded;
+
+ ret["active_time"] = m_active_time;
+ ret["finished_time"] = m_finished_time;
+ ret["seeding_time"] = m_seeding_time;
+ ret["last_seen_complete"] = m_last_seen_complete;
+
+ ret["num_seeds"] = m_complete;
+ ret["num_incomplete"] = m_incomplete;
+ ret["num_downloaders"] = m_downloaders;
+ | ||
relevance 0 | src/torrent.cpp:5349 | make this more generic to not just work if files have been renamed, but also if they have been merged into a single file for instance. using file_base |
make this more generic to not just work if files have been
+renamed, but also if they have been merged into a single file for instance.
+using file_basesrc/torrent.cpp:5349 entry::string_type& pieces = ret["pieces"].string();
+ pieces.resize(m_torrent_file->num_pieces());
+ if (is_seed())
+ {
+ std::memset(&pieces[0], 1, pieces.size());
+ }
+ else
+ {
+ for (int i = 0, end(pieces.size()); i < end; ++i)
+ pieces[i] = m_picker->have_piece(i) ? 1 : 0;
+ }
+
+ if (m_seed_mode)
+ {
+ TORRENT_ASSERT(m_verified.size() == pieces.size());
+ for (int i = 0, end(pieces.size()); i < end; ++i)
+ pieces[i] |= m_verified[i] ? 2 : 0;
+ }
+
+ // write renamed files
+ if (&m_torrent_file->files() != &m_torrent_file->orig_files()
+ && m_torrent_file->files().num_files() == m_torrent_file->orig_files().num_files())
+ {
+ entry::list_type& fl = ret["mapped_files"].list();
+ for (torrent_info::file_iterator i = m_torrent_file->begin_files()
+ , end(m_torrent_file->end_files()); i != end; ++i)
+ {
+ fl.push_back(m_torrent_file->files().file_path(*i));
+ }
+ }
+
+ // write local peers
+
+ std::back_insert_iterator<entry::string_type> peers(ret["peers"].string());
+ std::back_insert_iterator<entry::string_type> banned_peers(ret["banned_peers"].string());
+#if TORRENT_USE_IPV6
+ std::back_insert_iterator<entry::string_type> peers6(ret["peers6"].string());
+ std::back_insert_iterator<entry::string_type> banned_peers6(ret["banned_peers6"].string());
+#endif
+
+ // failcount is a 5 bit value
+ int max_failcount = (std::min)(settings().max_failcount, 31);
+
+ int num_saved_peers = 0;
+
+ for (policy::const_iterator i = m_policy.begin_peer()
+ , end(m_policy.end_peer()); i != end; ++i)
+ {
+ error_code ec;
+ policy::peer const* p = *i;
+ address addr = p->address();
+ | ||
relevance 0 | src/torrent.cpp:7820 | go through the pieces we have and count the total number of downloaders we have. Only count peers that are interested in us since some peers might not send have messages for pieces we have it num_interested == 0, we need to pick a new piece |
go through the pieces we have and count the total number
of downloaders we have. Only count peers that are interested in us
since some peers might not send have messages for pieces we have
it num_interested == 0, we need to pick a new piecesrc/torrent.cpp:7820 }
@@ -2659,7 +3240,7 @@ it num_interested == 0, we need to pick a new piecesrc/torrent.cpp:7820
{
// we don't keep track of availability, do it the expensive way
// do a linear search from the first piece
- | ||
relevance 0 | src/torrent.cpp:8047 | if there's been long enough since we requested something from this piece, request one of the backup blocks (the one with the least number of requests to it) and update the last request timestamp |
if there's been long enough since we requested something
+ | ||
relevance 0 | src/torrent.cpp:8047 | if there's been long enough since we requested something from this piece, request one of the backup blocks (the one with the least number of requests to it) and update the last request timestamp |
if there's been long enough since we requested something
from this piece, request one of the backup blocks (the one with
the least number of requests to it) and update the last request
timestampsrc/torrent.cpp:8047 std::vector<pending_block> const& rq = c.request_queue();
@@ -2713,203 +3294,7 @@ timestampsrc/torrent.cpp:8047src/torrent.cpp:8718 | with some response codes, we should just consider the tracker as a failure and not retry it anymore | |
with some response codes, we should just consider
-the tracker as a failure and not retry
-it anymoresrc/torrent.cpp:8718 TORRENT_ASSERT(m_ses.is_network_thread());
- TORRENT_ASSERT(b > 0);
- m_total_failed_bytes += b;
- m_ses.add_failed_bytes(b);
-// TORRENT_ASSERT(m_total_redundant_bytes + m_total_failed_bytes
-// <= m_stat.total_payload_download());
- }
-
- int torrent::num_seeds() const
- {
- TORRENT_ASSERT(m_ses.is_network_thread());
- INVARIANT_CHECK;
-
- int ret = 0;
- for (std::set<peer_connection*>::const_iterator i = m_connections.begin()
- , end(m_connections.end()); i != end; ++i)
- if ((*i)->is_seed()) ++ret;
- return ret;
- }
-
- void torrent::tracker_request_error(tracker_request const& r
- , int response_code, error_code const& ec, const std::string& msg
- , int retry_interval)
- {
- TORRENT_ASSERT(m_ses.is_network_thread());
-
- INVARIANT_CHECK;
-
-#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
- debug_log("*** tracker error: (%d) %s %s", ec.value(), ec.message().c_str(), msg.c_str());
-#endif
- if (r.kind == tracker_request::announce_request)
- {
- announce_entry* ae = find_tracker(r);
- if (ae)
- {
- ae->failed(settings(), retry_interval);
- ae->last_error = ec;
- ae->message = msg;
- int tracker_index = ae - &m_trackers[0];
-#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
- debug_log("*** increment tracker fail count [%d]", ae->fails);
-#endif
- deprioritize_tracker(tracker_index);
- }
- if (m_ses.m_alerts.should_post<tracker_error_alert>())
- {
- m_ses.m_alerts.post_alert(tracker_error_alert(get_handle()
- , ae?ae->fails:0, response_code, r.url, ec, msg));
- }
- }
- | ||
relevance 0 | src/torrent_info.cpp:187 | should this take a char const*? |
should this take a char const*?src/torrent_info.cpp:187 {
- tmp_path += i[0];
- tmp_path += i[1];
- tmp_path += i[2];
- tmp_path += i[3];
- i += 3;
- continue;
- }
-
- convert_to_utf8(tmp_path, *i);
- valid_encoding = false;
- }
- // the encoding was not valid utf-8
- // save the original encoding and replace the
- // commonly used path with the correctly
- // encoded string
- if (!valid_encoding) target = tmp_path;
- return valid_encoding;
- }
-
- bool valid_path_element(std::string const& element)
- {
- if (element.empty()
- || element == "." || element == ".."
- || element[0] == '/' || element[0] == '\\'
- || element[element.size()-1] == ':')
- return false;
- return true;
- }
-
- void trim_path_element(std::string& path_element)
- {
- const int max_path_len = TORRENT_MAX_PATH;
- if (int(path_element.size()) > max_path_len)
- {
- // truncate filenames that are too long. But keep extensions!
- std::string ext = extension(path_element);
- if (ext.size() > 15)
- {
- path_element.resize(max_path_len);
- }
- else
- {
- path_element.resize(max_path_len - ext.size());
- path_element += ext;
- }
- }
- }
-
- TORRENT_EXTRA_EXPORT std::string sanitize_path(std::string const& p)
- {
- | ||
relevance 0 | src/torrent_info.cpp:366 | this logic should be a separate step done once the torrent is loaded, and the original filenames should be preserved! |
this logic should be a separate step
-done once the torrent is loaded, and the original
-filenames should be preserved!src/torrent_info.cpp:366 }
- return false;
- }
- };
-
- bool extract_files(lazy_entry const& list, file_storage& target
- , std::string const& root_dir, ptrdiff_t info_ptr_diff)
- {
- if (list.type() != lazy_entry::list_t) return false;
- target.reserve(list.list_size());
- for (int i = 0, end(list.list_size()); i < end; ++i)
- {
- lazy_entry const* file_hash = 0;
- time_t mtime = 0;
- file_entry e;
- lazy_entry const* fee = 0;
- if (!extract_single_file(*list.list_at(i), e, root_dir
- , &file_hash, &fee, &mtime))
- return false;
-
- int cnt = 0;
- std::set<std::string, string_less_no_case> files;
-
- // as long as this file already exists
- // increase the counter
- while (!files.insert(e.path).second)
- {
- ++cnt;
- char suffix[50];
- snprintf(suffix, sizeof(suffix), ".%d%s", cnt, extension(e.path).c_str());
- replace_extension(e.path, suffix);
- }
- target.add_file(e, file_hash ? file_hash->string_ptr() + info_ptr_diff : 0);
-
- // This is a memory optimization! Instead of having
- // each entry keep a string for its filename, make it
- // simply point into the info-section buffer
- internal_file_entry const& fe = *target.rbegin();
- | ||
relevance 0 | src/torrent_info.cpp:387 | once the filename renaming is removed from here this check can be removed as well |
once the filename renaming is removed from here
-this check can be removed as wellsrc/torrent_info.cpp:387 }
- return false;
- }
- };
-
- bool extract_files(lazy_entry const& list, file_storage& target
- , std::string const& root_dir, ptrdiff_t info_ptr_diff)
- {
- if (list.type() != lazy_entry::list_t) return false;
- target.reserve(list.list_size());
- for (int i = 0, end(list.list_size()); i < end; ++i)
- {
- lazy_entry const* file_hash = 0;
- time_t mtime = 0;
- file_entry e;
- lazy_entry const* fee = 0;
- if (!extract_single_file(*list.list_at(i), e, root_dir
- , &file_hash, &fee, &mtime))
- return false;
-
- if (fee && fe.filename() == fee->string_value())
- {
- // this string pointer does not necessarily point into
- // the m_info_section buffer.
- char const* str_ptr = fee->string_ptr() + info_ptr_diff;
- const_cast<internal_file_entry&>(fe).set_name(str_ptr, fee->string_length());
- }
- }
- return true;
- }
-
- int merkle_get_parent(int tree_node)
- {
- // node 0 doesn't have a parent
- TORRENT_ASSERT(tree_node > 0);
- return (tree_node - 1) / 2;
- }
-
- int merkle_get_sibling(int tree_node)
- {
- // node 0 doesn't have a sibling
- TORRENT_ASSERT(tree_node > 0);
- // even numbers have their sibling to the left
- // odd numbers have their sibling to the right
- return tree_node + (tree_node&1?1:-1);
- }
-
- int merkle_num_nodes(int leafs)
- {
- TORRENT_ASSERT(leafs > 0);
- return (leafs << 1) - 1;
- | ||
relevance 0 | src/udp_tracker_connection.cpp:548 | it would be more efficient to not use a string here. however, the problem is that some trackers will respond with actual strings. For example i2p trackers |
it would be more efficient to not use a string here.
+ | ||
relevance 0 | src/udp_tracker_connection.cpp:548 | it would be more efficient to not use a string here. however, the problem is that some trackers will respond with actual strings. For example i2p trackers |
it would be more efficient to not use a string here.
however, the problem is that some trackers will respond
with actual strings. For example i2p trackerssrc/udp_tracker_connection.cpp:548 }
@@ -2962,256 +3347,7 @@ with actual strings. For example i2p trackerssrc/udp_tracker_connection
{
restart_read_timeout();
int action = detail::read_int32(buf);
- | ||
relevance 0 | src/utp_stream.cpp:1846 | we might want to do something else here as well, to resend the packet immediately without it being an MTU probe |
we might want to do something else here
-as well, to resend the packet immediately without
-it being an MTU probesrc/utp_stream.cpp:1846 , boost::uint32_t(h->timestamp_difference_microseconds), int(p->mtu_probe)
- , h->extension);
-#endif
-
- error_code ec;
-#ifdef TORRENT_DEBUG
- // simulate 1% packet loss
-// if ((rand() % 100) > 0)
-#endif
- m_sm->send_packet(udp::endpoint(m_remote_address, m_port)
- , (char const*)h, p->size, ec
- , p->mtu_probe ? utp_socket_manager::dont_fragment : 0);
-
- ++m_out_packets;
-
- if (ec == error::message_size)
- {
- m_mtu_ceiling = p->size - 1;
- if (m_mtu_floor > m_mtu_ceiling) m_mtu_floor = m_mtu_ceiling;
- update_mtu_limits();
- }
- else if (ec == error::would_block || ec == error::try_again)
- {
-#if TORRENT_UTP_LOG
- UTP_LOGV("%8p: socket stalled\n", this);
-#endif
- if (!m_stalled)
- {
- m_stalled = true;
- m_sm->subscribe_writable(this);
- }
- }
- else if (ec)
- {
- TORRENT_ASSERT(stack_alloced != bool(payload_size));
- if (payload_size) free(p);
- m_error = ec;
- m_state = UTP_STATE_ERROR_WAIT;
- test_socket_state();
- return false;
- }
-
- if (!m_stalled)
- ++p->num_transmissions;
-
- // if we have payload, we need to save the packet until it's acked
- // and progress m_seq_nr
- if (p->size > p->header_size)
- {
- // if we're sending a payload packet, there should not
- // be a nagle packet waiting for more data
- | ||
relevance 0 | src/kademlia/dht_tracker.cpp:641 | fix this stats logging ++m_replies_sent[e["r"]]; m_replies_bytes_sent[e["r"]] += int(m_send_buf.size()); |
fix this stats logging
-++m_replies_sent[e["r"]];
-m_replies_bytes_sent[e["r"]] += int(m_send_buf.size());src/kademlia/dht_tracker.cpp:641#ifdef TORRENT_DHT_VERBOSE_LOGGING
- std::stringstream log_line;
- lazy_entry print;
- int ret = lazy_bdecode(&m_send_buf[0], &m_send_buf[0] + m_send_buf.size(), print, ec);
- TORRENT_ASSERT(ret == 0);
- log_line << print_entry(print, true);
-#endif
-
- if (m_sock.send(addr, &m_send_buf[0], (int)m_send_buf.size(), ec, send_flags))
- {
- if (ec) return false;
-
- // account for IP and UDP overhead
- m_sent_bytes += m_send_buf.size() + (addr.address().is_v6() ? 48 : 28);
-
-#ifdef TORRENT_DHT_VERBOSE_LOGGING
- m_total_out_bytes += m_send_buf.size();
-
- if (e["y"].string() == "r")
- {
- }
- else if (e["y"].string() == "q")
- {
- m_queries_out_bytes += m_send_buf.size();
- }
- TORRENT_LOG(dht_tracker) << "==> " << addr << " " << log_line.str();
-#endif
- return true;
- }
- else
- {
-#ifdef TORRENT_DHT_VERBOSE_LOGGING
- TORRENT_LOG(dht_tracker) << "==> " << addr << " DROPPED " << log_line.str();
-#endif
- return false;
- }
- }
-
-}}
-
- | ||
relevance 0 | src/kademlia/node.cpp:63 | configurable? |
configurable?src/kademlia/node.cpp:63#include "libtorrent/alert.hpp"
-#include "libtorrent/socket.hpp"
-#include "libtorrent/random.hpp"
-#include "libtorrent/aux_/session_impl.hpp"
-#include "libtorrent/kademlia/node_id.hpp"
-#include "libtorrent/kademlia/rpc_manager.hpp"
-#include "libtorrent/kademlia/routing_table.hpp"
-#include "libtorrent/kademlia/node.hpp"
-
-#include "libtorrent/kademlia/refresh.hpp"
-#include "libtorrent/kademlia/find_data.hpp"
-#include "libtorrent/rsa.hpp"
-
-namespace libtorrent { namespace dht
-{
-
-void incoming_error(entry& e, char const* msg);
-
-using detail::write_endpoint;
-
-enum { announce_interval = 30 };
-
-#ifdef TORRENT_DHT_VERBOSE_LOGGING
-TORRENT_DEFINE_LOG(node)
-#endif
-
-// remove peers that have timed out
-void purge_peers(std::set<peer_entry>& peers)
-{
- for (std::set<peer_entry>::iterator i = peers.begin()
- , end(peers.end()); i != end;)
- {
- // the peer has timed out
- if (i->added + minutes(int(announce_interval * 1.5f)) < time_now())
- {
-#ifdef TORRENT_DHT_VERBOSE_LOGGING
- TORRENT_LOG(node) << "peer timed out at: " << i->addr;
-#endif
- peers.erase(i++);
- }
- else
- ++i;
- }
-}
-
-void nop() {}
-
-node_impl::node_impl(alert_dispatcher* alert_disp
- , udp_socket_interface* sock
- , dht_settings const& settings, node_id nid, address const& external_address
- , dht_observer* observer)
- | ||
relevance 0 | src/kademlia/node.cpp:690 | find_node should write directly to the response entry |
find_node should write directly to the response entrysrc/kademlia/node.cpp:690 {
- TORRENT_LOG(node) << " values: " << reply["values"].list().size();
- }
-#endif
- }
- else if (strcmp(query, "find_node") == 0)
- {
- key_desc_t msg_desc[] = {
- {"target", lazy_entry::string_t, 20, 0},
- };
-
- lazy_entry const* msg_keys[1];
- if (!verify_message(arg_ent, msg_desc, msg_keys, 1, error_string, sizeof(error_string)))
- {
- incoming_error(e, error_string);
- return;
- }
-
- sha1_hash target(msg_keys[0]->string_ptr());
-
- nodes_t n;
- m_table.find_node(target, n, 0);
- write_nodes_entry(reply, n);
- }
- else if (strcmp(query, "announce_peer") == 0)
- {
-#ifdef TORRENT_DHT_VERBOSE_LOGGING
- extern int g_failed_announces;
-#endif
- key_desc_t msg_desc[] = {
- {"info_hash", lazy_entry::string_t, 20, 0},
- {"port", lazy_entry::int_t, 0, 0},
- {"token", lazy_entry::string_t, 0, 0},
- {"n", lazy_entry::string_t, 0, key_desc_t::optional},
- {"seed", lazy_entry::int_t, 0, key_desc_t::optional},
- };
-
- lazy_entry const* msg_keys[5];
- if (!verify_message(arg_ent, msg_desc, msg_keys, 5, error_string, sizeof(error_string)))
- {
-#ifdef TORRENT_DHT_VERBOSE_LOGGING
- ++g_failed_announces;
-#endif
- incoming_error(e, error_string);
- return;
- }
-
- int port = int(msg_keys[1]->int_value());
- if (port < 0 || port >= 65536)
- {
-#ifdef TORRENT_DHT_VERBOSE_LOGGING
- | ||
relevance 0 | src/kademlia/rpc_manager.cpp:439 | don't call short_timeout() again if we've already called it once |
don't call short_timeout() again if we've
-already called it oncesrc/kademlia/rpc_manager.cpp:439 std::for_each(timeouts.begin(), timeouts.end(), boost::bind(&observer::timeout, _1));
- timeouts.clear();
-
- for (transactions_t::iterator i = m_transactions.begin();
- i != m_transactions.end(); ++i)
- {
- observer_ptr o = *i;
-
- // if we reach an observer that hasn't timed out
- // break, because every observer after this one will
- // also not have timed out yet
- time_duration diff = now - o->sent();
- if (diff < seconds(short_timeout))
- {
- ret = seconds(short_timeout) - diff;
- break;
- }
-
- if (o->has_short_timeout()) continue;
-
- timeouts.push_back(o);
- }
-
- std::for_each(timeouts.begin(), timeouts.end(), boost::bind(&observer::short_timeout, _1));
-
- return ret;
-}
-
-void rpc_manager::add_our_id(entry& e)
-{
- e["id"] = m_our_id.to_string();
-}
-
-bool rpc_manager::invoke(entry& e, udp::endpoint target_addr
- , observer_ptr o)
-{
- INVARIANT_CHECK;
-
- if (m_destructing) return false;
-
- e["y"] = "q";
- entry& a = e["a"];
- add_our_id(a);
-
- std::string transaction_id;
- transaction_id.resize(2);
- char* out = &transaction_id[0];
- int tid = random() ^ (random() << 5);
- io::write_uint16(tid, out);
- e["t"] = transaction_id;
-
- | ||
relevance 0 | include/libtorrent/config.hpp:283 | Make this count Unicode characters instead of bytes on windows |
Make this count Unicode characters instead of bytes on windowsinclude/libtorrent/config.hpp:283
+ | ||
relevance 0 | include/libtorrent/config.hpp:283 | Make this count Unicode characters instead of bytes on windows |
Make this count Unicode characters instead of bytes on windowsinclude/libtorrent/config.hpp:283
// ==== eCS(OS/2) ===
#elif defined __OS2__
#define TORRENT_OS2
@@ -3262,34 +3398,7 @@ bool rpc_manager::invoke(entry& e, udp::endpoint target_addr
#include <stdarg.h>
inline int snprintf(char* buf, int len, char const* fmt, ...)
- | ||
relevance 0 | include/libtorrent/ip_voter.hpp:100 | instead, have one instance per possible subnet, global IPv4, global IPv6, loopback, 192.168.x.x, 10.x.x.x, etc. |
instead, have one instance per possible subnet, global IPv4, global IPv6, loopback, 192.168.x.x, 10.x.x.x, etc.include/libtorrent/ip_voter.hpp:100 bloom_filter<32> m_external_address_voters;
- std::vector<external_ip_t> m_external_addresses;
- address m_external_address;
- };
-
- // this keeps track of multiple external IPs (for now, just IPv6 and IPv4, but
- // it could be extended to deal with loopback and local network addresses as well)
- struct TORRENT_EXTRA_EXPORT external_ip
- {
- // returns true if a different IP is the top vote now
- // i.e. we changed our idea of what our external IP is
- bool cast_vote(address const& ip, int source_type, address const& source);
-
- // the external IP as it would be observed from `ip`
- address external_address(address const& ip) const;
-
- private:
-
- // for now, assume one external IPv4 and one external IPv6 address
- // 0 = IPv4 1 = IPv6
- ip_voter m_vote_group[2];
- };
-
-}
-
-#endif
-
- | ||
relevance 0 | include/libtorrent/proxy_base.hpp:152 | it would be nice to remember the bind port and bind once we know where the proxy is m_sock.bind(endpoint, ec); |
it would be nice to remember the bind port and bind once we know where the proxy is
+ | ||
relevance 0 | include/libtorrent/proxy_base.hpp:152 | it would be nice to remember the bind port and bind once we know where the proxy is m_sock.bind(endpoint, ec); |
it would be nice to remember the bind port and bind once we know where the proxy is
m_sock.bind(endpoint, ec);include/libtorrent/proxy_base.hpp:152 {
return m_sock.set_option(opt, ec);
}
@@ -3341,259 +3450,4 @@ m_sock.bind(endpoint, ec);include/libtorrent/proxy_base.hpp:152 | ||
relevance 0 | include/libtorrent/torrent_info.hpp:448 | these strings could be lazy_entry* to save memory |
these strings could be lazy_entry* to save memoryinclude/libtorrent/torrent_info.hpp:448
- // the urls to the trackers
- std::vector<announce_entry> m_urls;
- std::vector<web_seed_entry> m_web_seeds;
- nodes_t m_nodes;
-
- // if this is a merkle torrent, this is the merkle
- // tree. It has space for merkle_num_nodes(merkle_num_leafs(num_pieces))
- // hashes
- std::vector<sha1_hash> m_merkle_tree;
-
- // this is a copy of the info section from the torrent.
- // it use maintained in this flat format in order to
- // make it available through the metadata extension
- boost::shared_array<char> m_info_section;
-
- // this is a pointer into the m_info_section buffer
- // pointing to the first byte of the first sha-1 hash
- char const* m_piece_hashes;
-
-
- // if a comment is found in the torrent file
- // this will be set to that comment
- std::string m_comment;
-
- // an optional string naming the software used
- // to create the torrent file
- std::string m_created_by;
-
-#ifdef TORRENT_USE_OPENSSL
- // for ssl-torrens, this contains the root
- // certificate, in .pem format (i.e. ascii
- // base64 encoded with head and tails)
- std::string m_ssl_root_cert;
-#endif
-
- // the info section parsed. points into m_info_section
- // parsed lazily
- mutable lazy_entry m_info_dict;
-
- // if a creation date is found in the torrent file
- // this will be set to that, otherwise it'll be
- // 1970, Jan 1
- time_t m_creation_date;
-
- // the hash that identifies this torrent
- sha1_hash m_info_hash;
-
- // the number of bytes in m_info_section
- boost::uint32_t m_info_section_size:24;
-
- | ||
relevance 0 | include/libtorrent/udp_socket.hpp:195 | move this debug facility into a base class. It's used in a lot of places |
move this debug facility into a base class. It's used in a lot of placesinclude/libtorrent/udp_socket.hpp:195 , error_code const& e, std::size_t bytes_transferred);
- void on_name_lookup(error_code const& e, tcp::resolver::iterator i);
- void on_timeout();
- void on_connect(int ticket);
- void on_connected(error_code const& ec);
- void handshake1(error_code const& e);
- void handshake2(error_code const& e);
- void handshake3(error_code const& e);
- void handshake4(error_code const& e);
- void socks_forward_udp();
- void connect1(error_code const& e);
- void connect2(error_code const& e);
- void hung_up(error_code const& e);
-
- void wrap(udp::endpoint const& ep, char const* p, int len, error_code& ec);
- void wrap(char const* hostname, int port, char const* p, int len, error_code& ec);
- void unwrap(error_code const& e, char const* buf, int size);
-
-#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
-
-#if defined BOOST_HAS_PTHREADS
- mutable pthread_t m_thread;
-#endif
- bool is_single_thread() const
- {
-#if defined BOOST_HAS_PTHREADS
- if (m_thread == 0)
- m_thread = pthread_self();
- return m_thread == pthread_self();
-#endif
- return true;
- }
-#endif
-
- udp::socket m_ipv4_sock;
- int m_buf_size;
-
- // if the buffer size is attempted
- // to be changed while the buffer is
- // being used, this member is set to
- // the desired size, and it's resized
- // later
- int m_new_buf_size;
- char* m_buf;
-
-#if TORRENT_USE_IPV6
- udp::socket m_ipv6_sock;
-#endif
-
- boost::uint16_t m_bind_port;
- boost::uint8_t m_v4_outstanding;
- | ||
relevance 0 | include/libtorrent/utp_stream.hpp:350 | implement |
implementinclude/libtorrent/utp_stream.hpp:350 for (typename Mutable_Buffers::const_iterator i = buffers.begin()
- , end(buffers.end()); i != end; ++i)
- {
- using asio::buffer_cast;
- using asio::buffer_size;
- add_read_buffer(buffer_cast<void*>(*i), buffer_size(*i));
-#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
- buf_size += buffer_size(*i);
-#endif
- }
- std::size_t ret = read_some(true);
- TORRENT_ASSERT(ret <= buf_size);
- TORRENT_ASSERT(ret > 0);
- return ret;
- }
-
- template <class Const_Buffers>
- std::size_t write_some(Const_Buffers const& buffers, error_code& ec)
- {
- TORRENT_ASSERT(false && "not implemented!");
- return 0;
- }
-
-#ifndef BOOST_NO_EXCEPTIONS
- template <class Mutable_Buffers>
- std::size_t read_some(Mutable_Buffers const& buffers)
- {
- error_code ec;
- std::size_t ret = read_some(buffers, ec);
- if (ec)
- boost::throw_exception(boost::system::system_error(ec));
- return ret;
- }
-
- template <class Const_Buffers>
- std::size_t write_some(Const_Buffers const& buffers)
- {
- error_code ec;
- std::size_t ret = write_some(buffers, ec);
- if (ec)
- boost::throw_exception(boost::system::system_error(ec));
- return ret;
- }
-#endif
-
- template <class Const_Buffers, class Handler>
- void async_write_some(Const_Buffers const& buffers, Handler const& handler)
- {
- if (m_impl == 0)
- {
- m_io_service.post(boost::bind<void>(handler, asio::error::not_connected, 0));
- | ||
relevance 0 | include/libtorrent/web_peer_connection.hpp:127 | if we make this be a disk_buffer_holder instead we would save a copy sometimes use allocate_disk_receive_buffer and release_disk_receive_buffer |
if we make this be a disk_buffer_holder instead
-we would save a copy sometimes
-use allocate_disk_receive_buffer and release_disk_receive_bufferinclude/libtorrent/web_peer_connection.hpp:127
- private:
-
- bool maybe_harvest_block();
-
- // returns the block currently being
- // downloaded. And the progress of that
- // block. If the peer isn't downloading
- // a piece for the moment, the boost::optional
- // will be invalid.
- boost::optional<piece_block_progress> downloading_piece_progress() const;
-
- // this has one entry per http-request
- // (might be more than the bt requests)
- std::deque<int> m_file_requests;
-
- std::string m_url;
-
- // this is used for intermediate storage of pieces
- // that are received in more than one HTTP response
- std::vector<char> m_piece;
-
- // the number of bytes received in the current HTTP
- // response. used to know where in the buffer the
- // next response starts
- size_type m_received_body;
-
- // position in the current range response
- size_type m_range_pos;
-
- // the position in the current block
- int m_block_pos;
-
- // this is the offset inside the current receive
- // buffer where the next chunk header will be.
- // this is updated for each chunk header that's
- // parsed. It does not necessarily point to a valid
- // offset in the receive buffer, if we haven't received
- // it yet. This offset never includes the HTTP header
- size_type m_chunk_pos;
-
- // this is the number of bytes we've already received
- // from the next chunk header we're waiting for
- int m_partial_chunk_header;
- };
-}
-
-#endif // TORRENT_WEB_PEER_CONNECTION_HPP_INCLUDED
-
- | ||
relevance 0 | include/libtorrent/kademlia/dht_tracker.hpp:79 | take a udp_socket_interface here instead. Move udp_socket_interface down into libtorrent core |
take a udp_socket_interface here instead. Move udp_socket_interface down into libtorrent coreinclude/libtorrent/kademlia/dht_tracker.hpp:79 struct lazy_entry;
-}
-
-namespace libtorrent { namespace dht
-{
-
-#ifdef TORRENT_DHT_VERBOSE_LOGGING
- TORRENT_DECLARE_LOG(dht_tracker);
-#endif
-
- struct dht_tracker;
-
- TORRENT_EXTRA_EXPORT void intrusive_ptr_add_ref(dht_tracker const*);
- TORRENT_EXTRA_EXPORT void intrusive_ptr_release(dht_tracker const*);
-
- struct dht_tracker : udp_socket_interface, udp_socket_observer
- {
- friend void intrusive_ptr_add_ref(dht_tracker const*);
- friend void intrusive_ptr_release(dht_tracker const*);
-
- dht_tracker(libtorrent::aux::session_impl& ses, rate_limited_udp_socket& sock
- , dht_settings const& settings, entry const* state = 0);
- virtual ~dht_tracker();
-
- void start(entry const& bootstrap);
- void stop();
-
- void add_node(udp::endpoint node);
- void add_node(std::pair<std::string, int> const& node);
- void add_router_node(udp::endpoint const& node);
-
- entry state() const;
-
- void announce(sha1_hash const& ih, int listen_port, bool seed
- , boost::function<void(std::vector<tcp::endpoint> const&)> f);
-
- void dht_status(session_status& s);
- void network_stats(int& sent, int& received);
-
- // translate bittorrent kademlia message into the generic kademlia message
- // used by the library
- virtual bool incoming_packet(error_code const& ec
- , udp::endpoint const&, char const* buf, int size);
-
- private:
-
- boost::intrusive_ptr<dht_tracker> self()
- { return boost::intrusive_ptr<dht_tracker>(this); }
-
- void on_name_lookup(error_code const& e
- , udp::resolver::iterator host);
| ||