upload only extension

This commit is contained in:
Arvid Norberg 2008-05-18 05:59:47 +00:00
parent 498a43c123
commit 111f5faecb
4 changed files with 27 additions and 2 deletions

View File

@ -198,6 +198,9 @@ namespace libtorrent
bool is_seed() const;
void set_upload_only(bool u) { m_upload_only = u; }
bool upload_only() const { return m_upload_only; }
bool has_timed_out() const;
// will send a keep-alive message to the peer
@ -638,6 +641,9 @@ namespace libtorrent
// is used to fill the bitmask in init()
bool m_have_all;
// set to true when this peer is only uploading
bool m_upload_only;
// the number of pieces this peer
// has. Must be the same as
// std::count(m_have_piece.begin(),

View File

@ -1301,6 +1301,12 @@ namespace libtorrent
m_max_out_request_queue = 1;
}
if (entry* upload_only = root.find_key("upload_only"))
{
if (upload_only->type() == entry::int_t && upload_only->integer() != 0)
set_upload_only(true);
}
if (entry* myip = root.find_key("yourip"))
{
// TODO: don't trust this blindly
@ -1321,6 +1327,11 @@ namespace libtorrent
}
}
}
// if we're finished and this peer is uploading only
// disconnect it
if (t->is_finished() && upload_only())
disconnect("upload to upload connection, closing");
}
bool bt_peer_connection::dispatch_message(int received)
@ -1556,6 +1567,9 @@ namespace libtorrent
detail::write_address(remote().address(), out);
handshake["yourip"] = remote_address;
handshake["reqq"] = m_ses.settings().max_allowed_in_request_queue;
boost::shared_ptr<torrent> t = associated_torrent().lock();
TORRENT_ASSERT(t);
if (t->is_finished()) handshake["upload_only"] = 1;
tcp::endpoint ep = m_ses.get_ipv6_interface();
if (ep != tcp::endpoint())

View File

@ -96,6 +96,7 @@ namespace libtorrent
, m_failed(false)
, m_ignore_bandwidth_limits(false)
, m_have_all(false)
, m_upload_only(false)
, m_num_pieces(0)
, m_desired_queue_size(2)
, m_free_upload(0)
@ -195,6 +196,7 @@ namespace libtorrent
, m_failed(false)
, m_ignore_bandwidth_limits(false)
, m_have_all(false)
, m_upload_only(false)
, m_num_pieces(0)
, m_desired_queue_size(2)
, m_free_upload(0)
@ -1108,10 +1110,10 @@ namespace libtorrent
}
}
if (is_seed())
if (upload_only())
{
TORRENT_ASSERT(m_peer_info);
m_peer_info->seed = true;
if (is_seed()) m_peer_info->seed = true;
if (t->is_finished() && m_ses.settings().close_redundant_connections)
{
disconnect("seed to seed connection redundant");
@ -1231,6 +1233,7 @@ namespace libtorrent
m_num_pieces = num_pieces;
if (interesting) t->get_policy().peer_is_interesting(*this);
else if (upload_only()) disconnect("upload to upload connections");
}
// -----------------------------

View File

@ -73,6 +73,8 @@ namespace libtorrent
// we want large blocks as well, so
// we can request more bytes at once
request_large_blocks(true);
set_upload_only(true);
// we only want left-over bandwidth
set_priority(0);
shared_ptr<torrent> tor = t.lock();