Michael Mckeown
2016-04-16 16:24:03 UTC
I'm using Libtorrent like so:
using namespace libtorrent;
libtorrent::session* Client_Session;
void start_client_session ( )
{
Client_Session = new libtorrent::session;
dht_settings dht;
dht_settings ( );
settings_pack pack;
pack.set_str ( settings_pack::user_agent , std::string ( "Test " )
+ TEST_VERSION_STRING );
pack.set_int ( settings_pack::alert_mask ,
alert::error_notification | alert::storage_notification |
alert::status_notification | alert::dht_notification );
pack.set_bool ( settings_pack::enable_upnp , true );
pack.set_bool ( settings_pack::enable_natpmp , true );
pack.set_bool ( settings_pack::enable_lsd , true );
pack.set_bool ( settings_pack::enable_dht , true );
std::string ip = "0.0.0.0:6881";
pack.set_str ( settings_pack::listen_interfaces , ip );
session Client_Session ( pack );
Client_Session.set_dht_settings ( dht );
std::vector<stats_metric> map = session_stats_metrics ( );
for ( std::vector<stats_metric>::const_iterator i = map.begin ( );
i != map.end ( ); ++i )
{
if ( i->name == "peer.num_peers_connected" )
{
statistics.num_peers_connected = i->value_index;
}
if ( i->name == "dht.dht_nodes" )
{
statistics.dht_nodes = i->value_index;
}
if ( i->name == "net.sent_payload_bytes" )
{
statistics.sent_payload_bytes = i->value_index;
}
if ( i->name == "net.recv_payload_bytes" )
{
statistics.recv_payload_bytes = i->value_index;
}
if ( i->name == "net.has_incoming_connections" )
{
statistics.has_incoming_connections = i->value_index;
}
}
}
on timer:
void timer_a ( )
{
Client_Session->post_session_stats ( );
std::vector<libtorrent::alert*> alerts;
Client_Session->pop_alerts ( &alerts );
for ( libtorrent::alert const* a : alerts )
{
if ( auto se = libtorrent::alert_cast<
libtorrent::session_stats_alert >( a ) )
{
no_dht_nodes = se->values [ statistics.dht_nodes ];
no_peers = se->values [ statistics.num_peers_connected ];
total_uploaded = se->values [ statistics.sent_payload_bytes ];
total_downloaded = se->values [
statistics.recv_payload_bytes ];
}
}
}
The port opens and I can turn on/off things and change settings but as
no torrents are added here and DHT is running I was expecting DHT nodes
to be greater than 0 and still have some
sent_payload_bytes/recv_payload_bytes but this is not the case.
In utorrent with no torrents added you get the no of dht nodes and there
is erroneous upload/download data, what is it I'm doing wrong here?
using namespace libtorrent;
libtorrent::session* Client_Session;
void start_client_session ( )
{
Client_Session = new libtorrent::session;
dht_settings dht;
dht_settings ( );
settings_pack pack;
pack.set_str ( settings_pack::user_agent , std::string ( "Test " )
+ TEST_VERSION_STRING );
pack.set_int ( settings_pack::alert_mask ,
alert::error_notification | alert::storage_notification |
alert::status_notification | alert::dht_notification );
pack.set_bool ( settings_pack::enable_upnp , true );
pack.set_bool ( settings_pack::enable_natpmp , true );
pack.set_bool ( settings_pack::enable_lsd , true );
pack.set_bool ( settings_pack::enable_dht , true );
std::string ip = "0.0.0.0:6881";
pack.set_str ( settings_pack::listen_interfaces , ip );
session Client_Session ( pack );
Client_Session.set_dht_settings ( dht );
std::vector<stats_metric> map = session_stats_metrics ( );
for ( std::vector<stats_metric>::const_iterator i = map.begin ( );
i != map.end ( ); ++i )
{
if ( i->name == "peer.num_peers_connected" )
{
statistics.num_peers_connected = i->value_index;
}
if ( i->name == "dht.dht_nodes" )
{
statistics.dht_nodes = i->value_index;
}
if ( i->name == "net.sent_payload_bytes" )
{
statistics.sent_payload_bytes = i->value_index;
}
if ( i->name == "net.recv_payload_bytes" )
{
statistics.recv_payload_bytes = i->value_index;
}
if ( i->name == "net.has_incoming_connections" )
{
statistics.has_incoming_connections = i->value_index;
}
}
}
on timer:
void timer_a ( )
{
Client_Session->post_session_stats ( );
std::vector<libtorrent::alert*> alerts;
Client_Session->pop_alerts ( &alerts );
for ( libtorrent::alert const* a : alerts )
{
if ( auto se = libtorrent::alert_cast<
libtorrent::session_stats_alert >( a ) )
{
no_dht_nodes = se->values [ statistics.dht_nodes ];
no_peers = se->values [ statistics.num_peers_connected ];
total_uploaded = se->values [ statistics.sent_payload_bytes ];
total_downloaded = se->values [
statistics.recv_payload_bytes ];
}
}
}
The port opens and I can turn on/off things and change settings but as
no torrents are added here and DHT is running I was expecting DHT nodes
to be greater than 0 and still have some
sent_payload_bytes/recv_payload_bytes but this is not the case.
In utorrent with no torrents added you get the no of dht nodes and there
is erroneous upload/download data, what is it I'm doing wrong here?