improve logging of adding peers and the state of torrents. the default flags for the external connect_peer() call now assumes encryption, uTP and holepunch support
This commit is contained in:
parent
efebbcb2bf
commit
a65b71b855
|
@ -56,7 +56,7 @@ namespace libtorrent
|
|||
// in the other end. In the case of a web seed, the server type and
|
||||
// version will be a part of this string.
|
||||
std::string client;
|
||||
|
||||
|
||||
// a bitfield, with one bit per piece in the torrent. Each bit tells you
|
||||
// if the peer has that piece (if it's set to 1) or if the peer miss that
|
||||
// piece (set to 0).
|
||||
|
@ -179,7 +179,7 @@ namespace libtorrent
|
|||
|
||||
// this connection is obfuscated with RC4
|
||||
rc4_encrypted = 0x100000,
|
||||
|
||||
|
||||
// the handshake of this connection was obfuscated
|
||||
// with a diffie-hellman exchange
|
||||
plaintext_encrypted = 0x200000
|
||||
|
@ -210,7 +210,7 @@ namespace libtorrent
|
|||
|
||||
// The peer was added from the fast resume data.
|
||||
resume_data = 0x10,
|
||||
|
||||
|
||||
// we received an incoming connection from this peer
|
||||
incoming = 0x20
|
||||
};
|
||||
|
@ -261,7 +261,7 @@ namespace libtorrent
|
|||
// this is the number of requests we have sent to this peer that we
|
||||
// haven't got a response for yet
|
||||
int download_queue_length;
|
||||
|
||||
|
||||
// the number of block requests that have timed out, and are still in the
|
||||
// download queue
|
||||
int timed_out_requests;
|
||||
|
@ -301,7 +301,7 @@ namespace libtorrent
|
|||
int downloading_block_index;
|
||||
int downloading_progress;
|
||||
int downloading_total;
|
||||
|
||||
|
||||
// the kind of connection this is. Used for the connection_type field.
|
||||
enum connection_type_t
|
||||
{
|
||||
|
@ -317,7 +317,7 @@ namespace libtorrent
|
|||
|
||||
// the kind of connection this peer uses. See connection_type_t.
|
||||
int connection_type;
|
||||
|
||||
|
||||
// an estimate of the rate this peer is downloading at, in
|
||||
// bytes per second.
|
||||
int remote_dl_rate;
|
||||
|
|
|
@ -1096,20 +1096,20 @@ namespace libtorrent
|
|||
// ``flags`` are the same flags that are passed along with the ``ut_pex`` extension.
|
||||
//
|
||||
// ==== ==========================================
|
||||
// 0x01 peer supports encryption
|
||||
// 0x01 peer supports encryption.
|
||||
//
|
||||
// 0x02 peer is a seed
|
||||
//
|
||||
// 0x04 supports uTP. This is only a positive flags
|
||||
// passing 0 doesn't mean the peer doesn't
|
||||
// support uTP
|
||||
// 0x04 supports uTP. If this is not set, the peer will only be contacted
|
||||
// over TCP.
|
||||
//
|
||||
// 0x08 supports holepunching protocol. If this
|
||||
// flag is received from a peer, it can be
|
||||
// used as a rendezvous point in case direct
|
||||
// connections to the peer fail
|
||||
// ==== ==========================================
|
||||
void connect_peer(tcp::endpoint const& adr, int source = 0, int flags = 0) const;
|
||||
void connect_peer(tcp::endpoint const& adr, int source = 0
|
||||
, int flags = 0x1 + 0x4 + 0x8) const;
|
||||
|
||||
// ``set_max_uploads()`` sets the maximum number of peers that's unchoked
|
||||
// at the same time on this torrent. If you set this to -1, there will be
|
||||
|
|
|
@ -62,6 +62,10 @@ namespace libtorrent
|
|||
|
||||
tcp::endpoint ip() const { return tcp::endpoint(address(), port); }
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
std::string to_string() const;
|
||||
#endif
|
||||
|
||||
// this is the accumulated amount of
|
||||
// uploaded and downloaded data to this
|
||||
// torrent_peer. It only accounts for what was
|
||||
|
|
|
@ -897,7 +897,8 @@ namespace libtorrent
|
|||
}
|
||||
|
||||
// this is an internal function
|
||||
bool peer_list::insert_peer(torrent_peer* p, iterator iter, int flags, torrent_state* state)
|
||||
bool peer_list::insert_peer(torrent_peer* p, iterator iter, int flags
|
||||
, torrent_state* state)
|
||||
{
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
TORRENT_ASSERT(p);
|
||||
|
|
|
@ -346,12 +346,6 @@ namespace libtorrent
|
|||
m_resume_data.reset(new resume_data_t);
|
||||
m_resume_data->buf = p.resume_data;
|
||||
}
|
||||
|
||||
update_want_peers();
|
||||
update_want_scrape();
|
||||
update_want_tick();
|
||||
update_state_list();
|
||||
|
||||
}
|
||||
|
||||
void torrent::inc_stats_counter(int c, int value)
|
||||
|
@ -710,8 +704,6 @@ namespace libtorrent
|
|||
{
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
|
||||
INVARIANT_CHECK;
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
debug_log("creating torrent: %s max-uploads: %d max-connections: %d "
|
||||
"upload-limit: %d download-limit: %d flags: %s%s%s%s%s%s%s%s%s%s%s%s"
|
||||
|
@ -822,6 +814,11 @@ namespace libtorrent
|
|||
}
|
||||
}
|
||||
|
||||
update_want_peers();
|
||||
update_want_scrape();
|
||||
update_want_tick();
|
||||
update_state_list();
|
||||
|
||||
if (!m_torrent_file->is_valid() && !m_url.empty())
|
||||
{
|
||||
// we need to download the .torrent file from m_url
|
||||
|
@ -838,6 +835,10 @@ namespace libtorrent
|
|||
set_state(torrent_status::downloading_metadata);
|
||||
start_announcing();
|
||||
}
|
||||
|
||||
#if TORRENT_USE_INVARIANT_CHECKS
|
||||
check_invariant();
|
||||
#endif
|
||||
}
|
||||
|
||||
void torrent::start_download_url()
|
||||
|
@ -7393,7 +7394,15 @@ namespace libtorrent
|
|||
sm = m_ses.utp_socket_manager();
|
||||
|
||||
// don't make a TCP connection if it's disabled
|
||||
if (sm == 0 && !settings().get_bool(settings_pack::enable_outgoing_tcp)) return false;
|
||||
if (sm == 0 && !settings().get_bool(settings_pack::enable_outgoing_tcp))
|
||||
{
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
debug_log("discarding peer \"%s\": TCP connections disabled "
|
||||
"[ supports-utp: %d ]", peerinfo->to_string().c_str()
|
||||
, peerinfo->supports_utp);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
void* userdata = 0;
|
||||
#ifdef TORRENT_USE_OPENSSL
|
||||
|
@ -7998,10 +8007,29 @@ namespace libtorrent
|
|||
, !m_allow_peers && m_auto_managed && !m_abort);
|
||||
}
|
||||
|
||||
char const* list_name(int idx)
|
||||
{
|
||||
#define TORRENT_LIST_NAME(n) case aux::session_interface:: n: return #n;
|
||||
switch (idx)
|
||||
{
|
||||
TORRENT_LIST_NAME(torrent_state_updates);
|
||||
TORRENT_LIST_NAME(torrent_want_tick);
|
||||
TORRENT_LIST_NAME(torrent_want_peers_download);
|
||||
TORRENT_LIST_NAME(torrent_want_peers_finished);
|
||||
TORRENT_LIST_NAME(torrent_want_scrape);
|
||||
TORRENT_LIST_NAME(torrent_downloading_auto_managed);
|
||||
TORRENT_LIST_NAME(torrent_seeding_auto_managed);
|
||||
TORRENT_LIST_NAME(torrent_checking_auto_managed);
|
||||
default: TORRENT_ASSERT_VAL(false, idx);
|
||||
}
|
||||
#undef TORRENT_LIST_NAME
|
||||
}
|
||||
|
||||
void torrent::update_list(int list, bool in)
|
||||
{
|
||||
link& l = m_links[list];
|
||||
std::vector<torrent*>& v = m_ses.torrent_list(list);
|
||||
|
||||
if (in)
|
||||
{
|
||||
if (l.in_list()) return;
|
||||
|
@ -8012,6 +8040,10 @@ namespace libtorrent
|
|||
if (!l.in_list()) return;
|
||||
l.unlink(v, list);
|
||||
}
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
debug_log("*** UPDATE LIST [ %s : %d ]", list_name(list), int(in));
|
||||
#endif
|
||||
}
|
||||
|
||||
void torrent::disconnect_all(error_code const& ec, operation_t op)
|
||||
|
@ -10904,7 +10936,15 @@ namespace libtorrent
|
|||
TORRENT_ASSERT(is_single_thread());
|
||||
|
||||
#if !TORRENT_USE_IPV6
|
||||
if (!adr.address().is_v4()) return NULL;
|
||||
if (!adr.address().is_v4())
|
||||
{
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
error_code ec;
|
||||
debug_log("add_peer() %s unsupported address family"
|
||||
, adr.address().to_string(ec).c_str());
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef TORRENT_DISABLE_DHT
|
||||
|
@ -10912,7 +10952,7 @@ namespace libtorrent
|
|||
{
|
||||
// try to send a DHT ping to this peer
|
||||
// as well, to figure out if it supports
|
||||
// DHT (uTorrent and BitComet doesn't
|
||||
// DHT (uTorrent and BitComet don't
|
||||
// advertise support)
|
||||
udp::endpoint node(adr.address(), adr.port());
|
||||
session().add_dht_node(node);
|
||||
|
@ -10971,6 +11011,13 @@ namespace libtorrent
|
|||
torrent_state st = get_peer_list_state();
|
||||
torrent_peer* p = m_peer_list->add_peer(adr, source, flags, &st);
|
||||
peers_erased(st.erased);
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
error_code ec;
|
||||
debug_log("add_peer() %s connect-candidates: %d"
|
||||
, adr.address().to_string(ec).c_str(), m_peer_list->num_connect_candidates());
|
||||
#endif
|
||||
|
||||
if (p)
|
||||
{
|
||||
state_updated();
|
||||
|
|
|
@ -184,6 +184,17 @@ namespace libtorrent
|
|||
return peer_rank;
|
||||
}
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
std::string torrent_peer::to_string() const
|
||||
{
|
||||
#if TORRENT_USE_I2P
|
||||
if (is_i2p_addr) return dest();
|
||||
#endif // TORRENT_USE_I2P
|
||||
error_code ec;
|
||||
return address().to_string(ec);
|
||||
}
|
||||
#endif
|
||||
|
||||
boost::uint64_t torrent_peer::total_download() const
|
||||
{
|
||||
if (connection != 0)
|
||||
|
|
Loading…
Reference in New Issue