Browse Source

Clean up SOCKS a bit

pull/133/head
Francisco Blas (klondike) Izquierdo Riera 10 years ago
parent
commit
17ccaab792
  1. 11
      SOCKS.cpp
  2. 23
      SOCKS.h

11
SOCKS.cpp

@ -4,17 +4,12 @@
#include "Destination.h" #include "Destination.h"
#include "ClientContext.h" #include "ClientContext.h"
#include "I2PEndian.h" #include "I2PEndian.h"
#include <cstring>
#include <cassert> #include <cassert>
#include <vector>
namespace i2p namespace i2p
{ {
namespace proxy namespace proxy
{ {
const uint8_t socks_leaseset_timeout = 10;
const uint8_t socks_timeout = 60;
void SOCKSHandler::AsyncSockRead() void SOCKSHandler::AsyncSockRead()
{ {
LogPrint(eLogDebug,"--- SOCKS async sock read"); LogPrint(eLogDebug,"--- SOCKS async sock read");
@ -129,10 +124,6 @@ namespace proxy
} }
} }
const size_t socks_hostname_size = 1024;
const size_t socks_ident_size = 1024;
const size_t destb32_len = 52;
std::size_t SOCKSHandler::HandleData(uint8_t *sock_buff, std::size_t len) std::size_t SOCKSHandler::HandleData(uint8_t *sock_buff, std::size_t len)
{ {
assert(len); // This should always be called with a least a byte left to parse assert(len); // This should always be called with a least a byte left to parse
@ -228,7 +219,7 @@ namespace proxy
m_need_more = false; m_need_more = false;
return rv; return rv;
} }
if (m_destination.size() > HOST_NAME_MAX) { if (m_destination.size() > max_socks_hostname_size) {
LogPrint(eLogError,"--- SOCKS4a destination is too large "); LogPrint(eLogError,"--- SOCKS4a destination is too large ");
SocksRequestFailed(); SocksRequestFailed();
return 0; return 0;

23
SOCKS.h

@ -1,33 +1,20 @@
#ifndef SOCKS4A_H__ #ifndef SOCKS_H__
#define SOCKS4A_H__ #define SOCKS_H__
#include <climits>
#include <memory> #include <memory>
#include <vector>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include "Identity.h" #include "Identity.h"
#include "Streaming.h" #include "Streaming.h"
#include "I2PTunnel.h" #include "I2PTunnel.h"
#ifdef MAC_OSX
/*
* - MAXHOSTNAMELEN from <sys/param.h>
* on MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, AIX 5.1, HP-UX 11,
* IRIX 6.5, OSF/1 5.1, Interix 3.5, Haiku,
* - MAXHOSTNAMELEN from <netdb.h>
* on Solaris 10, Cygwin, BeOS,
* - 256 on mingw.
*
* */
#include <sys/param.h>
#define HOST_NAME_MAX MAXHOSTNAMELEN
#endif
namespace i2p namespace i2p
{ {
namespace proxy namespace proxy
{ {
const size_t socks_buffer_size = 8192; const size_t socks_buffer_size = 8192;
const size_t max_socks_hostname_size = 255; // Limit for socks5 and bad idea to traverse
class SOCKSServer; class SOCKSServer;
class SOCKSHandler { class SOCKSHandler {
@ -128,7 +115,7 @@ namespace proxy
SOCKSHandler(SOCKSServer * parent, boost::asio::ip::tcp::socket * sock) : SOCKSHandler(SOCKSServer * parent, boost::asio::ip::tcp::socket * sock) :
m_parent(parent), m_sock(sock), m_stream(nullptr), m_state(GET_VERSION), m_parent(parent), m_sock(sock), m_stream(nullptr), m_state(GET_VERSION),
m_authchosen(0xff), m_addrtype(0x01), m_error(0x01) m_authchosen(0xff), m_addrtype(0x01), m_error(0x01)
{ AsyncSockRead(); m_destination.reserve(HOST_NAME_MAX+1); } { AsyncSockRead(); m_destination.reserve(max_socks_hostname_size+1); }
~SOCKSHandler() { CloseSock(); CloseStream(); } ~SOCKSHandler() { CloseSock(); CloseStream(); }
}; };

Loading…
Cancel
Save