| 622 | } |
| 623 | |
| 624 | void SOCKSHandler::HandleSockRecv(const boost::system::error_code & ecode, std::size_t len) |
| 625 | { |
| 626 | LogPrint(eLogDebug, "SOCKS: Received ", len, " bytes"); |
| 627 | if(ecode) |
| 628 | { |
| 629 | LogPrint(eLogWarning, "SOCKS: Recv got error: ", ecode); |
| 630 | Terminate(); |
| 631 | return; |
| 632 | } |
| 633 | |
| 634 | if (HandleData(m_sock_buff, len)) |
| 635 | { |
| 636 | if (m_state == READY) |
| 637 | { |
| 638 | const std::string addr = m_address.dns.ToString(); |
| 639 | LogPrint(eLogInfo, "SOCKS: Requested ", addr, ":" , m_port); |
| 640 | const size_t addrlen = addr.size(); |
| 641 | // does it end with .i2p? |
| 642 | if (addr.rfind(".i2p") == addrlen - 4) |
| 643 | { |
| 644 | // yes it does |
| 645 | switch (m_cmd) |
| 646 | { |
| 647 | case CMD_CONNECT: |
| 648 | //make an i2p session |
| 649 | GetOwner ()->UpdateLastActivityTime (); |
| 650 | GetOwner()->CreateStream ( std::bind (&SOCKSHandler::HandleStreamRequestComplete, |
| 651 | shared_from_this(), std::placeholders::_1), m_address.dns.ToString(), m_port); |
| 652 | break; |
| 653 | case CMD_UDP: |
| 654 | // create UDP client tunnel |
| 655 | LogPrint (eLogInfo, "SOCKS: New UDP associate connection"); |
| 656 | m_UDPTunnel = std::make_unique<i2p::client::I2PUDPClientTunnel>("", addr, |
| 657 | GetServer ()->GetNextLocalUDPEndpoint (), |
| 658 | GetOwner ()->GetLocalDestination (), m_port, false, i2p::datagram::eDatagramV3); |
| 659 | boost::asio::post (GetOwner ()->GetService (), [this](void) |
| 660 | { |
| 661 | SocksRequestSuccess(); |
| 662 | }); |
| 663 | break; |
| 664 | default: ; |
| 665 | } |
| 666 | } |
| 667 | else if (m_UseUpstreamProxy) |
| 668 | // forward it to upstream proxy |
| 669 | ForwardSOCKS(); |
| 670 | else |
| 671 | // no upstream proxy |
| 672 | SocksRequestFailed(SOCKS5_ADDR_UNSUP); |
| 673 | } |
| 674 | else |
| 675 | AsyncSockRead(); |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | void SOCKSHandler::SentSocksFailed(const boost::system::error_code & ecode) |
| 680 | { |
nothing calls this directly
no test coverage detected