forked from premiere/premiere-libtorrent
some more ASNum additions
This commit is contained in:
parent
9e63383458
commit
9a434a919f
|
@ -134,6 +134,7 @@ The ``session`` class has the following synopsis::
|
||||||
|
|
||||||
bool load_asnum_db(char const* file);
|
bool load_asnum_db(char const* file);
|
||||||
bool load_country_db(char const* file);
|
bool load_country_db(char const* file);
|
||||||
|
int as_for_ip(address const& adr);
|
||||||
|
|
||||||
void load_state(entry const& ses_state);
|
void load_state(entry const& ses_state);
|
||||||
entry state() const;
|
entry state() const;
|
||||||
|
@ -421,18 +422,22 @@ their turn to get connected.
|
||||||
``max_half_open_connections()`` returns the set limit. This limit defaults
|
``max_half_open_connections()`` returns the set limit. This limit defaults
|
||||||
to 8 on windows.
|
to 8 on windows.
|
||||||
|
|
||||||
load_asnum_db() load_country_db()
|
load_asnum_db() load_country_db() int as_for_ip()
|
||||||
---------------------------------
|
-------------------------------------------------
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
bool load_asnum_db(char const* file);
|
bool load_asnum_db(char const* file);
|
||||||
bool load_country_db(char const* file);
|
bool load_country_db(char const* file);
|
||||||
|
int as_for_ip(address const& adr);
|
||||||
|
|
||||||
These functions are not available if ``TORRENT_DISABLE_GEO_IP`` is defined. They
|
These functions are not available if ``TORRENT_DISABLE_GEO_IP`` is defined. They
|
||||||
expects a path to the `MaxMind ASN database`_ and `MaxMind GeoIP database`_
|
expects a path to the `MaxMind ASN database`_ and `MaxMind GeoIP database`_
|
||||||
respectively. This will be used to look up which AS and country peers belong to.
|
respectively. This will be used to look up which AS and country peers belong to.
|
||||||
|
|
||||||
|
``as_for_ip`` returns the AS number for the IP address specified. If the IP is not
|
||||||
|
in the database or the ASN database is not loaded, 0 is returned.
|
||||||
|
|
||||||
.. _`MaxMind ASN database`: http://www.maxmind.com/app/asnum
|
.. _`MaxMind ASN database`: http://www.maxmind.com/app/asnum
|
||||||
.. _`MaxMind GeoIP database`: http://www.maxmind.com/app/geolitecountry
|
.. _`MaxMind GeoIP database`: http://www.maxmind.com/app/geolitecountry
|
||||||
|
|
||||||
|
|
|
@ -980,6 +980,24 @@ int main(int ac, char* av[])
|
||||||
char c;
|
char c;
|
||||||
if (sleep_and_input(&c))
|
if (sleep_and_input(&c))
|
||||||
{
|
{
|
||||||
|
if (c == 'm')
|
||||||
|
{
|
||||||
|
std::cout << "saving peers for torrents" << std::endl;
|
||||||
|
|
||||||
|
std::vector<peer_list_entry> peers;
|
||||||
|
for (handles_t::iterator i = handles.begin();
|
||||||
|
i != handles.end(); ++i)
|
||||||
|
{
|
||||||
|
i->second.get_full_peer_list(peers);
|
||||||
|
std::ofstream f(("peers_" + i->second.name()).c_str());
|
||||||
|
for (std::vector<peer_list_entry>::iterator k = peers.begin()
|
||||||
|
, end(peers.end()); k != end; ++k)
|
||||||
|
{
|
||||||
|
f << k->ip.address() << "\t" << ses.as_for_ip(k->ip.address()) << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (c == 'q')
|
if (c == 'q')
|
||||||
{
|
{
|
||||||
// keep track of the number of resume data
|
// keep track of the number of resume data
|
||||||
|
|
|
@ -203,6 +203,7 @@ namespace libtorrent
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_GEO_IP
|
#ifndef TORRENT_DISABLE_GEO_IP
|
||||||
|
int as_for_ip(address const& addr);
|
||||||
bool load_asnum_db(char const* file);
|
bool load_asnum_db(char const* file);
|
||||||
bool load_country_db(char const* file);
|
bool load_country_db(char const* file);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -185,6 +185,13 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
return m_impl->load_country_db(file);
|
return m_impl->load_country_db(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int session::as_for_ip(address const& addr)
|
||||||
|
{
|
||||||
|
aux::session_impl::mutex_t::scoped_lock l(m_impl->m_mutex);
|
||||||
|
return m_impl->as_for_ip(addr);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void session::load_state(entry const& ses_state)
|
void session::load_state(entry const& ses_state)
|
||||||
|
|
|
@ -159,7 +159,7 @@ namespace aux {
|
||||||
, m_num_unchoked(0)
|
, m_num_unchoked(0)
|
||||||
, m_unchoke_time_scaler(0)
|
, m_unchoke_time_scaler(0)
|
||||||
, m_optimistic_unchoke_time_scaler(0)
|
, m_optimistic_unchoke_time_scaler(0)
|
||||||
, m_disconnect_time_scaler(0)
|
, m_disconnect_time_scaler(90)
|
||||||
, m_incoming_connection(false)
|
, m_incoming_connection(false)
|
||||||
, m_last_tick(time_now())
|
, m_last_tick(time_now())
|
||||||
#ifndef TORRENT_DISABLE_DHT
|
#ifndef TORRENT_DISABLE_DHT
|
||||||
|
@ -1355,7 +1355,7 @@ namespace aux {
|
||||||
--m_disconnect_time_scaler;
|
--m_disconnect_time_scaler;
|
||||||
if (m_disconnect_time_scaler <= 0)
|
if (m_disconnect_time_scaler <= 0)
|
||||||
{
|
{
|
||||||
m_disconnect_time_scaler = 60;
|
m_disconnect_time_scaler = 90;
|
||||||
|
|
||||||
// every 60 seconds, disconnect the worst peer
|
// every 60 seconds, disconnect the worst peer
|
||||||
// if we have reached the connection limit
|
// if we have reached the connection limit
|
||||||
|
@ -1366,6 +1366,7 @@ namespace aux {
|
||||||
< bind(&torrent::num_peers, bind(&torrent_map::value_type::second, _2)));
|
< bind(&torrent::num_peers, bind(&torrent_map::value_type::second, _2)));
|
||||||
|
|
||||||
TORRENT_ASSERT(i != m_torrents.end());
|
TORRENT_ASSERT(i != m_torrents.end());
|
||||||
|
// TODO: make the number of peers a percentage of the number of connected peers
|
||||||
i->second->get_policy().disconnect_one_peer();
|
i->second->get_policy().disconnect_one_peer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue