forked from premiere/premiere-libtorrent
make some stats more configurable and reorder some fields
This commit is contained in:
parent
cfa25b66e8
commit
5bc3028291
|
@ -180,6 +180,10 @@ void bind_session_settings()
|
||||||
.def_readwrite("tracker_backoff", &session_settings::tracker_backoff)
|
.def_readwrite("tracker_backoff", &session_settings::tracker_backoff)
|
||||||
.def_readwrite("ban_web_seeds", &session_settings::ban_web_seeds)
|
.def_readwrite("ban_web_seeds", &session_settings::ban_web_seeds)
|
||||||
.def_readwrite("max_http_recv_buffer_size", &session_settings::max_http_recv_buffer_size)
|
.def_readwrite("max_http_recv_buffer_size", &session_settings::max_http_recv_buffer_size)
|
||||||
|
.def_readwrite("support_share_mode", &session_settings::support_share_mode)
|
||||||
|
.def_readwrite("support_merkle_torrents", &session_settings::support_merkle_torrents)
|
||||||
|
.def_readwrite("handshake_client_version", &session_settings::handshake_client_version)
|
||||||
|
.def_readwrite("report_redundant_bytes", &session_settings::report_redundant_bytes)
|
||||||
;
|
;
|
||||||
|
|
||||||
enum_<proxy_settings::proxy_type>("proxy_type")
|
enum_<proxy_settings::proxy_type>("proxy_type")
|
||||||
|
|
|
@ -949,6 +949,22 @@ namespace libtorrent
|
||||||
// http_connection maximum receive buffer size
|
// http_connection maximum receive buffer size
|
||||||
// limits torrent file size for URL torrents
|
// limits torrent file size for URL torrents
|
||||||
int max_http_recv_buffer_size;
|
int max_http_recv_buffer_size;
|
||||||
|
|
||||||
|
// enables/disables the share-mode extension
|
||||||
|
bool support_share_mode;
|
||||||
|
|
||||||
|
// if this is false, don't advertise support for
|
||||||
|
// the Tribler merkle tree piece message
|
||||||
|
bool support_merkle_torrents;
|
||||||
|
|
||||||
|
// if this is true, the number of redundant bytes
|
||||||
|
// is sent to the tracker
|
||||||
|
bool report_redundant_bytes;
|
||||||
|
|
||||||
|
// the version string to advertise for this client
|
||||||
|
// in the peer protocol handshake. If this is empty
|
||||||
|
// the user_agent is used
|
||||||
|
std::string handshake_client_version;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_DHT
|
#ifndef TORRENT_DISABLE_DHT
|
||||||
|
|
|
@ -729,8 +729,11 @@ namespace libtorrent
|
||||||
*(ptr + 5) |= 0x10;
|
*(ptr + 5) |= 0x10;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (m_ses.m_settings.support_merkle_torrents)
|
||||||
|
{
|
||||||
// we support merkle torrents
|
// we support merkle torrents
|
||||||
*(ptr + 5) |= 0x08;
|
*(ptr + 5) |= 0x08;
|
||||||
|
}
|
||||||
|
|
||||||
// we support FAST extension
|
// we support FAST extension
|
||||||
*(ptr + 7) |= 0x04;
|
*(ptr + 7) |= 0x04;
|
||||||
|
@ -745,7 +748,7 @@ namespace libtorrent
|
||||||
else bitmask += '0';
|
else bitmask += '0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
peer_log(">>> EXTENSION_BITS [ %s ]", bitmask.c_str());
|
peer_log("==> EXTENSION [ %s ]", bitmask.c_str());
|
||||||
#endif
|
#endif
|
||||||
ptr += 8;
|
ptr += 8;
|
||||||
|
|
||||||
|
@ -1746,7 +1749,8 @@ namespace libtorrent
|
||||||
if (root.dict_find_int_value("upload_only", 0))
|
if (root.dict_find_int_value("upload_only", 0))
|
||||||
set_upload_only(true);
|
set_upload_only(true);
|
||||||
|
|
||||||
if (root.dict_find_int_value("share_mode", 0))
|
if (m_ses.m_settings.support_share_mode
|
||||||
|
&& root.dict_find_int_value("share_mode", 0))
|
||||||
set_share_mode(true);
|
set_share_mode(true);
|
||||||
|
|
||||||
std::string myip = root.dict_find_string_value("yourip");
|
std::string myip = root.dict_find_string_value("yourip");
|
||||||
|
@ -1801,7 +1805,10 @@ namespace libtorrent
|
||||||
|
|
||||||
TORRENT_ASSERT(recv_buffer.left() >= 1);
|
TORRENT_ASSERT(recv_buffer.left() >= 1);
|
||||||
int packet_type = (unsigned char)recv_buffer[0];
|
int packet_type = (unsigned char)recv_buffer[0];
|
||||||
if (packet_type == 250) packet_type = msg_piece;
|
|
||||||
|
if (m_ses.m_settings.support_merkle_torrents
|
||||||
|
&& packet_type == 250) packet_type = msg_piece;
|
||||||
|
|
||||||
if (packet_type < 0
|
if (packet_type < 0
|
||||||
|| packet_type >= num_supported_messages
|
|| packet_type >= num_supported_messages
|
||||||
|| m_message_handler[packet_type] == 0)
|
|| m_message_handler[packet_type] == 0)
|
||||||
|
@ -2095,7 +2102,8 @@ namespace libtorrent
|
||||||
if (!m_ses.m_settings.anonymous_mode)
|
if (!m_ses.m_settings.anonymous_mode)
|
||||||
{
|
{
|
||||||
if (is_outgoing()) handshake["p"] = m_ses.listen_port();
|
if (is_outgoing()) handshake["p"] = m_ses.listen_port();
|
||||||
handshake["v"] = m_ses.settings().user_agent;
|
handshake["v"] = m_ses.settings().handshake_client_version.empty()
|
||||||
|
? m_ses.settings().user_agent : m_ses.settings().handshake_client_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string remote_address;
|
std::string remote_address;
|
||||||
|
@ -2108,6 +2116,7 @@ namespace libtorrent
|
||||||
|
|
||||||
m["upload_only"] = upload_only_msg;
|
m["upload_only"] = upload_only_msg;
|
||||||
m["ut_holepunch"] = holepunch_msg;
|
m["ut_holepunch"] = holepunch_msg;
|
||||||
|
if (m_ses.m_settings.support_share_mode)
|
||||||
m["share_mode"] = share_mode_msg;
|
m["share_mode"] = share_mode_msg;
|
||||||
m["lt_donthave"] = dont_have_msg;
|
m["lt_donthave"] = dont_have_msg;
|
||||||
|
|
||||||
|
@ -2134,7 +2143,8 @@ namespace libtorrent
|
||||||
))
|
))
|
||||||
handshake["upload_only"] = 1;
|
handshake["upload_only"] = 1;
|
||||||
|
|
||||||
if (t->share_mode())
|
if (m_ses.m_settings.support_share_mode
|
||||||
|
&& t->share_mode())
|
||||||
handshake["share_mode"] = 1;
|
handshake["share_mode"] = 1;
|
||||||
|
|
||||||
if (!m_ses.m_settings.anonymous_mode)
|
if (!m_ses.m_settings.anonymous_mode)
|
||||||
|
@ -2268,7 +2278,7 @@ namespace libtorrent
|
||||||
char* ptr = msg;
|
char* ptr = msg;
|
||||||
TORRENT_ASSERT(r.length <= 16 * 1024);
|
TORRENT_ASSERT(r.length <= 16 * 1024);
|
||||||
detail::write_int32(r.length + 1 + 4 + 4, ptr);
|
detail::write_int32(r.length + 1 + 4 + 4, ptr);
|
||||||
if (merkle)
|
if (m_ses.m_settings.support_merkle_torrents && merkle)
|
||||||
detail::write_uint8(250, ptr);
|
detail::write_uint8(250, ptr);
|
||||||
else
|
else
|
||||||
detail::write_uint8(msg_piece, ptr);
|
detail::write_uint8(msg_piece, ptr);
|
||||||
|
|
|
@ -183,15 +183,15 @@ void http_connection::get(std::string const& url, time_duration timeout, int pri
|
||||||
|
|
||||||
// APPEND_FMT("Accept: */*\r\n");
|
// APPEND_FMT("Accept: */*\r\n");
|
||||||
|
|
||||||
if (!auth.empty())
|
|
||||||
APPEND_FMT1("Authorization: Basic %s\r\n", base64encode(auth).c_str());
|
|
||||||
|
|
||||||
if (!m_user_agent.empty())
|
if (!m_user_agent.empty())
|
||||||
APPEND_FMT1("User-Agent: %s\r\n", m_user_agent.c_str());
|
APPEND_FMT1("User-Agent: %s\r\n", m_user_agent.c_str());
|
||||||
|
|
||||||
if (m_bottled)
|
if (m_bottled)
|
||||||
APPEND_FMT("Accept-Encoding: gzip\r\n");
|
APPEND_FMT("Accept-Encoding: gzip\r\n");
|
||||||
|
|
||||||
|
if (!auth.empty())
|
||||||
|
APPEND_FMT1("Authorization: Basic %s\r\n", base64encode(auth).c_str());
|
||||||
|
|
||||||
APPEND_FMT("Connection: close\r\n\r\n");
|
APPEND_FMT("Connection: close\r\n\r\n");
|
||||||
|
|
||||||
sendbuffer.assign(request);
|
sendbuffer.assign(request);
|
||||||
|
|
|
@ -131,16 +131,26 @@ namespace libtorrent
|
||||||
else
|
else
|
||||||
url += "?";
|
url += "?";
|
||||||
|
|
||||||
url += "info_hash=";
|
|
||||||
url += escape_string((const char*)&tracker_req().info_hash[0], 20);
|
|
||||||
|
|
||||||
if (tracker_req().kind == tracker_request::announce_request)
|
if (tracker_req().kind == tracker_request::announce_request)
|
||||||
{
|
{
|
||||||
|
const char* event_string[] = {"completed", "started", "stopped", "paused"};
|
||||||
|
|
||||||
char str[1024];
|
char str[1024];
|
||||||
const bool stats = tracker_req().send_stats;
|
const bool stats = tracker_req().send_stats;
|
||||||
snprintf(str, sizeof(str), "&peer_id=%s&port=%d&uploaded=%"PRId64
|
snprintf(str, sizeof(str)
|
||||||
"&downloaded=%"PRId64"&left=%"PRId64"&corrupt=%"PRId64"&redundant=%"PRId64
|
, "info_hash=%s"
|
||||||
"&compact=1&numwant=%d&key=%x&no_peer_id=1"
|
"&peer_id=%s"
|
||||||
|
"&port=%d"
|
||||||
|
"&uploaded=%"PRId64
|
||||||
|
"&downloaded=%"PRId64
|
||||||
|
"&left=%"PRId64
|
||||||
|
"&corrupt=%"PRId64
|
||||||
|
"&key=%x"
|
||||||
|
"%s%s" // event
|
||||||
|
"&numwant=%d"
|
||||||
|
"&compact=1"
|
||||||
|
"&no_peer_id=1"
|
||||||
|
, escape_string((const char*)&tracker_req().info_hash[0], 20).c_str()
|
||||||
, escape_string((const char*)&tracker_req().pid[0], 20).c_str()
|
, escape_string((const char*)&tracker_req().pid[0], 20).c_str()
|
||||||
// the i2p tracker seems to verify that the port is not 0,
|
// the i2p tracker seems to verify that the port is not 0,
|
||||||
// even though it ignores it otherwise
|
// even though it ignores it otherwise
|
||||||
|
@ -149,14 +159,20 @@ namespace libtorrent
|
||||||
, stats ? tracker_req().downloaded : 0
|
, stats ? tracker_req().downloaded : 0
|
||||||
, stats ? tracker_req().left : 0
|
, stats ? tracker_req().left : 0
|
||||||
, stats ? tracker_req().corrupt : 0
|
, stats ? tracker_req().corrupt : 0
|
||||||
, stats ? tracker_req().redundant: 0
|
, tracker_req().key
|
||||||
, tracker_req().num_want
|
, (tracker_req().event != tracker_request::none) ? "&event=" : ""
|
||||||
, tracker_req().key);
|
, (tracker_req().event != tracker_request::none) ? event_string[tracker_req().event - 1] : ""
|
||||||
|
, tracker_req().num_want);
|
||||||
url += str;
|
url += str;
|
||||||
#ifndef TORRENT_DISABLE_ENCRYPTION
|
#ifndef TORRENT_DISABLE_ENCRYPTION
|
||||||
if (m_ses.get_pe_settings().in_enc_policy != pe_settings::disabled)
|
if (m_ses.get_pe_settings().in_enc_policy != pe_settings::disabled)
|
||||||
url += "&supportcrypto=1";
|
url += "&supportcrypto=1";
|
||||||
#endif
|
#endif
|
||||||
|
if (stats && m_ses.settings().report_redundant_bytes)
|
||||||
|
{
|
||||||
|
url += "&redundant=";
|
||||||
|
url += to_string(tracker_req().redundant).elems;
|
||||||
|
}
|
||||||
if (!tracker_req().trackerid.empty())
|
if (!tracker_req().trackerid.empty())
|
||||||
{
|
{
|
||||||
std::string id = tracker_req().trackerid;
|
std::string id = tracker_req().trackerid;
|
||||||
|
@ -164,13 +180,6 @@ namespace libtorrent
|
||||||
url += escape_string(id.c_str(), id.length());
|
url += escape_string(id.c_str(), id.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tracker_req().event != tracker_request::none)
|
|
||||||
{
|
|
||||||
const char* event_string[] = {"completed", "started", "stopped", "paused"};
|
|
||||||
url += "&event=";
|
|
||||||
url += event_string[tracker_req().event - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
#if TORRENT_USE_I2P
|
#if TORRENT_USE_I2P
|
||||||
if (i2p)
|
if (i2p)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1292,6 +1292,9 @@ namespace libtorrent
|
||||||
, tracker_backoff(250)
|
, tracker_backoff(250)
|
||||||
, ban_web_seeds(true)
|
, ban_web_seeds(true)
|
||||||
, max_http_recv_buffer_size(2*1024*1024)
|
, max_http_recv_buffer_size(2*1024*1024)
|
||||||
|
, support_share_mode(true)
|
||||||
|
, support_merkle_torrents(false)
|
||||||
|
, report_redundant_bytes(true)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
session_settings::~session_settings() {}
|
session_settings::~session_settings() {}
|
||||||
|
|
Loading…
Reference in New Issue