Merge, fixed build issues by refactoring SOCKS 5 code.
parent
d5ea63119d
commit
f91d40c259
|
|
@ -24,13 +24,16 @@
|
|||
* $/LicenseInfo$
|
||||
*/
|
||||
|
||||
#include "linden_common.h"
|
||||
|
||||
#include "llsocks5.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "linden_common.h"
|
||||
#include "net.h"
|
||||
#include "llapr.h"
|
||||
#include "llhost.h"
|
||||
#include "message.h"
|
||||
#include "llsocks5.h"
|
||||
#include "net.h"
|
||||
|
||||
// Static class variable instances
|
||||
|
||||
|
|
@ -40,6 +43,12 @@
|
|||
bool LLSocks::sUDPProxyEnabled;
|
||||
bool LLSocks::sHTTPProxyEnabled;
|
||||
|
||||
// Some helpful TCP functions
|
||||
static LLSocket::ptr_t tcp_open_channel(LLHost host); // Open a TCP channel to a given host
|
||||
static void tcp_close_channel(LLSocket::ptr_t handle); // Close an open TCP channel
|
||||
static int tcp_handshake(LLSocket::ptr_t handle, char * dataout, apr_size_t outlen, char * datain, apr_size_t maxinlen); // Do a TCP data handshake
|
||||
|
||||
|
||||
LLSocks::LLSocks()
|
||||
{
|
||||
sUDPProxyEnabled = false;
|
||||
|
|
@ -214,3 +223,63 @@ void LLSocks::enableHTTPProxy(LLHost httpHost, LLHttpProxyType type)
|
|||
mHTTPProxy = httpHost;
|
||||
mProxyType = type;
|
||||
}
|
||||
|
||||
static int tcp_handshake(LLSocket::ptr_t handle, char * dataout, apr_size_t outlen, char * datain, apr_size_t maxinlen)
|
||||
{
|
||||
apr_socket_t* apr_socket = handle->getSocket();
|
||||
apr_status_t rv;
|
||||
|
||||
apr_size_t expected_len = outlen;
|
||||
|
||||
apr_socket_opt_set(apr_socket, APR_SO_NONBLOCK, -5); // Blocking connection, 5 second timeout
|
||||
apr_socket_timeout_set(apr_socket, (APR_USEC_PER_SEC * 5));
|
||||
|
||||
rv = apr_socket_send(apr_socket, dataout, &outlen);
|
||||
if (rv != APR_SUCCESS || expected_len != outlen)
|
||||
{
|
||||
llwarns << "Error sending data to proxy control channel" << llendl;
|
||||
ll_apr_warn_status(rv);
|
||||
return -1;
|
||||
}
|
||||
|
||||
expected_len = maxinlen;
|
||||
do
|
||||
{
|
||||
rv = apr_socket_recv(apr_socket, datain, &maxinlen);
|
||||
llinfos << "Receiving packets." << llendl;
|
||||
llwarns << "Proxy control channel status: " << rv << llendl;
|
||||
} while (APR_STATUS_IS_EAGAIN(rv));
|
||||
|
||||
if (rv != APR_SUCCESS)
|
||||
{
|
||||
llwarns << "Error receiving data from proxy control channel, status: " << rv << llendl;
|
||||
llwarns << "Received " << maxinlen << " bytes." << llendl;
|
||||
ll_apr_warn_status(rv);
|
||||
return rv;
|
||||
}
|
||||
else if (expected_len != maxinlen)
|
||||
{
|
||||
llwarns << "Incorrect data received length in proxy control channel" << llendl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static LLSocket::ptr_t tcp_open_channel(LLHost host)
|
||||
{
|
||||
LLSocket::ptr_t socket = LLSocket::create(gAPRPoolp, LLSocket::STREAM_TCP);
|
||||
bool connected = socket->blockingConnect(host);
|
||||
if (!connected)
|
||||
{
|
||||
tcp_close_channel(socket);
|
||||
}
|
||||
|
||||
return socket;
|
||||
}
|
||||
|
||||
static void tcp_close_channel(LLSocket::ptr_t handle)
|
||||
{
|
||||
handle.reset();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
#define LL_SOCKS5_H
|
||||
|
||||
#include "llhost.h"
|
||||
#include "lliosocket.h"
|
||||
#include "llmemory.h"
|
||||
#include "llsingleton.h"
|
||||
#include <string>
|
||||
|
|
|
|||
|
|
@ -664,63 +664,4 @@ BOOL send_packet(int hSocket, const char * sendBuffer, int size, U32 recipient,
|
|||
|
||||
#endif
|
||||
|
||||
int tcp_handshake(LLSocket::ptr_t handle, char * dataout, apr_size_t outlen, char * datain, apr_size_t maxinlen)
|
||||
{
|
||||
apr_socket_t* apr_socket = handle->getSocket();
|
||||
apr_status_t rv;
|
||||
|
||||
apr_size_t expected_len = outlen;
|
||||
|
||||
apr_socket_opt_set(apr_socket, APR_SO_NONBLOCK, -5); // Blocking connection, 5 second timeout
|
||||
apr_socket_timeout_set(apr_socket, (APR_USEC_PER_SEC * 5));
|
||||
|
||||
rv = apr_socket_send(apr_socket, dataout, &outlen);
|
||||
if (rv != APR_SUCCESS || expected_len != outlen)
|
||||
{
|
||||
llwarns << "Error sending data to proxy control channel" << llendl;
|
||||
ll_apr_warn_status(rv);
|
||||
return -1;
|
||||
}
|
||||
|
||||
expected_len = maxinlen;
|
||||
do
|
||||
{
|
||||
rv = apr_socket_recv(apr_socket, datain, &maxinlen);
|
||||
llinfos << "Receiving packets." << llendl;
|
||||
llwarns << "Proxy control channel status: " << rv << llendl;
|
||||
} while (APR_STATUS_IS_EAGAIN(rv));
|
||||
|
||||
if (rv != APR_SUCCESS)
|
||||
{
|
||||
llwarns << "Error receiving data from proxy control channel, status: " << rv << llendl;
|
||||
llwarns << "Received " << maxinlen << " bytes." << llendl;
|
||||
ll_apr_warn_status(rv);
|
||||
return rv;
|
||||
}
|
||||
else if (expected_len != maxinlen)
|
||||
{
|
||||
llwarns << "Incorrect data received length in proxy control channel" << llendl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
LLSocket::ptr_t tcp_open_channel(LLHost host)
|
||||
{
|
||||
LLSocket::ptr_t socket = LLSocket::create(gAPRPoolp, LLSocket::STREAM_TCP);
|
||||
bool connected = socket->blockingConnect(host);
|
||||
if (!connected)
|
||||
{
|
||||
tcp_close_channel(socket);
|
||||
}
|
||||
|
||||
return socket;
|
||||
}
|
||||
|
||||
void tcp_close_channel(LLSocket::ptr_t handle)
|
||||
{
|
||||
handle.reset();
|
||||
}
|
||||
|
||||
//EOF
|
||||
|
|
|
|||
|
|
@ -27,9 +27,6 @@
|
|||
#ifndef LL_NET_H
|
||||
#define LL_NET_H
|
||||
|
||||
#include "lliosocket.h"
|
||||
#include "llapr.h"
|
||||
|
||||
class LLTimer;
|
||||
class LLHost;
|
||||
|
||||
|
|
@ -55,11 +52,6 @@ U32 get_sender_ip(void);
|
|||
LLHost get_receiving_interface();
|
||||
U32 get_receiving_interface_ip(void);
|
||||
|
||||
// Some helpful TCP functions
|
||||
LLSocket::ptr_t tcp_open_channel(LLHost host); // Open a TCP channel to a given host
|
||||
void tcp_close_channel(LLSocket::ptr_t handle); // Close an open TCP channel
|
||||
int tcp_handshake(LLSocket::ptr_t handle, char * dataout, apr_size_t outlen, char * datain, apr_size_t maxinlen); // Do a TCP data handshake
|
||||
|
||||
const char* u32_to_ip_string(U32 ip); // Returns pointer to internal string buffer, "(bad IP addr)" on failure, cannot nest calls
|
||||
char* u32_to_ip_string(U32 ip, char *ip_string); // NULL on failure, ip_string on success, you must allocate at least MAXADDRSTR chars
|
||||
U32 ip_string_to_u32(const char* ip_string); // Wrapper for inet_addr()
|
||||
|
|
|
|||
Loading…
Reference in New Issue