forked from premiere/premiere-libtorrent
added unit tests for identify_client. replaced iostream for rendering. renamed 'Deluge Torrent' -> 'Deluge'
This commit is contained in:
parent
3426385226
commit
91065d7a08
|
@ -163,7 +163,7 @@ namespace
|
|||
, {"BX", "BittorrentX"}
|
||||
, {"CD", "Enhanced CTorrent"}
|
||||
, {"CT", "CTorrent"}
|
||||
, {"DE", "Deluge Torrent"}
|
||||
, {"DE", "Deluge"}
|
||||
, {"EB", "EBit"}
|
||||
, {"ES", "electric sheep"}
|
||||
, {"HL", "Halite"}
|
||||
|
@ -260,7 +260,7 @@ namespace
|
|||
|
||||
std::string lookup(fingerprint const& f)
|
||||
{
|
||||
std::stringstream identity;
|
||||
char identity[200];
|
||||
|
||||
const int size = sizeof(name_map)/sizeof(name_map[0]);
|
||||
map_entry tmp = {f.name, ""};
|
||||
|
@ -276,22 +276,31 @@ namespace
|
|||
}
|
||||
#endif
|
||||
|
||||
char temp[3];
|
||||
char const* name = 0;
|
||||
if (i < name_map + size && std::equal(f.name, f.name + 2, i->id))
|
||||
identity << i->name;
|
||||
{
|
||||
name = i->name;
|
||||
}
|
||||
else
|
||||
{
|
||||
identity << f.name[0];
|
||||
if (f.name[1] != 0) identity << f.name[1];
|
||||
// if we don't have this client in the list
|
||||
// just use the one or two letter code
|
||||
memcpy(temp, f.name, 2);
|
||||
temp[2] = 0;
|
||||
name = temp;
|
||||
}
|
||||
|
||||
identity << " " << (int)f.major_version
|
||||
<< "." << (int)f.minor_version
|
||||
<< "." << (int)f.revision_version;
|
||||
int num_chars = snprintf(identity, sizeof(identity), "%s %u.%u.%u", name
|
||||
, f.major_version, f.minor_version, f.revision_version);
|
||||
|
||||
if (f.name[1] != 0)
|
||||
identity << "." << (int)f.tag_version;
|
||||
if (f.tag_version != 0)
|
||||
{
|
||||
snprintf(identity + num_chars, sizeof(identity) - num_chars
|
||||
, ".%u", f.tag_version);
|
||||
}
|
||||
|
||||
return identity.str();
|
||||
return identity;
|
||||
}
|
||||
|
||||
bool find_string(unsigned char const* id, char const* search)
|
||||
|
@ -355,7 +364,7 @@ namespace libtorrent
|
|||
if (std::equal(PID, PID + 13, "\0\0\0\0\0\0\0\0\0\0\0\0\0"))
|
||||
return "Experimental 3.1";
|
||||
|
||||
|
||||
|
||||
// look for azureus style id
|
||||
f = parse_az_style(p);
|
||||
if (f) return lookup(*f);
|
||||
|
@ -367,8 +376,8 @@ namespace libtorrent
|
|||
// look for mainline style id
|
||||
f = parse_mainline_style(p);
|
||||
if (f) return lookup(*f);
|
||||
|
||||
|
||||
|
||||
|
||||
if (std::equal(PID, PID + 12, "\0\0\0\0\0\0\0\0\0\0\0\0"))
|
||||
return "Generic";
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/torrent_info.hpp"
|
||||
#include "libtorrent/escape_string.hpp"
|
||||
#include "libtorrent/broadcast_socket.hpp"
|
||||
#include "libtorrent/identify_client.hpp"
|
||||
#ifndef TORRENT_DISABLE_DHT
|
||||
#include "libtorrent/kademlia/node_id.hpp"
|
||||
#include "libtorrent/kademlia/routing_table.hpp"
|
||||
|
@ -354,6 +355,13 @@ int test_main()
|
|||
{
|
||||
using namespace libtorrent;
|
||||
|
||||
// test identify_client
|
||||
|
||||
TEST_CHECK(identify_client(peer_id("-AZ1234-............")) == "Azureus 1.2.3.4");
|
||||
TEST_CHECK(identify_client(peer_id("-AZ1230-............")) == "Azureus 1.2.3");
|
||||
TEST_CHECK(identify_client(peer_id("S123--..............")) == "Shadow 1.2.3");
|
||||
TEST_CHECK(identify_client(peer_id("M1-2-3--............")) == "Mainline 1.2.3");
|
||||
|
||||
// test to/from hex conversion
|
||||
|
||||
char const* str = "0123456789012345678901234567890123456789";
|
||||
|
|
Loading…
Reference in New Issue