merge some cleanup and fixes from libtorrent_aio
This commit is contained in:
@@ -221,6 +221,9 @@ namespace libtorrent
|
||||
|
||||
void bt_peer_connection::on_metadata()
|
||||
{
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
peer_log("*** ON_METADATA");
|
||||
#endif
|
||||
// connections that are still in the handshake
|
||||
// will send their bitfield when the handshake
|
||||
// is done
|
||||
@@ -758,13 +761,13 @@ namespace libtorrent
|
||||
// in anonymous mode, every peer connection
|
||||
// has a unique peer-id
|
||||
for (int i = 0; i < 20; ++i)
|
||||
*ptr++ = random();
|
||||
ptr[i] = random();
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(ptr, &m_ses.get_peer_id()[0], 20);
|
||||
// ptr += 20;
|
||||
}
|
||||
// ptr += 20;
|
||||
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
peer_log("==> HANDSHAKE [ ih: %s ]", to_hex(ih.to_string()).c_str());
|
||||
@@ -2020,7 +2023,7 @@ namespace libtorrent
|
||||
|
||||
if (t->is_seed())
|
||||
{
|
||||
memset(ptr, 0xff, packet_size - 6);
|
||||
memset(ptr, 0xff, packet_size - 5);
|
||||
|
||||
// Clear trailing bits
|
||||
unsigned char *p = ((unsigned char *)msg) + packet_size - 1;
|
||||
|
@@ -289,8 +289,8 @@ namespace libtorrent { namespace
|
||||
if (m_message_index == 0) return;
|
||||
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
(*m_pc.m_logger) << time_now_string()
|
||||
<< " ==> METADATA_REQUEST [ start: " << start << " | size: " << size << " ]\n";
|
||||
m_pc.peer_log("==> METADATA_REQUEST [ start: %d | size: %d ]\n"
|
||||
, start, size);
|
||||
#endif
|
||||
|
||||
char msg[9];
|
||||
@@ -327,12 +327,8 @@ namespace libtorrent { namespace
|
||||
char* ptr = msg;
|
||||
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
(*m_pc.m_logger) << time_now_string()
|
||||
<< " ==> METADATA [ start: " << req.first
|
||||
<< " | size: " << req.second
|
||||
<< " | offset: " << offset.first
|
||||
<< " | byte_size: " << offset.second
|
||||
<< " ]\n";
|
||||
m_pc.peer_log("==> METADATA [ start: %d | total_size: %d | offset: %d | data_size: %d ]"
|
||||
, req.first, req.second, offset.first, offset.second);
|
||||
#endif
|
||||
// yes, we have metadata, send it
|
||||
detail::write_uint32(11 + offset.second, ptr);
|
||||
@@ -349,8 +345,7 @@ namespace libtorrent { namespace
|
||||
else
|
||||
{
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
(*m_pc.m_logger) << time_now_string()
|
||||
<< " ==> DONT HAVE METADATA\n";
|
||||
m_pc.peer_log("==> DONT HAVE METADATA\n");
|
||||
#endif
|
||||
char msg[4+3];
|
||||
char* ptr = msg;
|
||||
@@ -391,10 +386,8 @@ namespace libtorrent { namespace
|
||||
int size = detail::read_uint8(body.begin) + 1;
|
||||
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
(*m_pc.m_logger) << time_now_string()
|
||||
<< " <== METADATA_REQUEST [ start: " << start
|
||||
<< " | size: " << size
|
||||
<< " ]\n";
|
||||
m_pc.peer_log("<== METADATA_REQUEST [ start: %d | size: %d ]\n"
|
||||
, start, size);
|
||||
#endif
|
||||
|
||||
if (length != 3)
|
||||
@@ -416,11 +409,8 @@ namespace libtorrent { namespace
|
||||
int data_size = length - 9;
|
||||
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
(*m_pc.m_logger) << time_now_string()
|
||||
<< " <== METADATA [ total_size: " << total_size
|
||||
<< " | offset: " << offset
|
||||
<< " | data_size: " << data_size
|
||||
<< " ]\n";
|
||||
m_pc.peer_log("<== METADATA [ total_size: %d | offset: %d | data_size: %d ]"
|
||||
,total_size, offset, data_size);
|
||||
#endif
|
||||
|
||||
if (total_size > m_torrent.session().settings().max_metadata_size)
|
||||
@@ -462,8 +452,7 @@ namespace libtorrent { namespace
|
||||
m_tp.cancel_metadata_request(m_last_metadata_request);
|
||||
m_waiting_metadata_request = false;
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
(*m_pc.m_logger) << time_now_string()
|
||||
<< " <== DONT HAVE METADATA\n";
|
||||
m_pc.peer_log("<== DONT HAVE METADATA\n");
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
|
@@ -6527,24 +6527,35 @@ namespace libtorrent
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!m_connections_initialized)
|
||||
m_connections_initialized = true;
|
||||
m_files_checked = true;
|
||||
|
||||
for (torrent::peer_iterator i = m_connections.begin();
|
||||
i != m_connections.end();)
|
||||
{
|
||||
m_connections_initialized = true;
|
||||
peer_connection* pc = *i;
|
||||
++i;
|
||||
|
||||
// all peer connections have to initialize themselves now that the metadata
|
||||
// is available
|
||||
for (torrent::peer_iterator i = m_connections.begin();
|
||||
i != m_connections.end();)
|
||||
if (!m_connections_initialized)
|
||||
{
|
||||
peer_connection* pc = *i;
|
||||
++i;
|
||||
if (pc->is_disconnecting()) continue;
|
||||
pc->on_metadata_impl();
|
||||
if (pc->is_disconnecting()) continue;
|
||||
pc->init();
|
||||
}
|
||||
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
pc->peer_log("*** ON_FILES_CHECKED");
|
||||
#endif
|
||||
if (pc->is_interesting() && !pc->has_peer_choked())
|
||||
{
|
||||
request_a_block(*this, *pc);
|
||||
pc->send_block_requests();
|
||||
}
|
||||
}
|
||||
|
||||
m_files_checked = true;
|
||||
|
||||
start_announcing();
|
||||
|
||||
|
@@ -238,7 +238,10 @@ namespace libtorrent { namespace
|
||||
TORRENT_ASSERT(!m_pc.associated_torrent().expired());
|
||||
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
m_pc.peer_log("==> UT_METADATA [ type: %d | piece: %d ]", type, piece);
|
||||
char const* names[] = {"request", "data", "dont-have"};
|
||||
char const* n = "";
|
||||
if (type >= 0 && type < 3) n = names[type];
|
||||
m_pc.peer_log("==> UT_METADATA [ type: %d (%s) | piece: %d ]", type, n, piece);
|
||||
#endif
|
||||
|
||||
// abort if the peer doesn't support the metadata extension
|
||||
|
Reference in New Issue
Block a user