fix build with encryption disabled

This commit is contained in:
Arvid Norberg 2013-11-10 11:05:11 +00:00
parent 5284de9d80
commit fde0d6994d
2 changed files with 54 additions and 52 deletions

View File

@ -286,6 +286,13 @@ namespace libtorrent
// initializes m_enc_handler
void init_pe_rc4_handler(char const* secret, sha1_hash const& stream_key);
// Returns offset at which bytestream (src, src + src_size)
// matches bytestream(target, target + target_size).
// If no sync found, return -1
int get_syncoffset(char const* src, int src_size
, char const* target, int target_size) const;
#endif
public:
// these functions encrypt the send buffer if m_rc4_encrypted
@ -306,13 +313,6 @@ public:
private:
// Returns offset at which bytestream (src, src + src_size)
// matches bytestream(target, target + target_size).
// If no sync found, return -1
int get_syncoffset(char const* src, int src_size
, char const* target, int target_size) const;
#endif
enum state
{
#ifndef TORRENT_DISABLE_ENCRYPTION

View File

@ -604,51 +604,6 @@ namespace libtorrent
#endif
}
void bt_peer_connection::append_const_send_buffer(char const* buffer, int size)
{
#ifndef TORRENT_DISABLE_ENCRYPTION
if (m_encrypted && m_rc4_encrypted)
{
// if we're encrypting this buffer, we need to make a copy
// since we'll mutate it
char* buf = (char*)malloc(size);
memcpy(buf, buffer, size);
bt_append_send_buffer(buf, size, boost::bind(&::free, _1));
}
else
#endif
{
peer_connection::append_const_send_buffer(buffer, size);
}
}
void encrypt(char* buf, int len, void* userdata)
{
rc4_handler* rc4 = (rc4_handler*)userdata;
rc4->encrypt(buf, len);
}
void bt_peer_connection::send_buffer(char const* buf, int size, int flags
, void (*f)(char*, int, void*), void* ud)
{
TORRENT_ASSERT(f == 0);
TORRENT_ASSERT(ud == 0);
TORRENT_ASSERT(buf);
TORRENT_ASSERT(size > 0);
void* userdata = 0;
void (*fun)(char*, int, void*) = 0;
#ifndef TORRENT_DISABLE_ENCRYPTION
if (m_encrypted && m_rc4_encrypted)
{
fun = encrypt;
userdata = m_enc_handler.get();
}
#endif
peer_connection::send_buffer(buf, size, flags, fun, userdata);
}
int bt_peer_connection::get_syncoffset(char const* src, int src_size,
char const* target, int target_size) const
{
@ -695,6 +650,53 @@ namespace libtorrent
}
#endif // #ifndef TORRENT_DISABLE_ENCRYPTION
void bt_peer_connection::append_const_send_buffer(char const* buffer, int size)
{
#ifndef TORRENT_DISABLE_ENCRYPTION
if (m_encrypted && m_rc4_encrypted)
{
// if we're encrypting this buffer, we need to make a copy
// since we'll mutate it
char* buf = (char*)malloc(size);
memcpy(buf, buffer, size);
bt_append_send_buffer(buf, size, boost::bind(&::free, _1));
}
else
#endif
{
peer_connection::append_const_send_buffer(buffer, size);
}
}
#ifndef TORRENT_DISABLE_ENCRYPTION
void encrypt(char* buf, int len, void* userdata)
{
rc4_handler* rc4 = (rc4_handler*)userdata;
rc4->encrypt(buf, len);
}
#endif
void bt_peer_connection::send_buffer(char const* buf, int size, int flags
, void (*f)(char*, int, void*), void* ud)
{
TORRENT_ASSERT(f == 0);
TORRENT_ASSERT(ud == 0);
TORRENT_ASSERT(buf);
TORRENT_ASSERT(size > 0);
void* userdata = 0;
void (*fun)(char*, int, void*) = 0;
#ifndef TORRENT_DISABLE_ENCRYPTION
if (m_encrypted && m_rc4_encrypted)
{
fun = encrypt;
userdata = m_enc_handler.get();
}
#endif
peer_connection::send_buffer(buf, size, flags, fun, userdata);
}
void bt_peer_connection::write_handshake()
{
INVARIANT_CHECK;