converted a whole lot of error strings into error_codes. Documented some previously undocumented alerts as well as all the error codes
This commit is contained in:
@@ -390,7 +390,7 @@ namespace libtorrent
|
||||
m_dh_key_exchange.reset(new (std::nothrow) dh_key_exchange);
|
||||
if (!m_dh_key_exchange || !m_dh_key_exchange->good())
|
||||
{
|
||||
disconnect("out of memory");
|
||||
disconnect(error_code(errors::no_memory, libtorrent_category));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -403,7 +403,7 @@ namespace libtorrent
|
||||
buffer::interval send_buf = allocate_send_buffer(dh_key_len + pad_size);
|
||||
if (send_buf.begin == 0)
|
||||
{
|
||||
disconnect("out of memory");
|
||||
disconnect(error_code(errors::no_memory, libtorrent_category));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -621,7 +621,7 @@ namespace libtorrent
|
||||
m_RC4_handler.reset(new (std::nothrow) RC4_handler(local_key, remote_key));
|
||||
if (!m_RC4_handler)
|
||||
{
|
||||
disconnect("no memory");
|
||||
disconnect(error_code(errors::no_memory, libtorrent_category));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -884,7 +884,7 @@ namespace libtorrent
|
||||
m_statistics.received_bytes(0, received);
|
||||
if (packet_size() != 1)
|
||||
{
|
||||
disconnect("'choke' message size != 1", 2);
|
||||
disconnect(error_code(errors::invalid_choke, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
if (!packet_finished()) return;
|
||||
@@ -919,7 +919,7 @@ namespace libtorrent
|
||||
m_statistics.received_bytes(0, received);
|
||||
if (packet_size() != 1)
|
||||
{
|
||||
disconnect("'unchoke' message size != 1", 2);
|
||||
disconnect(error_code(errors::invalid_unchoke, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
if (!packet_finished()) return;
|
||||
@@ -939,7 +939,7 @@ namespace libtorrent
|
||||
m_statistics.received_bytes(0, received);
|
||||
if (packet_size() != 1)
|
||||
{
|
||||
disconnect("'interested' message size != 1", 2);
|
||||
disconnect(error_code(errors::invalid_interested, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
if (!packet_finished()) return;
|
||||
@@ -959,7 +959,7 @@ namespace libtorrent
|
||||
m_statistics.received_bytes(0, received);
|
||||
if (packet_size() != 1)
|
||||
{
|
||||
disconnect("'not interested' message size != 1", 2);
|
||||
disconnect(error_code(errors::invalid_not_interested, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
if (!packet_finished()) return;
|
||||
@@ -979,7 +979,7 @@ namespace libtorrent
|
||||
m_statistics.received_bytes(0, received);
|
||||
if (packet_size() != 5)
|
||||
{
|
||||
disconnect("'have' message size != 5", 2);
|
||||
disconnect(error_code(errors::invalid_have, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
if (!packet_finished()) return;
|
||||
@@ -1011,10 +1011,7 @@ namespace libtorrent
|
||||
if (t->valid_metadata()
|
||||
&& packet_size() - 1 != (t->torrent_file().num_pieces() + 7) / 8)
|
||||
{
|
||||
char msg[200];
|
||||
snprintf(msg, 200, "got bitfield with invalid size: %d bytes. expected: %d bytes"
|
||||
, int(packet_size()-1), int((t->torrent_file().num_pieces() + 7) / 8));
|
||||
disconnect(msg, 2);
|
||||
disconnect(error_code(errors::invalid_bitfield_size, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1041,7 +1038,7 @@ namespace libtorrent
|
||||
m_statistics.received_bytes(0, received);
|
||||
if (packet_size() != 13)
|
||||
{
|
||||
disconnect("'request' message size != 13", 2);
|
||||
disconnect(error_code(errors::invalid_request, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
if (!packet_finished()) return;
|
||||
@@ -1096,7 +1093,7 @@ namespace libtorrent
|
||||
|
||||
if (list_size > packet_size() - 13)
|
||||
{
|
||||
disconnect("invalid hash list in hash piece message");
|
||||
disconnect(error_code(errors::invalid_hash_list, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1194,7 +1191,7 @@ namespace libtorrent
|
||||
lazy_entry hash_list;
|
||||
if (lazy_bdecode(recv_buffer.begin + 13, recv_buffer.end + 13 + list_size, hash_list) != 0)
|
||||
{
|
||||
disconnect("invalid bencoding in hashpiece message");
|
||||
disconnect(error_code(errors::invalid_hash_piece, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1202,7 +1199,7 @@ namespace libtorrent
|
||||
// [ [node-index, hash], [node-index, hash], ... ]
|
||||
if (hash_list.type() != lazy_entry::list_t)
|
||||
{
|
||||
disconnect("invalid hash-list in hashpiece message");
|
||||
disconnect(error_code(errors::invalid_hash_list, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1228,7 +1225,7 @@ namespace libtorrent
|
||||
#endif
|
||||
if (!nodes.empty() && !t->add_merkle_nodes(nodes, p.piece))
|
||||
{
|
||||
disconnect("invalid hashes in hashpiece message");
|
||||
disconnect(error_code(errors::invalid_hash_piece, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1249,7 +1246,7 @@ namespace libtorrent
|
||||
m_statistics.received_bytes(0, received);
|
||||
if (packet_size() != 13)
|
||||
{
|
||||
disconnect("'cancel' message size != 13", 2);
|
||||
disconnect(error_code(errors::invalid_cancel, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
if (!packet_finished()) return;
|
||||
@@ -1277,12 +1274,12 @@ namespace libtorrent
|
||||
m_statistics.received_bytes(0, received);
|
||||
if (!m_supports_dht_port)
|
||||
{
|
||||
disconnect("got 'dht_port' message from peer that doesn't support it", 2);
|
||||
disconnect(error_code(errors::invalid_dht_port, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
if (packet_size() != 3)
|
||||
{
|
||||
disconnect("'dht_port' message size != 3", 2);
|
||||
disconnect(error_code(errors::invalid_dht_port, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
if (!packet_finished()) return;
|
||||
@@ -1302,7 +1299,7 @@ namespace libtorrent
|
||||
m_statistics.received_bytes(0, received);
|
||||
if (!m_supports_fast)
|
||||
{
|
||||
disconnect("got 'suggest_piece' without FAST excension support", 2);
|
||||
disconnect(error_code(errors::invalid_suggest, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1322,7 +1319,7 @@ namespace libtorrent
|
||||
m_statistics.received_bytes(0, received);
|
||||
if (!m_supports_fast)
|
||||
{
|
||||
disconnect("got 'have_all' without FAST extension support", 2);
|
||||
disconnect(error_code(errors::invalid_have_all, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
incoming_have_all();
|
||||
@@ -1335,7 +1332,7 @@ namespace libtorrent
|
||||
m_statistics.received_bytes(0, received);
|
||||
if (!m_supports_fast)
|
||||
{
|
||||
disconnect("got 'have_none' without FAST extension support", 2);
|
||||
disconnect(error_code(errors::invalid_have_none, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
incoming_have_none();
|
||||
@@ -1348,7 +1345,7 @@ namespace libtorrent
|
||||
m_statistics.received_bytes(0, received);
|
||||
if (!m_supports_fast)
|
||||
{
|
||||
disconnect("got 'reject_request' without FAST extension support", 2);
|
||||
disconnect(error_code(errors::invalid_reject, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1372,7 +1369,7 @@ namespace libtorrent
|
||||
m_statistics.received_bytes(0, received);
|
||||
if (!m_supports_fast)
|
||||
{
|
||||
disconnect("got 'allowed_fast' without FAST extension support", 2);
|
||||
disconnect(error_code(errors::invalid_allow_fast, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1396,13 +1393,13 @@ namespace libtorrent
|
||||
m_statistics.received_bytes(0, received);
|
||||
if (packet_size() < 2)
|
||||
{
|
||||
disconnect("'extended' message smaller than 2 bytes", 2);
|
||||
disconnect(error_code(errors::invalid_extended, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
if (associated_torrent().expired())
|
||||
{
|
||||
disconnect("'extended' message sent before proper handshake", 2);
|
||||
disconnect(error_code(errors::invalid_extended, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1430,9 +1427,7 @@ namespace libtorrent
|
||||
}
|
||||
#endif
|
||||
|
||||
char msg[200];
|
||||
snprintf(msg, 200, "unknown extended message id: %d", extended_id);
|
||||
disconnect(msg, 2);
|
||||
disconnect(error_code(errors::invalid_message, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1518,7 +1513,7 @@ 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");
|
||||
disconnect(error_code(errors::upload_upload_connection, libtorrent_category));
|
||||
}
|
||||
|
||||
bool bt_peer_connection::dispatch_message(int received)
|
||||
@@ -1555,9 +1550,7 @@ namespace libtorrent
|
||||
#endif
|
||||
|
||||
m_statistics.received_bytes(0, received);
|
||||
char msg[200];
|
||||
snprintf(msg, 200, "unknown message message id: %d size: %d", packet_type, packet_size());
|
||||
disconnect(msg, 2);
|
||||
disconnect(error_code(errors::invalid_message, libtorrent_category));
|
||||
return packet_finished();
|
||||
}
|
||||
|
||||
@@ -2046,7 +2039,7 @@ namespace libtorrent
|
||||
// read dh key, generate shared secret
|
||||
if (m_dh_key_exchange->compute_secret(recv_buffer.begin) == -1)
|
||||
{
|
||||
disconnect("out of memory");
|
||||
disconnect(error_code(errors::no_memory, libtorrent_category));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2103,7 +2096,7 @@ namespace libtorrent
|
||||
m_statistics.received_bytes(0, bytes_transferred);
|
||||
|
||||
if (packet_finished())
|
||||
disconnect("sync hash not found", 2);
|
||||
disconnect(error_code(errors::sync_hash_not_found, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2120,7 +2113,7 @@ namespace libtorrent
|
||||
if (!m_sync_hash)
|
||||
{
|
||||
m_statistics.received_bytes(0, bytes_transferred);
|
||||
disconnect("no memory");
|
||||
disconnect(error_code(errors::no_memory, libtorrent_category));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -2137,7 +2130,7 @@ namespace libtorrent
|
||||
m_sync_bytes_read += bytes_processed;
|
||||
if (m_sync_bytes_read >= 512)
|
||||
{
|
||||
disconnect("sync hash not found within 532 bytes", 2);
|
||||
disconnect(error_code(errors::sync_hash_not_found, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2211,7 +2204,7 @@ namespace libtorrent
|
||||
|
||||
if (!m_RC4_handler.get())
|
||||
{
|
||||
disconnect("invalid streamkey identifier (info hash) in encrypted handshake", 2);
|
||||
disconnect(error_code(errors::invalid_info_hash, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2223,7 +2216,7 @@ namespace libtorrent
|
||||
const char sh_vc[] = {0,0,0,0, 0,0,0,0};
|
||||
if (!std::equal(sh_vc, sh_vc+8, recv_buffer.begin + 20))
|
||||
{
|
||||
disconnect("unable to verify constant", 2);
|
||||
disconnect(error_code(errors::invalid_encryption_constant, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2246,7 +2239,7 @@ namespace libtorrent
|
||||
{
|
||||
m_statistics.received_bytes(0, bytes_transferred);
|
||||
if (packet_finished())
|
||||
disconnect("sync verification constant not found", 2);
|
||||
disconnect(error_code(errors::invalid_encryption_constant, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2258,7 +2251,7 @@ namespace libtorrent
|
||||
m_sync_vc.reset(new (std::nothrow) char[8]);
|
||||
if (!m_sync_vc)
|
||||
{
|
||||
disconnect("no memory");
|
||||
disconnect(error_code(errors::no_memory, libtorrent_category));
|
||||
return;
|
||||
}
|
||||
std::fill(m_sync_vc.get(), m_sync_vc.get() + 8, 0);
|
||||
@@ -2278,7 +2271,7 @@ namespace libtorrent
|
||||
|
||||
if (m_sync_bytes_read >= 512)
|
||||
{
|
||||
disconnect("sync verification constant not found within 520 bytes", 2);
|
||||
disconnect(error_code(errors::invalid_encryption_constant, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2348,7 +2341,7 @@ namespace libtorrent
|
||||
case pe_settings::plaintext:
|
||||
if (!(crypto_field & 0x01))
|
||||
{
|
||||
disconnect("plaintext not provided", 1);
|
||||
disconnect(error_code(errors::no_plaintext_mode, libtorrent_category), 1);
|
||||
return;
|
||||
}
|
||||
crypto_select = 0x01;
|
||||
@@ -2356,7 +2349,7 @@ namespace libtorrent
|
||||
case pe_settings::rc4:
|
||||
if (!(crypto_field & 0x02))
|
||||
{
|
||||
disconnect("rc4 not provided", 1);
|
||||
disconnect(error_code(errors::no_rc4_mode, libtorrent_category), 1);
|
||||
return;
|
||||
}
|
||||
crypto_select = 0x02;
|
||||
@@ -2378,7 +2371,7 @@ namespace libtorrent
|
||||
}
|
||||
if (!crypto_select)
|
||||
{
|
||||
disconnect("rc4/plaintext not provided", 1);
|
||||
disconnect(error_code(errors::unsupported_encryption_mode, libtorrent_category), 1);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@@ -2396,7 +2389,8 @@ namespace libtorrent
|
||||
{
|
||||
if (allowed_enc_level == pe_settings::plaintext)
|
||||
{
|
||||
disconnect("rc4 selected by peer when not provided", 2);
|
||||
disconnect(error_code(errors::unsupported_encryption_mode_selected
|
||||
, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
m_rc4_encrypted = true;
|
||||
@@ -2405,14 +2399,16 @@ namespace libtorrent
|
||||
{
|
||||
if (allowed_enc_level == pe_settings::rc4)
|
||||
{
|
||||
disconnect("plaintext selected by peer when not provided", 2);
|
||||
disconnect(error_code(errors::unsupported_encryption_mode_selected
|
||||
, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
m_rc4_encrypted = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
disconnect("unsupported crypto method selected by peer", 2);
|
||||
disconnect(error_code(errors::unsupported_encryption_mode_selected
|
||||
, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -2420,7 +2416,7 @@ namespace libtorrent
|
||||
int len_pad = detail::read_int16(recv_buffer.begin);
|
||||
if (len_pad < 0 || len_pad > 512)
|
||||
{
|
||||
disconnect("invalid pad length", 2);
|
||||
disconnect(error_code(errors::invalid_pad_size, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2460,7 +2456,7 @@ namespace libtorrent
|
||||
|
||||
if (len_ia < 0)
|
||||
{
|
||||
disconnect("invalid len_ia in handshake", 2);
|
||||
disconnect(error_code(errors::invalid_encrypt_handshake, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2579,7 +2575,7 @@ namespace libtorrent
|
||||
#ifndef TORRENT_DISABLE_ENCRYPTION
|
||||
if (!is_local() && m_ses.get_pe_settings().in_enc_policy == pe_settings::disabled)
|
||||
{
|
||||
disconnect("encrypted incoming connections disabled");
|
||||
disconnect(error_code(errors::no_incoming_encrypted, libtorrent_category));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2598,7 +2594,7 @@ namespace libtorrent
|
||||
|
||||
TORRENT_ASSERT((!is_local() && m_encrypted) || is_local());
|
||||
#endif // #ifndef TORRENT_DISABLE_ENCRYPTION
|
||||
disconnect("incorrect protocol identifier", 2);
|
||||
disconnect(error_code(errors::invalid_info_hash, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2609,7 +2605,7 @@ namespace libtorrent
|
||||
(m_ses.get_pe_settings().in_enc_policy == pe_settings::forced) &&
|
||||
!m_encrypted)
|
||||
{
|
||||
disconnect("non encrypted incoming connections disabled");
|
||||
disconnect(error_code(errors::no_incoming_regular, libtorrent_category));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -2684,7 +2680,7 @@ namespace libtorrent
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
(*m_logger) << " received invalid info_hash\n";
|
||||
#endif
|
||||
disconnect("invalid info-hash in handshake", 2);
|
||||
disconnect(error_code(errors::invalid_info_hash, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2763,11 +2759,12 @@ namespace libtorrent
|
||||
// if not, we should close the outgoing one.
|
||||
if (pid < m_ses.get_peer_id() && is_local())
|
||||
{
|
||||
(*i)->connection->disconnect("duplicate peer-id, connection closed");
|
||||
(*i)->connection->disconnect(error_code(errors::duplicate_peer_id
|
||||
, libtorrent_category));
|
||||
}
|
||||
else
|
||||
{
|
||||
disconnect("duplicate peer-id, connection closed");
|
||||
disconnect(error_code(errors::duplicate_peer_id, libtorrent_category));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -2778,7 +2775,7 @@ namespace libtorrent
|
||||
if (pid == m_ses.get_peer_id())
|
||||
{
|
||||
if (peer_info_struct()) peer_info_struct()->banned = true;
|
||||
disconnect("closing connection to ourself", 1);
|
||||
disconnect(error_code(errors::self_connection, libtorrent_category), 1);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2869,9 +2866,7 @@ namespace libtorrent
|
||||
{
|
||||
m_statistics.received_bytes(0, bytes_transferred);
|
||||
// packet too large
|
||||
char msg[200];
|
||||
printf("packet > 1 MB (%u bytes)", (unsigned int)packet_size);
|
||||
disconnect(msg, 2);
|
||||
disconnect(error_code(errors::packet_too_large, libtorrent_category), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2903,7 +2898,7 @@ namespace libtorrent
|
||||
if (!t)
|
||||
{
|
||||
m_statistics.received_bytes(0, bytes_transferred);
|
||||
disconnect("torrent removed", 1);
|
||||
disconnect(error_code(errors::torrent_removed, libtorrent_category), 1);
|
||||
return;
|
||||
}
|
||||
#ifdef TORRENT_DEBUG
|
||||
|
Reference in New Issue
Block a user