fix python binding build (and expose the new dht stats alert)

This commit is contained in:
Arvid Norberg 2015-01-18 21:36:24 +00:00
parent a7bec127f1
commit 431fa2ac55
5 changed files with 91 additions and 7 deletions

View File

@ -21,6 +21,12 @@ tuple endpoint_to_tuple(tcp::endpoint const& ep)
return boost::python::make_tuple(ep.address().to_string(), ep.port());
}
tuple endpoint_to_tuple(udp::endpoint const& ep)
{
return boost::python::make_tuple(ep.address().to_string(), ep.port());
}
tuple peer_alert_ip(peer_alert const& pa)
{
return endpoint_to_tuple(pa.ip);
@ -43,6 +49,11 @@ tuple incoming_connection_alert_ip(incoming_connection_alert const& ica)
return endpoint_to_tuple(ica.ip);
}
tuple dht_outgoing_get_peers_alert_ip(dht_outgoing_get_peers_alert const& a)
{
return endpoint_to_tuple(a.ip);
}
std::string external_ip_alert_ip(external_ip_alert const& eia)
{
return eia.external_address.to_string();
@ -93,6 +104,45 @@ dict get_params(add_torrent_alert const& alert)
return ret;
}
list dht_stats_active_requests(dht_stats_alert const& a)
{
list result;
for (std::vector<dht_lookup>::const_iterator i = a.active_requests.begin();
i != a.active_requests.end(); ++i)
{
dict d;
d["type"] = i->type;
d["outstanding_requests"] = i->outstanding_requests;
d["timeouts"] = i->timeouts;
d["responses"] = i->responses;
d["branch_factor"] = i->branch_factor;
d["nodes_left"] = i->nodes_left;
d["last_sent"] = i->last_sent;
d["first_timeout"] = i->first_timeout;
result.append(d);
}
return result;
}
list dht_stats_routing_table(dht_stats_alert const& a)
{
list result;
for (std::vector<dht_routing_bucket>::const_iterator i = a.routing_table.begin();
i != a.routing_table.end(); ++i)
{
dict d;
d["num_nodes"] = i->num_nodes;
d["num_replacements"] = i->num_replacements;
result.append(d);
}
return result;
}
void bind_alert()
{
@ -546,4 +596,38 @@ void bind_alert()
.def_readonly("old_ih", &torrent_update_alert::old_ih)
.def_readonly("new_ih", &torrent_update_alert::new_ih)
;
class_<dht_outgoing_get_peers_alert, bases<alert>, noncopyable>(
"dht_outgoing_get_peers_alert", no_init)
.def_readonly("info_hash", &dht_outgoing_get_peers_alert::info_hash)
.def_readonly("obfuscated_info_hash", &dht_outgoing_get_peers_alert::obfuscated_info_hash)
.add_property("ip", &dht_outgoing_get_peers_alert_ip)
;
class_<log_alert, bases<alert>, noncopyable>(
"log_alert", no_init)
.def_readonly("msg", &log_alert::msg)
;
class_<torrent_log_alert, bases<torrent_alert>, noncopyable>(
"torrent_log_alert", no_init)
.def_readonly("msg", &torrent_log_alert::msg)
;
class_<peer_log_alert, bases<peer_alert>, noncopyable>(
"peer_log_alert", no_init)
.def_readonly("msg", &peer_log_alert::msg)
;
class_<lsd_error_alert, bases<alert>, noncopyable>(
"lsd_error_alert", no_init)
.def_readonly("error", &lsd_error_alert::error)
;
class_<dht_stats_alert, bases<alert>, noncopyable>(
"dht_stats_alert", no_init)
.add_property("active_requests", &dht_stats_active_requests)
.add_property("routing_table", &dht_stats_routing_table)
;
}

View File

@ -554,9 +554,8 @@ void bind_session()
.def_readonly("dht_global_nodes", &session_status::dht_global_nodes)
.def_readonly("active_requests", &session_status::active_requests)
.def_readonly("dht_total_allocations", &session_status::dht_total_allocations)
#endif
#endif // TORRENT_DISABLE_DHT
.add_property("utp_stats", &get_utp_stats)
#endif
;
#ifndef TORRENT_DISABLE_DHT
@ -567,7 +566,8 @@ void bind_session()
.def_readonly("response", &dht_lookup::responses)
.def_readonly("branch_factor", &dht_lookup::branch_factor)
;
#endif
#endif // TORRENT_DISABLE_DHT
#endif // TORRENT_NO_DEPRECATE
enum_<storage_mode_t>("storage_mode_t")
.value("storage_mode_allocate", storage_mode_allocate)

View File

@ -2150,7 +2150,7 @@ namespace libtorrent
error_code error;
};
// This alert is generated we send a get_peers request
// This alert is generated when we send a get_peers request
// It belongs to the ``dht_notification`` category.
struct TORRENT_EXPORT dht_outgoing_get_peers_alert: alert
{
@ -2341,7 +2341,7 @@ namespace libtorrent
// contains information about every bucket in the DHT routing
// table.
std::vector<dht_routing_bucket> dht_routing_table;
std::vector<dht_routing_bucket> routing_table;
};

View File

@ -740,7 +740,7 @@ namespace libtorrent {
char buf[2048];
snprintf(buf, sizeof(buf), "DHT stats: reqs: %d buckets: %d"
, int(active_requests.size())
, int(dht_routing_table.size()));
, int(routing_table.size()));
return buf;
}

View File

@ -4383,7 +4383,7 @@ retry:
#ifndef TORRENT_DISABLE_DHT
if (m_dht)
m_dht->dht_status(alert->dht_routing_table, alert->active_requests);
m_dht->dht_status(alert->routing_table, alert->active_requests);
#endif
m_alerts.post_alert_ptr(alert.release());