2023-02-11 20:49:42 +00:00
|
|
|
// This file Copyright © 2008-2023 Mnemosyne LLC.
|
2022-02-07 16:25:02 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2008-04-29 16:57:16 +00:00
|
|
|
/* thanks amc1! */
|
|
|
|
|
2021-10-09 02:46:10 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <array>
|
2021-10-17 20:17:18 +00:00
|
|
|
#include <cctype> /* isprint() */
|
2021-11-09 03:30:03 +00:00
|
|
|
#include <optional>
|
|
|
|
#include <string_view>
|
2021-10-09 02:46:10 +00:00
|
|
|
#include <tuple>
|
2021-11-19 18:37:38 +00:00
|
|
|
#include <utility>
|
2021-11-09 03:30:03 +00:00
|
|
|
#include <vector>
|
2007-07-18 17:25:42 +00:00
|
|
|
|
2022-04-04 18:36:48 +00:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
2023-04-14 19:33:23 +00:00
|
|
|
#include "libtransmission/transmission.h"
|
2022-09-03 07:13:22 +00:00
|
|
|
|
2023-04-14 19:33:23 +00:00
|
|
|
#include "libtransmission/clients.h"
|
|
|
|
#include "libtransmission/utils.h"
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2022-09-03 07:13:22 +00:00
|
|
|
using namespace std::literals;
|
2021-10-09 02:46:10 +00:00
|
|
|
|
|
|
|
namespace
|
2006-12-11 01:23:09 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-09-03 07:13:22 +00:00
|
|
|
template<typename T>
|
|
|
|
constexpr std::pair<char*, size_t> buf_append(char* buf, size_t buflen, T const& value)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
2022-09-03 07:13:22 +00:00
|
|
|
if (buflen == 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-09-03 07:13:22 +00:00
|
|
|
return { buf, buflen };
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2022-09-03 07:13:22 +00:00
|
|
|
auto const [out, len] = fmt::format_to_n(buf, buflen, "{}", value);
|
|
|
|
auto* const end = buf + std::min(buflen - 1, static_cast<size_t>(out - buf));
|
|
|
|
*end = '\0';
|
|
|
|
return { end, buflen - (end - buf) };
|
2009-08-10 20:04:08 +00:00
|
|
|
}
|
2008-10-01 18:11:28 +00:00
|
|
|
|
2021-10-09 02:46:10 +00:00
|
|
|
template<typename T, typename... ArgTypes>
|
2021-10-14 19:26:38 +00:00
|
|
|
constexpr std::pair<char*, size_t> buf_append(char* buf, size_t buflen, T t, ArgTypes... args)
|
2017-08-01 08:43:33 +00:00
|
|
|
{
|
2021-10-09 02:46:10 +00:00
|
|
|
std::tie(buf, buflen) = buf_append(buf, buflen, t);
|
|
|
|
return buf_append(buf, buflen, args...);
|
2017-08-01 08:43:33 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 21:53:10 +00:00
|
|
|
constexpr std::string_view base62str(uint8_t chr)
|
2022-09-03 07:13:22 +00:00
|
|
|
{
|
|
|
|
// clang-format off
|
|
|
|
auto constexpr Strings = std::array<std::string_view, 256>{
|
|
|
|
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
|
|
|
|
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
|
|
|
|
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
|
|
|
|
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
|
|
|
|
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "0"sv, "1"sv,
|
|
|
|
"2"sv, "3"sv, "4"sv, "5"sv, "6"sv, "7"sv, "8"sv, "9"sv, "x"sv, "x"sv,
|
|
|
|
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "10"sv, "11"sv, "12"sv, "13"sv, "14"sv,
|
|
|
|
"15"sv, "16"sv, "17"sv, "18"sv, "19"sv, "20"sv, "21"sv, "22"sv, "23"sv, "24"sv,
|
|
|
|
"25"sv, "26"sv, "27"sv, "28"sv, "29"sv, "30"sv, "31"sv, "32"sv, "33"sv, "34"sv,
|
2022-10-05 21:53:10 +00:00
|
|
|
"35"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "36"sv, "37"sv, "38"sv,
|
|
|
|
"39"sv, "40"sv, "41"sv, "42"sv, "43"sv, "44"sv, "45"sv, "46"sv, "47"sv, "48"sv,
|
|
|
|
"49"sv, "50"sv, "51"sv, "52"sv, "53"sv, "54"sv, "55"sv, "56"sv, "57"sv, "58"sv,
|
|
|
|
"59"sv, "60"sv, "61"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
|
2022-09-03 07:13:22 +00:00
|
|
|
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
|
|
|
|
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
|
|
|
|
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
|
|
|
|
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
|
|
|
|
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
|
|
|
|
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
|
|
|
|
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
|
|
|
|
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
|
|
|
|
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
|
|
|
|
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
|
|
|
|
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
|
|
|
|
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
|
|
|
|
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv
|
|
|
|
} ;
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
return Strings[chr];
|
2022-04-06 17:06:11 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
|
2022-07-27 21:53:39 +00:00
|
|
|
int strint(char const* pch, int span, int base = 10)
|
2008-04-29 16:57:16 +00:00
|
|
|
{
|
2022-07-27 21:53:39 +00:00
|
|
|
auto sv = std::string_view{ pch, static_cast<size_t>(span) };
|
2022-09-02 06:04:09 +00:00
|
|
|
return tr_parseNum<int>(sv, nullptr, base).value_or(0);
|
2008-04-29 16:57:16 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 21:53:10 +00:00
|
|
|
constexpr std::string_view utSuffix(uint8_t ch)
|
2008-04-29 16:57:16 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
switch (ch)
|
2008-04-29 16:57:16 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case 'b':
|
|
|
|
case 'B':
|
2021-10-09 02:46:10 +00:00
|
|
|
return " (Beta)"sv;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
case 'd':
|
2021-10-09 02:46:10 +00:00
|
|
|
return " (Debug)"sv;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
case 'x':
|
|
|
|
case 'X':
|
|
|
|
case 'Z':
|
2021-10-09 02:46:10 +00:00
|
|
|
return " (Dev)"sv;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
default:
|
2021-10-09 02:46:10 +00:00
|
|
|
return ""sv;
|
2008-04-29 16:57:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
void two_major_two_minor_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2008-04-29 16:57:16 +00:00
|
|
|
{
|
2021-10-22 20:24:30 +00:00
|
|
|
std::tie(buf, buflen) = buf_append(buf, buflen, name, ' ', strint(&id[3], 2), '.');
|
2022-04-04 18:36:48 +00:00
|
|
|
*fmt::format_to_n(buf, buflen - 1, FMT_STRING("{:02d}"), strint(&id[5], 2)).out = '\0';
|
2008-04-29 16:57:16 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-06-01 16:56:59 +00:00
|
|
|
// Shad0w with his experimental BitTorrent implementation and BitTornado
|
|
|
|
// introduced peer ids that begin with a character which is``T`` in the
|
|
|
|
// case of BitTornado followed by up to five ascii characters for version
|
|
|
|
// number, padded with dashes if less than 5, followed by ---. The ascii
|
|
|
|
// characters denoting version are limited to the following characters:
|
|
|
|
// 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-
|
|
|
|
// For example: 'S58B-----'... for Shadow's 5.8.11
|
2022-10-25 16:14:42 +00:00
|
|
|
std::optional<int> get_shad0w_int(char ch)
|
2008-04-29 16:57:16 +00:00
|
|
|
{
|
2022-06-01 16:56:59 +00:00
|
|
|
auto constexpr Str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-"sv;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-06-01 16:56:59 +00:00
|
|
|
if (auto const pos = Str.find(ch); pos != std::string_view::npos)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
2022-06-01 16:56:59 +00:00
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
bool decodeShad0wClient(char* buf, size_t buflen, std::string_view in)
|
|
|
|
{
|
|
|
|
auto const* const buf_in = buf;
|
2006-12-11 01:23:09 +00:00
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
auto peer_id = std::string_view{ std::data(in), 9 };
|
|
|
|
|
2021-10-09 02:46:10 +00:00
|
|
|
if (std::size(peer_id) != 9 || peer_id[6] != '-' || peer_id[7] != '-' || peer_id[8] != '-')
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-09 02:46:10 +00:00
|
|
|
return false;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
while (!std::empty(peer_id) && peer_id.back() == '-')
|
|
|
|
{
|
|
|
|
peer_id.remove_suffix(1);
|
|
|
|
}
|
|
|
|
auto vals = std::vector<int>{};
|
|
|
|
while (std::size(peer_id) > 1)
|
|
|
|
{
|
|
|
|
auto const num = get_shad0w_int(peer_id.back());
|
|
|
|
if (!num)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
vals.push_back(*num);
|
|
|
|
peer_id.remove_suffix(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto name = std::string_view{};
|
|
|
|
switch (peer_id.front())
|
|
|
|
{
|
|
|
|
case 'A':
|
|
|
|
name = "ABC"sv;
|
|
|
|
break;
|
|
|
|
case 'O':
|
2022-09-03 07:13:22 +00:00
|
|
|
name = "Osprey"sv;
|
2021-10-09 02:46:10 +00:00
|
|
|
break;
|
|
|
|
case 'Q':
|
2022-09-03 07:13:22 +00:00
|
|
|
name = "BTQueue"sv;
|
2021-10-09 02:46:10 +00:00
|
|
|
break;
|
|
|
|
case 'R':
|
2022-09-03 07:13:22 +00:00
|
|
|
name = "Tribler"sv;
|
2021-10-09 02:46:10 +00:00
|
|
|
break;
|
|
|
|
case 'S':
|
2022-09-03 07:13:22 +00:00
|
|
|
name = "Shad0w"sv;
|
2021-10-09 02:46:10 +00:00
|
|
|
break;
|
|
|
|
case 'T':
|
2022-09-03 07:13:22 +00:00
|
|
|
name = "BitTornado"sv;
|
2021-10-09 02:46:10 +00:00
|
|
|
break;
|
|
|
|
case 'U':
|
2022-09-03 07:13:22 +00:00
|
|
|
name = "UPnP NAT Bit Torrent"sv;
|
2021-10-09 02:46:10 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2008-04-29 16:57:16 +00:00
|
|
|
|
2021-10-09 02:46:10 +00:00
|
|
|
std::tie(buf, buflen) = buf_append(buf, buflen, name, ' ');
|
|
|
|
std::for_each(
|
|
|
|
std::rbegin(vals),
|
|
|
|
std::rend(vals),
|
|
|
|
[&buf, &buflen](int num) { std::tie(buf, buflen) = buf_append(buf, buflen, num, '.'); });
|
2021-12-30 03:48:50 +00:00
|
|
|
if (buf > buf_in)
|
|
|
|
{
|
|
|
|
buf[-1] = '\0'; // remove trailing '.'
|
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
return true;
|
2008-04-29 16:57:16 +00:00
|
|
|
}
|
|
|
|
|
2021-10-09 02:46:10 +00:00
|
|
|
bool decodeBitCometClient(char* buf, size_t buflen, std::string_view peer_id)
|
2008-06-16 17:26:19 +00:00
|
|
|
{
|
2021-10-09 02:46:10 +00:00
|
|
|
// BitComet produces peer ids that consists of four ASCII characters exbc,
|
|
|
|
// followed by two bytes x and y, followed by random characters. The version
|
|
|
|
// number is x in decimal before the decimal point and y as two decimal
|
|
|
|
// digits after the decimal point. BitLord uses the same scheme, but adds
|
|
|
|
// LORD after the version bytes. An unofficial patch for BitComet once
|
|
|
|
// replaced exbc with FUTB. The encoding for BitComet Peer IDs changed
|
|
|
|
// to Azureus-style as of BitComet version 0.59.
|
|
|
|
auto mod = std::string_view{};
|
2022-11-29 03:03:28 +00:00
|
|
|
if (auto const lead = std::string_view{ std::data(peer_id), std::min(std::size(peer_id), size_t{ 4 }) }; lead == "exbc")
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-09-03 07:13:22 +00:00
|
|
|
mod = ""sv;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
else if (lead == "FUTB")
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-09-03 07:13:22 +00:00
|
|
|
mod = "(Solidox Mod) "sv;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
else if (lead == "xUTB"sv)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-09-03 07:13:22 +00:00
|
|
|
mod = "(Mod 2) "sv;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2008-06-16 17:26:19 +00:00
|
|
|
|
2021-10-09 02:46:10 +00:00
|
|
|
bool const is_bitlord = std::string_view(std::data(peer_id) + 6, 4) == "LORD"sv;
|
|
|
|
auto const name = is_bitlord ? "BitLord"sv : "BitComet"sv;
|
2022-02-07 04:28:36 +00:00
|
|
|
int const major = uint8_t(peer_id[4]);
|
|
|
|
int const minor = uint8_t(peer_id[5]);
|
2008-06-16 17:26:19 +00:00
|
|
|
|
2021-10-09 02:46:10 +00:00
|
|
|
std::tie(buf, buflen) = buf_append(buf, buflen, name, ' ', mod, major, '.');
|
2022-04-04 18:36:48 +00:00
|
|
|
*fmt::format_to_n(buf, buflen - 1, FMT_STRING("{:02d}"), minor).out = '\0';
|
2011-03-22 15:19:54 +00:00
|
|
|
return true;
|
2008-06-16 17:26:19 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
using format_func = void (*)(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id);
|
2021-10-09 02:46:10 +00:00
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void three_digit_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2008-04-29 16:57:16 +00:00
|
|
|
{
|
2022-10-05 21:53:10 +00:00
|
|
|
buf_append(buf, buflen, name, ' ', base62str(id[3]), '.', base62str(id[4]), '.', base62str(id[5]));
|
2021-10-09 02:46:10 +00:00
|
|
|
}
|
2008-04-29 16:57:16 +00:00
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void four_digit_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
2022-10-05 21:53:10 +00:00
|
|
|
buf_append(buf, buflen, name, ' ', base62str(id[3]), '.', base62str(id[4]), '.', base62str(id[5]), '.', base62str(id[6]));
|
2021-10-09 02:46:10 +00:00
|
|
|
}
|
2008-04-29 16:57:16 +00:00
|
|
|
|
2022-04-06 17:06:11 +00:00
|
|
|
void no_version_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t /*id*/)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
|
|
|
buf_append(buf, buflen, name);
|
|
|
|
}
|
2008-07-24 18:53:17 +00:00
|
|
|
|
2021-10-09 02:46:10 +00:00
|
|
|
// specific clients
|
2017-08-01 08:43:33 +00:00
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void amazon_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
|
|
|
buf_append(buf, buflen, name, ' ', id[3], '.', id[5], '.', id[7]);
|
|
|
|
}
|
2008-04-29 16:57:16 +00:00
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void aria2_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
|
|
|
if (id[4] == '-' && id[6] == '-' && id[8] == '-')
|
|
|
|
{
|
|
|
|
buf_append(buf, buflen, name, ' ', id[3], '.', id[5], '.', id[7]);
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
else if (id[4] == '-' && id[7] == '-' && id[9] == '-')
|
2011-11-22 03:02:18 +00:00
|
|
|
{
|
2021-10-09 02:46:10 +00:00
|
|
|
buf_append(buf, buflen, name, ' ', id[3], '.', id[5], id[6], '.', id[8]);
|
2011-11-22 03:02:18 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
else
|
2008-02-19 16:55:13 +00:00
|
|
|
{
|
2021-10-09 02:46:10 +00:00
|
|
|
buf_append(buf, buflen, name);
|
|
|
|
}
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void bitbuddy_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
|
|
|
buf_append(buf, buflen, name, ' ', id[3], '.', id[4], id[5], id[6]);
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void bitlord_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
2021-10-22 20:24:30 +00:00
|
|
|
buf_append(buf, buflen, name, ' ', id[3], '.', id[4], '.', id[5], '-', std::string_view(&id[6], 3));
|
2021-10-09 02:46:10 +00:00
|
|
|
}
|
2008-04-29 16:57:16 +00:00
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void bitrocket_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
|
|
|
buf_append(buf, buflen, name, ' ', id[3], '.', id[4], ' ', '(', id[5], id[6], ')');
|
|
|
|
}
|
2008-06-16 17:26:19 +00:00
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
void bittorrent_dna_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
|
|
|
std::tie(buf, buflen) = buf_append(buf, buflen, name, ' ');
|
2022-04-04 18:36:48 +00:00
|
|
|
*fmt::format_to_n(buf, buflen - 1, FMT_STRING("{:d}.{:d}.{:d}"), strint(&id[3], 2), strint(&id[5], 2), strint(&id[7], 2))
|
|
|
|
.out = '\0';
|
2021-10-09 02:46:10 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
void bits_on_wheels_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
|
|
|
// Bits on Wheels uses the pattern -BOWxxx-yyyyyyyyyyyy, where y is random
|
|
|
|
// (uppercase letters) and x depends on the version.
|
|
|
|
// Version 1.0.6 has xxx = A0C.
|
|
|
|
|
2022-09-03 07:13:22 +00:00
|
|
|
if (std::equal(&id[4], &id[7], "A0B"))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-09 02:46:10 +00:00
|
|
|
buf_append(buf, buflen, name, " 1.0.5"sv);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2022-09-03 07:13:22 +00:00
|
|
|
else if (std::equal(&id[4], &id[7], "A0C"))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-09 02:46:10 +00:00
|
|
|
buf_append(buf, buflen, name, " 1.0.6"sv);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
else
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-09 02:46:10 +00:00
|
|
|
buf_append(buf, buflen, name, ' ', id[4], '.', id[5], '.', id[6]);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void blizzard_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
|
|
|
buf_append(buf, buflen, name, ' ', int(id[3] + 1), int(id[4]));
|
|
|
|
}
|
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void btpd_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
2021-10-22 20:24:30 +00:00
|
|
|
buf_append(buf, buflen, name, ' ', std::string_view(&id[5], 3));
|
2021-10-09 02:46:10 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void burst_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
|
|
|
buf_append(buf, buflen, name, ' ', id[5], '.', id[7], '.', id[9]);
|
|
|
|
}
|
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void ctorrent_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
2022-10-05 21:53:10 +00:00
|
|
|
buf_append(buf, buflen, name, ' ', base62str(id[3]), '.', base62str(id[4]), '.', id[5], id[6]);
|
2021-10-09 02:46:10 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void folx_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
2022-10-05 21:53:10 +00:00
|
|
|
buf_append(buf, buflen, name, ' ', base62str(id[3]), '.', 'x');
|
2021-10-09 02:46:10 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void ktorrent_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
|
|
|
if (id[5] == 'D')
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-10-05 21:53:10 +00:00
|
|
|
buf_append(buf, buflen, name, ' ', base62str(id[3]), '.', base62str(id[4]), " Dev "sv, base62str(id[6]));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
else if (id[5] == 'R')
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-10-05 21:53:10 +00:00
|
|
|
buf_append(buf, buflen, name, ' ', base62str(id[3]), '.', base62str(id[4]), " RC "sv, base62str(id[6]));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
else
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
2021-10-09 02:46:10 +00:00
|
|
|
three_digit_formatter(buf, buflen, name, id);
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void mainline_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
|
|
|
// Queen Bee uses Bram`s new style:
|
|
|
|
// Q1-0-0-- or Q1-10-0- followed by random bytes.
|
|
|
|
|
|
|
|
if (id[4] == '-' && id[6] == '-') // Mx-y-z--
|
2006-09-12 01:38:57 +00:00
|
|
|
{
|
2021-10-09 02:46:10 +00:00
|
|
|
buf_append(buf, buflen, name, ' ', id[1], '.', id[3], '.', id[5]);
|
2006-09-12 01:38:57 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
else if (id[5] == '-') // Mx-yy-z-
|
2006-09-22 10:05:51 +00:00
|
|
|
{
|
2021-10-09 02:46:10 +00:00
|
|
|
buf_append(buf, buflen, name, ' ', id[1], '.', id[3], id[4], '.', id[6]);
|
2006-12-20 17:26:32 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
else
|
2007-08-06 21:34:38 +00:00
|
|
|
{
|
2021-10-09 02:46:10 +00:00
|
|
|
buf_append(buf, buflen, name);
|
2007-08-06 21:34:38 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void mediaget_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
2022-10-05 21:53:10 +00:00
|
|
|
buf_append(buf, buflen, name, ' ', base62str(id[3]), '.', base62str(id[4]));
|
2021-10-09 02:46:10 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void mldonkey_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
|
|
|
// MLdonkey use the following peer_id scheme: the first characters are
|
|
|
|
// -ML followed by a dotted version then a - followed by randomness.
|
|
|
|
// e.g. -ML2.7.2-kgjjfkd
|
2021-10-22 20:24:30 +00:00
|
|
|
buf_append(buf, buflen, name, ' ', std::string_view(&id[3], 5));
|
2021-10-09 02:46:10 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void opera_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
|
|
|
// Opera 8 previews and Opera 9.x releases use the following peer_id
|
|
|
|
// scheme: The first two characters are OP and the next four digits equal
|
|
|
|
// the build number. All following characters are random lowercase
|
2022-08-31 16:28:54 +00:00
|
|
|
// hexadecimal digits.
|
2021-10-22 20:24:30 +00:00
|
|
|
buf_append(buf, buflen, name, ' ', std::string_view(&id[2], 4));
|
2021-10-09 02:46:10 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void picotorrent_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
2022-10-05 21:53:10 +00:00
|
|
|
buf_append(buf, buflen, name, ' ', base62str(id[3]), '.', id[4], id[5], '.', base62str(id[6]));
|
2021-10-09 02:46:10 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void plus_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
|
|
|
buf_append(buf, buflen, name, ' ', id[4], '.', id[5], id[6]);
|
|
|
|
}
|
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void qvod_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
2022-10-05 21:53:10 +00:00
|
|
|
buf_append(buf, buflen, name, ' ', base62str(id[4]), '.', base62str(id[5]), '.', base62str(id[6]), '.', base62str(id[7]));
|
2021-10-09 02:46:10 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
void transmission_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
|
|
|
std::tie(buf, buflen) = buf_append(buf, buflen, name, ' ');
|
|
|
|
|
2022-09-03 07:13:22 +00:00
|
|
|
if (std::equal(&id[3], &id[6], "000")) // very old client style: -TR0006- is 0.6
|
2006-12-22 23:34:35 +00:00
|
|
|
{
|
2022-04-04 18:36:48 +00:00
|
|
|
*fmt::format_to_n(buf, buflen - 1, FMT_STRING("0.{:c}"), id[6]).out = '\0';
|
2006-12-22 23:34:35 +00:00
|
|
|
}
|
2022-10-05 21:53:10 +00:00
|
|
|
else if (std::equal(&id[3], &id[5], "00")) // pre-1.0 style: -TR0072- is 0.72
|
2006-12-15 05:39:06 +00:00
|
|
|
{
|
2022-04-04 18:36:48 +00:00
|
|
|
*fmt::format_to_n(buf, buflen - 1, FMT_STRING("0.{:02d}"), strint(&id[5], 2)).out = '\0';
|
2006-12-15 05:39:06 +00:00
|
|
|
}
|
2022-10-05 21:53:10 +00:00
|
|
|
else if (id[3] <= '3') // style up through 3.00: -TR111Z- is 1.11+
|
2006-12-29 02:09:16 +00:00
|
|
|
{
|
2022-10-05 21:53:10 +00:00
|
|
|
*fmt::format_to_n(buf, buflen - 1, FMT_STRING("{:s}.{:02d}{:s}"), base62str(id[3]), strint(&id[4], 2), utSuffix(id[6]))
|
2022-04-04 18:36:48 +00:00
|
|
|
.out = '\0';
|
2006-12-29 02:09:16 +00:00
|
|
|
}
|
2022-10-05 21:53:10 +00:00
|
|
|
else // -TR400X- is 4.0.0 (Beta)"
|
|
|
|
{
|
|
|
|
buf_append(buf, buflen, base62str(id[3]), '.', base62str(id[4]), '.', base62str(id[5]), utSuffix(id[6]));
|
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
}
|
|
|
|
|
2022-01-16 16:27:23 +00:00
|
|
|
void utorrent_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
|
|
|
if (id[7] == '-')
|
2007-01-02 03:33:55 +00:00
|
|
|
{
|
2022-01-16 16:27:23 +00:00
|
|
|
buf_append(
|
|
|
|
buf,
|
|
|
|
buflen,
|
|
|
|
name,
|
|
|
|
' ',
|
|
|
|
strint(&id[3], 1, 16),
|
|
|
|
'.',
|
|
|
|
strint(&id[4], 1, 16),
|
|
|
|
'.',
|
|
|
|
strint(&id[5], 1, 16),
|
2022-10-05 21:53:10 +00:00
|
|
|
utSuffix(id[6]));
|
2007-05-09 02:55:10 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
else // uTorrent replaces the trailing dash with an extra digit for longer version numbers
|
2007-05-21 15:02:11 +00:00
|
|
|
{
|
2022-01-16 16:27:23 +00:00
|
|
|
buf_append(
|
|
|
|
buf,
|
|
|
|
buflen,
|
|
|
|
name,
|
|
|
|
' ',
|
|
|
|
strint(&id[3], 1, 16),
|
|
|
|
'.',
|
|
|
|
strint(&id[4], 1, 16),
|
|
|
|
'.',
|
|
|
|
strint(&id[5], 2, 10),
|
2022-10-05 21:53:10 +00:00
|
|
|
utSuffix(id[7]));
|
2007-10-19 00:19:16 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void xbt_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
2022-10-05 21:53:10 +00:00
|
|
|
buf_append(buf, buflen, name, ' ', id[3], '.', id[4], '.', id[5], utSuffix(id[6]));
|
2021-10-09 02:46:10 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
constexpr void xfplay_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
|
|
|
if (id[6] == '0')
|
2009-11-16 23:14:47 +00:00
|
|
|
{
|
2021-10-09 02:46:10 +00:00
|
|
|
three_digit_formatter(buf, buflen, name, id);
|
2009-11-16 23:14:47 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
else
|
2007-07-15 05:02:30 +00:00
|
|
|
{
|
2021-10-09 02:46:10 +00:00
|
|
|
buf_append(buf, buflen, name, ' ', id[3], '.', id[4], '.', id[5], id[6]);
|
2007-07-15 05:02:30 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
void xtorrent_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
2022-10-05 21:53:10 +00:00
|
|
|
std::tie(buf, buflen) = buf_append(buf, buflen, name, ' ', base62str(id[3]), '.', base62str(id[4]), " ("sv);
|
2022-04-04 18:36:48 +00:00
|
|
|
*fmt::format_to_n(buf, buflen - 1, FMT_STRING("{:d}"), strint(&id[5], 2)).out = '\0';
|
2021-10-09 02:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Client
|
|
|
|
{
|
|
|
|
std::string_view begins_with;
|
|
|
|
std::string_view name;
|
|
|
|
format_func formatter;
|
|
|
|
};
|
|
|
|
|
2022-09-22 21:55:51 +00:00
|
|
|
auto constexpr Clients = std::array<Client, 131>{ {
|
2022-09-02 17:37:25 +00:00
|
|
|
{ "-AD", "Advanced Download Manager", three_digit_formatter },
|
2021-10-09 02:46:10 +00:00
|
|
|
{ "-AG", "Ares", four_digit_formatter },
|
|
|
|
{ "-AR", "Arctic", four_digit_formatter },
|
|
|
|
{ "-AT", "Artemis", four_digit_formatter },
|
|
|
|
{ "-AV", "Avicora", four_digit_formatter },
|
|
|
|
{ "-AX", "BitPump", two_major_two_minor_formatter },
|
|
|
|
{ "-AZ", "Azureus / Vuze", four_digit_formatter },
|
|
|
|
{ "-A~", "Ares", three_digit_formatter },
|
|
|
|
{ "-BB", "BitBuddy", bitbuddy_formatter },
|
|
|
|
{ "-BC", "BitComet", two_major_two_minor_formatter },
|
|
|
|
{ "-BE", "BitTorrent SDK", four_digit_formatter },
|
|
|
|
{ "-BF", "BitFlu", no_version_formatter },
|
|
|
|
{ "-BG", "BTGetit", four_digit_formatter },
|
|
|
|
{ "-BH", "BitZilla", four_digit_formatter },
|
|
|
|
{ "-BI", "BiglyBT", four_digit_formatter },
|
|
|
|
{ "-BL", "BitLord", bitlord_formatter },
|
|
|
|
{ "-BM", "BitMagnet", four_digit_formatter },
|
|
|
|
{ "-BN", "Baidu Netdisk", no_version_formatter },
|
|
|
|
{ "-BOW", "Bits on Wheels", bits_on_wheels_formatter },
|
|
|
|
{ "-BP", "BitTorrent Pro (Azureus + Spyware)", four_digit_formatter },
|
|
|
|
{ "-BR", "BitRocket", bitrocket_formatter },
|
|
|
|
{ "-BS", "BTSlave", four_digit_formatter },
|
|
|
|
{ "-BT", "BitTorrent", utorrent_formatter },
|
2022-09-22 21:55:51 +00:00
|
|
|
{ "-BW", "BitTorrent Web", utorrent_formatter },
|
2021-10-09 02:46:10 +00:00
|
|
|
{ "-BX", "BittorrentX", four_digit_formatter },
|
|
|
|
{ "-CD", "Enhanced CTorrent", two_major_two_minor_formatter },
|
|
|
|
{ "-CT", "CTorrent", ctorrent_formatter },
|
|
|
|
{ "-DE", "Deluge", four_digit_formatter },
|
|
|
|
{ "-DP", "Propagate Data Client", four_digit_formatter },
|
|
|
|
{ "-EB", "EBit", four_digit_formatter },
|
|
|
|
{ "-ES", "Electric Sheep", three_digit_formatter },
|
|
|
|
{ "-FC", "FileCroc", four_digit_formatter },
|
|
|
|
{ "-FD", "Free Download Manager", three_digit_formatter },
|
|
|
|
{ "-FG", "FlashGet", two_major_two_minor_formatter },
|
|
|
|
{ "-FL", "Folx", folx_formatter },
|
|
|
|
{ "-FT", "FoxTorrent/RedSwoosh", four_digit_formatter },
|
|
|
|
{ "-FW", "FrostWire", three_digit_formatter },
|
|
|
|
{ "-FX", "Freebox", four_digit_formatter },
|
|
|
|
{ "-G3", "G3 Torrent", no_version_formatter },
|
|
|
|
{ "-GR", "GetRight", four_digit_formatter },
|
|
|
|
{ "-GS", "GSTorrent", four_digit_formatter },
|
|
|
|
{ "-HK", "Hekate", four_digit_formatter },
|
|
|
|
{ "-HL", "Halite", three_digit_formatter },
|
|
|
|
{ "-HN", "Hydranode", four_digit_formatter },
|
|
|
|
{ "-KG", "KGet", four_digit_formatter },
|
|
|
|
{ "-KT", "KTorrent", ktorrent_formatter },
|
|
|
|
{ "-LC", "LeechCraft", four_digit_formatter },
|
|
|
|
{ "-LH", "LH-ABC", four_digit_formatter },
|
|
|
|
{ "-LP", "Lphant", two_major_two_minor_formatter },
|
|
|
|
{ "-LT", "libtorrent (Rasterbar)", three_digit_formatter },
|
|
|
|
{ "-LW", "LimeWire", no_version_formatter },
|
2022-09-02 17:37:25 +00:00
|
|
|
{ "-Lr", "LibreTorrent", three_digit_formatter },
|
2021-10-09 02:46:10 +00:00
|
|
|
{ "-MG", "MediaGet", mediaget_formatter },
|
|
|
|
{ "-MK", "Meerkat", four_digit_formatter },
|
|
|
|
{ "-ML", "MLDonkey", mldonkey_formatter },
|
|
|
|
{ "-MO", "MonoTorrent", four_digit_formatter },
|
|
|
|
{ "-MP", "MooPolice", three_digit_formatter },
|
|
|
|
{ "-MR", "Miro", four_digit_formatter },
|
|
|
|
{ "-MT", "Moonlight", four_digit_formatter },
|
|
|
|
{ "-NE", "BT Next Evolution", four_digit_formatter },
|
|
|
|
{ "-NX", "Net Transport", four_digit_formatter },
|
|
|
|
{ "-OS", "OneSwarm", four_digit_formatter },
|
|
|
|
{ "-OT", "OmegaTorrent", four_digit_formatter },
|
|
|
|
{ "-PD", "Pando", four_digit_formatter },
|
|
|
|
{ "-PI", "PicoTorrent", picotorrent_formatter },
|
|
|
|
{ "-QD", "QQDownload", four_digit_formatter },
|
|
|
|
{ "-QT", "QT 4 Torrent example", four_digit_formatter },
|
|
|
|
{ "-RS", "Rufus", four_digit_formatter },
|
|
|
|
{ "-RT", "Retriever", four_digit_formatter },
|
|
|
|
{ "-RZ", "RezTorrent", four_digit_formatter },
|
|
|
|
{ "-SB", "~Swiftbit", four_digit_formatter },
|
|
|
|
{ "-SD", "Thunder", four_digit_formatter },
|
|
|
|
{ "-SM", "SoMud", four_digit_formatter },
|
|
|
|
{ "-SP", "BitSpirit", three_digit_formatter },
|
|
|
|
{ "-SS", "SwarmScope", four_digit_formatter },
|
|
|
|
{ "-ST", "SymTorrent", four_digit_formatter },
|
|
|
|
{ "-SZ", "Shareaza", four_digit_formatter },
|
|
|
|
{ "-S~", "Shareaza", four_digit_formatter },
|
2022-09-22 21:55:51 +00:00
|
|
|
{ "-TB", "Torch Browser", no_version_formatter },
|
2021-10-09 02:46:10 +00:00
|
|
|
{ "-TN", "Torrent .NET", four_digit_formatter },
|
|
|
|
{ "-TR", "Transmission", transmission_formatter },
|
|
|
|
{ "-TS", "Torrentstorm", four_digit_formatter },
|
|
|
|
{ "-TT", "TuoTu", four_digit_formatter },
|
|
|
|
{ "-UE", "\xc2\xb5Torrent Embedded", utorrent_formatter },
|
|
|
|
{ "-UL", "uLeecher!", four_digit_formatter },
|
|
|
|
{ "-UM", "\xc2\xb5Torrent Mac", utorrent_formatter },
|
|
|
|
{ "-UT", "\xc2\xb5Torrent", utorrent_formatter },
|
|
|
|
{ "-UW", "\xc2\xb5Torrent Web", utorrent_formatter },
|
|
|
|
{ "-VG", "Vagaa", four_digit_formatter },
|
|
|
|
{ "-WS", "HTTP Seed", no_version_formatter },
|
|
|
|
{ "-WT", "BitLet", four_digit_formatter },
|
|
|
|
{ "-WT-", "BitLet", no_version_formatter },
|
|
|
|
{ "-WW", "WebTorrent", four_digit_formatter },
|
|
|
|
{ "-WY", "FireTorrent", four_digit_formatter },
|
|
|
|
{ "-XC", "Xtorrent", xtorrent_formatter },
|
|
|
|
{ "-XF", "Xfplay", xfplay_formatter },
|
|
|
|
{ "-XL", "Xunlei", four_digit_formatter },
|
|
|
|
{ "-XS", "XSwifter", four_digit_formatter },
|
|
|
|
{ "-XT", "XanTorrent", four_digit_formatter },
|
|
|
|
{ "-XX", "Xtorrent", xtorrent_formatter },
|
|
|
|
{ "-ZO", "Zona", four_digit_formatter },
|
|
|
|
{ "-ZT", "Zip Torrent", four_digit_formatter },
|
|
|
|
{ "-bk", "BitKitten (libtorrent)", four_digit_formatter },
|
|
|
|
{ "-lt", "libTorrent (Rakshasa)", three_digit_formatter },
|
|
|
|
{ "-pb", "pbTorrent", three_digit_formatter },
|
|
|
|
{ "-qB", "qBittorrent", three_digit_formatter },
|
|
|
|
{ "-st", "SharkTorrent", four_digit_formatter },
|
|
|
|
{ "10-------", "JVtorrent", no_version_formatter },
|
|
|
|
{ "346-", "TorrentTopia", no_version_formatter },
|
|
|
|
{ "A2", "aria2", aria2_formatter },
|
|
|
|
{ "AZ2500BT", "BitTyrant (Azureus Mod)", no_version_formatter },
|
|
|
|
{ "BLZ", "Blizzard Downloader", blizzard_formatter },
|
|
|
|
{ "DNA", "BitTorrent DNA", bittorrent_dna_formatter },
|
2022-09-22 21:55:51 +00:00
|
|
|
{ "FD6", "Free Download Manager 6", no_version_formatter },
|
2021-10-09 02:46:10 +00:00
|
|
|
{ "LIME", "Limewire", no_version_formatter },
|
|
|
|
{ "M", "BitTorrent", mainline_formatter },
|
|
|
|
{ "Mbrst", "burst!", burst_formatter },
|
|
|
|
{ "OP", "Opera", opera_formatter },
|
|
|
|
{ "Pando", "Pando", no_version_formatter },
|
|
|
|
{ "Plus", "Plus!", plus_formatter },
|
|
|
|
{ "Q", "Queen Bee", mainline_formatter },
|
|
|
|
{ "QVOD", "QVOD", qvod_formatter },
|
|
|
|
{ "S3", "Amazon S3", amazon_formatter },
|
|
|
|
{ "TIX", "Tixati", two_major_two_minor_formatter },
|
|
|
|
{ "XBT", "XBT Client", xbt_formatter },
|
|
|
|
{ "a00---0", "Swarmy", no_version_formatter },
|
|
|
|
{ "a02---0", "Swarmy", no_version_formatter },
|
|
|
|
{ "aria2-", "aria2", no_version_formatter },
|
|
|
|
{ "btpd", "BT Protocol Daemon", btpd_formatter },
|
|
|
|
{ "eX", "eXeem", no_version_formatter },
|
|
|
|
{ "martini", "Martini Man", no_version_formatter },
|
|
|
|
} };
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2022-09-03 07:13:22 +00:00
|
|
|
void tr_clientForId(char* buf, size_t buflen, tr_peer_id_t peer_id)
|
2021-10-09 02:46:10 +00:00
|
|
|
{
|
|
|
|
*buf = '\0';
|
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
auto const key = std::string_view{ std::data(peer_id), std::size(peer_id) };
|
2021-10-09 02:46:10 +00:00
|
|
|
|
|
|
|
if (decodeShad0wClient(buf, buflen, key) || decodeBitCometClient(buf, buflen, key))
|
2008-10-25 15:08:29 +00:00
|
|
|
{
|
2022-09-03 07:13:22 +00:00
|
|
|
return;
|
2008-10-25 15:08:29 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
|
2021-10-22 20:24:30 +00:00
|
|
|
if (peer_id[0] == '\0' && peer_id[2] == 'B' && peer_id[3] == 'S')
|
2013-07-29 04:29:22 +00:00
|
|
|
{
|
2022-04-04 18:36:48 +00:00
|
|
|
*fmt::format_to_n(buf, buflen - 1, FMT_STRING("BitSpirit {:d}"), peer_id[1] == '\0' ? 1 : int(peer_id[1])).out = '\0';
|
2022-09-03 07:13:22 +00:00
|
|
|
return;
|
2013-07-29 04:29:22 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
|
|
|
|
struct Compare
|
2021-04-25 16:04:19 +00:00
|
|
|
{
|
2021-10-09 02:46:10 +00:00
|
|
|
bool operator()(std::string_view const& key, Client const& client) const
|
2021-04-25 16:04:19 +00:00
|
|
|
{
|
2022-09-03 07:13:22 +00:00
|
|
|
return key.substr(0, std::min(std::size(key), std::size(client.begins_with))) < client.begins_with;
|
2021-04-25 16:04:19 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
bool operator()(Client const& client, std::string_view const& key) const
|
2021-04-25 16:04:19 +00:00
|
|
|
{
|
2022-09-03 07:13:22 +00:00
|
|
|
return client.begins_with < key.substr(0, std::min(std::size(key), std::size(client.begins_with)));
|
2021-04-25 16:04:19 +00:00
|
|
|
}
|
2021-10-09 02:46:10 +00:00
|
|
|
};
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2022-11-29 00:26:03 +00:00
|
|
|
if (auto const [eq_begin, eq_end] = std::equal_range(std::begin(Clients), std::end(Clients), key, Compare{});
|
|
|
|
eq_begin != std::end(Clients) && eq_begin != eq_end)
|
2008-10-01 18:11:28 +00:00
|
|
|
{
|
2022-11-29 00:26:03 +00:00
|
|
|
eq_begin->formatter(buf, buflen, eq_begin->name, peer_id);
|
2022-09-03 07:13:22 +00:00
|
|
|
return;
|
2008-10-01 18:11:28 +00:00
|
|
|
}
|
|
|
|
|
2021-10-09 02:46:10 +00:00
|
|
|
// no match
|
2022-09-03 07:13:22 +00:00
|
|
|
if (*buf == '\0')
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
2021-10-09 02:46:10 +00:00
|
|
|
auto out = std::array<char, 32>{};
|
|
|
|
char* walk = std::data(out);
|
|
|
|
char const* const begin = walk;
|
|
|
|
char const* const end = begin + std::size(out);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (size_t i = 0; i < 8; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-22 20:24:30 +00:00
|
|
|
char const c = peer_id[i];
|
2017-05-13 22:38:31 +00:00
|
|
|
|
2022-02-07 04:28:36 +00:00
|
|
|
if (isprint((unsigned char)c) != 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
*walk++ = c;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-04-06 17:06:11 +00:00
|
|
|
walk = fmt::format_to_n(walk, end - walk - 1, FMT_STRING("%{:02X}"), static_cast<unsigned char>(c)).out;
|
2009-05-29 19:17:12 +00:00
|
|
|
}
|
2008-07-24 18:53:17 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-09 02:46:10 +00:00
|
|
|
buf_append(buf, buflen, std::string_view(begin, walk - begin));
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
}
|