| 342 | } |
| 343 | |
| 344 | void SOCKSHandler::SocksRequestSuccess() |
| 345 | { |
| 346 | boost::asio::const_buffer response(nullptr,0); |
| 347 | // TODO: this should depend on things like the command type and callbacks may change |
| 348 | switch (m_socksv) |
| 349 | { |
| 350 | case SOCKS4: |
| 351 | LogPrint(eLogInfo, "SOCKS: v4 connection success"); |
| 352 | response = GenerateSOCKS4Response(SOCKS4_OK, m_4aip, m_port); |
| 353 | break; |
| 354 | case SOCKS5: |
| 355 | LogPrint(eLogInfo, "SOCKS: v5 connection success"); |
| 356 | if (m_cmd == CMD_UDP && m_UDPTunnel) |
| 357 | { |
| 358 | address ad; |
| 359 | // TODO: implement ipv6 |
| 360 | ad.ip = m_UDPTunnel->GetLocalEndpoint ().address ().to_v4 ().to_uint (); |
| 361 | response = GenerateSOCKS5Response(SOCKS5_OK, ADDR_IPV4, ad, m_UDPTunnel->GetLocalEndpoint ().port ()); |
| 362 | } |
| 363 | else |
| 364 | { |
| 365 | auto s = i2p::client::context.GetAddressBook().ToAddress(GetOwner()->GetLocalDestination()->GetIdentHash()); |
| 366 | address ad; ad.dns.FromString(s); |
| 367 | // HACK only 16 bits passed in port as SOCKS5 doesn't allow for more |
| 368 | response = GenerateSOCKS5Response(SOCKS5_OK, ADDR_DNS, ad, m_stream ? m_stream->GetRecvStreamID() : 0); |
| 369 | } |
| 370 | break; |
| 371 | } |
| 372 | boost::asio::async_write(*m_sock, response, std::bind(&SOCKSHandler::SentSocksDone, shared_from_this(), std::placeholders::_1)); |
| 373 | } |
| 374 | |
| 375 | void SOCKSHandler::EnterState(SOCKSHandler::state nstate, uint8_t parseleft) { |
| 376 | switch (nstate) |
nothing calls this directly
no test coverage detected