Commit 9204c700 authored by rakshasa's avatar rakshasa

DHT logging.

parent 79d5fb14
......@@ -39,11 +39,15 @@
#include "torrent/exceptions.h"
#include "torrent/object.h"
#include "torrent/utils/log.h"
#include "net/address_list.h" // For SA.
#include "dht_node.h"
#define LT_LOG_THIS(log_fmt, ...) \
lt_log_print_hash(torrent::LOG_DHT_NODE, this->id(), "dht_node", log_fmt, __VA_ARGS__);
namespace torrent {
DhtNode::DhtNode(const HashString& id, const rak::socket_address* sa) :
......@@ -54,9 +58,13 @@ DhtNode::DhtNode(const HashString& id, const rak::socket_address* sa) :
m_recentlyInactive(0),
m_bucket(NULL) {
if (sa->family() != rak::socket_address::af_inet &&
(sa->family() != rak::socket_address::af_inet6 || !sa->sa_inet6()->is_any()))
throw resource_error("Addres not af_inet or in6addr_any");
// TODO: Change this to use the id hash similar to how peer info
// hash'es are logged.
LT_LOG_THIS("created (address:%s)", sa->pretty_address_str().c_str());
// if (sa->family() != rak::socket_address::af_inet &&
// (sa->family() != rak::socket_address::af_inet6 || !sa->sa_inet6()->is_any()))
// throw resource_error("Address not af_inet or in6addr_any");
}
DhtNode::DhtNode(const std::string& id, const Object& cache) :
......@@ -65,11 +73,17 @@ DhtNode::DhtNode(const std::string& id, const Object& cache) :
m_recentlyInactive(0),
m_bucket(NULL) {
// TODO: Check how DHT handles inet6.
rak::socket_address_inet* sa = m_socketAddress.sa_inet();
sa->set_family();
sa->set_address_h(cache.get_key_value("i"));
sa->set_port(cache.get_key_value("p"));
m_lastSeen = cache.get_key_value("t");
LT_LOG_THIS("initializing (address:%s)", sa->address_str().c_str());
update();
}
......
......@@ -51,6 +51,9 @@
#include "dht_tracker.h"
#include "dht_transaction.h"
#define LT_LOG_THIS(log_fmt, ...) \
lt_log_print_subsystem(torrent::LOG_DHT_ROUTER, "dht_router", log_fmt, __VA_ARGS__);
namespace torrent {
HashString DhtRouter::zero_id;
......
......@@ -38,12 +38,16 @@
#include <torrent/exceptions.h>
#include <torrent/throttle.h>
#include <torrent/utils/log.h>
#include "manager.h"
#include "dht/dht_router.h"
#include "dht_manager.h"
#define LT_LOG_THIS(log_fmt, ...) \
lt_log_print_subsystem(torrent::LOG_DHT_MANAGER, "dht_manager", log_fmt, __VA_ARGS__);
namespace torrent {
DhtManager::~DhtManager() {
......@@ -53,10 +57,18 @@ DhtManager::~DhtManager() {
void
DhtManager::initialize(const Object& dhtCache) {
auto bind_address = rak::socket_address::cast_from(manager->connection_manager()->bind_address());
LT_LOG_THIS("initializing (bind_address:%s)", bind_address->pretty_address_str().c_str());
if (m_router != NULL)
throw internal_error("DhtManager::initialize called with DHT already active.");
m_router = new DhtRouter(dhtCache, rak::socket_address::cast_from(manager->connection_manager()->bind_address()));
try {
m_router = new DhtRouter(dhtCache, bind_address);
} catch (torrent::local_error& e) {
LT_LOG_THIS("initialization failed (error:%s)", e.what());
}
}
void
......
......@@ -249,6 +249,8 @@ log_initialize() {
LOG_CHILDREN_CASCADE(LOG_CRITICAL, LOG_TORRENT_CRITICAL);
LOG_LINK(LOG_DHT_ALL, LOG_DHT_MANAGER);
LOG_LINK(LOG_DHT_ALL, LOG_DHT_NODE);
LOG_LINK(LOG_DHT_ALL, LOG_DHT_ROUTER);
std::sort(log_children.begin(), log_children.end());
......
......@@ -115,6 +115,8 @@ enum {
LOG_DHT_ALL,
LOG_DHT_MANAGER,
LOG_DHT_NODE,
LOG_DHT_ROUTER,
LOG_INSTRUMENTATION_MEMORY,
LOG_INSTRUMENTATION_MINCORE,
......@@ -157,6 +159,10 @@ enum {
if (torrent::log_groups[log_group].valid()) \
torrent::log_groups[log_group].internal_print(NULL, NULL, log_dump_data, log_dump_size, __VA_ARGS__); \
#define lt_log_print_hash(log_group, log_hash, log_subsystem, ...) \
if (torrent::log_groups[log_group].valid()) \
torrent::log_groups[log_group].internal_print(&log_hash, log_subsystem, NULL, 0, __VA_ARGS__);
#define lt_log_print_info_dump(log_group, log_dump_data, log_dump_size, log_info, log_subsystem, ...) \
if (torrent::log_groups[log_group].valid()) \
torrent::log_groups[log_group].internal_print(&log_info->hash(), log_subsystem, log_dump_data, log_dump_size, __VA_ARGS__); \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment