Add dht_live_nodes and dht_sample_infohashes to Python bindings

Add 'dht_live_nodes' and 'dht_sample_infohashes' functionality to
Python bindings:
- add function 'dht_live_nodes' to libtorrent.session
- add function 'dht_sample_infohashes' to libtorrent.session
- add alert 'dht_live_nodes_alert' to alerts
- add alert 'dht_sample_infohashes_alert' to alerts
- add alert 'dht_bootstrap_alert' to alerts
This commit is contained in:
Fonic 2019-08-07 10:15:56 +02:00 committed by Arvid Norberg
parent faa807c0f3
commit b148e9ddc4
2 changed files with 54 additions and 0 deletions

View File

@ -135,6 +135,34 @@ dict session_stats_values(session_stats_alert const& alert)
return d;
}
list dht_live_nodes_nodes(dht_live_nodes_alert const& alert)
{
list result;
std::vector<std::pair<sha1_hash, udp::endpoint>> const nodes = alert.nodes();
for (std::pair<sha1_hash, udp::endpoint> const& node : nodes)
{
dict d;
d["nid"] = node.first;
d["endpoint"] = node.second;
result.append(d);
}
return result;
}
list dht_sample_infohashes_nodes(dht_sample_infohashes_alert const& alert)
{
list result;
std::vector<std::pair<sha1_hash, udp::endpoint>> const nodes = alert.nodes();
for (std::pair<sha1_hash, udp::endpoint> const& node : nodes)
{
dict d;
d["nid"] = node.first;
d["endpoint"] = node.second;
result.append(d);
}
return result;
}
#if TORRENT_ABI_VERSION == 1
entry const& get_resume_data_entry(save_resume_data_alert const& self)
{
@ -1070,6 +1098,30 @@ void bind_alert()
.add_property("ip", make_getter(&socks5_alert::ip, by_value()))
;
class_<dht_live_nodes_alert, bases<alert>, noncopyable>(
"dht_live_nodes_alert", no_init)
.add_property("node_id", &dht_live_nodes_alert::node_id)
.add_property("num_nodes", &dht_live_nodes_alert::num_nodes)
.add_property("nodes", &dht_live_nodes_nodes)
;
std::vector<sha1_hash> (dht_sample_infohashes_alert::*samples)() const = &dht_sample_infohashes_alert::samples;
class_<dht_sample_infohashes_alert, bases<alert>, noncopyable>(
"dht_sample_infohashes_alert", no_init)
.add_property("endpoint", make_getter(&dht_sample_infohashes_alert::endpoint, by_value()))
.add_property("interval", make_getter(&dht_sample_infohashes_alert::interval, by_value()))
.add_property("num_infohashes", &dht_sample_infohashes_alert::num_infohashes)
.add_property("num_samples", &dht_sample_infohashes_alert::num_samples)
.add_property("samples", samples)
.add_property("num_nodes", &dht_sample_infohashes_alert::num_nodes)
.add_property("nodes", &dht_sample_infohashes_nodes)
;
class_<dht_bootstrap_alert, bases<alert>, noncopyable>(
"dht_bootstrap_alert", no_init)
;
}
#ifdef _MSC_VER

View File

@ -1017,6 +1017,8 @@ void bind_session()
.def("dht_put_mutable_item", &dht_put_mutable_item)
.def("dht_get_peers", allow_threads(&lt::session::dht_get_peers))
.def("dht_announce", allow_threads(&lt::session::dht_announce))
.def("dht_live_nodes", allow_threads(&lt::session::dht_live_nodes))
.def("dht_sample_infohashes", allow_threads(&lt::session::dht_sample_infohashes))
#endif // TORRENT_DISABLE_DHT
.def("add_torrent", &add_torrent)
.def("async_add_torrent", &async_add_torrent)