Browse Source

post propagation via torrent working!

miguelfreitas
miguel 11 years ago
parent
commit
931c484c26
  1. 4
      libtorrent/src/disk_io_thread.cpp
  2. 49
      libtorrent/src/peer_connection.cpp

4
libtorrent/src/disk_io_thread.cpp

@ -1159,7 +1159,7 @@ namespace libtorrent @@ -1159,7 +1159,7 @@ namespace libtorrent
if (p.blocks[start_block].buf != 0 && min_blocks_to_read > 1)
++start_block;
int piece_size = j.storage->info()->piece_size(j.piece);
int piece_size = p.piece_size;
int blocks_in_piece = (piece_size + m_block_size - 1) / m_block_size;
TORRENT_ASSERT(start_block < blocks_in_piece);
@ -1273,6 +1273,8 @@ namespace libtorrent @@ -1273,6 +1273,8 @@ namespace libtorrent
ret = cache_read_block(j, l);
hit = false;
if (ret < 0) return ret;
//[MF]
j.buffer_size = ret;
p = find_cached_piece(m_read_pieces, j, l);
TORRENT_ASSERT(!m_read_pieces.empty());

49
libtorrent/src/peer_connection.cpp

@ -58,6 +58,8 @@ POSSIBILITY OF SUCH DAMAGE. @@ -58,6 +58,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/bt_peer_connection.hpp"
#include "libtorrent/error.hpp"
#include "../../src/twister.h"
#ifdef TORRENT_DEBUG
#include <set>
#endif
@ -536,7 +538,8 @@ namespace libtorrent @@ -536,7 +538,8 @@ namespace libtorrent
va_end(v);
char buf[450];
snprintf(buf, sizeof(buf), "%s: %s\n", time_now_string(), usr);
(*m_logger) << buf;
//(*m_logger) << buf;
printf(buf);
}
#endif
@ -649,7 +652,7 @@ namespace libtorrent @@ -649,7 +652,7 @@ namespace libtorrent
}
}
void peer_connection::on_metadata_impl()
void peer_connection::on_metadata_impl()
{
boost::shared_ptr<torrent> t = associated_torrent().lock();
m_have_piece.resize(t->torrent_file().num_pieces(), m_have_all);
@ -1580,6 +1583,7 @@ namespace libtorrent @@ -1580,6 +1583,7 @@ namespace libtorrent
if (is_disconnecting()) return;
/* [MF]
if (!t->valid_metadata() && index >= int(m_have_piece.size()))
{
if (index < 131072)
@ -1604,6 +1608,15 @@ namespace libtorrent @@ -1604,6 +1608,15 @@ namespace libtorrent
disconnect(errors::invalid_have, 2);
return;
}
*/
// [MF]
if(validatePostNumberForUser(t->name(), index)) {
t->increase_num_pieces(index+2);
} else {
disconnect(errors::invalid_have, 2);
return;
}
if (t->super_seeding() && !m_ses.settings().strict_super_seeding)
{
@ -2063,7 +2076,7 @@ namespace libtorrent @@ -2063,7 +2076,7 @@ namespace libtorrent
{
m_last_piece = time_now();
TORRENT_ASSERT(m_outstanding_bytes >= bytes);
m_outstanding_bytes -= bytes;
m_outstanding_bytes -= bytes;
if (m_outstanding_bytes < 0) m_outstanding_bytes = 0;
boost::shared_ptr<torrent> t = associated_torrent().lock();
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
@ -4529,7 +4542,7 @@ namespace libtorrent @@ -4529,7 +4542,7 @@ namespace libtorrent
return;
}
if (ret != r.length)
if (ret <= 0)
{
if (ret == -3)
{
@ -4547,6 +4560,8 @@ namespace libtorrent @@ -4547,6 +4560,8 @@ namespace libtorrent
}
return;
}
//[MF]
r.length = j.buffer_size;
if (t)
{
@ -4568,8 +4583,10 @@ namespace libtorrent @@ -4568,8 +4583,10 @@ namespace libtorrent
void peer_connection::assign_bandwidth(int channel, int amount)
{
#ifdef TORRENT_VERBOSE_LOGGING
/*
peer_log("%s ASSIGN BANDWIDHT [ bytes: %d ]"
, channel == upload_channel ? ">>>" : "<<<", amount);
*/
#endif
TORRENT_ASSERT(amount > 0);
@ -4639,6 +4656,7 @@ namespace libtorrent @@ -4639,6 +4656,7 @@ namespace libtorrent
// peers that we are not interested in are non-prioritized
#ifdef TORRENT_VERBOSE_LOGGING
/*
peer_log(">>> REQUEST_BANDWIDTH [ upload: %d prio: %d "
"channels: %p %p %p %p limits: %d %d %d %d ignore: %d ]"
, int(m_send_buffer.size()), priority
@ -4647,7 +4665,8 @@ namespace libtorrent @@ -4647,7 +4665,8 @@ namespace libtorrent
, (bwc2?bwc2->throttle():0)
, (bwc3?bwc3->throttle():0)
, (bwc4?bwc4->throttle():0)
, m_ignore_bandwidth_limits);
, m_ignore_bandwidth_limits);
*/
#endif
int ret = m_ses.m_upload_rate.request_bandwidth(self()
@ -4663,7 +4682,7 @@ namespace libtorrent @@ -4663,7 +4682,7 @@ namespace libtorrent
{
m_quota[upload_channel] += ret;
#ifdef TORRENT_VERBOSE_LOGGING
peer_log(">>> ASSIGN BANDWIDTH [ bytes: %d ]", ret);
//peer_log(">>> ASSIGN BANDWIDTH [ bytes: %d ]", ret);
#endif
}
return ret;
@ -4690,6 +4709,7 @@ namespace libtorrent @@ -4690,6 +4709,7 @@ namespace libtorrent
shared_ptr<torrent> t = m_torrent.lock();
#ifdef TORRENT_VERBOSE_LOGGING
/*
peer_log("<<< REQUEST_BANDWIDTH [ download: %d prio: %d "
"channels: %p %p %p %p limits: %d %d %d %d ignore: %d ]"
, int(m_download_queue.size() * 16 * 1024 + 30), m_priority
@ -4699,6 +4719,7 @@ namespace libtorrent @@ -4699,6 +4719,7 @@ namespace libtorrent
, (bwc3?bwc3->throttle():0)
, (bwc4?bwc4->throttle():0)
, m_ignore_bandwidth_limits);
*/
#endif
TORRENT_ASSERT(m_priority <= 255);
@ -4716,7 +4737,7 @@ namespace libtorrent @@ -4716,7 +4737,7 @@ namespace libtorrent
else
{
#ifdef TORRENT_VERBOSE_LOGGING
peer_log("<<< ASSIGN BANDWIDTH [ bytes: %d ]", ret);
//peer_log("<<< ASSIGN BANDWIDTH [ bytes: %d ]", ret);
#endif
m_quota[download_channel] += ret;
}
@ -5006,7 +5027,7 @@ namespace libtorrent @@ -5006,7 +5027,7 @@ namespace libtorrent
TORRENT_ASSERT((m_channel_state[download_channel] & peer_info::bw_network) == 0);
m_channel_state[download_channel] |= peer_info::bw_network;
#ifdef TORRENT_VERBOSE_LOGGING
peer_log("<<< ASYNC_READ [ max: %d bytes ]", max_receive);
//peer_log("<<< ASYNC_READ [ max: %d bytes ]", max_receive);
#endif
#if defined TORRENT_ASIO_DEBUGGING
@ -5038,7 +5059,7 @@ namespace libtorrent @@ -5038,7 +5059,7 @@ namespace libtorrent
}
#ifdef TORRENT_VERBOSE_LOGGING
peer_log("<<< SYNC_READ [ max: %d ret: %d e: %s ]", max_receive, ret, ec ? ec.message().c_str() : "");
//peer_log("<<< SYNC_READ [ max: %d ret: %d e: %s ]", max_receive, ret, ec ? ec.message().c_str() : "");
#endif
return ret;
}
@ -5193,8 +5214,8 @@ namespace libtorrent @@ -5193,8 +5214,8 @@ namespace libtorrent
INVARIANT_CHECK;
#ifdef TORRENT_VERBOSE_LOGGING
peer_log("<<< ON_RECEIVE_DATA [ bytes: %d error: %s ]"
, bytes_transferred, error.message().c_str());
//peer_log("<<< ON_RECEIVE_DATA [ bytes: %d error: %s ]"
// , bytes_transferred, error.message().c_str());
#endif
#if defined TORRENT_ASIO_DEBUGGING
complete_async("peer_connection::on_receive_data");
@ -5227,7 +5248,7 @@ namespace libtorrent @@ -5227,7 +5248,7 @@ namespace libtorrent
{
TORRENT_ASSERT(int(m_recv_pos + bytes_transferred) <= m_packet_size);
#ifdef TORRENT_VERBOSE_LOGGING
peer_log("<<< read %d bytes", int(bytes_transferred));
//peer_log("<<< read %d bytes", int(bytes_transferred));
#endif
// correct the dl quota usage, if not all of the buffer was actually read
TORRENT_ASSERT(int(bytes_transferred) <= m_quota[download_channel]);
@ -5599,7 +5620,7 @@ namespace libtorrent @@ -5599,7 +5620,7 @@ namespace libtorrent
m_statistics.trancieve_ip_packet(bytes_transferred, m_remote.address().is_v6());
#ifdef TORRENT_VERBOSE_LOGGING
peer_log(">>> wrote %d bytes", int(bytes_transferred));
//peer_log(">>> wrote %d bytes", int(bytes_transferred));
#endif
if (error)
@ -5711,7 +5732,7 @@ namespace libtorrent @@ -5711,7 +5732,7 @@ namespace libtorrent
}
//if (p && p->bytes_downloaded < p->full_block_bytes) TORRENT_ASSERT(in_download_queue);
TORRENT_ASSERT(m_outstanding_bytes == outstanding_bytes);
//TORRENT_ASSERT(m_outstanding_bytes == outstanding_bytes);
}
std::set<piece_block> unique;

Loading…
Cancel
Save