aux::to_hex(sha1) -> sha1.to_hex() (#1418)
generate hex strings into std::string instead of stack-allocated char arrays
This commit is contained in:
parent
3f1084d63d
commit
6afb1f3e83
|
@ -54,6 +54,7 @@ namespace libtorrent
|
||||||
// by ``out`` is large enough, i.e. has at least len * 2 bytes of space.
|
// by ``out`` is large enough, i.e. has at least len * 2 bytes of space.
|
||||||
TORRENT_DEPRECATED_EXPORT std::string to_hex(span<char const> s);
|
TORRENT_DEPRECATED_EXPORT std::string to_hex(span<char const> s);
|
||||||
TORRENT_DEPRECATED_EXPORT void to_hex(span<char const> in, char* out);
|
TORRENT_DEPRECATED_EXPORT void to_hex(span<char const> in, char* out);
|
||||||
|
TORRENT_DEPRECATED_EXPORT void to_hex(char const* in, size_t const len, char* out);
|
||||||
|
|
||||||
// converts the buffer [``in``, ``in`` + len) from hexadecimal to
|
// converts the buffer [``in``, ``in`` + len) from hexadecimal to
|
||||||
// binary. The binary output is written to the buffer pointed to
|
// binary. The binary output is written to the buffer pointed to
|
||||||
|
|
|
@ -68,9 +68,7 @@ namespace libtorrent {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char msg[41];
|
m_name_idx = alloc.copy_string(aux::to_hex(t->info_hash()));
|
||||||
aux::to_hex(t->info_hash(), msg);
|
|
||||||
m_name_idx = alloc.copy_string(msg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1120,11 +1118,9 @@ namespace libtorrent {
|
||||||
std::string dht_announce_alert::message() const
|
std::string dht_announce_alert::message() const
|
||||||
{
|
{
|
||||||
error_code ec;
|
error_code ec;
|
||||||
char ih_hex[41];
|
|
||||||
aux::to_hex(info_hash, ih_hex);
|
|
||||||
char msg[200];
|
char msg[200];
|
||||||
std::snprintf(msg, sizeof(msg), "incoming dht announce: %s:%u (%s)"
|
std::snprintf(msg, sizeof(msg), "incoming dht announce: %s:%u (%s)"
|
||||||
, ip.to_string(ec).c_str(), port, ih_hex);
|
, ip.to_string(ec).c_str(), port, aux::to_hex(info_hash).c_str());
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1135,10 +1131,8 @@ namespace libtorrent {
|
||||||
|
|
||||||
std::string dht_get_peers_alert::message() const
|
std::string dht_get_peers_alert::message() const
|
||||||
{
|
{
|
||||||
char ih_hex[41];
|
|
||||||
aux::to_hex(info_hash, ih_hex);
|
|
||||||
char msg[200];
|
char msg[200];
|
||||||
std::snprintf(msg, sizeof(msg), "incoming dht get_peers: %s", ih_hex);
|
std::snprintf(msg, sizeof(msg), "incoming dht get_peers: %s", aux::to_hex(info_hash).c_str());
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1988,10 +1982,8 @@ namespace libtorrent {
|
||||||
|
|
||||||
std::string dht_get_peers_reply_alert::message() const
|
std::string dht_get_peers_reply_alert::message() const
|
||||||
{
|
{
|
||||||
char ih_hex[41];
|
|
||||||
aux::to_hex(info_hash, ih_hex);
|
|
||||||
char msg[200];
|
char msg[200];
|
||||||
std::snprintf(msg, sizeof(msg), "incoming dht get_peers reply: %s, peers %d", ih_hex, m_num_peers);
|
std::snprintf(msg, sizeof(msg), "incoming dht get_peers reply: %s, peers %d", aux::to_hex(info_hash).c_str(), m_num_peers);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -845,12 +845,9 @@ namespace libtorrent
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
if (should_log(peer_log_alert::outgoing))
|
if (should_log(peer_log_alert::outgoing))
|
||||||
{
|
{
|
||||||
char hex_pid[41];
|
|
||||||
aux::to_hex(m_our_peer_id, hex_pid);
|
|
||||||
hex_pid[40] = 0;
|
|
||||||
peer_log(peer_log_alert::outgoing, "HANDSHAKE"
|
peer_log(peer_log_alert::outgoing, "HANDSHAKE"
|
||||||
, "sent peer_id: %s client: %s"
|
, "sent peer_id: %s client: %s"
|
||||||
, hex_pid, identify_client(m_our_peer_id).c_str());
|
, aux::to_hex(m_our_peer_id).c_str(), identify_client(m_our_peer_id).c_str());
|
||||||
}
|
}
|
||||||
if (should_log(peer_log_alert::outgoing_message))
|
if (should_log(peer_log_alert::outgoing_message))
|
||||||
{
|
{
|
||||||
|
|
27
src/hex.cpp
27
src/hex.cpp
|
@ -73,28 +73,31 @@ namespace libtorrent
|
||||||
extern char const hex_chars[];
|
extern char const hex_chars[];
|
||||||
|
|
||||||
char const hex_chars[] = "0123456789abcdef";
|
char const hex_chars[] = "0123456789abcdef";
|
||||||
|
void to_hex(char const* in, size_t const len, char* out)
|
||||||
|
{
|
||||||
|
int idx = 0;
|
||||||
|
for (size_t i=0; i < len; ++i)
|
||||||
|
{
|
||||||
|
out[idx++] = hex_chars[std::uint8_t(in[i]) >> 4];
|
||||||
|
out[idx++] = hex_chars[std::uint8_t(in[i]) & 0xf];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string to_hex(span<char const> s)
|
std::string to_hex(span<char const> in)
|
||||||
{
|
{
|
||||||
std::string ret;
|
std::string ret;
|
||||||
ret.resize(s.size() * 2);
|
if (!in.empty())
|
||||||
int idx = 0;
|
|
||||||
for (char const i : s)
|
|
||||||
{
|
{
|
||||||
ret[idx++] = hex_chars[std::uint8_t(i) >> 4];
|
ret.resize(in.size() * 2);
|
||||||
ret[idx++] = hex_chars[std::uint8_t(i) & 0xf];
|
to_hex(in.data(), in.size(), &ret[0]);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void to_hex(span<char const> in, char* out)
|
void to_hex(span<char const> in, char* out)
|
||||||
{
|
{
|
||||||
for (char const i : in)
|
to_hex(in.data(), in.size(), out);
|
||||||
{
|
out[in.size() * 2] = '\0';
|
||||||
*out++ = hex_chars[std::uint8_t(i) >> 4];
|
|
||||||
*out++ = hex_chars[std::uint8_t(i) & 0xf];
|
|
||||||
}
|
|
||||||
*out = '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // aux namespace
|
} // aux namespace
|
||||||
|
|
|
@ -362,10 +362,8 @@ namespace
|
||||||
auto logger = node.observer();
|
auto logger = node.observer();
|
||||||
if (logger != nullptr && logger->should_log(dht_logger::node))
|
if (logger != nullptr && logger->should_log(dht_logger::node))
|
||||||
{
|
{
|
||||||
char hex_ih[41];
|
|
||||||
aux::to_hex(ih, hex_ih);
|
|
||||||
logger->log(dht_logger::node, "sending announce_peer [ ih: %s "
|
logger->log(dht_logger::node, "sending announce_peer [ ih: %s "
|
||||||
" p: %d nodes: %d ]", hex_ih, listen_port, int(v.size()));
|
" p: %d nodes: %d ]", aux::to_hex(ih).c_str(), listen_port, int(v.size()));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -444,10 +442,8 @@ void node::announce(sha1_hash const& info_hash, int const listen_port, int const
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
if (m_observer != nullptr && m_observer->should_log(dht_logger::node))
|
if (m_observer != nullptr && m_observer->should_log(dht_logger::node))
|
||||||
{
|
{
|
||||||
char hex_ih[41];
|
|
||||||
aux::to_hex(info_hash, hex_ih);
|
|
||||||
m_observer->log(dht_logger::node, "announcing [ ih: %s p: %d ]"
|
m_observer->log(dht_logger::node, "announcing [ ih: %s p: %d ]"
|
||||||
, hex_ih, listen_port);
|
, aux::to_hex(info_hash).c_str(), listen_port);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -476,10 +472,8 @@ void node::get_item(sha1_hash const& target
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
if (m_observer != nullptr && m_observer->should_log(dht_logger::node))
|
if (m_observer != nullptr && m_observer->should_log(dht_logger::node))
|
||||||
{
|
{
|
||||||
char hex_target[41];
|
|
||||||
aux::to_hex(target, hex_target);
|
|
||||||
m_observer->log(dht_logger::node, "starting get for [ hash: %s ]"
|
m_observer->log(dht_logger::node, "starting get for [ hash: %s ]"
|
||||||
, hex_target);
|
, aux::to_hex(target).c_str());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -533,10 +527,8 @@ void node::put_item(sha1_hash const& target, entry const& data, std::function<vo
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
if (m_observer != nullptr && m_observer->should_log(dht_logger::node))
|
if (m_observer != nullptr && m_observer->should_log(dht_logger::node))
|
||||||
{
|
{
|
||||||
char hex_target[41];
|
|
||||||
aux::to_hex(target, hex_target);
|
|
||||||
m_observer->log(dht_logger::node, "starting get for [ hash: %s ]"
|
m_observer->log(dht_logger::node, "starting get for [ hash: %s ]"
|
||||||
, hex_target);
|
, aux::to_hex(target).c_str());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -488,10 +488,8 @@ routing_table::add_node_status_t routing_table::add_node_impl(node_entry e)
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
if (m_log != nullptr && m_log->should_log(dht_logger::routing_table))
|
if (m_log != nullptr && m_log->should_log(dht_logger::routing_table))
|
||||||
{
|
{
|
||||||
char hex_id[41];
|
|
||||||
aux::to_hex(e.id, hex_id);
|
|
||||||
m_log->log(dht_logger::routing_table, "ignoring node (duplicate IP): %s %s"
|
m_log->log(dht_logger::routing_table, "ignoring node (duplicate IP): %s %s"
|
||||||
, hex_id, print_address(e.addr()).c_str());
|
, aux::to_hex(e.id).c_str(), print_address(e.addr()).c_str());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return failed_to_add;
|
return failed_to_add;
|
||||||
|
@ -531,12 +529,8 @@ routing_table::add_node_status_t routing_table::add_node_impl(node_entry e)
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
if (m_log != nullptr && m_log->should_log(dht_logger::routing_table))
|
if (m_log != nullptr && m_log->should_log(dht_logger::routing_table))
|
||||||
{
|
{
|
||||||
char hex_id_new[41];
|
|
||||||
char hex_id_old[41];
|
|
||||||
aux::to_hex(e.id, hex_id_new);
|
|
||||||
aux::to_hex(existing->id, hex_id_old);
|
|
||||||
m_log->log(dht_logger::routing_table, "evicting node (changed ID): old: %s new: %s %s"
|
m_log->log(dht_logger::routing_table, "evicting node (changed ID): old: %s new: %s %s"
|
||||||
, hex_id_old, hex_id_new, print_address(e.addr()).c_str());
|
, aux::to_hex(existing->id).c_str(), aux::to_hex(e.id).c_str(), print_address(e.addr()).c_str());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -628,13 +622,9 @@ routing_table::add_node_status_t routing_table::add_node_impl(node_entry e)
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
if (m_log != nullptr && m_log->should_log(dht_logger::routing_table))
|
if (m_log != nullptr && m_log->should_log(dht_logger::routing_table))
|
||||||
{
|
{
|
||||||
char hex_id1[41];
|
|
||||||
aux::to_hex(e.id, hex_id1);
|
|
||||||
char hex_id2[41];
|
|
||||||
aux::to_hex(j->id, hex_id2);
|
|
||||||
m_log->log(dht_logger::routing_table, "ignoring node: %s %s existing node: %s %s"
|
m_log->log(dht_logger::routing_table, "ignoring node: %s %s existing node: %s %s"
|
||||||
, hex_id1, print_address(e.addr()).c_str()
|
, aux::to_hex(e.id).c_str(), print_address(e.addr()).c_str()
|
||||||
, hex_id2, print_address(j->addr()).c_str());
|
, aux::to_hex(j->id).c_str(), print_address(j->addr()).c_str());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return failed_to_add;
|
return failed_to_add;
|
||||||
|
@ -822,10 +812,8 @@ ip_ok:
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
if (m_log != nullptr && m_log->should_log(dht_logger::routing_table))
|
if (m_log != nullptr && m_log->should_log(dht_logger::routing_table))
|
||||||
{
|
{
|
||||||
char hex_id[41];
|
|
||||||
aux::to_hex(e.id, hex_id);
|
|
||||||
m_log->log(dht_logger::routing_table, "replacing node with higher RTT: %s %s"
|
m_log->log(dht_logger::routing_table, "replacing node with higher RTT: %s %s"
|
||||||
, hex_id, print_address(e.addr()).c_str());
|
, aux::to_hex(e.id).c_str(), print_address(e.addr()).c_str());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return node_added;
|
return node_added;
|
||||||
|
@ -1019,10 +1007,8 @@ void routing_table::node_failed(node_id const& nid, udp::endpoint const& ep)
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
if (m_log != nullptr && m_log->should_log(dht_logger::routing_table))
|
if (m_log != nullptr && m_log->should_log(dht_logger::routing_table))
|
||||||
{
|
{
|
||||||
char hex_id[41];
|
|
||||||
aux::to_hex(nid, hex_id);
|
|
||||||
m_log->log(dht_logger::routing_table, "NODE FAILED id: %s ip: %s fails: %d pinged: %d up-time: %d"
|
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()
|
, aux::to_hex(nid).c_str(), print_endpoint(j->ep()).c_str()
|
||||||
, j->fail_count()
|
, j->fail_count()
|
||||||
, int(j->pinged())
|
, int(j->pinged())
|
||||||
, int(total_seconds(aux::time_now() - j->first_seen)));
|
, int(total_seconds(aux::time_now() - j->first_seen)));
|
||||||
|
@ -1043,10 +1029,8 @@ void routing_table::node_failed(node_id const& nid, udp::endpoint const& ep)
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
if (m_log != nullptr && m_log->should_log(dht_logger::routing_table))
|
if (m_log != nullptr && m_log->should_log(dht_logger::routing_table))
|
||||||
{
|
{
|
||||||
char hex_id[41];
|
|
||||||
aux::to_hex(nid, hex_id);
|
|
||||||
m_log->log(dht_logger::routing_table, "NODE FAILED id: %s ip: %s fails: %d pinged: %d up-time: %d"
|
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()
|
, aux::to_hex(nid).c_str(), print_endpoint(j->ep()).c_str()
|
||||||
, j->fail_count()
|
, j->fail_count()
|
||||||
, int(j->pinged())
|
, int(j->pinged())
|
||||||
, int(total_seconds(aux::time_now() - j->first_seen)));
|
, int(total_seconds(aux::time_now() - j->first_seen)));
|
||||||
|
|
|
@ -87,10 +87,8 @@ traversal_algorithm::traversal_algorithm(
|
||||||
dht_observer* logger = get_node().observer();
|
dht_observer* logger = get_node().observer();
|
||||||
if (logger != nullptr && logger->should_log(dht_logger::traversal))
|
if (logger != nullptr && logger->should_log(dht_logger::traversal))
|
||||||
{
|
{
|
||||||
char hex_target[41];
|
|
||||||
aux::to_hex(target, hex_target);
|
|
||||||
logger->log(dht_logger::traversal, "[%p] NEW target: %s k: %d"
|
logger->log(dht_logger::traversal, "[%p] NEW target: %s k: %d"
|
||||||
, static_cast<void*>(this), hex_target, m_node.m_table.bucket_size());
|
, static_cast<void*>(this), aux::to_hex(target).c_str(), m_node.m_table.bucket_size());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -168,11 +166,9 @@ void traversal_algorithm::add_entry(node_id const& id
|
||||||
dht_observer* logger = get_node().observer();
|
dht_observer* logger = get_node().observer();
|
||||||
if (logger != nullptr && logger->should_log(dht_logger::traversal))
|
if (logger != nullptr && logger->should_log(dht_logger::traversal))
|
||||||
{
|
{
|
||||||
char hex_id[41];
|
|
||||||
aux::to_hex(o->id(), hex_id);
|
|
||||||
logger->log(dht_logger::traversal
|
logger->log(dht_logger::traversal
|
||||||
, "[%p] traversal DUPLICATE node. id: %s addr: %s type: %s"
|
, "[%p] traversal DUPLICATE node. id: %s addr: %s type: %s"
|
||||||
, static_cast<void*>(this), hex_id, print_address(o->target_addr()).c_str(), name());
|
, static_cast<void*>(this), aux::to_hex(o->id()).c_str(), print_address(o->target_addr()).c_str(), name());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
|
@ -188,11 +184,9 @@ void traversal_algorithm::add_entry(node_id const& id
|
||||||
dht_observer* logger = get_node().observer();
|
dht_observer* logger = get_node().observer();
|
||||||
if (logger != nullptr && logger->should_log(dht_logger::traversal))
|
if (logger != nullptr && logger->should_log(dht_logger::traversal))
|
||||||
{
|
{
|
||||||
char hex_id[41];
|
|
||||||
aux::to_hex(id, hex_id);
|
|
||||||
logger->log(dht_logger::traversal
|
logger->log(dht_logger::traversal
|
||||||
, "[%p] ADD id: %s addr: %s distance: %d invoke-count: %d type: %s"
|
, "[%p] ADD id: %s addr: %s distance: %d invoke-count: %d type: %s"
|
||||||
, static_cast<void*>(this), hex_id, print_endpoint(addr).c_str()
|
, static_cast<void*>(this), aux::to_hex(id).c_str(), print_endpoint(addr).c_str()
|
||||||
, distance_exp(m_target, id), m_invoke_count, name());
|
, distance_exp(m_target, id), m_invoke_count, name());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -317,12 +311,10 @@ void traversal_algorithm::failed(observer_ptr o, int const flags)
|
||||||
dht_observer* logger = get_node().observer();
|
dht_observer* logger = get_node().observer();
|
||||||
if (logger != nullptr && logger->should_log(dht_logger::traversal))
|
if (logger != nullptr && logger->should_log(dht_logger::traversal))
|
||||||
{
|
{
|
||||||
char hex_id[41];
|
|
||||||
aux::to_hex(o->id(), hex_id);
|
|
||||||
logger->log(dht_logger::traversal
|
logger->log(dht_logger::traversal
|
||||||
, "[%p] 1ST_TIMEOUT id: %s distance: %d addr: %s branch-factor: %d "
|
, "[%p] 1ST_TIMEOUT id: %s distance: %d addr: %s branch-factor: %d "
|
||||||
"invoke-count: %d type: %s"
|
"invoke-count: %d type: %s"
|
||||||
, static_cast<void*>(this), hex_id, distance_exp(m_target, o->id())
|
, static_cast<void*>(this), aux::to_hex(o->id()).c_str(), distance_exp(m_target, o->id())
|
||||||
, print_address(o->target_addr()).c_str(), m_branch_factor
|
, print_address(o->target_addr()).c_str(), m_branch_factor
|
||||||
, m_invoke_count, name());
|
, m_invoke_count, name());
|
||||||
}
|
}
|
||||||
|
@ -339,12 +331,10 @@ void traversal_algorithm::failed(observer_ptr o, int const flags)
|
||||||
dht_observer* logger = get_node().observer();
|
dht_observer* logger = get_node().observer();
|
||||||
if (logger != nullptr && logger->should_log(dht_logger::traversal))
|
if (logger != nullptr && logger->should_log(dht_logger::traversal))
|
||||||
{
|
{
|
||||||
char hex_id[41];
|
|
||||||
aux::to_hex(o->id(), hex_id);
|
|
||||||
logger->log(dht_logger::traversal
|
logger->log(dht_logger::traversal
|
||||||
, "[%p] TIMEOUT id: %s distance: %d addr: %s branch-factor: %d "
|
, "[%p] TIMEOUT id: %s distance: %d addr: %s branch-factor: %d "
|
||||||
"invoke-count: %d type: %s"
|
"invoke-count: %d type: %s"
|
||||||
, static_cast<void*>(this), hex_id, distance_exp(m_target, o->id())
|
, static_cast<void*>(this), aux::to_hex(o->id()).c_str(), distance_exp(m_target, o->id())
|
||||||
, print_address(o->target_addr()).c_str(), m_branch_factor
|
, print_address(o->target_addr()).c_str(), m_branch_factor
|
||||||
, m_invoke_count, name());
|
, m_invoke_count, name());
|
||||||
}
|
}
|
||||||
|
@ -393,11 +383,9 @@ void traversal_algorithm::done()
|
||||||
&& logger != nullptr && logger->should_log(dht_logger::traversal))
|
&& logger != nullptr && logger->should_log(dht_logger::traversal))
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(o->flags & observer::flag_queried);
|
TORRENT_ASSERT(o->flags & observer::flag_queried);
|
||||||
char hex_id[41];
|
|
||||||
aux::to_hex(o->id(), hex_id);
|
|
||||||
logger->log(dht_logger::traversal
|
logger->log(dht_logger::traversal
|
||||||
, "[%p] id: %s distance: %d addr: %s"
|
, "[%p] id: %s distance: %d addr: %s"
|
||||||
, static_cast<void*>(this), hex_id, closest_target
|
, static_cast<void*>(this), aux::to_hex(o->id()).c_str(), closest_target
|
||||||
, print_endpoint(o->target_ep()).c_str());
|
, print_endpoint(o->target_ep()).c_str());
|
||||||
|
|
||||||
--results_target;
|
--results_target;
|
||||||
|
@ -474,14 +462,12 @@ bool traversal_algorithm::add_requests()
|
||||||
dht_observer* logger = get_node().observer();
|
dht_observer* logger = get_node().observer();
|
||||||
if (logger != nullptr && logger->should_log(dht_logger::traversal))
|
if (logger != nullptr && logger->should_log(dht_logger::traversal))
|
||||||
{
|
{
|
||||||
char hex_id[41];
|
|
||||||
aux::to_hex(o->id(), hex_id);
|
|
||||||
logger->log(dht_logger::traversal
|
logger->log(dht_logger::traversal
|
||||||
, "[%p] INVOKE nodes-left: %d top-invoke-count: %d "
|
, "[%p] INVOKE nodes-left: %d top-invoke-count: %d "
|
||||||
"invoke-count: %d branch-factor: %d "
|
"invoke-count: %d branch-factor: %d "
|
||||||
"distance: %d id: %s addr: %s type: %s"
|
"distance: %d id: %s addr: %s type: %s"
|
||||||
, static_cast<void*>(this), int(m_results.end() - i), outstanding, int(m_invoke_count)
|
, static_cast<void*>(this), int(m_results.end() - i), outstanding, int(m_invoke_count)
|
||||||
, int(m_branch_factor), distance_exp(m_target, o->id()), hex_id
|
, int(m_branch_factor), distance_exp(m_target, o->id()), aux::to_hex(o->id()).c_str()
|
||||||
, print_address(o->target_addr()).c_str(), name());
|
, print_address(o->target_addr()).c_str(), name());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -128,18 +128,16 @@ void lsd::announce_impl(sha1_hash const& ih, int const listen_port
|
||||||
if (m_disabled) return;
|
if (m_disabled) return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char ih_hex[41];
|
|
||||||
aux::to_hex(ih, ih_hex);
|
|
||||||
char msg[200];
|
char msg[200];
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
debug_log("==> LSD: ih: %s port: %u\n", ih_hex, listen_port);
|
debug_log("==> LSD: ih: %s port: %u\n", aux::to_hex(ih).c_str(), listen_port);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
error_code ec;
|
error_code ec;
|
||||||
if (!m_disabled)
|
if (!m_disabled)
|
||||||
{
|
{
|
||||||
int const msg_len = render_lsd_packet(msg, sizeof(msg), listen_port, ih_hex
|
int const msg_len = render_lsd_packet(msg, sizeof(msg), listen_port, aux::to_hex(ih).c_str()
|
||||||
, m_cookie, "239.192.152.143");
|
, m_cookie, "239.192.152.143");
|
||||||
m_socket.send(msg, msg_len, ec, broadcast ? broadcast_socket::flag_broadcast : 0);
|
m_socket.send(msg, msg_len, ec, broadcast ? broadcast_socket::flag_broadcast : 0);
|
||||||
if (ec)
|
if (ec)
|
||||||
|
@ -158,7 +156,7 @@ void lsd::announce_impl(sha1_hash const& ih, int const listen_port
|
||||||
#if TORRENT_USE_IPV6
|
#if TORRENT_USE_IPV6
|
||||||
if (!m_disabled6)
|
if (!m_disabled6)
|
||||||
{
|
{
|
||||||
int const msg_len = render_lsd_packet(msg, sizeof(msg), listen_port, ih_hex
|
int const msg_len = render_lsd_packet(msg, sizeof(msg), listen_port, aux::to_hex(ih).c_str()
|
||||||
, m_cookie, "[ff15::efc0:988f]");
|
, m_cookie, "[ff15::efc0:988f]");
|
||||||
m_socket6.send(msg, msg_len, ec, broadcast ? broadcast_socket::flag_broadcast : 0);
|
m_socket6.send(msg, msg_len, ec, broadcast ? broadcast_socket::flag_broadcast : 0);
|
||||||
if (ec)
|
if (ec)
|
||||||
|
|
|
@ -45,9 +45,7 @@ namespace libtorrent
|
||||||
// print a sha1_hash object to an ostream as 40 hexadecimal digits
|
// print a sha1_hash object to an ostream as 40 hexadecimal digits
|
||||||
std::ostream& operator<<(std::ostream& os, sha1_hash const& peer)
|
std::ostream& operator<<(std::ostream& os, sha1_hash const& peer)
|
||||||
{
|
{
|
||||||
char out[sha1_hash::size() * 2 + 1];
|
return os << aux::to_hex(peer);
|
||||||
aux::to_hex(peer, out);
|
|
||||||
return os << out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// read 40 hexadecimal digits from an istream into a sha1_hash
|
// read 40 hexadecimal digits from an istream into a sha1_hash
|
||||||
|
|
|
@ -529,13 +529,11 @@ namespace libtorrent
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
if (cb && cb->should_log())
|
if (cb && cb->should_log())
|
||||||
{
|
{
|
||||||
char hex_ih[41];
|
|
||||||
aux::to_hex(tracker_req().info_hash, hex_ih);
|
|
||||||
cb->debug_log("==> UDP_TRACKER_CONNECT [ to: %s ih: %s]"
|
cb->debug_log("==> UDP_TRACKER_CONNECT [ to: %s ih: %s]"
|
||||||
, m_hostname.empty()
|
, m_hostname.empty()
|
||||||
? print_endpoint(m_target).c_str()
|
? print_endpoint(m_target).c_str()
|
||||||
: (m_hostname + ":" + to_string(m_target.port()).data()).c_str()
|
: (m_hostname + ":" + to_string(m_target.port()).data()).c_str()
|
||||||
, hex_ih);
|
, aux::to_hex(tracker_req().info_hash).c_str());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -754,9 +752,7 @@ namespace libtorrent
|
||||||
std::shared_ptr<request_callback> cb = requester();
|
std::shared_ptr<request_callback> cb = requester();
|
||||||
if (cb && cb->should_log())
|
if (cb && cb->should_log())
|
||||||
{
|
{
|
||||||
char hex_ih[41];
|
cb->debug_log("==> UDP_TRACKER_ANNOUNCE [%s]", aux::to_hex(req.info_hash).c_str());
|
||||||
aux::to_hex(req.info_hash, hex_ih);
|
|
||||||
cb->debug_log("==> UDP_TRACKER_ANNOUNCE [%s]", hex_ih);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -841,9 +841,7 @@ setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3
|
||||||
remove_all(combine_path("tmp2" + suffix, "temporary"), ec);
|
remove_all(combine_path("tmp2" + suffix, "temporary"), ec);
|
||||||
remove_all(combine_path("tmp3" + suffix, "temporary"), ec);
|
remove_all(combine_path("tmp3" + suffix, "temporary"), ec);
|
||||||
}
|
}
|
||||||
char ih_hex[41];
|
std::printf("generated torrent: %s tmp1%s/temporary\n", aux::to_hex(t->info_hash()).c_str(), suffix.c_str());
|
||||||
aux::to_hex(t->info_hash(), ih_hex);
|
|
||||||
std::printf("generated torrent: %s tmp1%s/temporary\n", ih_hex, suffix.c_str());
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -65,8 +65,15 @@ void test_vector(std::string s, std::string output, int const n = 1)
|
||||||
hasher h;
|
hasher h;
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
h.update(s);
|
h.update(s);
|
||||||
std::string digest = h.final().to_string();
|
std::string const digest = h.final().to_string();
|
||||||
TEST_EQUAL(aux::to_hex(digest), output);
|
std::string const digest_hex = aux::to_hex(digest);
|
||||||
|
|
||||||
|
TEST_EQUAL(digest_hex, output);
|
||||||
|
|
||||||
|
std::string output_hex = digest_hex;
|
||||||
|
aux::to_hex(digest.c_str(), digest.size(), &output_hex[0]);
|
||||||
|
|
||||||
|
TEST_EQUAL(output_hex, digest_hex);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue