added btgdaemon to identify client and applied wojci's patch to add num_connections() and num_uploads() to session

This commit is contained in:
Arvid Norberg 2007-01-01 21:04:30 +00:00
parent 373b18233a
commit 0f3874028b
6 changed files with 44 additions and 2 deletions

View File

@ -254,6 +254,8 @@ namespace libtorrent
void set_max_connections(int limit); void set_max_connections(int limit);
void set_max_uploads(int limit); void set_max_uploads(int limit);
int num_uploads() const;
int num_connections() const;
session_status status() const; session_status status() const;
void set_peer_id(peer_id const& id); void set_peer_id(peer_id const& id);

View File

@ -208,10 +208,18 @@ namespace libtorrent
// returns the port we ended up listening on // returns the port we ended up listening on
unsigned short listen_port() const; unsigned short listen_port() const;
// Get the number of uploads.
int num_uploads() const;
// Get the number of connections. This number also contains the
// number of half open connections.
int num_connections() const;
void remove_torrent(const torrent_handle& h); void remove_torrent(const torrent_handle& h);
void set_settings(session_settings const& s); void set_settings(session_settings const& s);
session_settings const& settings(); session_settings const& settings();
void set_upload_rate_limit(int bytes_per_second); void set_upload_rate_limit(int bytes_per_second);
void set_download_rate_limit(int bytes_per_second); void set_download_rate_limit(int bytes_per_second);
void set_max_uploads(int limit); void set_max_uploads(int limit);

View File

@ -146,6 +146,7 @@ namespace
, map_entry("BB", "BitBuddy") , map_entry("BB", "BitBuddy")
, map_entry("BC", "BitComet") , map_entry("BC", "BitComet")
, map_entry("BF", "Bitflu") , map_entry("BF", "Bitflu")
, map_entry("BG", "btgdaemon")
, map_entry("BS", "BTSlave") , map_entry("BS", "BTSlave")
, map_entry("BX", "BittorrentX") , map_entry("BX", "BittorrentX")
, map_entry("CD", "Enhanced CTorrent") , map_entry("CD", "Enhanced CTorrent")

View File

@ -1020,6 +1020,7 @@ namespace libtorrent
piece_picker& picker = t->picker(); piece_picker& picker = t->picker();
piece_manager& fs = t->filesystem(); piece_manager& fs = t->filesystem();
policy& pol = t->get_policy();
std::vector<piece_block> finished_blocks; std::vector<piece_block> finished_blocks;
piece_block block_finished(p.piece, p.start / t->block_size()); piece_block block_finished(p.piece, p.start / t->block_size());
@ -1108,7 +1109,7 @@ namespace libtorrent
try try
{ {
t->get_policy().block_finished(*this, block_finished); pol.block_finished(*this, block_finished);
send_block_requests(); send_block_requests();
} }
catch (std::exception const&) {} catch (std::exception const&) {}
@ -1158,7 +1159,7 @@ namespace libtorrent
t->piece_failed(p.piece); t->piece_failed(p.piece);
} }
t->get_policy().piece_finished(p.piece, verified); pol.piece_finished(p.piece, verified);
if (!was_seed && t->is_seed()) if (!was_seed && t->is_seed())
{ {

View File

@ -282,6 +282,16 @@ namespace libtorrent
m_impl->set_download_rate_limit(bytes_per_second); m_impl->set_download_rate_limit(bytes_per_second);
} }
int session::num_uploads() const
{
return m_impl->num_uploads();
}
int session::num_connections() const
{
return m_impl->num_connections();
}
std::auto_ptr<alert> session::pop_alert() std::auto_ptr<alert> session::pop_alert()
{ {
return m_impl->pop_alert(); return m_impl->pop_alert();

View File

@ -1633,6 +1633,7 @@ namespace libtorrent { namespace detail
{ {
assert(limit > 0 || limit == -1); assert(limit > 0 || limit == -1);
mutex_t::scoped_lock l(m_mutex); mutex_t::scoped_lock l(m_mutex);
m_half_open_limit = limit; m_half_open_limit = limit;
} }
@ -1643,6 +1644,25 @@ namespace libtorrent { namespace detail
m_upload_rate = bytes_per_second; m_upload_rate = bytes_per_second;
} }
int session_impl::num_uploads() const
{
int uploads = 0;
mutex_t::scoped_lock l(m_mutex);
for (torrent_map::const_iterator i = m_torrents.begin()
, end(m_torrents.end()); i != end; i++)
{
uploads += i->second->get_policy().num_uploads();
}
return uploads;
}
int session_impl::num_connections() const
{
mutex_t::scoped_lock l(m_mutex);
return m_connections.size() + m_half_open.size();
}
std::auto_ptr<alert> session_impl::pop_alert() std::auto_ptr<alert> session_impl::pop_alert()
{ {
mutex_t::scoped_lock l(m_mutex); mutex_t::scoped_lock l(m_mutex);