added invariant checks
This commit is contained in:
parent
2030420f9a
commit
7996d35395
|
@ -277,6 +277,8 @@ namespace libtorrent
|
|||
|
||||
void bt_peer_connection::write_pe1_2_dhkey()
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
assert(!m_encrypted);
|
||||
assert(!m_rc4_encrypted);
|
||||
assert(!m_DH_key_exchange.get());
|
||||
|
@ -305,6 +307,8 @@ namespace libtorrent
|
|||
|
||||
void bt_peer_connection::write_pe3_sync()
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
assert (!m_encrypted);
|
||||
assert (!m_rc4_encrypted);
|
||||
assert (is_local());
|
||||
|
@ -383,6 +387,8 @@ namespace libtorrent
|
|||
|
||||
void bt_peer_connection::write_pe4_sync(int crypto_select)
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
assert(!is_local());
|
||||
assert(!m_encrypted);
|
||||
assert(!m_rc4_encrypted);
|
||||
|
@ -415,6 +421,8 @@ namespace libtorrent
|
|||
void bt_peer_connection::write_pe_vc_cryptofield(buffer::interval& write_buf,
|
||||
int crypto_field, int pad_size)
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
assert(crypto_field <= 0x03 && crypto_field > 0);
|
||||
assert(pad_size == 0); // pad not used yet
|
||||
// vc,crypto_field,len(pad),pad, (len(ia))
|
||||
|
@ -444,6 +452,8 @@ namespace libtorrent
|
|||
|
||||
void bt_peer_connection::init_pe_RC4_handler(char const* secret, sha1_hash const& stream_key)
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
assert(secret);
|
||||
|
||||
hasher h;
|
||||
|
@ -483,8 +493,9 @@ namespace libtorrent
|
|||
assert (begin);
|
||||
assert (end);
|
||||
assert (end > begin);
|
||||
assert (!m_rc4_encrypted || m_encrypted);
|
||||
|
||||
if (m_rc4_encrypted && m_encrypted)
|
||||
if (m_rc4_encrypted)
|
||||
m_RC4_handler->encrypt(begin, end - begin);
|
||||
|
||||
peer_connection::send_buffer(begin, end);
|
||||
|
@ -492,7 +503,9 @@ namespace libtorrent
|
|||
|
||||
buffer::interval bt_peer_connection::allocate_send_buffer(int size)
|
||||
{
|
||||
if (m_rc4_encrypted && m_encrypted)
|
||||
assert(!m_rc4_encrypted || m_encrypted);
|
||||
|
||||
if (m_rc4_encrypted)
|
||||
{
|
||||
m_enc_send_buffer = peer_connection::allocate_send_buffer(size);
|
||||
return m_enc_send_buffer;
|
||||
|
@ -506,7 +519,9 @@ namespace libtorrent
|
|||
|
||||
void bt_peer_connection::setup_send()
|
||||
{
|
||||
if (m_rc4_encrypted && m_encrypted)
|
||||
assert(!m_rc4_encrypted || m_encrypted);
|
||||
|
||||
if (m_rc4_encrypted)
|
||||
{
|
||||
assert (m_enc_send_buffer.begin);
|
||||
assert (m_enc_send_buffer.end);
|
||||
|
@ -1383,7 +1398,8 @@ namespace libtorrent
|
|||
m_statistics.received_bytes(0, bytes_transferred);
|
||||
|
||||
#ifndef TORRENT_DISABLE_ENCRYPTION
|
||||
if (m_rc4_encrypted && m_encrypted)
|
||||
assert(in_handshake() || !m_rc4_encrypted || m_encrypted);
|
||||
if (m_rc4_encrypted)
|
||||
{
|
||||
buffer::interval wr_buf = wr_recv_buffer();
|
||||
m_RC4_handler->decrypt((wr_buf.end - bytes_transferred), bytes_transferred);
|
||||
|
@ -1973,8 +1989,6 @@ namespace libtorrent
|
|||
, (char*)info_hash.begin());
|
||||
|
||||
attach_to_torrent(info_hash);
|
||||
t = associated_torrent().lock();
|
||||
assert(t);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1991,11 +2005,11 @@ namespace libtorrent
|
|||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
(*m_logger) << " info_hash received\n";
|
||||
#endif
|
||||
t = associated_torrent().lock();
|
||||
assert(t);
|
||||
}
|
||||
|
||||
// Respond with handshake and bitfield
|
||||
t = associated_torrent().lock();
|
||||
assert(t);
|
||||
|
||||
if (!is_local())
|
||||
{
|
||||
write_handshake();
|
||||
|
@ -2240,8 +2254,10 @@ namespace libtorrent
|
|||
void bt_peer_connection::check_invariant() const
|
||||
{
|
||||
#ifndef TORRENT_DISABLE_ENCRYPTION
|
||||
assert(bool(m_state == read_pe_dhkey) == bool(m_DH_key_exchange)
|
||||
|| !is_local());
|
||||
assert( (bool(m_state != read_pe_dhkey) || m_DH_key_exchange.get())
|
||||
|| !is_local());
|
||||
|
||||
assert(!m_rc4_encrypted || m_RC4_handler.get());
|
||||
#endif
|
||||
if (!m_in_constructor)
|
||||
peer_connection::check_invariant();
|
||||
|
|
Loading…
Reference in New Issue