deprecated public to_hex() and from_hex() functions (#784)
This commit is contained in:
parent
7c4d92a627
commit
8c8f5bb03b
|
@ -1,3 +1,4 @@
|
|||
* deprecated public to_hex() and from_hex() functions
|
||||
* separated address and port fields in listen alerts
|
||||
* added support for parsing new x.pe parameter from BEP 9
|
||||
* peer_blocked_alert now derives from peer_alert
|
||||
|
|
|
@ -63,7 +63,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/time.hpp"
|
||||
#include "libtorrent/create_torrent.hpp"
|
||||
#include "libtorrent/read_resume_data.hpp"
|
||||
#include "libtorrent/hex.hpp" // for to_hex, from_hex
|
||||
|
||||
#include "torrent_view.hpp"
|
||||
#include "session_view.hpp"
|
||||
|
@ -188,6 +187,13 @@ std::vector<libtorrent::dht_routing_bucket> dht_routing_table;
|
|||
torrent_view view;
|
||||
session_view ses_view;
|
||||
|
||||
std::string to_hex(lt::sha1_hash const& s)
|
||||
{
|
||||
std::stringstream ret;
|
||||
ret << s;
|
||||
return ret.str();
|
||||
}
|
||||
|
||||
int load_file(std::string const& filename, std::vector<char>& v
|
||||
, libtorrent::error_code& ec, int limit = 8000000)
|
||||
{
|
||||
|
@ -869,7 +875,7 @@ bool handle_alert(libtorrent::session& ses, libtorrent::alert* a
|
|||
if (torrent_need_cert_alert* p = alert_cast<torrent_need_cert_alert>(a))
|
||||
{
|
||||
torrent_handle h = p->handle;
|
||||
std::string base_name = path_append("certificates", to_hex(h.info_hash().to_string()));
|
||||
std::string base_name = path_append("certificates", to_hex(h.info_hash()));
|
||||
std::string cert = base_name + ".pem";
|
||||
std::string priv = base_name + "_key.pem";
|
||||
|
||||
|
@ -948,7 +954,7 @@ bool handle_alert(libtorrent::session& ses, libtorrent::alert* a
|
|||
std::vector<char> buffer;
|
||||
bencode(std::back_inserter(buffer), te);
|
||||
sha1_hash hash = ti->info_hash();
|
||||
std::string filename = ti->name() + "." + to_hex(hash.to_string()) + ".torrent";
|
||||
std::string filename = ti->name() + "." + to_hex(hash) + ".torrent";
|
||||
filename = path_append(monitor_dir, filename);
|
||||
save_file(filename, buffer);
|
||||
|
||||
|
@ -1230,35 +1236,6 @@ int main(int argc, char* argv[])
|
|||
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
if (argv[i][0] != '-')
|
||||
{
|
||||
// match it against the <hash>@<tracker> format
|
||||
if (strlen(argv[i]) > 45
|
||||
&& ::is_hex(argv[i], 40)
|
||||
&& (strncmp(argv[i] + 40, "@http://", 8) == 0
|
||||
|| strncmp(argv[i] + 40, "@udp://", 7) == 0))
|
||||
{
|
||||
sha1_hash info_hash;
|
||||
from_hex(argv[i], 40, (char*)&info_hash[0]);
|
||||
|
||||
add_torrent_params p;
|
||||
if (seed_mode) p.flags |= add_torrent_params::flag_seed_mode;
|
||||
if (disable_storage) p.storage = disabled_storage_constructor;
|
||||
if (share_mode) p.flags |= add_torrent_params::flag_share_mode;
|
||||
p.trackers.push_back(argv[i] + 41);
|
||||
p.info_hash = info_hash;
|
||||
p.save_path = save_path;
|
||||
p.storage_mode = (storage_mode_t)allocation_mode;
|
||||
p.flags &= ~add_torrent_params::flag_duplicate_is_error;
|
||||
p.flags |= add_torrent_params::flag_pinned;
|
||||
magnet_links.push_back(p);
|
||||
continue;
|
||||
}
|
||||
|
||||
torrents.push_back(argv[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (std::strcmp(argv[i], "--list-settings") == 0)
|
||||
{
|
||||
// print all libtorrent settings and exit
|
||||
|
@ -1458,7 +1435,7 @@ int main(int argc, char* argv[])
|
|||
if (ec) continue;
|
||||
|
||||
std::string filename = path_append(save_path, path_append(".resume"
|
||||
, to_hex(tmp.info_hash.to_string()) + ".resume"));
|
||||
, to_hex(tmp.info_hash) + ".resume"));
|
||||
|
||||
std::vector<char> resume_data;
|
||||
load_file(filename, resume_data, ec);
|
||||
|
@ -1603,7 +1580,7 @@ int main(int argc, char* argv[])
|
|||
if (ec) continue;
|
||||
|
||||
std::string filename = path_append(save_path, path_append(".resume"
|
||||
, to_hex(tmp.info_hash.to_string()) + ".resume"));
|
||||
, to_hex(tmp.info_hash) + ".resume"));
|
||||
|
||||
std::vector<char> resume_data;
|
||||
load_file(filename, resume_data, ec);
|
||||
|
|
|
@ -39,7 +39,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/announce_entry.hpp"
|
||||
#include "libtorrent/bdecode.hpp"
|
||||
#include "libtorrent/magnet_uri.hpp"
|
||||
#include "libtorrent/hex.hpp" // for to_hex, from_hex
|
||||
|
||||
int load_file(std::string const& filename, std::vector<char>& v
|
||||
, libtorrent::error_code& ec, int limit = 8000000)
|
||||
|
@ -175,8 +174,8 @@ int main(int argc, char* argv[])
|
|||
std::printf("%2d: %s\n", i->tier, i->url.c_str());
|
||||
}
|
||||
|
||||
char ih[41];
|
||||
to_hex((char const*)&t.info_hash()[0], 20, ih);
|
||||
std::stringstream ih;
|
||||
ih << t.info_hash();
|
||||
std::printf("number of pieces: %d\n"
|
||||
"piece length: %d\n"
|
||||
"info hash: %s\n"
|
||||
|
@ -188,7 +187,7 @@ int main(int argc, char* argv[])
|
|||
"files:\n"
|
||||
, t.num_pieces()
|
||||
, t.piece_length()
|
||||
, ih
|
||||
, ih.str().c_str()
|
||||
, t.comment().c_str()
|
||||
, t.creator().c_str()
|
||||
, make_magnet_uri(t).c_str()
|
||||
|
@ -197,9 +196,12 @@ int main(int argc, char* argv[])
|
|||
file_storage const& st = t.files();
|
||||
for (int i = 0; i < st.num_files(); ++i)
|
||||
{
|
||||
int first = st.map_file(i, 0, 0).piece;
|
||||
int last = st.map_file(i, (std::max)(boost::int64_t(st.file_size(i))-1, boost::int64_t(0)), 0).piece;
|
||||
int flags = st.file_flags(i);
|
||||
int const first = st.map_file(i, 0, 0).piece;
|
||||
int const last = st.map_file(i, (std::max)(boost::int64_t(st.file_size(i))-1, boost::int64_t(0)), 0).piece;
|
||||
int const flags = st.file_flags(i);
|
||||
std::stringstream file_hash;
|
||||
if (!st.hash(i).is_all_zeros())
|
||||
file_hash << st.hash(i);
|
||||
std::printf(" %8" PRIx64 " %11" PRId64 " %c%c%c%c [ %5d, %5d ] %7u %s %s %s%s\n"
|
||||
, st.file_offset(i)
|
||||
, st.file_size(i)
|
||||
|
@ -209,7 +211,7 @@ int main(int argc, char* argv[])
|
|||
, ((flags & file_storage::flag_symlink)?'l':'-')
|
||||
, first, last
|
||||
, boost::uint32_t(st.mtime(i))
|
||||
, st.hash(i) != sha1_hash(0) ? to_hex(st.hash(i).to_string()).c_str() : ""
|
||||
, file_hash.str().c_str()
|
||||
, st.file_path(i).c_str()
|
||||
, (flags & file_storage::flag_symlink) ? "-> " : ""
|
||||
, (flags & file_storage::flag_symlink) ? st.symlink(i).c_str() : "");
|
||||
|
|
|
@ -39,7 +39,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/create_torrent.hpp"
|
||||
#include "libtorrent/file.hpp"
|
||||
#include "libtorrent/file_pool.hpp"
|
||||
#include "libtorrent/hex.hpp" // for from_hex
|
||||
#include "libtorrent/aux_/max_path.hpp" // for TORRENT_MAX_PATH
|
||||
|
||||
#include <functional>
|
||||
|
@ -307,8 +306,10 @@ int main(int argc, char* argv[])
|
|||
print_usage();
|
||||
return 1;
|
||||
}
|
||||
std::stringstream hash(argv[i]);
|
||||
sha1_hash ih;
|
||||
if (!from_hex(argv[i], 40, (char*)&ih[0]))
|
||||
hash >> ih;
|
||||
if (hash.fail())
|
||||
{
|
||||
std::fprintf(stderr, "invalid info-hash for -S\n");
|
||||
print_usage();
|
||||
|
|
|
@ -46,29 +46,33 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
namespace libtorrent
|
||||
{
|
||||
namespace detail {
|
||||
namespace aux {
|
||||
|
||||
TORRENT_EXTRA_EXPORT int hex_to_int(char in);
|
||||
TORRENT_EXTRA_EXPORT bool is_hex(char const *in, int len);
|
||||
|
||||
}
|
||||
|
||||
// The overload taking a ``std::string`` converts (binary) the string ``s``
|
||||
// to hexadecimal representation and returns it.
|
||||
// The overload taking a ``char const*`` and a length converts the binary
|
||||
// buffer [``in``, ``in`` + len) to hexadecimal and prints it to the buffer
|
||||
// ``out``. The caller is responsible for making sure the buffer pointed to
|
||||
// by ``out`` is large enough, i.e. has at least len * 2 bytes of space.
|
||||
TORRENT_EXPORT std::string to_hex(std::string const& s);
|
||||
TORRENT_EXPORT void to_hex(char const *in, int len, char* out);
|
||||
TORRENT_DEPRECATED_EXPORT std::string to_hex(std::string const& s);
|
||||
TORRENT_DEPRECATED_EXPORT void to_hex(char const *in, int len, char* out);
|
||||
|
||||
// converts the buffer [``in``, ``in`` + len) from hexadecimal to
|
||||
// binary. The binary output is written to the buffer pointed to
|
||||
// by ``out``. The caller is responsible for making sure the buffer
|
||||
// at ``out`` has enough space for the result to be written to, i.e.
|
||||
// (len + 1) / 2 bytes.
|
||||
TORRENT_EXPORT bool from_hex(char const *in, int len, char* out);
|
||||
TORRENT_DEPRECATED_EXPORT bool from_hex(char const *in, int len, char* out);
|
||||
|
||||
}
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
using aux::to_hex;
|
||||
using aux::from_hex;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // TORRENT_HEX_HPP_INCLUDED
|
||||
|
|
|
@ -182,8 +182,7 @@ TORRENT_TEST(dht_dual_stack_get_peers)
|
|||
{
|
||||
if (lt::dht_get_peers_reply_alert const* p = lt::alert_cast<lt::dht_get_peers_reply_alert>(a))
|
||||
{
|
||||
std::vector<lt::tcp::endpoint> peers;
|
||||
p->peers(peers);
|
||||
std::vector<lt::tcp::endpoint> peers = p->peers();
|
||||
for (lt::tcp::endpoint const& peer : peers)
|
||||
{
|
||||
// TODO: verify that the endpoint matches the session's
|
||||
|
|
|
@ -32,17 +32,19 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include "test.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "setup_transfer.hpp" // for ep()
|
||||
#include "libtorrent/config.hpp"
|
||||
#include "libtorrent/kademlia/node.hpp" // for verify_message
|
||||
#include "libtorrent/kademlia/dht_storage.hpp"
|
||||
|
||||
#include "libtorrent/io_service.hpp"
|
||||
#include "libtorrent/address.hpp"
|
||||
#include "libtorrent/hex.hpp" // to_hex, from_hex
|
||||
#include "libtorrent/aux_/time.hpp"
|
||||
|
||||
#include "simulator/simulator.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <sstream>
|
||||
|
||||
using namespace libtorrent;
|
||||
using namespace libtorrent::dht;
|
||||
|
@ -67,8 +69,10 @@ namespace
|
|||
}
|
||||
|
||||
sha1_hash to_hash(char const *s) {
|
||||
std::stringstream hash(s);
|
||||
sha1_hash ret;
|
||||
from_hex(s, 40, (char *) &ret[0]);
|
||||
hash >> ret;
|
||||
TORRENT_ASSERT(!hash.fail());
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -117,10 +121,10 @@ TORRENT_TEST(dht_storage_counters)
|
|||
sha1_hash n3 = to_hash("5fbfbff10c5d6a4ec8a88e4c6ab4c28b95eee403");
|
||||
sha1_hash n4 = to_hash("5fbfbff10c5d6a4ec8a88e4c6ab4c28b95eee404");
|
||||
|
||||
tcp::endpoint p1 = tcp::endpoint(address::from_string("124.31.75.21"), 1);
|
||||
tcp::endpoint p2 = tcp::endpoint(address::from_string("124.31.75.22"), 1);
|
||||
tcp::endpoint p3 = tcp::endpoint(address::from_string("124.31.75.23"), 1);
|
||||
tcp::endpoint p4 = tcp::endpoint(address::from_string("124.31.75.24"), 1);
|
||||
tcp::endpoint const p1 = ep("124.31.75.21", 1);
|
||||
tcp::endpoint const p2 = ep("124.31.75.22", 1);
|
||||
tcp::endpoint const p3 = ep("124.31.75.23", 1);
|
||||
tcp::endpoint const p4 = ep("124.31.75.24", 1);
|
||||
|
||||
s->announce_peer(n1, p1, "torrent_name", false);
|
||||
s->announce_peer(n2, p2, "torrent_name1", false);
|
||||
|
|
|
@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include <functional>
|
||||
#include "libtorrent/address.hpp"
|
||||
#include "libtorrent/socket.hpp"
|
||||
|
||||
namespace libtorrent
|
||||
{
|
||||
|
|
|
@ -47,7 +47,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/performance_counters.hpp"
|
||||
#include "libtorrent/stack_allocator.hpp"
|
||||
#include "libtorrent/piece_picker.hpp" // for piece_block
|
||||
#include "libtorrent/hex.hpp" // to_hex, from_hex
|
||||
#include "libtorrent/hex.hpp" // to_hex
|
||||
|
||||
#include "libtorrent/aux_/escape_string.hpp" // for convert_from_native
|
||||
#include "libtorrent/aux_/max_path.hpp" // for TORRENT_MAX_PATH
|
||||
|
@ -75,7 +75,7 @@ namespace libtorrent {
|
|||
else
|
||||
{
|
||||
char msg[41];
|
||||
to_hex(t->info_hash().data(), 20, msg);
|
||||
aux::to_hex(t->info_hash().data(), 20, msg);
|
||||
m_name_idx = alloc.copy_string(msg);
|
||||
}
|
||||
}
|
||||
|
@ -1137,7 +1137,7 @@ namespace libtorrent {
|
|||
{
|
||||
error_code ec;
|
||||
char ih_hex[41];
|
||||
to_hex(info_hash.data(), 20, ih_hex);
|
||||
aux::to_hex(info_hash.data(), 20, ih_hex);
|
||||
char msg[200];
|
||||
std::snprintf(msg, sizeof(msg), "incoming dht announce: %s:%u (%s)"
|
||||
, ip.to_string(ec).c_str(), port, ih_hex);
|
||||
|
@ -1152,7 +1152,7 @@ namespace libtorrent {
|
|||
std::string dht_get_peers_alert::message() const
|
||||
{
|
||||
char ih_hex[41];
|
||||
to_hex(info_hash.data(), 20, ih_hex);
|
||||
aux::to_hex(info_hash.data(), 20, ih_hex);
|
||||
char msg[200];
|
||||
std::snprintf(msg, sizeof(msg), "incoming dht get_peers: %s", ih_hex);
|
||||
return msg;
|
||||
|
@ -1378,7 +1378,7 @@ namespace libtorrent {
|
|||
if (params.ti) torrent_name = params.ti->name().c_str();
|
||||
else if (!params.name.empty()) torrent_name = params.name.c_str();
|
||||
else if (!params.url.empty()) torrent_name = params.url.c_str();
|
||||
else to_hex(params.info_hash.data(), 20, info_hash);
|
||||
else aux::to_hex(params.info_hash.data(), 20, info_hash);
|
||||
|
||||
if (error)
|
||||
{
|
||||
|
@ -1480,8 +1480,8 @@ namespace libtorrent {
|
|||
{
|
||||
char msg[200];
|
||||
std::snprintf(msg, sizeof(msg), " torrent changed info-hash from: %s to %s"
|
||||
, to_hex(old_ih.to_string()).c_str()
|
||||
, to_hex(new_ih.to_string()).c_str());
|
||||
, aux::to_hex(old_ih.to_string()).c_str()
|
||||
, aux::to_hex(new_ih.to_string()).c_str());
|
||||
return torrent_alert::message() + msg;
|
||||
}
|
||||
#endif
|
||||
|
@ -1547,7 +1547,7 @@ namespace libtorrent {
|
|||
{
|
||||
char msg[1050];
|
||||
std::snprintf(msg, sizeof(msg), "DHT immutable item %s [ %s ]"
|
||||
, to_hex(target.to_string()).c_str()
|
||||
, aux::to_hex(target.to_string()).c_str()
|
||||
, item.to_string().c_str());
|
||||
return msg;
|
||||
}
|
||||
|
@ -1568,7 +1568,7 @@ namespace libtorrent {
|
|||
{
|
||||
char msg[1050];
|
||||
std::snprintf(msg, sizeof(msg), "DHT mutable item (key=%s salt=%s seq=%" PRId64 " %s) [ %s ]"
|
||||
, to_hex(std::string(&key[0], 32)).c_str()
|
||||
, aux::to_hex(std::string(&key[0], 32)).c_str()
|
||||
, salt.c_str()
|
||||
, seq
|
||||
, authoritative ? "auth" : "non-auth"
|
||||
|
@ -1603,8 +1603,8 @@ namespace libtorrent {
|
|||
{
|
||||
std::snprintf(msg, sizeof(msg), "DHT put complete (success=%d key=%s sig=%s salt=%s seq=%" PRId64 ")"
|
||||
, num_success
|
||||
, to_hex(std::string(&public_key[0], 32)).c_str()
|
||||
, to_hex(std::string(&signature[0], 64)).c_str()
|
||||
, aux::to_hex(std::string(&public_key[0], 32)).c_str()
|
||||
, aux::to_hex(std::string(&signature[0], 64)).c_str()
|
||||
, salt.c_str()
|
||||
, seq);
|
||||
return msg;
|
||||
|
@ -1612,7 +1612,7 @@ namespace libtorrent {
|
|||
|
||||
std::snprintf(msg, sizeof(msg), "DHT put commplete (success=%d hash=%s)"
|
||||
, num_success
|
||||
, to_hex(target.to_string()).c_str());
|
||||
, aux::to_hex(target.to_string()).c_str());
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
@ -1644,10 +1644,10 @@ namespace libtorrent {
|
|||
if (obfuscated_info_hash != info_hash)
|
||||
{
|
||||
std::snprintf(obf, sizeof(obf), " [obfuscated: %s]"
|
||||
, to_hex(obfuscated_info_hash.to_string()).c_str());
|
||||
, aux::to_hex(obfuscated_info_hash.to_string()).c_str());
|
||||
}
|
||||
std::snprintf(msg, sizeof(msg), "outgoing dht get_peers : %s%s -> %s"
|
||||
, to_hex(info_hash.to_string()).c_str()
|
||||
, aux::to_hex(info_hash.to_string()).c_str()
|
||||
, obf
|
||||
, print_endpoint(ip).c_str());
|
||||
return msg;
|
||||
|
@ -1949,7 +1949,7 @@ namespace libtorrent {
|
|||
std::string dht_get_peers_reply_alert::message() const
|
||||
{
|
||||
char ih_hex[41];
|
||||
to_hex(info_hash.data(), 20, ih_hex);
|
||||
aux::to_hex(info_hash.data(), 20, ih_hex);
|
||||
char msg[200];
|
||||
std::snprintf(msg, sizeof(msg), "incoming dht get_peers reply: %s, peers %d", ih_hex, m_num_peers);
|
||||
return msg;
|
||||
|
|
|
@ -50,7 +50,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/aux_/disable_warnings_pop.hpp"
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
#include "libtorrent/hex.hpp" // to_hex, from_hex
|
||||
#include "libtorrent/hex.hpp" // to_hex
|
||||
#endif
|
||||
|
||||
#include "libtorrent/bt_peer_connection.hpp"
|
||||
|
@ -861,14 +861,14 @@ namespace libtorrent
|
|||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
{
|
||||
char hex_pid[41];
|
||||
to_hex(m_our_peer_id.data(), 20, hex_pid);
|
||||
aux::to_hex(m_our_peer_id.data(), 20, hex_pid);
|
||||
hex_pid[40] = 0;
|
||||
peer_log(peer_log_alert::outgoing, "HANDSHAKE"
|
||||
, "sent peer_id: %s client: %s"
|
||||
, hex_pid, identify_client(m_our_peer_id).c_str());
|
||||
}
|
||||
peer_log(peer_log_alert::outgoing_message, "HANDSHAKE"
|
||||
, "ih: %s", to_hex(ih.to_string()).c_str());
|
||||
, "ih: %s", aux::to_hex(ih.to_string()).c_str());
|
||||
#endif
|
||||
send_buffer(handshake, sizeof(handshake));
|
||||
|
||||
|
@ -3405,7 +3405,7 @@ namespace libtorrent
|
|||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
{
|
||||
char hex_pid[41];
|
||||
to_hex(recv_buffer.begin, 20, hex_pid);
|
||||
aux::to_hex(recv_buffer.begin, 20, hex_pid);
|
||||
hex_pid[40] = 0;
|
||||
char ascii_pid[21];
|
||||
ascii_pid[20] = 0;
|
||||
|
|
|
@ -711,7 +711,7 @@ namespace libtorrent
|
|||
}
|
||||
if (binary_string)
|
||||
{
|
||||
out += to_hex(string());
|
||||
out += aux::to_hex(string());
|
||||
out += "\n";
|
||||
}
|
||||
else
|
||||
|
@ -744,7 +744,7 @@ namespace libtorrent
|
|||
}
|
||||
for (int j = 0; j < indent+1; ++j) out += " ";
|
||||
out += "[";
|
||||
if (binary_string) out += to_hex(i->first);
|
||||
if (binary_string) out += aux::to_hex(i->first);
|
||||
else out += i->first;
|
||||
out += "]";
|
||||
|
||||
|
|
|
@ -63,7 +63,9 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
namespace libtorrent
|
||||
{
|
||||
// defined in hex.cpp
|
||||
extern const char hex_chars[];
|
||||
namespace aux {
|
||||
extern const char hex_chars[];
|
||||
}
|
||||
|
||||
std::string unescape_string(std::string const& s, error_code& ec)
|
||||
{
|
||||
|
@ -122,7 +124,7 @@ namespace libtorrent
|
|||
|
||||
// http://www.ietf.org/rfc/rfc2396.txt
|
||||
// section 2.3
|
||||
static const char unreserved_chars[] =
|
||||
static char const unreserved_chars[] =
|
||||
// when determining if a url needs encoding
|
||||
// % should be ok
|
||||
"%+"
|
||||
|
@ -135,8 +137,10 @@ namespace libtorrent
|
|||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789";
|
||||
|
||||
namespace {
|
||||
|
||||
// the offset is used to ignore the first characters in the unreserved_chars table.
|
||||
static std::string escape_string_impl(const char* str, int len, int offset)
|
||||
std::string escape_string_impl(const char* str, int len, int offset)
|
||||
{
|
||||
TORRENT_ASSERT(str != 0);
|
||||
TORRENT_ASSERT(len >= 0);
|
||||
|
@ -153,14 +157,16 @@ namespace libtorrent
|
|||
else
|
||||
{
|
||||
ret += '%';
|
||||
ret += hex_chars[boost::uint8_t(*str) >> 4];
|
||||
ret += hex_chars[boost::uint8_t(*str) & 15];
|
||||
ret += aux::hex_chars[boost::uint8_t(*str) >> 4];
|
||||
ret += aux::hex_chars[boost::uint8_t(*str) & 15];
|
||||
}
|
||||
++str;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
std::string escape_string(const char* str, int len)
|
||||
{
|
||||
return escape_string_impl(str, len, 11);
|
||||
|
@ -263,7 +269,7 @@ namespace libtorrent
|
|||
|
||||
std::string base64encode(const std::string& s)
|
||||
{
|
||||
static const char base64_table[] =
|
||||
static char const base64_table[] =
|
||||
{
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
|
@ -315,14 +321,14 @@ namespace libtorrent
|
|||
|
||||
std::string base32encode(std::string const& s, int flags)
|
||||
{
|
||||
static const char base32_table_canonical[] =
|
||||
static char const base32_table_canonical[] =
|
||||
{
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
||||
'Y', 'Z', '2', '3', '4', '5', '6', '7'
|
||||
};
|
||||
static const char base32_table_lowercase[] =
|
||||
static char const base32_table_lowercase[] =
|
||||
{
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
|
||||
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
|
||||
|
|
24
src/hex.cpp
24
src/hex.cpp
|
@ -35,9 +35,9 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
namespace libtorrent
|
||||
{
|
||||
|
||||
namespace detail {
|
||||
namespace aux {
|
||||
|
||||
TORRENT_EXTRA_EXPORT int hex_to_int(char in)
|
||||
int hex_to_int(char in)
|
||||
{
|
||||
if (in >= '0' && in <= '9') return int(in) - '0';
|
||||
if (in >= 'A' && in <= 'F') return int(in) - 'A' + 10;
|
||||
|
@ -45,7 +45,7 @@ namespace libtorrent
|
|||
return -1;
|
||||
}
|
||||
|
||||
TORRENT_EXTRA_EXPORT bool is_hex(char const *in, int len)
|
||||
bool is_hex(char const *in, int len)
|
||||
{
|
||||
for (char const* end = in + len; in < end; ++in)
|
||||
{
|
||||
|
@ -55,28 +55,26 @@ namespace libtorrent
|
|||
return true;
|
||||
}
|
||||
|
||||
} // detail namespace
|
||||
|
||||
TORRENT_EXPORT bool from_hex(char const *in, int len, char* out)
|
||||
bool from_hex(char const *in, int len, char* out)
|
||||
{
|
||||
for (char const* end = in + len; in < end; ++in, ++out)
|
||||
{
|
||||
int t = detail::hex_to_int(*in);
|
||||
int t = aux::hex_to_int(*in);
|
||||
if (t == -1) return false;
|
||||
*out = t << 4;
|
||||
++in;
|
||||
t = detail::hex_to_int(*in);
|
||||
t = aux::hex_to_int(*in);
|
||||
if (t == -1) return false;
|
||||
*out |= t & 15;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
extern const char hex_chars[];
|
||||
extern char const hex_chars[];
|
||||
|
||||
const char hex_chars[] = "0123456789abcdef";
|
||||
char const hex_chars[] = "0123456789abcdef";
|
||||
|
||||
TORRENT_EXPORT std::string to_hex(std::string const& s)
|
||||
std::string to_hex(std::string const& s)
|
||||
{
|
||||
std::string ret;
|
||||
for (std::string::const_iterator i = s.begin(); i != s.end(); ++i)
|
||||
|
@ -87,7 +85,7 @@ namespace libtorrent
|
|||
return ret;
|
||||
}
|
||||
|
||||
TORRENT_EXPORT void to_hex(char const *in, int len, char* out)
|
||||
void to_hex(char const *in, int len, char* out)
|
||||
{
|
||||
for (char const* end = in + len; in < end; ++in)
|
||||
{
|
||||
|
@ -97,5 +95,7 @@ namespace libtorrent
|
|||
*out = '\0';
|
||||
}
|
||||
|
||||
} // aux namespace
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -366,7 +366,7 @@ namespace libtorrent
|
|||
buffer::const_interval chunk_start = recv_buffer;
|
||||
chunk_start.begin += m_chunk_pos;
|
||||
TORRENT_ASSERT(chunk_start.begin[0] == '\r'
|
||||
|| detail::is_hex(chunk_start.begin, 1));
|
||||
|| aux::is_hex(chunk_start.begin, 1));
|
||||
bool ret = m_parser.parse_chunk_header(chunk_start, &chunk_size, &header_size);
|
||||
if (!ret)
|
||||
{
|
||||
|
|
|
@ -36,7 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/error_code.hpp"
|
||||
#include "libtorrent/string_util.hpp"
|
||||
#include "libtorrent/settings_pack.hpp"
|
||||
#include "libtorrent/hex.hpp"
|
||||
#include "libtorrent/hex.hpp" // for to_hex
|
||||
|
||||
#if TORRENT_USE_I2P
|
||||
|
||||
|
@ -133,7 +133,7 @@ namespace libtorrent
|
|||
char tmp[20];
|
||||
std::generate(tmp, tmp + sizeof(tmp), &std::rand);
|
||||
m_session_id.resize(sizeof(tmp)*2);
|
||||
to_hex(tmp, 20, &m_session_id[0]);
|
||||
aux::to_hex(tmp, 20, &m_session_id[0]);
|
||||
|
||||
m_sam_socket.reset(new i2p_stream(m_io_service));
|
||||
m_sam_socket->set_proxy(m_hostname, m_port);
|
||||
|
|
|
@ -52,7 +52,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/aux_/time.hpp"
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
#include "libtorrent/hex.hpp" // to_hex, from_hex
|
||||
#include "libtorrent/hex.hpp" // to_hex
|
||||
#endif
|
||||
|
||||
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
||||
|
@ -134,10 +134,10 @@ namespace libtorrent { namespace dht
|
|||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
m_log->log(dht_logger::tracker, "starting IPv4 DHT tracker with node id: %s"
|
||||
, to_hex(m_dht.nid().to_string()).c_str());
|
||||
, aux::to_hex(m_dht.nid().to_string()).c_str());
|
||||
#if TORRENT_USE_IPV6
|
||||
m_log->log(dht_logger::tracker, "starting IPv6 DHT tracker with node id: %s"
|
||||
, to_hex(m_dht6.nid().to_string()).c_str());
|
||||
, aux::to_hex(m_dht6.nid().to_string()).c_str());
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <libtorrent/socket_io.hpp>
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
#include <libtorrent/hex.hpp> // to_hex, from_hex
|
||||
#include <libtorrent/hex.hpp> // to_hex
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
|
@ -120,8 +120,8 @@ void find_data::got_write_token(node_id const& n, std::string const& write_token
|
|||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
get_node().observer()->log(dht_logger::traversal
|
||||
, "[%p] adding write token '%s' under id '%s'"
|
||||
, static_cast<void*>(this), to_hex(write_token).c_str()
|
||||
, to_hex(n.to_string()).c_str());
|
||||
, static_cast<void*>(this), aux::to_hex(write_token).c_str()
|
||||
, aux::to_hex(n.to_string()).c_str());
|
||||
#endif
|
||||
m_write_tokens[n] = write_token;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <libtorrent/performance_counters.hpp>
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
#include <libtorrent/hex.hpp> // to_hex, from_hex
|
||||
#include <libtorrent/hex.hpp> // to_hex
|
||||
#endif
|
||||
|
||||
namespace libtorrent { namespace dht
|
||||
|
@ -84,7 +84,7 @@ void get_peers_observer::reply(msg const& m)
|
|||
, algorithm()->invoke_count()
|
||||
, algorithm()->branch_factor()
|
||||
, print_endpoint(m.addr).c_str()
|
||||
, to_hex(id.string_value()).c_str()
|
||||
, aux::to_hex(id.string_value()).c_str()
|
||||
, distance_exp(algorithm()->target(), node_id(id.string_ptr()))
|
||||
, int((end - peers) / 6));
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ void get_peers_observer::reply(msg const& m)
|
|||
, algorithm()->invoke_count()
|
||||
, algorithm()->branch_factor()
|
||||
, print_endpoint(m.addr).c_str()
|
||||
, to_hex(id.string_value()).c_str()
|
||||
, aux::to_hex(id.string_value()).c_str()
|
||||
, distance_exp(algorithm()->target(), node_id(id.string_ptr()))
|
||||
, int(n.list_size()));
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/aux_/disable_warnings_pop.hpp"
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
#include "libtorrent/hex.hpp" // to_hex, from_hex
|
||||
#include "libtorrent/hex.hpp" // to_hex
|
||||
#endif
|
||||
|
||||
#include "libtorrent/io.hpp"
|
||||
|
@ -359,7 +359,7 @@ namespace
|
|||
if (node.observer())
|
||||
{
|
||||
char hex_ih[41];
|
||||
to_hex(reinterpret_cast<char const*>(&ih[0]), 20, hex_ih);
|
||||
aux::to_hex(reinterpret_cast<char const*>(&ih[0]), 20, hex_ih);
|
||||
node.observer()->log(dht_logger::node, "sending announce_peer [ ih: %s "
|
||||
" p: %d nodes: %d ]", hex_ih, listen_port, int(v.size()));
|
||||
}
|
||||
|
@ -449,7 +449,7 @@ void node::announce(sha1_hash const& info_hash, int listen_port, int flags
|
|||
if (m_observer)
|
||||
{
|
||||
char hex_ih[41];
|
||||
to_hex(reinterpret_cast<char const*>(&info_hash[0]), 20, hex_ih);
|
||||
aux::to_hex(reinterpret_cast<char const*>(&info_hash[0]), 20, hex_ih);
|
||||
m_observer->log(dht_logger::node, "announcing [ ih: %s p: %d ]"
|
||||
, hex_ih, listen_port);
|
||||
}
|
||||
|
@ -483,7 +483,7 @@ void node::get_item(sha1_hash const& target
|
|||
if (m_observer)
|
||||
{
|
||||
char hex_target[41];
|
||||
to_hex(reinterpret_cast<char const*>(&target[0]), 20, hex_target);
|
||||
aux::to_hex(reinterpret_cast<char const*>(&target[0]), 20, hex_target);
|
||||
m_observer->log(dht_logger::node, "starting get for [ hash: %s ]"
|
||||
, hex_target);
|
||||
}
|
||||
|
@ -501,7 +501,7 @@ void node::get_item(char const* pk, std::string const& salt
|
|||
if (m_observer)
|
||||
{
|
||||
char hex_key[65];
|
||||
to_hex(pk, 32, hex_key);
|
||||
aux::to_hex(pk, 32, hex_key);
|
||||
m_observer->log(dht_logger::node, "starting get for [ key: %s ]", hex_key);
|
||||
}
|
||||
#endif
|
||||
|
@ -540,7 +540,7 @@ void node::put_item(sha1_hash const& target, entry const& data, boost::function<
|
|||
if (m_observer)
|
||||
{
|
||||
char hex_target[41];
|
||||
to_hex(target.data(), 20, hex_target);
|
||||
aux::to_hex(target.data(), 20, hex_target);
|
||||
m_observer->log(dht_logger::node, "starting get for [ hash: %s ]"
|
||||
, hex_target);
|
||||
}
|
||||
|
@ -566,7 +566,7 @@ void node::put_item(char const* pk, std::string const& salt
|
|||
if (m_observer)
|
||||
{
|
||||
char hex_key[65];
|
||||
to_hex(pk, 32, hex_key);
|
||||
aux::to_hex(pk, 32, hex_key);
|
||||
m_observer->log(dht_logger::node, "starting get for [ key: %s ]", hex_key);
|
||||
}
|
||||
#endif
|
||||
|
@ -1041,9 +1041,9 @@ void node::incoming_request(msg const& m, entry& e)
|
|||
|
||||
// std::fprintf(stderr, "%s PUT target: %s salt: %s key: %s\n"
|
||||
// , mutable_put ? "mutable":"immutable"
|
||||
// , to_hex(target.to_string()).c_str()
|
||||
// , aux::to_hex(target.to_string()).c_str()
|
||||
// , salt.second > 0 ? std::string(salt.first, salt.second).c_str() : ""
|
||||
// , pk ? to_hex(std::string(pk, 32)).c_str() : "");
|
||||
// , pk ? aux::to_hex(std::string(pk, 32)).c_str() : "");
|
||||
|
||||
// verify the write-token. tokens are only valid to write to
|
||||
// specific target hashes. it must match the one we got a "get" for
|
||||
|
@ -1147,7 +1147,7 @@ void node::incoming_request(msg const& m, entry& e)
|
|||
|
||||
// std::fprintf(stderr, "%s GET target: %s\n"
|
||||
// , msg_keys[1] ? "mutable":"immutable"
|
||||
// , to_hex(target.to_string()).c_str());
|
||||
// , aux::to_hex(target.to_string()).c_str());
|
||||
|
||||
reply["token"] = generate_token(m.addr, msg_keys[1].string_ptr());
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include "libtorrent/config.hpp"
|
||||
|
||||
#include <libtorrent/hex.hpp> // to_hex, from_hex
|
||||
#include <libtorrent/hex.hpp> // to_hex
|
||||
#include "libtorrent/kademlia/routing_table.hpp"
|
||||
#include "libtorrent/broadcast_socket.hpp" // for cidr_distance
|
||||
#include "libtorrent/session_status.hpp"
|
||||
|
@ -267,7 +267,7 @@ void routing_table::print_state(std::ostream& os) const
|
|||
"number of nodes per bucket:\n"
|
||||
, m_bucket_size
|
||||
, num_global_nodes()
|
||||
, to_hex(m_id.to_string()).c_str());
|
||||
, aux::to_hex(m_id.to_string()).c_str());
|
||||
if (cursor > buf.size() - 500) buf.resize(buf.size() * 3 / 2);
|
||||
|
||||
int idx = 0;
|
||||
|
@ -329,7 +329,7 @@ void routing_table::print_state(std::ostream& os) const
|
|||
cursor += std::snprintf(&buf[cursor], buf.size() - cursor
|
||||
, " prefix: %2x id: %s"
|
||||
, ((id[0] & top_mask) >> mask_shift)
|
||||
, to_hex(j->id.to_string()).c_str());
|
||||
, aux::to_hex(j->id.to_string()).c_str());
|
||||
|
||||
if (j->rtt == 0xffff)
|
||||
{
|
||||
|
@ -663,7 +663,7 @@ routing_table::add_node_status_t routing_table::add_node_impl(node_entry e)
|
|||
{
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
char hex_id[41];
|
||||
to_hex(reinterpret_cast<char const*>(&e.id[0]), 20, hex_id);
|
||||
aux::to_hex(reinterpret_cast<char const*>(&e.id[0]), 20, hex_id);
|
||||
m_log->log(dht_logger::routing_table, "ignoring node (duplicate IP): %s %s"
|
||||
, hex_id, print_address(e.addr()).c_str());
|
||||
#endif
|
||||
|
@ -767,9 +767,9 @@ routing_table::add_node_status_t routing_table::add_node_impl(node_entry e)
|
|||
// it claims a different node-ID. Ignore this to avoid attacks
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
char hex_id1[41];
|
||||
to_hex(e.id.data(), 20, hex_id1);
|
||||
aux::to_hex(e.id.data(), 20, hex_id1);
|
||||
char hex_id2[41];
|
||||
to_hex(j->id.data(), 20, hex_id2);
|
||||
aux::to_hex(j->id.data(), 20, hex_id2);
|
||||
m_log->log(dht_logger::routing_table, "ignoring node: %s %s existing node: %s %s"
|
||||
, hex_id1, print_address(e.addr()).c_str()
|
||||
, hex_id2, print_address(j->addr()).c_str());
|
||||
|
@ -959,7 +959,7 @@ ip_ok:
|
|||
if (m_log)
|
||||
{
|
||||
char hex_id[41];
|
||||
to_hex(e.id.data(), sha1_hash::size, hex_id);
|
||||
aux::to_hex(e.id.data(), sha1_hash::size, hex_id);
|
||||
m_log->log(dht_logger::routing_table, "replacing node with higher RTT: %s %s"
|
||||
, hex_id, print_address(e.addr()).c_str());
|
||||
}
|
||||
|
@ -1167,7 +1167,7 @@ void routing_table::node_failed(node_id const& nid, udp::endpoint const& ep)
|
|||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
char hex_id[41];
|
||||
to_hex(nid.data(), 20, hex_id);
|
||||
aux::to_hex(nid.data(), 20, hex_id);
|
||||
m_log->log(dht_logger::routing_table, "NODE FAILED id: %s ip: %s fails: %d pinged: %d up-time: %d"
|
||||
, hex_id, print_endpoint(j->ep()).c_str()
|
||||
, int(j->fail_count())
|
||||
|
@ -1188,7 +1188,7 @@ void routing_table::node_failed(node_id const& nid, udp::endpoint const& ep)
|
|||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
char hex_id[41];
|
||||
to_hex(nid.data(), 20, hex_id);
|
||||
aux::to_hex(nid.data(), 20, hex_id);
|
||||
m_log->log(dht_logger::routing_table, "NODE FAILED id: %s ip: %s fails: %d pinged: %d up-time: %d"
|
||||
, hex_id, print_endpoint(j->ep()).c_str()
|
||||
, int(j->fail_count())
|
||||
|
|
|
@ -43,7 +43,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <libtorrent/aux_/time.hpp>
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
#include <libtorrent/hex.hpp> // to_hex, from_hex
|
||||
#include <libtorrent/hex.hpp> // to_hex
|
||||
#endif
|
||||
|
||||
#include <functional>
|
||||
|
@ -100,7 +100,7 @@ traversal_algorithm::traversal_algorithm(
|
|||
if (get_node().observer())
|
||||
{
|
||||
char hex_target[41];
|
||||
to_hex(reinterpret_cast<char const*>(&target[0]), 20, hex_target);
|
||||
aux::to_hex(reinterpret_cast<char const*>(&target[0]), 20, hex_target);
|
||||
get_node().observer()->log(dht_logger::traversal, "[%p] NEW target: %s k: %d"
|
||||
, static_cast<void*>(this), hex_target, int(m_node.m_table.bucket_size()));
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ void traversal_algorithm::add_entry(node_id const& id, udp::endpoint addr, unsig
|
|||
if (get_node().observer())
|
||||
{
|
||||
char hex_id[41];
|
||||
to_hex(reinterpret_cast<char const*>(&o->id()[0]), 20, hex_id);
|
||||
aux::to_hex(reinterpret_cast<char const*>(&o->id()[0]), 20, hex_id);
|
||||
get_node().observer()->log(dht_logger::traversal
|
||||
, "[%p] traversal DUPLICATE node. id: %s addr: %s type: %s"
|
||||
, static_cast<void*>(this), hex_id, print_address(o->target_addr()).c_str(), name());
|
||||
|
@ -200,7 +200,7 @@ void traversal_algorithm::add_entry(node_id const& id, udp::endpoint addr, unsig
|
|||
if (get_node().observer())
|
||||
{
|
||||
char hex_id[41];
|
||||
to_hex(reinterpret_cast<char const*>(&id[0]), 20, hex_id);
|
||||
aux::to_hex(reinterpret_cast<char const*>(&id[0]), 20, hex_id);
|
||||
get_node().observer()->log(dht_logger::traversal
|
||||
, "[%p] ADD id: %s addr: %s distance: %d invoke-count: %d type: %s"
|
||||
, static_cast<void*>(this), hex_id, print_endpoint(addr).c_str()
|
||||
|
@ -332,7 +332,7 @@ void traversal_algorithm::failed(observer_ptr o, int flags)
|
|||
if (get_node().observer())
|
||||
{
|
||||
char hex_id[41];
|
||||
to_hex(reinterpret_cast<char const*>(&o->id()[0]), 20, hex_id);
|
||||
aux::to_hex(reinterpret_cast<char const*>(&o->id()[0]), 20, hex_id);
|
||||
get_node().observer()->log(dht_logger::traversal
|
||||
, "[%p] 1ST_TIMEOUT id: %s distance: %d addr: %s branch-factor: %d "
|
||||
"invoke-count: %d type: %s"
|
||||
|
@ -354,7 +354,7 @@ void traversal_algorithm::failed(observer_ptr o, int flags)
|
|||
if (get_node().observer())
|
||||
{
|
||||
char hex_id[41];
|
||||
to_hex(reinterpret_cast<char const*>(&o->id()[0]), 20, hex_id);
|
||||
aux::to_hex(reinterpret_cast<char const*>(&o->id()[0]), 20, hex_id);
|
||||
get_node().observer()->log(dht_logger::traversal
|
||||
, "[%p] TIMEOUT id: %s distance: %d addr: %s branch-factor: %d "
|
||||
"invoke-count: %d type: %s"
|
||||
|
@ -402,7 +402,7 @@ void traversal_algorithm::done()
|
|||
{
|
||||
TORRENT_ASSERT(o->flags & observer::flag_queried);
|
||||
char hex_id[41];
|
||||
to_hex(reinterpret_cast<char const*>(&o->id()[0]), 20, hex_id);
|
||||
aux::to_hex(reinterpret_cast<char const*>(&o->id()[0]), 20, hex_id);
|
||||
get_node().observer()->log(dht_logger::traversal
|
||||
, "[%p] id: %s distance: %d addr: %s"
|
||||
, static_cast<void*>(this), hex_id, closest_target
|
||||
|
@ -482,7 +482,7 @@ bool traversal_algorithm::add_requests()
|
|||
if (get_node().observer())
|
||||
{
|
||||
char hex_id[41];
|
||||
to_hex(reinterpret_cast<char const*>(&o->id()[0]), 20, hex_id);
|
||||
aux::to_hex(reinterpret_cast<char const*>(&o->id()[0]), 20, hex_id);
|
||||
get_node().observer()->log(dht_logger::traversal
|
||||
, "[%p] INVOKE nodes-left: %d top-invoke-count: %d "
|
||||
"invoke-count: %d branch-factor: %d "
|
||||
|
@ -590,7 +590,7 @@ void traversal_observer::reply(msg const& m)
|
|||
{
|
||||
bdecode_node nid = r.dict_find_string("id");
|
||||
char hex_id[41];
|
||||
to_hex(nid.string_ptr(), 20, hex_id);
|
||||
aux::to_hex(nid.string_ptr(), 20, hex_id);
|
||||
get_observer()->log(dht_logger::traversal
|
||||
, "[%p] RESPONSE id: %s invoke-count: %d addr: %s type: %s"
|
||||
, static_cast<void*>(algorithm()), hex_id, algorithm()->invoke_count()
|
||||
|
|
|
@ -142,7 +142,7 @@ void lsd::announce_impl(sha1_hash const& ih, int listen_port, bool broadcast
|
|||
#endif
|
||||
|
||||
char ih_hex[41];
|
||||
to_hex(ih.data(), 20, ih_hex);
|
||||
aux::to_hex(ih.data(), 20, ih_hex);
|
||||
char msg[200];
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
|
@ -279,7 +279,7 @@ void lsd::on_announce(udp::endpoint const& from, char* buf
|
|||
}
|
||||
|
||||
sha1_hash ih(0);
|
||||
from_hex(ih_str.c_str(), 40, ih.data());
|
||||
aux::from_hex(ih_str.c_str(), 40, ih.data());
|
||||
|
||||
if (!ih.is_all_zeros() && port != 0)
|
||||
{
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace libtorrent
|
|||
std::string ret;
|
||||
sha1_hash const& ih = handle.info_hash();
|
||||
ret += "magnet:?xt=urn:btih:";
|
||||
ret += to_hex(ih.to_string());
|
||||
ret += aux::to_hex(ih.to_string());
|
||||
|
||||
torrent_status st = handle.status(torrent_handle::query_name);
|
||||
if (!st.name.empty())
|
||||
|
@ -82,7 +82,7 @@ namespace libtorrent
|
|||
std::string ret;
|
||||
sha1_hash const& ih = info.info_hash();
|
||||
ret += "magnet:?xt=urn:btih:";
|
||||
ret += to_hex(ih.to_string());
|
||||
ret += aux::to_hex(ih.to_string());
|
||||
|
||||
std::string const& name = info.name();
|
||||
|
||||
|
@ -158,7 +158,7 @@ namespace libtorrent
|
|||
|
||||
if (btih.compare(0, 9, "urn:btih:") != 0) return torrent_handle();
|
||||
|
||||
if (btih.size() == 40 + 9) from_hex(&btih[9], 40, params.info_hash.data());
|
||||
if (btih.size() == 40 + 9) aux::from_hex(&btih[9], 40, params.info_hash.data());
|
||||
else params.info_hash.assign(base32decode(btih.substr(9)));
|
||||
|
||||
return ses.add_torrent(params);
|
||||
|
@ -265,7 +265,7 @@ namespace libtorrent
|
|||
#endif
|
||||
|
||||
sha1_hash info_hash;
|
||||
if (btih.size() == 40 + 9) from_hex(&btih[9], 40, info_hash.data());
|
||||
if (btih.size() == 40 + 9) aux::from_hex(&btih[9], 40, info_hash.data());
|
||||
else if (btih.size() == 32 + 9)
|
||||
{
|
||||
std::string ih = base32decode(btih.substr(9));
|
||||
|
|
|
@ -51,7 +51,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <cstdarg> // for va_start, va_end
|
||||
#include <cstdio> // for vsnprintf
|
||||
#include "libtorrent/socket_io.hpp"
|
||||
#include "libtorrent/hex.hpp" // to_hex, from_hex
|
||||
#include "libtorrent/hex.hpp" // to_hex
|
||||
#endif
|
||||
|
||||
#include "libtorrent/peer_connection.hpp"
|
||||
|
@ -1203,7 +1203,7 @@ namespace libtorrent
|
|||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
if (t)
|
||||
peer_log(peer_log_alert::info, "ATTACH"
|
||||
, "Delay loaded torrent: %s:", to_hex(ih.to_string()).c_str());
|
||||
, "Delay loaded torrent: %s:", aux::to_hex(ih.to_string()).c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1213,7 +1213,7 @@ namespace libtorrent
|
|||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
peer_log(peer_log_alert::info, "ATTACH"
|
||||
, "couldn't find a torrent with the given info_hash: %s torrents:"
|
||||
, to_hex(ih.to_string()).c_str());
|
||||
, aux::to_hex(ih.to_string()).c_str());
|
||||
#endif
|
||||
|
||||
#ifndef TORRENT_DISABLE_DHT
|
||||
|
@ -2690,7 +2690,7 @@ namespace libtorrent
|
|||
peer_log(peer_log_alert::incoming_message, "PIECE", "piece: %d s: %x l: %x ds: %d qs: %d q: %d hash: %s"
|
||||
, p.piece, p.start, p.length, statistics().download_rate()
|
||||
, int(m_desired_queue_size), int(m_download_queue.size())
|
||||
, to_hex(h.final().to_string()).c_str());
|
||||
, aux::to_hex(h.final().to_string()).c_str());
|
||||
#endif
|
||||
|
||||
if (p.length == 0)
|
||||
|
|
|
@ -43,16 +43,16 @@ namespace libtorrent
|
|||
std::ostream& operator<<(std::ostream& os, sha1_hash const& peer)
|
||||
{
|
||||
char out[sha1_hash::size * 2 + 1];
|
||||
to_hex(peer.data(), sha1_hash::size, out);
|
||||
aux::to_hex(peer.data(), sha1_hash::size, out);
|
||||
return os << out;
|
||||
}
|
||||
|
||||
// read 40 hexadecimal digits from an istream into a sha1_hash
|
||||
std::istream& operator>>(std::istream& is, sha1_hash& peer)
|
||||
{
|
||||
char hex[sha1_hash::size];
|
||||
is.read(hex, sha1_hash::size);
|
||||
if (!from_hex(hex, sha1_hash::size, peer.data()))
|
||||
char hex[sha1_hash::size * 2];
|
||||
is.read(hex, sha1_hash::size * 2);
|
||||
if (!aux::from_hex(hex, sha1_hash::size * 2, peer.data()))
|
||||
is.setstate(std::ios_base::failbit);
|
||||
return is;
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
#include "libtorrent/socket_io.hpp"
|
||||
#include "libtorrent/hex.hpp" // to_hex, from_hex
|
||||
#include "libtorrent/hex.hpp" // to_hex
|
||||
#endif
|
||||
|
||||
using namespace std::placeholders;
|
||||
|
@ -227,8 +227,8 @@ namespace
|
|||
m_torrent.debug_log(" BANNING PEER [ p: %d | b: %d | c: %s"
|
||||
" | hash1: %s | hash2: %s | ip: %s ]"
|
||||
, b.piece_index, b.block_index, client
|
||||
, to_hex(i->second.digest.to_string()).c_str()
|
||||
, to_hex(e.digest.to_string()).c_str()
|
||||
, aux::to_hex(i->second.digest.to_string()).c_str()
|
||||
, aux::to_hex(e.digest.to_string()).c_str()
|
||||
, print_endpoint(p->ip()).c_str());
|
||||
#endif
|
||||
m_torrent.ban_peer(p);
|
||||
|
@ -253,7 +253,7 @@ namespace
|
|||
m_torrent.debug_log(" STORE BLOCK CRC [ p: %d | b: %d | c: %s"
|
||||
" | digest: %s | ip: %s ]"
|
||||
, b.piece_index, b.block_index, client
|
||||
, to_hex(e.digest.to_string()).c_str()
|
||||
, aux::to_hex(e.digest.to_string()).c_str()
|
||||
, print_address(p->ip().address()).c_str());
|
||||
#endif
|
||||
}
|
||||
|
@ -297,8 +297,8 @@ namespace
|
|||
m_torrent.debug_log(" BANNING PEER [ p: %d | b: %d | c: %s"
|
||||
" | ok_digest: %s | bad_digest: %s | ip: %s ]"
|
||||
, b.first.piece_index, b.first.block_index, client
|
||||
, to_hex(ok_digest.to_string()).c_str()
|
||||
, to_hex(b.second.digest.to_string()).c_str()
|
||||
, aux::to_hex(ok_digest.to_string()).c_str()
|
||||
, aux::to_hex(b.second.digest.to_string()).c_str()
|
||||
, print_address(p->ip().address()).c_str());
|
||||
#endif
|
||||
m_torrent.ban_peer(p);
|
||||
|
|
|
@ -76,7 +76,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/disk_buffer_holder.hpp"
|
||||
#include "libtorrent/alloca.hpp"
|
||||
#include "libtorrent/stat_cache.hpp"
|
||||
#include "libtorrent/hex.hpp" // to_hex, from_hex
|
||||
#include "libtorrent/hex.hpp" // to_hex
|
||||
// for convert_to_wstring and convert_to_native
|
||||
#include "libtorrent/aux_/escape_string.hpp"
|
||||
|
||||
|
@ -409,7 +409,7 @@ namespace libtorrent
|
|||
TORRENT_ASSERT(m_files.num_files() > 0);
|
||||
m_save_path = complete(params.path);
|
||||
m_part_file_name = "." + (params.info
|
||||
? to_hex(params.info->info_hash().to_string())
|
||||
? aux::to_hex(params.info->info_hash().to_string())
|
||||
: params.files->name()) + ".parts";
|
||||
}
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/alert_manager.hpp"
|
||||
#include "libtorrent/disk_interface.hpp"
|
||||
#include "libtorrent/broadcast_socket.hpp" // for is_ip_address
|
||||
#include "libtorrent/hex.hpp" // to_hex, from_hex
|
||||
#include "libtorrent/hex.hpp" // to_hex
|
||||
// TODO: factor out cache_status to its own header
|
||||
#include "libtorrent/disk_io_thread.hpp" // for cache_status
|
||||
|
||||
|
@ -3280,7 +3280,7 @@ namespace libtorrent
|
|||
i != resp.peers.end(); ++i)
|
||||
{
|
||||
debug_log(" %16s %5d %s %s", i->hostname.c_str(), i->port
|
||||
, i->pid.is_all_zeros()?"":to_hex(i->pid.to_string()).c_str()
|
||||
, i->pid.is_all_zeros()?"":aux::to_hex(i->pid.to_string()).c_str()
|
||||
, identify_client(i->pid).c_str());
|
||||
}
|
||||
for (std::vector<ipv4_peer_entry>::const_iterator i = resp.peers4.begin();
|
||||
|
@ -7039,7 +7039,7 @@ namespace libtorrent
|
|||
if (is_ssl_torrent())
|
||||
{
|
||||
// for ssl sockets, set the hostname
|
||||
std::string host_name = to_hex(m_torrent_file->info_hash().to_string());
|
||||
std::string host_name = aux::to_hex(m_torrent_file->info_hash().to_string());
|
||||
|
||||
#define CASE(t) case socket_type_int_impl<ssl_stream<t> >::value: \
|
||||
s->get<ssl_stream<t> >()->set_host_name(host_name); break;
|
||||
|
|
|
@ -49,7 +49,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/add_torrent_params.hpp"
|
||||
#include "libtorrent/magnet_uri.hpp"
|
||||
#include "libtorrent/announce_entry.hpp"
|
||||
#include "libtorrent/hex.hpp" // to_hex, from_hex
|
||||
#include "libtorrent/hex.hpp" // to_hex
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
#include "libtorrent/lazy_entry.hpp"
|
||||
|
@ -1190,7 +1190,7 @@ namespace libtorrent
|
|||
std::string name;
|
||||
sanitize_append_path_element(name, name_ent.string_ptr()
|
||||
, name_ent.string_length());
|
||||
if (name.empty()) name = to_hex(m_info_hash.to_string());
|
||||
if (name.empty()) name = aux::to_hex(m_info_hash.to_string());
|
||||
|
||||
// extract file list
|
||||
bdecode_node files_node = info.dict_find_list("files");
|
||||
|
|
|
@ -531,7 +531,7 @@ namespace libtorrent
|
|||
if (cb)
|
||||
{
|
||||
char hex_ih[41];
|
||||
to_hex(tracker_req().info_hash.data(), 20, hex_ih);
|
||||
aux::to_hex(tracker_req().info_hash.data(), 20, hex_ih);
|
||||
cb->debug_log("==> UDP_TRACKER_CONNECT [ to: %s ih: %s]"
|
||||
, m_hostname.empty()
|
||||
? print_endpoint(m_target).c_str()
|
||||
|
@ -763,7 +763,7 @@ namespace libtorrent
|
|||
if (cb)
|
||||
{
|
||||
char hex_ih[41];
|
||||
to_hex(req.info_hash.data(), 20, hex_ih);
|
||||
aux::to_hex(req.info_hash.data(), 20, hex_ih);
|
||||
cb->debug_log("==> UDP_TRACKER_ANNOUNCE [%s]", hex_ih);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -831,7 +831,7 @@ void web_peer_connection::on_receive(error_code const& error
|
|||
buffer::const_interval chunk_start = recv_buffer;
|
||||
chunk_start.begin += m_chunk_pos;
|
||||
TORRENT_ASSERT(chunk_start.begin[0] == '\r'
|
||||
|| detail::is_hex(chunk_start.begin, 1));
|
||||
|| aux::is_hex(chunk_start.begin, 1));
|
||||
bool ret = m_parser.parse_chunk_header(chunk_start, &chunk_size, &header_size);
|
||||
if (!ret)
|
||||
{
|
||||
|
|
|
@ -48,7 +48,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/random.hpp"
|
||||
#include "libtorrent/torrent_info.hpp"
|
||||
#include "libtorrent/broadcast_socket.hpp" // for supports_ipv6()
|
||||
#include "libtorrent/hex.hpp" // to_hex, from_hex
|
||||
#include "libtorrent/hex.hpp" // to_hex
|
||||
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <functional>
|
||||
|
@ -767,7 +767,7 @@ setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3
|
|||
remove_all(combine_path("tmp3" + suffix, "temporary"), ec);
|
||||
}
|
||||
char ih_hex[41];
|
||||
to_hex((char const*)&t->info_hash()[0], 20, ih_hex);
|
||||
aux::to_hex((char const*)&t->info_hash()[0], 20, ih_hex);
|
||||
std::fprintf(stderr, "generated torrent: %s tmp1%s/temporary\n", ih_hex, suffix.c_str());
|
||||
}
|
||||
else
|
||||
|
@ -930,5 +930,7 @@ void stop_web_server()
|
|||
tcp::endpoint ep(char const* ip, int port)
|
||||
{
|
||||
error_code ec;
|
||||
return tcp::endpoint(address::from_string(ip, ec), port);
|
||||
tcp::endpoint ret(address::from_string(ip, ec), port);
|
||||
TEST_CHECK(!ec);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <sys/stat.h> // for chmod
|
||||
#include "libtorrent/torrent_info.hpp"
|
||||
#include "libtorrent/torrent_status.hpp"
|
||||
#include "libtorrent/hex.hpp" // to_hex, from_hex
|
||||
#include "libtorrent/hex.hpp" // to_hex
|
||||
|
||||
static const int file_sizes[] =
|
||||
{ 5, 16 - 5, 16000, 17, 10, 8000, 8000, 1,1,1,1,1,100,1,1,1,1,100,1,1,1,1,1,1
|
||||
|
@ -117,7 +117,7 @@ void test_checking(int flags = read_only_files)
|
|||
boost::shared_ptr<torrent_info> ti(new torrent_info(&buf[0], int(buf.size()), ec));
|
||||
|
||||
std::fprintf(stderr, "generated torrent: %s tmp1_checking/test_torrent_dir\n"
|
||||
, to_hex(ti->info_hash().to_string()).c_str());
|
||||
, aux::to_hex(ti->info_hash().to_string()).c_str());
|
||||
|
||||
// truncate every file in half
|
||||
if (flags & incomplete_files)
|
||||
|
|
|
@ -63,7 +63,7 @@ using namespace std::placeholders;
|
|||
static sha1_hash to_hash(char const* s)
|
||||
{
|
||||
sha1_hash ret;
|
||||
from_hex(s, 40, (char*)&ret[0]);
|
||||
aux::from_hex(s, 40, (char*)&ret[0]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -845,16 +845,16 @@ void do_test_dht(address(&rand_addr)())
|
|||
// these are test vectors from BEP 33
|
||||
// http://www.bittorrent.org/beps/bep_0033.html
|
||||
std::fprintf(stderr, "test.size: %f\n", test.size());
|
||||
std::fprintf(stderr, "%s\n", to_hex(test.to_string()).c_str());
|
||||
std::fprintf(stderr, "%s\n", aux::to_hex(test.to_string()).c_str());
|
||||
if (supports_ipv6())
|
||||
{
|
||||
TEST_CHECK(fabs(test.size() - 1224.93f) < 0.001);
|
||||
TEST_CHECK(to_hex(test.to_string()) == "f6c3f5eaa07ffd91bde89f777f26fb2bff37bdb8fb2bbaa2fd3ddde7bacfff75ee7ccbaefe5eedb1fbfaff67f6abff5e43ddbca3fd9b9ffdf4ffd3e9dff12d1bdf59db53dbe9fa5b7ff3b8fdfcde1afb8bedd7be2f3ee71ebbbfe93bcdeefe148246c2bc5dbff7e7efdcf24fd8dc7adffd8fffdfddfff7a4bbeedf5cb95ce81fc7fcff1ff4ffffdfe5f7fdcbb7fd79b3fa1fc77bfe07fff905b7b7ffc7fefeffe0b8370bb0cd3f5b7f2bd93feb4386cfdd6f7fd5bfaf2e9ebffffeecd67adbf7c67f17efd5d75eba6ffeba7fff47a91eb1bfbb53e8abfb5762abe8ff237279bfefbfeef5ffc5febfdfe5adffadfee1fb737ffffbfd9f6aeffeee76b6fd8f72ef");
|
||||
TEST_CHECK(aux::to_hex(test.to_string()) == "f6c3f5eaa07ffd91bde89f777f26fb2bff37bdb8fb2bbaa2fd3ddde7bacfff75ee7ccbaefe5eedb1fbfaff67f6abff5e43ddbca3fd9b9ffdf4ffd3e9dff12d1bdf59db53dbe9fa5b7ff3b8fdfcde1afb8bedd7be2f3ee71ebbbfe93bcdeefe148246c2bc5dbff7e7efdcf24fd8dc7adffd8fffdfddfff7a4bbeedf5cb95ce81fc7fcff1ff4ffffdfe5f7fdcbb7fd79b3fa1fc77bfe07fff905b7b7ffc7fefeffe0b8370bb0cd3f5b7f2bd93feb4386cfdd6f7fd5bfaf2e9ebffffeecd67adbf7c67f17efd5d75eba6ffeba7fff47a91eb1bfbb53e8abfb5762abe8ff237279bfefbfeef5ffc5febfdfe5adffadfee1fb737ffffbfd9f6aeffeee76b6fd8f72ef");
|
||||
}
|
||||
else
|
||||
{
|
||||
TEST_CHECK(fabs(test.size() - 257.854f) < 0.001);
|
||||
TEST_CHECK(to_hex(test.to_string()) == "24c0004020043000102012743e00480037110820422110008000c0e302854835a05401a4045021302a306c060001881002d8a0a3a8001901b40a800900310008d2108110c2496a0028700010d804188b01415200082004088026411104a804048002002000080680828c400080cc40020c042c0494447280928041402104080d4240040414a41f0205654800b0811830d2020042b002c5800004a71d0204804a0028120a004c10017801490b834004044106005421000c86900a0020500203510060144e900100924a1018141a028012913f0041802250042280481200002004430804210101c08111c10801001080002038008211004266848606b035001048");
|
||||
TEST_CHECK(aux::to_hex(test.to_string()) == "24c0004020043000102012743e00480037110820422110008000c0e302854835a05401a4045021302a306c060001881002d8a0a3a8001901b40a800900310008d2108110c2496a0028700010d804188b01415200082004088026411104a804048002002000080680828c400080cc40020c042c0494447280928041402104080d4240040414a41f0205654800b0811830d2020042b002c5800004a71d0204804a0028120a004c10017801490b834004044106005421000c86900a0020500203510060144e900100924a1018141a028012913f0041802250042280481200002004430804210101c08111c10801001080002038008211004266848606b035001048");
|
||||
}
|
||||
|
||||
response.clear();
|
||||
|
@ -922,8 +922,8 @@ void do_test_dht(address(&rand_addr)())
|
|||
|
||||
ed25519_create_keypair((unsigned char*)public_key, (unsigned char*)private_key, seed);
|
||||
std::fprintf(stderr, "pub: %s priv: %s\n"
|
||||
, to_hex(std::string(public_key, item_pk_len)).c_str()
|
||||
, to_hex(std::string(private_key, item_sk_len)).c_str());
|
||||
, aux::to_hex(std::string(public_key, item_pk_len)).c_str()
|
||||
, aux::to_hex(std::string(private_key, item_sk_len)).c_str());
|
||||
|
||||
TEST_CHECK(ret);
|
||||
|
||||
|
@ -936,7 +936,7 @@ void do_test_dht(address(&rand_addr)())
|
|||
sha1_hash target_id = h.final();
|
||||
|
||||
std::fprintf(stderr, "target_id: %s\n"
|
||||
, to_hex(target_id.to_string()).c_str());
|
||||
, aux::to_hex(target_id.to_string()).c_str());
|
||||
|
||||
send_dht_request(node, "get", source, &response
|
||||
, msg_args().target((char*)&target_id[0]));
|
||||
|
@ -960,7 +960,7 @@ void do_test_dht(address(&rand_addr)())
|
|||
token = desc_keys[2].string_value();
|
||||
std::fprintf(stderr, "get response: %s\n"
|
||||
, print_entry(response).c_str());
|
||||
std::fprintf(stderr, "got token: %s\n", to_hex(token).c_str());
|
||||
std::fprintf(stderr, "got token: %s\n", aux::to_hex(token).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1002,7 +1002,7 @@ void do_test_dht(address(&rand_addr)())
|
|||
, msg_args().target((char*)&target_id[0]));
|
||||
|
||||
std::fprintf(stderr, "target_id: %s\n"
|
||||
, to_hex(target_id.to_string()).c_str());
|
||||
, aux::to_hex(target_id.to_string()).c_str());
|
||||
|
||||
key_desc_t desc3[] =
|
||||
{
|
||||
|
@ -1380,7 +1380,7 @@ void do_test_dht(address(&rand_addr)())
|
|||
|
||||
TEST_CHECK(id[19] == rs[i]);
|
||||
std::fprintf(stderr, "IP address: %s r: %d node ID: %s\n", ips[i]
|
||||
, rs[i], to_hex(id.to_string()).c_str());
|
||||
, rs[i], aux::to_hex(id.to_string()).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2155,8 +2155,8 @@ TORRENT_TEST(dht_dual_stack)
|
|||
|
||||
void get_test_keypair(char* public_key, char* private_key)
|
||||
{
|
||||
from_hex("77ff84905a91936367c01360803104f92432fcd904a43511876df5cdf3e7e548", 64, public_key);
|
||||
from_hex("e06d3183d14159228433ed599221b80bd0a5ce8352e4bdf0262f76786ef1c74d"
|
||||
aux::from_hex("77ff84905a91936367c01360803104f92432fcd904a43511876df5cdf3e7e548", 64, public_key);
|
||||
aux::from_hex("e06d3183d14159228433ed599221b80bd0a5ce8352e4bdf0262f76786ef1c74d"
|
||||
"b7e7a9fea2c0eb269d61e3b38e450a22e754941ac78479d6c54e1faf6037881d", 128, private_key);
|
||||
}
|
||||
|
||||
|
@ -2179,12 +2179,12 @@ TORRENT_TEST(signing_test1)
|
|||
sign_mutable_item(test_content, empty_salt, 1, public_key
|
||||
, private_key, signature);
|
||||
|
||||
TEST_EQUAL(to_hex(std::string(signature, 64))
|
||||
TEST_EQUAL(aux::to_hex(std::string(signature, 64))
|
||||
, "305ac8aeb6c9c151fa120f120ea2cfb923564e11552d06a5d856091e5e853cff"
|
||||
"1260d3f39e4999684aa92eb73ffd136e6f4f3ecbfda0ce53a1608ecd7ae21f01");
|
||||
|
||||
sha1_hash target_id = item_target_id(empty_salt, public_key);
|
||||
TEST_EQUAL(to_hex(target_id.to_string()), "4a533d47ec9c7d95b1ad75f576cffc641853b750");
|
||||
TEST_EQUAL(aux::to_hex(target_id.to_string()), "4a533d47ec9c7d95b1ad75f576cffc641853b750");
|
||||
}
|
||||
|
||||
TORRENT_TEST(signing_test2)
|
||||
|
@ -2205,12 +2205,12 @@ TORRENT_TEST(signing_test2)
|
|||
sign_mutable_item(test_content, test_salt, 1, public_key
|
||||
, private_key, signature);
|
||||
|
||||
TEST_EQUAL(to_hex(std::string(signature, 64))
|
||||
TEST_EQUAL(aux::to_hex(std::string(signature, 64))
|
||||
, "6834284b6b24c3204eb2fea824d82f88883a3d95e8b4a21b8c0ded553d17d17d"
|
||||
"df9a8a7104b1258f30bed3787e6cb896fca78c58f8e03b5f18f14951a87d9a08");
|
||||
|
||||
sha1_hash target_id = item_target_id(test_salt, public_key);
|
||||
TEST_EQUAL(to_hex(target_id.to_string()), "411eba73b6f087ca51a3795d9c8c938d365e32c1");
|
||||
TEST_EQUAL(aux::to_hex(target_id.to_string()), "411eba73b6f087ca51a3795d9c8c938d365e32c1");
|
||||
}
|
||||
|
||||
TORRENT_TEST(signing_test3)
|
||||
|
@ -2221,7 +2221,7 @@ TORRENT_TEST(signing_test3)
|
|||
std::pair<char const*, int> test_content("12:Hello World!", 15);
|
||||
|
||||
sha1_hash target_id = item_target_id(test_content);
|
||||
TEST_EQUAL(to_hex(target_id.to_string()), "e5f96f6f38320f0f33959cb4d3d656452117aadb");
|
||||
TEST_EQUAL(aux::to_hex(target_id.to_string()), "e5f96f6f38320f0f33959cb4d3d656452117aadb");
|
||||
}
|
||||
|
||||
// TODO: 2 split this up into smaller test cases
|
||||
|
|
|
@ -41,7 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/performance_counters.hpp" // for counters
|
||||
#include "libtorrent/random.hpp"
|
||||
#include "libtorrent/ed25519.hpp"
|
||||
#include "libtorrent/hex.hpp" // to_hex, from_hex
|
||||
#include "libtorrent/hex.hpp" // from_hex
|
||||
|
||||
#include "libtorrent/kademlia/dht_storage.hpp"
|
||||
#include "libtorrent/kademlia/node_id.hpp"
|
||||
|
@ -68,9 +68,10 @@ namespace
|
|||
return sett;
|
||||
}
|
||||
|
||||
static sha1_hash to_hash(char const *s) {
|
||||
sha1_hash to_hash(char const *s) {
|
||||
std::stringstream hash(s);
|
||||
sha1_hash ret;
|
||||
from_hex(s, 40, (char *) &ret[0]);
|
||||
hash >> ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ TORRENT_TEST(hasher)
|
|||
h.update(test_array[test], int(std::strlen(test_array[test])));
|
||||
|
||||
sha1_hash result;
|
||||
from_hex(result_array[test], 40, (char*)&result[0]);
|
||||
aux::from_hex(result_array[test], 40, (char*)&result[0]);
|
||||
TEST_CHECK(result == h.final());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/bencode.hpp"
|
||||
#include "libtorrent/torrent_info.hpp" // for announce_entry
|
||||
#include "libtorrent/announce_entry.hpp"
|
||||
#include "libtorrent/hex.hpp" // to_hex, from_hex
|
||||
#include "libtorrent/hex.hpp" // to_hex
|
||||
|
||||
using namespace libtorrent;
|
||||
namespace lt = libtorrent;
|
||||
|
@ -177,7 +177,7 @@ TORRENT_TEST(magnet)
|
|||
std::fprintf(stderr, "3: %s\n", trackers[2].url.c_str());
|
||||
}
|
||||
|
||||
TEST_EQUAL(to_hex(t.info_hash().to_string()), "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd");
|
||||
TEST_EQUAL(aux::to_hex(t.info_hash().to_string()), "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd");
|
||||
|
||||
p1 = s->abort();
|
||||
s.reset(new lt::session());
|
||||
|
|
|
@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/broadcast_socket.hpp"
|
||||
#include "libtorrent/socket_io.hpp" // for print_endpoint
|
||||
#include "libtorrent/announce_entry.hpp"
|
||||
#include "libtorrent/hex.hpp" // to_hex, from_hex
|
||||
#include "libtorrent/hex.hpp" // from_hex
|
||||
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
|
@ -44,7 +44,7 @@ using namespace libtorrent;
|
|||
sha1_hash to_hash(char const* s)
|
||||
{
|
||||
sha1_hash ret;
|
||||
from_hex(s, 40, (char*)&ret[0]);
|
||||
aux::from_hex(s, 40, (char*)&ret[0]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/create_torrent.hpp"
|
||||
#include "libtorrent/alert_types.hpp"
|
||||
#include "libtorrent/torrent_info.hpp"
|
||||
#include "libtorrent/hex.hpp" // to_hex, from_hex
|
||||
#include "libtorrent/hex.hpp" // to_hex
|
||||
|
||||
enum flags_t
|
||||
{
|
||||
|
@ -87,7 +87,7 @@ void test_read_piece(int flags)
|
|||
boost::shared_ptr<torrent_info> ti(new torrent_info(&buf[0], int(buf.size()), ec));
|
||||
|
||||
std::fprintf(stderr, "generated torrent: %s tmp1_read_piece/test_torrent\n"
|
||||
, to_hex(ti->info_hash().to_string()).c_str());
|
||||
, aux::to_hex(ti->info_hash().to_string()).c_str());
|
||||
|
||||
const int mask = alert::all_categories
|
||||
& ~(alert::progress_notification
|
||||
|
|
|
@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/torrent_info.hpp"
|
||||
#include "libtorrent/resolve_links.hpp"
|
||||
#include "libtorrent/file.hpp" // for combine_path
|
||||
#include "libtorrent/hex.hpp" // to_hex, from_hex
|
||||
#include "libtorrent/hex.hpp" // to_hex
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <functional>
|
||||
|
||||
|
@ -121,7 +121,7 @@ TORRENT_TEST(resolve_links)
|
|||
{
|
||||
TORRENT_ASSERT(i < fs.num_files());
|
||||
std::fprintf(stderr, "%s --> %s : %d\n", fs.file_name(i).c_str()
|
||||
, links[i].ti ? to_hex(links[i].ti->info_hash()
|
||||
, links[i].ti ? aux::to_hex(links[i].ti->info_hash()
|
||||
.to_string()).c_str() : "", links[i].file_idx);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,14 +32,14 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include "test.hpp"
|
||||
#include "libtorrent/sha1_hash.hpp"
|
||||
#include "libtorrent/hex.hpp" // to_hex, from_hex
|
||||
#include "libtorrent/hex.hpp" // from_hex
|
||||
|
||||
using namespace libtorrent;
|
||||
|
||||
static sha1_hash to_hash(char const* s)
|
||||
{
|
||||
sha1_hash ret;
|
||||
from_hex(s, 40, (char*)&ret[0]);
|
||||
aux::from_hex(s, 40, (char*)&ret[0]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -53,13 +53,13 @@ TORRENT_TEST(string)
|
|||
|
||||
char const* str = "0123456789012345678901234567890123456789";
|
||||
char bin[20];
|
||||
TEST_CHECK(from_hex(str, 40, bin));
|
||||
TEST_CHECK(aux::from_hex(str, 40, bin));
|
||||
char hex[41];
|
||||
to_hex(bin, 20, hex);
|
||||
aux::to_hex(bin, 20, hex);
|
||||
TEST_CHECK(strcmp(hex, str) == 0);
|
||||
|
||||
TEST_CHECK(to_hex("\x55\x73") == "5573");
|
||||
TEST_CHECK(to_hex("\xaB\xd0") == "abd0");
|
||||
TEST_CHECK(aux::to_hex("\x55\x73") == "5573");
|
||||
TEST_CHECK(aux::to_hex("\xaB\xd0") == "abd0");
|
||||
|
||||
// test is_space
|
||||
|
||||
|
@ -206,16 +206,16 @@ TORRENT_TEST(string)
|
|||
{
|
||||
bool hex = strchr(hex_chars, i) != NULL;
|
||||
char c = i;
|
||||
TEST_EQUAL(detail::is_hex(&c, 1), hex);
|
||||
TEST_EQUAL(aux::is_hex(&c, 1), hex);
|
||||
}
|
||||
|
||||
TEST_EQUAL(detail::hex_to_int('0'), 0);
|
||||
TEST_EQUAL(detail::hex_to_int('7'), 7);
|
||||
TEST_EQUAL(detail::hex_to_int('a'), 10);
|
||||
TEST_EQUAL(detail::hex_to_int('f'), 15);
|
||||
TEST_EQUAL(detail::hex_to_int('b'), 11);
|
||||
TEST_EQUAL(detail::hex_to_int('t'), -1);
|
||||
TEST_EQUAL(detail::hex_to_int('g'), -1);
|
||||
TEST_EQUAL(aux::hex_to_int('0'), 0);
|
||||
TEST_EQUAL(aux::hex_to_int('7'), 7);
|
||||
TEST_EQUAL(aux::hex_to_int('a'), 10);
|
||||
TEST_EQUAL(aux::hex_to_int('f'), 15);
|
||||
TEST_EQUAL(aux::hex_to_int('b'), 11);
|
||||
TEST_EQUAL(aux::hex_to_int('t'), -1);
|
||||
TEST_EQUAL(aux::hex_to_int('g'), -1);
|
||||
|
||||
std::string path = "a\\b\\c";
|
||||
convert_path_to_posix(path);
|
||||
|
|
|
@ -36,7 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/create_torrent.hpp"
|
||||
#include "libtorrent/announce_entry.hpp"
|
||||
#include "libtorrent/aux_/escape_string.hpp" // for convert_path_to_posix
|
||||
#include "libtorrent/hex.hpp" // to_hex, from_hex
|
||||
#include "libtorrent/hex.hpp" // to_hex
|
||||
|
||||
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
||||
#include <boost/make_shared.hpp>
|
||||
|
@ -728,7 +728,7 @@ TORRENT_TEST(parse_torrents)
|
|||
, (flags & file_storage::flag_symlink)?'l':'-'
|
||||
, first, last
|
||||
, boost::uint32_t(fs.mtime(i))
|
||||
, fs.hash(i) != sha1_hash(0) ? to_hex(fs.hash(i).to_string()).c_str() : ""
|
||||
, fs.hash(i) != sha1_hash(0) ? aux::to_hex(fs.hash(i).to_string()).c_str() : ""
|
||||
, fs.file_path(i).c_str()
|
||||
, flags & file_storage::flag_symlink ? "-> ": ""
|
||||
, flags & file_storage::flag_symlink ? fs.symlink(i).c_str() : "");
|
||||
|
|
|
@ -47,6 +47,10 @@ using namespace libtorrent;
|
|||
using namespace std::placeholders;
|
||||
namespace lt = libtorrent;
|
||||
|
||||
// TODO: don't use internal functions to libtorrent
|
||||
using libtorrent::aux::from_hex;
|
||||
using libtorrent::aux::to_hex;
|
||||
|
||||
#ifdef TORRENT_DISABLE_DHT
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
|
@ -278,7 +282,7 @@ int main(int argc, char* argv[])
|
|||
{
|
||||
++argv;
|
||||
--argc;
|
||||
|
||||
|
||||
if (argc < 1) usage();
|
||||
|
||||
if (strlen(argv[0]) != 40)
|
||||
|
|
Loading…
Reference in New Issue