Browse Source

Reduce memory usage a bit

pull/136/head
Francisco Blas (klondike) Izquierdo Riera 10 years ago
parent
commit
610fd2ac67
  1. 40
      SOCKS.cpp
  2. 12
      SOCKS.h

40
SOCKS.cpp

@ -193,14 +193,14 @@ namespace proxy @@ -193,14 +193,14 @@ namespace proxy
switch (m_pstate)
{
case GET5_AUTHNUM:
m_authleft = *sock_buff;
m_parseleft = *sock_buff;
m_pstate = GET5_AUTH;
break;
case GET5_AUTH:
m_authleft --;
m_parseleft --;
if (*sock_buff == AUTH_NONE)
m_authchosen = AUTH_NONE;
if ( m_authleft == 0 ) {
if ( m_parseleft == 0 ) {
if (m_authchosen == AUTH_UNACCEPTABLE) {
//TODO: we maybe want support for other methods!
LogPrint(eLogError,"--- SOCKS5 couldn't negotiate authentication");
@ -276,25 +276,25 @@ namespace proxy @@ -276,25 +276,25 @@ namespace proxy
m_cmd = (SOCKSHandler::cmdTypes)*sock_buff;
switch (m_socksv) {
case SOCKS5: m_pstate = GET5_GETRSV; break;
case SOCKS4: m_pstate = GET_PORT; m_addrleft = 2; break;
case SOCKS4: m_pstate = GET_PORT; m_parseleft = 2; break;
}
break;
case GET_PORT:
m_port = (m_port << 8)|((uint16_t)*sock_buff);
m_addrleft--;
if (m_addrleft == 0) {
m_parseleft--;
if (m_parseleft == 0) {
switch (m_socksv) {
case SOCKS5: m_pstate = DONE; break;
case SOCKS4: m_pstate = GET_IPV4; m_address.ip = 0; m_addrleft = 4; break;
case SOCKS4: m_pstate = GET_IPV4; m_address.ip = 0; m_parseleft = 4; break;
}
}
break;
case GET_IPV4:
m_address.ip = (m_address.ip << 8)|((uint32_t)*sock_buff);
m_addrleft--;
if (m_addrleft == 0) {
m_parseleft--;
if (m_parseleft == 0) {
switch (m_socksv) {
case SOCKS5: m_pstate = GET_PORT; m_addrleft = 2; break;
case SOCKS5: m_pstate = GET_PORT; m_parseleft = 2; break;
case SOCKS4: m_pstate = GET4_IDENT; m_4aip = m_address.ip; break;
}
}
@ -341,8 +341,8 @@ namespace proxy @@ -341,8 +341,8 @@ namespace proxy
break;
case GET5_GETADDRTYPE:
switch (*sock_buff) {
case ADDR_IPV4: m_pstate = GET_IPV4; m_address.ip = 0; m_addrleft = 4; break;
case ADDR_IPV6: m_pstate = GET5_IPV6; m_addrleft = 16; break;
case ADDR_IPV4: m_pstate = GET_IPV4; m_address.ip = 0; m_parseleft = 4; break;
case ADDR_IPV6: m_pstate = GET5_IPV6; m_parseleft = 16; break;
case ADDR_DNS : m_pstate = GET5_HOST_SIZE; break;
default:
LogPrint(eLogError,"--- SOCKS5 unknown address type: ", ((int)*sock_buff));
@ -352,24 +352,24 @@ namespace proxy @@ -352,24 +352,24 @@ namespace proxy
m_addrtype = (SOCKSHandler::addrTypes)*sock_buff;
break;
case GET5_IPV6:
m_address.ipv6[16-m_addrleft] = *sock_buff;
m_addrleft--;
if (m_addrleft == 0) {
m_address.ipv6[16-m_parseleft] = *sock_buff;
m_parseleft--;
if (m_parseleft == 0) {
m_pstate = GET_PORT;
m_addrleft = 2;
m_parseleft = 2;
}
break;
case GET5_HOST_SIZE:
m_addrleft = *sock_buff;
m_parseleft = *sock_buff;
m_address.dns.size = 0;
m_pstate = GET5_HOST;
break;
case GET5_HOST:
m_address.dns.push_back(*sock_buff);
m_addrleft--;
if (m_addrleft == 0) {
m_parseleft--;
if (m_parseleft == 0) {
m_pstate = GET_PORT;
m_addrleft = 2;
m_parseleft = 2;
}
break;
default:

12
SOCKS.h

@ -123,19 +123,17 @@ namespace proxy @@ -123,19 +123,17 @@ namespace proxy
std::shared_ptr<i2p::stream::Stream> m_stream;
state m_state;
parseState m_pstate;
uint8_t m_command;
uint16_t m_port;
uint8_t response[7+max_socks_hostname_size];
address m_address; //Address
uint32_t m_4aip; //Used in 4a requests
uint8_t m_authleft; //Authentication methods left
//TODO: this will probably be more elegant as enums
uint16_t m_port;
uint8_t m_command;
uint8_t m_parseleft; //Octets left to parse
authMethods m_authchosen; //Authentication chosen
addrTypes m_addrtype; //Address type chosen
address m_address; //Address
uint8_t m_addrleft; //Octets of current address left
socksVersions m_socksv; //Socks version
cmdTypes m_cmd; // Command requested
bool m_need_more; //The parser still needs to receive more data
uint8_t response[7+max_socks_hostname_size];
public:
SOCKSHandler(SOCKSServer * parent, boost::asio::ip::tcp::socket * sock) :

Loading…
Cancel
Save