added num_seeds and distributed_copies to torrent_status

This commit is contained in:
Magnus Jonsson 2004-08-05 13:56:26 +00:00
parent 2dccc01b31
commit 7fe3323ced
7 changed files with 67 additions and 10 deletions

View File

@ -1082,6 +1082,9 @@ It contains the following fields::
const std::vector<bool>* pieces; const std::vector<bool>* pieces;
size_type total_done; size_type total_done;
int num_seeds;
float distributed_copies;
}; };
``progress`` is a value in the range [0, 1], that represents the progress of the ``progress`` is a value in the range [0, 1], that represents the progress of the
@ -1151,6 +1154,18 @@ be slightly smaller than the other rates, but if projected over a long time
this does not necessarily has to be downloaded during this session (that's this does not necessarily has to be downloaded during this session (that's
``total_download_payload``). ``total_download_payload``).
``num_seeds`` is the number of peers that are seeding that this torrent
currently is connected to.
``distributed_copies`` is the number of distributed copies of the torrent.
Note that one copy may be spread out among many peers. The whole number part
tells how many copies there are currently of the rarest piece(s) among the
peers this torrent is connected to. The fractional part tells the share of
pieces that have more copies than the rarest piece(s). For example: 2.5 would
mean that the rarest pieces have only 2 copies among the peers this torrent is
connected to, and that there are as many pieces that have 2 copies as there are
pieces that have more than two copies.
peer_info peer_info

View File

@ -199,7 +199,7 @@ std::string add_suffix(float val)
{ {
if (fabs(val) < 1000.f) if (fabs(val) < 1000.f)
return to_string(val, i==0?7:6) + prefix[i]; return to_string(val, i==0?7:6) + prefix[i];
val /= 1000.f; val /= 1024.f;
} }
return to_string(val, 6) + "PB"; return to_string(val, 6) + "PB";
} }
@ -282,8 +282,7 @@ int main(int argc, char* argv[])
session ses(fingerprint("LT", 0, 1, 0, 0)); session ses(fingerprint("LT", 0, 1, 0, 0));
ses.listen_on(std::make_pair(6881, 6889)); ses.listen_on(std::make_pair(6881, 6889));
ses.set_upload_rate_limit(31 * 1024); ses.set_upload_rate_limit(512 * 1024);
// ses.set_download_rate_limit(50000);
ses.set_http_settings(settings); ses.set_http_settings(settings);
ses.set_severity_level(alert::debug); ses.set_severity_level(alert::debug);
// ses.set_severity_level(alert::info); // ses.set_severity_level(alert::info);
@ -301,7 +300,7 @@ int main(int argc, char* argv[])
handles.push_back(ses.add_torrent(argv[i+1], info_hash, save_path)); handles.push_back(ses.add_torrent(argv[i+1], info_hash, save_path));
handles.back().set_max_connections(60); handles.back().set_max_connections(60);
handles.back().set_max_uploads(7); handles.back().set_max_uploads(7);
handles.back().set_ratio(1.02f); handles.back().set_ratio(1.1f);
++i; ++i;
continue; continue;
@ -328,8 +327,8 @@ int main(int argc, char* argv[])
handles.push_back(ses.add_torrent(e, save_path, resume_data)); handles.push_back(ses.add_torrent(e, save_path, resume_data));
handles.back().set_max_connections(100); handles.back().set_max_connections(100);
handles.back().set_max_uploads(3); handles.back().set_max_uploads(-1);
handles.back().set_ratio(0.f); handles.back().set_ratio(1.02f);
} }
catch (std::exception& e) catch (std::exception& e)
{ {
@ -484,10 +483,12 @@ int main(int argc, char* argv[])
out << progress_bar(s.progress, 49); out << progress_bar(s.progress, 49);
out << "\n"; out << "\n";
out << "total downloaded: " << s.total_done << " Bytes\n"; out << "total downloaded: " << s.total_done << " Bytes\n";
out << "peers: " << (int)peers.size() << " " out << "peers: " << s.num_peers << " "
<< "d:" << add_suffix(s.download_rate) << "/s " << "seeds: " << s.num_seeds << " "
<< "distributed copies: " << s.distributed_copies << "\n";
out << "download:" << add_suffix(s.download_rate) << "/s "
<< "(" << add_suffix(s.total_download) << ") " << "(" << add_suffix(s.total_download) << ") "
<< "u:" << add_suffix(s.upload_rate) << "/s " << "upload:" << add_suffix(s.upload_rate) << "/s "
<< "(" << add_suffix(s.total_upload) << ") " << "(" << add_suffix(s.total_upload) << ") "
<< "ratio: " << ratio(s.total_payload_download, s.total_payload_upload) << "\n"; << "ratio: " << ratio(s.total_payload_download, s.total_payload_upload) << "\n";
out << "info-hash: " << i->info_hash() << "\n"; out << "info-hash: " << i->info_hash() << "\n";

View File

@ -199,6 +199,8 @@ namespace libtorrent
int blocks_in_last_piece() const int blocks_in_last_piece() const
{ return m_blocks_in_last_piece; } { return m_blocks_in_last_piece; }
float distributed_copies() const;
private: private:
struct piece_pos struct piece_pos

View File

@ -169,6 +169,7 @@ namespace libtorrent
// the number of peers that belong to this torrent // the number of peers that belong to this torrent
int num_peers() const { return (int)m_connections.size(); } int num_peers() const { return (int)m_connections.size(); }
int num_seeds() const;
typedef std::map<address, peer_connection*>::iterator peer_iterator; typedef std::map<address, peer_connection*>::iterator peer_iterator;
typedef std::map<address, peer_connection*>::const_iterator const_peer_iterator; typedef std::map<address, peer_connection*>::const_iterator const_peer_iterator;

View File

@ -85,6 +85,8 @@ namespace libtorrent
, num_peers(0) , num_peers(0)
, pieces(0) , pieces(0)
, total_done(0) , total_done(0)
, num_seeds(0)
, distributed_copies(0.f)
{} {}
enum state_t enum state_t
@ -136,6 +138,20 @@ namespace libtorrent
// the number of bytes of the file we have // the number of bytes of the file we have
size_type total_done; size_type total_done;
// the number of peers this torrent is connected to
// that are seeding.
int num_seeds;
// the number of distributed copies of the file.
// note that one copy may be spread out among many peers.
//
// the whole number part tells how many copies
// there are of the rarest piece(s)
//
// the fractional part tells the fraction of pieces that
// have more copies than the rarest piece(s).
float distributed_copies;
}; };
struct partial_piece_info struct partial_piece_info

View File

@ -247,6 +247,18 @@ namespace libtorrent
} }
#endif #endif
float piece_picker::distributed_copies() const
{
for(int count=0;count<(int)m_piece_info.size();count++)
{
if(!m_piece_info[count].empty()) {
float fraction_above_count =
1.f - float(m_piece_info[count].size())/float(m_piece_map.size());
return count+fraction_above_count;
}
}
return 0.f;
}
void piece_picker::move(bool downloading, int peer_count, int elem_index) void piece_picker::move(bool downloading, int peer_count, int elem_index)
{ {

View File

@ -45,6 +45,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/filesystem/convenience.hpp> #include <boost/filesystem/convenience.hpp>
#include <boost/bind.hpp>
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(pop)
@ -872,7 +873,7 @@ namespace libtorrent
torrent_status st; torrent_status st;
st.num_peers = (int)m_connections.size(); st.num_peers = num_peers();
st.paused = m_paused; st.paused = m_paused;
st.total_done = bytes_done(); st.total_done = bytes_done();
@ -934,9 +935,18 @@ namespace libtorrent
else else
st.state = torrent_status::downloading; st.state = torrent_status::downloading;
st.num_seeds = num_seeds();
st.distributed_copies = m_picker->distributed_copies();
return st; return st;
} }
int torrent::num_seeds() const
{
return (int)count_if(m_connections.begin(), m_connections.end(),
boost::bind(&peer_connection::is_seed,
boost::bind(&std::map<address,peer_connection*>::value_type::second, _1)));
}
bool torrent::received_metadata(char const* buf, int size, int offset, int total_size) bool torrent::received_metadata(char const* buf, int size, int offset, int total_size)
{ {
INVARIANT_CHECK; INVARIANT_CHECK;