some more ASNum additions

This commit is contained in:
Arvid Norberg 2008-04-22 00:05:23 +00:00
parent 9e63383458
commit 9a434a919f
5 changed files with 36 additions and 4 deletions

View File

@ -134,6 +134,7 @@ The ``session`` class has the following synopsis::
bool load_asnum_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);
entry state() const;
@ -421,18 +422,22 @@ their turn to get connected.
``max_half_open_connections()`` returns the set limit. This limit defaults
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_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
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.
``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 GeoIP database`: http://www.maxmind.com/app/geolitecountry

View File

@ -980,6 +980,24 @@ int main(int ac, char* av[])
char 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')
{
// keep track of the number of resume data

View File

@ -203,6 +203,7 @@ namespace libtorrent
#endif
#ifndef TORRENT_DISABLE_GEO_IP
int as_for_ip(address const& addr);
bool load_asnum_db(char const* file);
bool load_country_db(char const* file);
#endif

View File

@ -185,6 +185,13 @@ namespace libtorrent
{
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
void session::load_state(entry const& ses_state)

View File

@ -159,7 +159,7 @@ namespace aux {
, m_num_unchoked(0)
, m_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_last_tick(time_now())
#ifndef TORRENT_DISABLE_DHT
@ -1355,7 +1355,7 @@ namespace aux {
--m_disconnect_time_scaler;
if (m_disconnect_time_scaler <= 0)
{
m_disconnect_time_scaler = 60;
m_disconnect_time_scaler = 90;
// every 60 seconds, disconnect the worst peer
// if we have reached the connection limit
@ -1366,6 +1366,7 @@ namespace aux {
< bind(&torrent::num_peers, bind(&torrent_map::value_type::second, _2)));
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();
}
}