lt sync 3106

This commit is contained in:
Andrew Resch 2008-12-29 16:58:56 +00:00
parent 5e0d3bedef
commit 7bdabc207d
3 changed files with 30 additions and 19 deletions

View file

@ -81,13 +81,12 @@ namespace libtorrent
public:
// Input longkeys must be 20 bytes
RC4_handler(const sha1_hash& rc4_local_longkey,
const sha1_hash& rc4_remote_longkey)
const sha1_hash& rc4_remote_longkey)
{
RC4_set_key(&m_local_key, 20,
reinterpret_cast<unsigned char const*>(rc4_local_longkey.begin()));
reinterpret_cast<unsigned char const*>(rc4_local_longkey.begin()));
RC4_set_key(&m_remote_key, 20,
reinterpret_cast<unsigned char const*>(rc4_remote_longkey.begin()));
reinterpret_cast<unsigned char const*>(rc4_remote_longkey.begin()));
// Discard first 1024 bytes
char buf[1024];
@ -102,8 +101,8 @@ namespace libtorrent
TORRENT_ASSERT(len >= 0);
TORRENT_ASSERT(pos);
RC4 (&m_local_key, len, reinterpret_cast<unsigned char const*>(pos),
reinterpret_cast<unsigned char*>(pos));
RC4(&m_local_key, len, reinterpret_cast<unsigned char const*>(pos),
reinterpret_cast<unsigned char*>(pos));
}
void decrypt(char* pos, int len)
@ -111,15 +110,15 @@ namespace libtorrent
TORRENT_ASSERT(len >= 0);
TORRENT_ASSERT(pos);
RC4 (&m_remote_key, len, reinterpret_cast<unsigned char const*>(pos),
reinterpret_cast<unsigned char*>(pos));
RC4(&m_remote_key, len, reinterpret_cast<unsigned char const*>(pos),
reinterpret_cast<unsigned char*>(pos));
}
private:
RC4_KEY m_local_key; // Key to encrypt outgoing data
RC4_KEY m_remote_key; // Key to decrypt incoming data
};
} // namespace libtorrent
#endif // TORRENT_PE_CRYPTO_HPP_INCLUDED

View file

@ -51,6 +51,7 @@ namespace libtorrent
, udp::endpoint const&, char const* buf, int size)> callback_t;
udp_socket(io_service& ios, callback_t const& c, connection_queue& cc);
~udp_socket();
bool is_open() const { return m_ipv4_sock.is_open() || m_ipv6_sock.is_open(); }
io_service& get_io_service() { return m_ipv4_sock.get_io_service(); }
@ -64,16 +65,6 @@ namespace libtorrent
void set_proxy_settings(proxy_settings const& ps);
proxy_settings const& get_proxy_settings() { return m_proxy_settings; }
#ifdef TORRENT_DEBUG
~udp_socket()
{
TORRENT_ASSERT(m_magic == 0x1337);
TORRENT_ASSERT(m_outstanding == 0);
TORRENT_ASSERT(!m_callback);
m_magic = 0;
}
#endif
private:
callback_t m_callback;
@ -113,6 +104,7 @@ namespace libtorrent
tcp::resolver m_resolver;
char m_tmp_buf[100];
bool m_tunnel_packets;
bool m_abort;
udp::endpoint m_proxy_addr;
#ifdef TORRENT_DEBUG
int m_magic;

View file

@ -24,12 +24,23 @@ udp_socket::udp_socket(asio::io_service& ios, udp_socket::callback_t const& c
, m_cc(cc)
, m_resolver(ios)
, m_tunnel_packets(false)
, m_abort(false)
{
#ifdef TORRENT_DEBUG
m_magic = 0x1337;
#endif
}
udp_socket::~udp_socket()
{
#ifdef TORRENT_DEBUG
TORRENT_ASSERT(m_magic == 0x1337);
TORRENT_ASSERT(!m_callback);
TORRENT_ASSERT(m_outstanding == 0);
m_magic = 0;
#endif
}
#ifdef TORRENT_DEBUG
#define CHECK_MAGIC check_magic_ cm_(m_magic)
struct check_magic_
@ -119,6 +130,8 @@ void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_
return;
}
if (m_abort) return;
if (s == &m_ipv4_sock)
s->async_receive_from(asio::buffer(m_v4_buf, sizeof(m_v4_buf))
, m_v4_ep, boost::bind(&udp_socket::on_read, this, s, _1, _2));
@ -151,6 +164,9 @@ void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_
#ifndef BOOST_NO_EXCEPTIONS
} catch(std::exception&) {}
#endif
if (m_abort) return;
s->async_receive_from(asio::buffer(m_v4_buf, sizeof(m_v4_buf))
, m_v4_ep, boost::bind(&udp_socket::on_read, this, s, _1, _2));
}
@ -175,6 +191,9 @@ void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_
} catch(std::exception&) {}
#endif
l.lock();
if (m_abort) return;
s->async_receive_from(asio::buffer(m_v6_buf, sizeof(m_v6_buf))
, m_v6_ep, boost::bind(&udp_socket::on_read, this, s, _1, _2));
}
@ -252,6 +271,7 @@ void udp_socket::close()
m_ipv6_sock.close(ec);
m_socks5_sock.close(ec);
m_resolver.cancel();
m_abort = true;
if (m_connection_ticket >= 0)
{
m_cc.done(m_connection_ticket);