fix internal use of deprecated function identify_client

This commit is contained in:
arvidn 2017-06-09 21:30:36 +02:00 committed by Arvid Norberg
parent fc0cbfb789
commit f3d319b677
7 changed files with 31 additions and 17 deletions

View File

@ -48,13 +48,20 @@ POSSIBILITY OF SUCH DAMAGE.
// remove its internal use
namespace libtorrent {
namespace aux {
TORRENT_EXTRA_EXPORT
std::string identify_client_impl(const peer_id& p);
}
// these functions don't really need to be public. This mechanism of
// advertising client software and version is also out-dated.
// This function can can be used to extract a string describing a client
// version from its peer-id. It will recognize most clients that have this
// kind of identification in the peer-id.
TORRENT_DEPRECATED_EXPORT TORRENT_DEPRECATED
TORRENT_DEPRECATED_EXPORT
std::string identify_client(const peer_id& p);
#ifndef TORRENT_NO_DEPRECATE

View File

@ -128,7 +128,7 @@ TORRENT_TEST(dht_bootstrap)
else if (lt::session_stats_alert const* sa = lt::alert_cast<lt::session_stats_alert>(a))
{
int const dht_nodes = lt::find_metric_idx("dht.nodes");
TEST_CHECK(sa->values[dht_nodes] > 2);
TEST_CHECK(sa->counters()[dht_nodes] > 2);
}
}
// terminate?

View File

@ -133,8 +133,8 @@ TORRENT_TEST(session_stats)
if (!ss) return;
// there's one downloading torrent
TEST_EQUAL(ss->values[downloading_idx], 1);
TEST_EQUAL(ss->values[incoming_extended_idx], 1);
TEST_EQUAL(ss->counters()[downloading_idx], 1);
TEST_EQUAL(ss->counters()[incoming_extended_idx], 1);
}
// terminate
, [](int const ticks, lt::session& ses) -> bool

View File

@ -89,8 +89,8 @@ int get_cache_size(lt::session& ses)
{
if (auto const* st = alert_cast<session_stats_alert>(a))
{
cache_size = st->values[read_cache_idx];
cache_size += st->values[write_cache_idx];
cache_size = st->counters()[read_cache_idx];
cache_size += st->counters()[write_cache_idx];
break;
}
}

View File

@ -113,7 +113,7 @@ namespace libtorrent {
std::string peer_alert::message() const
{
return torrent_alert::message() + " peer (" + print_endpoint(endpoint)
+ ", " + identify_client(pid) + ")";
+ ", " + aux::identify_client_impl(pid) + ")";
}
tracker_alert::tracker_alert(aux::stack_allocator& alloc

View File

@ -367,6 +367,13 @@ namespace libtorrent {
#endif
std::string identify_client(peer_id const& p)
{
return aux::identify_client_impl(p);
}
namespace aux {
std::string identify_client_impl(peer_id const& p)
{
char const* PID = p.data();
@ -424,5 +431,7 @@ namespace libtorrent {
unknown += "]";
return unknown;
}
}
} // aux
} // libtorrent

View File

@ -37,14 +37,12 @@ using namespace lt;
TORRENT_TEST(identify_client)
{
#ifndef TORRENT_NO_DEPRECATE
TEST_EQUAL(identify_client(peer_id("-AZ123B-............")), "Azureus 1.2.3.11");
TEST_EQUAL(identify_client(peer_id("-AZ1230-............")), "Azureus 1.2.3");
TEST_EQUAL(identify_client(peer_id("S123--..............")), "Shadow 1.2.3");
TEST_EQUAL(identify_client(peer_id("S\x1\x2\x3....\0...........")), "Shadow 1.2.3");
TEST_EQUAL(identify_client(peer_id("M1-2-3--............")), "Mainline 1.2.3");
TEST_EQUAL(identify_client(peer_id("\0\0\0\0\0\0\0\0\0\0\0\0........")), "Generic");
TEST_EQUAL(identify_client(peer_id("-xx1230-............")), "xx 1.2.3");
#endif
TEST_EQUAL(aux::identify_client_impl(peer_id("-AZ123B-............")), "Azureus 1.2.3.11");
TEST_EQUAL(aux::identify_client_impl(peer_id("-AZ1230-............")), "Azureus 1.2.3");
TEST_EQUAL(aux::identify_client_impl(peer_id("S123--..............")), "Shadow 1.2.3");
TEST_EQUAL(aux::identify_client_impl(peer_id("S\x1\x2\x3....\0...........")), "Shadow 1.2.3");
TEST_EQUAL(aux::identify_client_impl(peer_id("M1-2-3--............")), "Mainline 1.2.3");
TEST_EQUAL(aux::identify_client_impl(peer_id("\0\0\0\0\0\0\0\0\0\0\0\0........")), "Generic");
TEST_EQUAL(aux::identify_client_impl(peer_id("-xx1230-............")), "xx 1.2.3");
}