rename is_local to is_outgoing and m_active to m_outgoing

This commit is contained in:
Arvid Norberg 2012-02-07 03:46:21 +00:00
parent c82695ef8e
commit a6b5f761e8
6 changed files with 46 additions and 46 deletions

View File

@ -399,7 +399,7 @@ namespace libtorrent
// a connection is local if it was initiated by us.
// if it was an incoming connection, it is remote
bool is_local() const { return m_active; }
bool is_outgoing() const { return m_outgoing; }
bool received_listen_port() const { return m_received_listen_port; }
void received_listen_port()
@ -1054,7 +1054,7 @@ namespace libtorrent
// is true if it was we that connected to the peer
// and false if we got an incoming connection
// could be considered: true = local, false = remote
bool m_active:1;
bool m_outgoing:1;
// is true if we learn the incoming connections listening
// during the extended handshake

View File

@ -413,7 +413,7 @@ namespace libtorrent
if (is_peer_interested()) p.flags |= peer_info::remote_interested;
if (has_peer_choked()) p.flags |= peer_info::remote_choked;
if (support_extensions()) p.flags |= peer_info::supports_extensions;
if (is_local()) p.flags |= peer_info::local_connection;
if (is_outgoing()) p.flags |= peer_info::local_connection;
#ifndef TORRENT_DISABLE_ENCRYPTION
if (m_encrypted)
@ -452,7 +452,7 @@ namespace libtorrent
TORRENT_ASSERT(!m_sent_handshake);
#ifdef TORRENT_VERBOSE_LOGGING
if (is_local())
if (is_outgoing())
peer_log("*** initiating encrypted handshake");
#endif
@ -490,7 +490,7 @@ namespace libtorrent
TORRENT_ASSERT(!m_encrypted);
TORRENT_ASSERT(!m_rc4_encrypted);
TORRENT_ASSERT(is_local());
TORRENT_ASSERT(is_outgoing());
TORRENT_ASSERT(!m_sent_handshake);
boost::shared_ptr<torrent> t = associated_torrent().lock();
@ -562,7 +562,7 @@ namespace libtorrent
{
INVARIANT_CHECK;
TORRENT_ASSERT(!is_local());
TORRENT_ASSERT(!is_outgoing());
TORRENT_ASSERT(!m_encrypted);
TORRENT_ASSERT(!m_rc4_encrypted);
TORRENT_ASSERT(crypto_select == 0x02 || crypto_select == 0x01);
@ -596,8 +596,8 @@ namespace libtorrent
TORRENT_ASSERT(crypto_field <= 0x03 && crypto_field > 0);
// vc,crypto_field,len(pad),pad, (len(ia))
TORRENT_ASSERT((len >= 8+4+2+pad_size+2 && is_local())
|| (len >= 8+4+2+pad_size && !is_local()));
TORRENT_ASSERT((len >= 8+4+2+pad_size+2 && is_outgoing())
|| (len >= 8+4+2+pad_size && !is_outgoing()));
TORRENT_ASSERT(!m_sent_handshake);
// encrypt(vc, crypto_provide/select, len(Pad), len(IA))
@ -615,7 +615,7 @@ namespace libtorrent
write_buf += pad_size;
// append len(ia) if we are initiating
if (is_local())
if (is_outgoing())
detail::write_uint16(handshake_len, write_buf); // len(IA)
}
@ -633,7 +633,7 @@ namespace libtorrent
// outgoing connection : hash ('keyA',S,SKEY)
// incoming connection : hash ('keyB',S,SKEY)
if (is_local()) h.update(keyA, 4); else h.update(keyB, 4);
if (is_outgoing()) h.update(keyA, 4); else h.update(keyB, 4);
h.update(secret, dh_key_len);
h.update((char const*)stream_key.begin(), 20);
const sha1_hash local_key = h.final();
@ -644,7 +644,7 @@ namespace libtorrent
// outgoing connection : hash ('keyB',S,SKEY)
// incoming connection : hash ('keyA',S,SKEY)
if (is_local()) h.update(keyB, 4); else h.update(keyA, 4);
if (is_outgoing()) h.update(keyB, 4); else h.update(keyA, 4);
h.update(secret, dh_key_len);
h.update((char const*)stream_key.begin(), 20);
const sha1_hash remote_key = h.final();
@ -2138,7 +2138,7 @@ namespace libtorrent
// our listen port
if (!m_ses.m_settings.anonymous_mode)
{
if (is_local()) handshake["p"] = m_ses.listen_port();
if (is_outgoing()) handshake["p"] = m_ses.listen_port();
handshake["v"] = m_ses.settings().user_agent;
}
@ -2425,7 +2425,7 @@ namespace libtorrent
// write our dh public key. m_dh_key_exchange is
// initialized in write_pe1_2_dhkey()
if (!is_local()) write_pe1_2_dhkey();
if (!is_outgoing()) write_pe1_2_dhkey();
if (is_disconnecting()) return;
// read dh key, generate shared secret
@ -2446,7 +2446,7 @@ namespace libtorrent
// possible to ensure we do not overshoot the standard
// handshake.
if (is_local())
if (is_outgoing())
{
m_state = read_pe_syncvc;
write_pe3_sync();
@ -2480,7 +2480,7 @@ namespace libtorrent
{
TORRENT_ASSERT(!m_encrypted);
TORRENT_ASSERT(!m_rc4_encrypted);
TORRENT_ASSERT(!is_local());
TORRENT_ASSERT(!is_outgoing());
TORRENT_ASSERT(recv_buffer == receive_buffer());
if (recv_buffer.left() < 20)
@ -2558,7 +2558,7 @@ namespace libtorrent
TORRENT_ASSERT(!m_encrypted);
TORRENT_ASSERT(!m_rc4_encrypted);
TORRENT_ASSERT(!is_local());
TORRENT_ASSERT(!is_outgoing());
TORRENT_ASSERT(packet_size() == 28);
if (!packet_finished()) return;
@ -2629,7 +2629,7 @@ namespace libtorrent
// cannot fall through into
if (m_state == read_pe_syncvc)
{
TORRENT_ASSERT(is_local());
TORRENT_ASSERT(is_outgoing());
TORRENT_ASSERT(!m_encrypted);
TORRENT_ASSERT(!m_rc4_encrypted);
TORRENT_ASSERT(recv_buffer == receive_buffer());
@ -2720,12 +2720,12 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING
peer_log("*** crypto %s : [%s%s ]"
, is_local() ? "select" : "provide"
, is_outgoing() ? "select" : "provide"
, (crypto_field & 1) ? " plaintext" : ""
, (crypto_field & 2) ? " rc4" : "");
#endif
if (!is_local())
if (!is_outgoing())
{
// select a crypto method
int allowed_encryption = m_ses.get_pe_settings().allowed_enc_level;
@ -2761,7 +2761,7 @@ namespace libtorrent
// write the pe4 step
write_pe4_sync(crypto_select);
}
else // is_local()
else // is_outgoing()
{
// check if crypto select is valid
int allowed_encryption = m_ses.get_pe_settings().allowed_enc_level;
@ -2788,7 +2788,7 @@ namespace libtorrent
}
m_state = read_pe_pad;
if (!is_local())
if (!is_outgoing())
reset_recv_buffer(len_pad + 2); // len(IA) at the end of pad
else
{
@ -2809,14 +2809,14 @@ namespace libtorrent
bytes_transferred = 0;
if (!packet_finished()) return;
int pad_size = is_local() ? packet_size() : packet_size() - 2;
int pad_size = is_outgoing() ? packet_size() : packet_size() - 2;
buffer::interval wr_buf = wr_recv_buffer();
m_enc_handler->decrypt(wr_buf.begin, packet_size());
recv_buffer = receive_buffer();
if (!is_local())
if (!is_outgoing())
{
recv_buffer.begin += pad_size;
int len_ia = detail::read_int16(recv_buffer.begin);
@ -2842,7 +2842,7 @@ namespace libtorrent
reset_recv_buffer(len_ia);
}
}
else // is_local()
else // is_outgoing()
{
// everything that arrives after this is Encrypt2
m_encrypted = true;
@ -2854,7 +2854,7 @@ namespace libtorrent
{
m_statistics.received_bytes(0, bytes_transferred);
bytes_transferred = 0;
TORRENT_ASSERT(!is_local());
TORRENT_ASSERT(!is_outgoing());
TORRENT_ASSERT(!m_encrypted);
if (!packet_finished()) return;
@ -2912,7 +2912,7 @@ namespace libtorrent
// encrypted portion of handshake completed, toggle
// peer_info pe_support flag back to true
if (is_local() &&
if (is_outgoing() &&
m_ses.get_pe_settings().out_enc_policy == pe_settings::enabled)
{
policy::peer* pi = peer_info_struct();
@ -2957,7 +2957,7 @@ namespace libtorrent
bool found_encrypted_torrent = false;
#ifdef TORRENT_USE_OPENSSL
if (!is_local())
if (!is_outgoing())
{
std::auto_ptr<encryption_handler> handler(new aes256_handler);
boost::uint8_t temp_pad[20];
@ -2991,7 +2991,7 @@ namespace libtorrent
if (!found_encrypted_torrent)
{
if (!is_local()
if (!is_outgoing()
&& m_ses.get_pe_settings().in_enc_policy == pe_settings::disabled)
{
disconnect(errors::no_incoming_encrypted);
@ -3002,7 +3002,7 @@ namespace libtorrent
// within an encrypted connection. For local connections,
// we're expected to already have passed the encrypted
// handshake by this point
if (m_encrypted || is_local())
if (m_encrypted || is_outgoing())
{
disconnect(errors::invalid_info_hash, 1);
return;
@ -3017,7 +3017,7 @@ namespace libtorrent
return;
}
TORRENT_ASSERT((!is_local() && m_encrypted) || is_local());
TORRENT_ASSERT((!is_outgoing() && m_encrypted) || is_outgoing());
#else
disconnect(errors::invalid_info_hash, 1);
return;
@ -3028,7 +3028,7 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_ENCRYPTION
TORRENT_ASSERT(m_state != read_pe_dhkey);
if (!is_local()
if (!is_outgoing()
&& m_ses.get_pe_settings().in_enc_policy == pe_settings::forced
&& !m_encrypted
&& !is_ssl(*get_socket()))
@ -3129,7 +3129,7 @@ namespace libtorrent
// if this is a local connection, we have already
// sent the handshake
if (!is_local()) write_handshake();
if (!is_outgoing()) write_handshake();
// if (t->valid_metadata())
// write_bitfield();
TORRENT_ASSERT(m_sent_handshake);
@ -3194,7 +3194,7 @@ namespace libtorrent
// initiate connections. So, if our peer-id is greater than
// the others, we should close the incoming connection,
// if not, we should close the outgoing one.
if (pid < m_ses.get_peer_id() && is_local())
if (pid < m_ses.get_peer_id() && is_outgoing())
{
(*i)->connection->disconnect(errors::duplicate_peer_id);
}
@ -3250,7 +3250,7 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_ENCRYPTION
// Toggle pe_support back to false if this is a
// standard successful connection
if (is_local() && !m_encrypted &&
if (is_outgoing() && !m_encrypted &&
m_ses.get_pe_settings().out_enc_policy == pe_settings::enabled)
{
policy::peer* pi = peer_info_struct();
@ -3423,7 +3423,7 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_ENCRYPTION
TORRENT_ASSERT( (bool(m_state != read_pe_dhkey) || m_dh_key_exchange.get())
|| !is_local());
|| !is_outgoing());
TORRENT_ASSERT(!m_rc4_encrypted || m_enc_handler.get());
#endif

View File

@ -169,7 +169,7 @@ namespace libtorrent
, m_desired_queue_size(2)
, m_choke_rejects(0)
, m_fast_reconnect(false)
, m_active(outgoing)
, m_outgoing(outgoing)
, m_received_listen_port(false)
, m_peer_interested(false)
, m_peer_choked(true)
@ -241,7 +241,7 @@ namespace libtorrent
m_logger = m_ses.create_log(m_remote.address().to_string(ec) + "_"
+ to_string(m_remote.port()).elems, m_ses.listen_port());
peer_log("%s [ ep: %s type: %s seed: %d p: %p local: %s]"
, m_active ? ">>> OUTGOING_CONNECTION" : "<<< INCOMING CONNECTION"
, m_outgoing ? ">>> OUTGOING_CONNECTION" : "<<< INCOMING CONNECTION"
, print_endpoint(m_remote).c_str()
, m_socket->type_name()
, m_peer_info ? m_peer_info->seed : 0, m_peer_info
@ -320,7 +320,7 @@ namespace libtorrent
, m_desired_queue_size(2)
, m_choke_rejects(0)
, m_fast_reconnect(false)
, m_active(false)
, m_outgoing(false)
, m_received_listen_port(false)
, m_peer_interested(false)
, m_peer_choked(true)
@ -388,7 +388,7 @@ namespace libtorrent
m_logger = m_ses.create_log(remote().address().to_string(ec) + "_"
+ to_string(remote().port()).elems, m_ses.listen_port());
peer_log("%s [ ep: %s type: %s local: %s]"
, m_active ? ">>> OUTGOING_CONNECTION" : "<<< INCOMING CONNECTION"
, m_outgoing ? ">>> OUTGOING_CONNECTION" : "<<< INCOMING CONNECTION"
, print_endpoint(m_remote).c_str()
, m_socket->type_name()
, print_endpoint(m_socket->local_endpoint(ec)).c_str());
@ -578,7 +578,7 @@ namespace libtorrent
TORRENT_ASSERT(m_peer_info == 0 || m_peer_info->connection == this);
boost::shared_ptr<torrent> t = m_torrent.lock();
if (!m_active)
if (!m_outgoing)
{
tcp::socket::non_blocking_io ioc(true);
error_code ec;

View File

@ -730,7 +730,7 @@ namespace libtorrent
bool policy::new_connection(peer_connection& c, int session_time)
{
TORRENT_ASSERT(!c.is_local());
TORRENT_ASSERT(!c.is_outgoing());
INVARIANT_CHECK;
@ -848,7 +848,7 @@ namespace libtorrent
i->connection->disconnect(ec2);
TORRENT_ASSERT(i->connection == 0);
}
else if (!i->connection->is_connecting() || c.is_local())
else if (!i->connection->is_connecting() || c.is_outgoing())
{
c.disconnect(errors::duplicate_peer_id);
return false;

View File

@ -5644,7 +5644,7 @@ namespace libtorrent
#endif // TORRENT_USE_OPENSSL
TORRENT_ASSERT(p != 0);
TORRENT_ASSERT(!p->is_local());
TORRENT_ASSERT(!p->is_outgoing());
m_has_incoming = true;

View File

@ -75,7 +75,7 @@ namespace libtorrent { namespace
// don't send out those peers that we haven't connected to
// (that have connected to us) and that aren't sharing their
// listening port
if (!p.is_local() && !p.received_listen_port()) return false;
if (!p.is_outgoing() && !p.received_listen_port()) return false;
// don't send out peers that we haven't successfully connected to
if (p.is_connecting()) return false;
return true;
@ -156,7 +156,7 @@ namespace libtorrent { namespace
// use that port. But only if we didn't connect to the peer.
// if we connected to it, use the port we know works
policy::peer *pi = 0;
if (!p->is_local() && (pi = peer->peer_info_struct()) && pi->port > 0)
if (!p->is_outgoing() && (pi = peer->peer_info_struct()) && pi->port > 0)
remote.port(pi->port);
// no supported flags to set yet
@ -527,7 +527,7 @@ namespace libtorrent { namespace
tcp::endpoint remote = peer->remote();
policy::peer *pi = 0;
if (!p->is_local() && (pi = peer->peer_info_struct()) && pi->port > 0)
if (!p->is_outgoing() && (pi = peer->peer_info_struct()) && pi->port > 0)
remote.port(pi->port);
// i->first was added since the last time