| 681 | } |
| 682 | |
| 683 | void SAMSocket::ProcessStreamForward (std::string_view buf) |
| 684 | { |
| 685 | LogPrint(eLogDebug, "SAM: Stream forward: ", buf); |
| 686 | |
| 687 | auto params = ExtractParams(buf); |
| 688 | auto id = params[SAM_PARAM_ID]; |
| 689 | if (id.empty ()) |
| 690 | { |
| 691 | SendSessionI2PError("Missing ID"); |
| 692 | return; |
| 693 | } |
| 694 | |
| 695 | auto session = m_Owner.FindSession(id); |
| 696 | if (!session) |
| 697 | { |
| 698 | SendMessageReply(SAM_STREAM_STATUS_INVALID_ID, true); |
| 699 | return; |
| 700 | } |
| 701 | if (session->GetLocalDestination()->IsAcceptingStreams()) |
| 702 | { |
| 703 | SendSessionI2PError("Already accepting"); |
| 704 | return; |
| 705 | } |
| 706 | |
| 707 | auto portStr = params[SAM_PARAM_PORT]; |
| 708 | if (portStr.empty ()) |
| 709 | { |
| 710 | SendSessionI2PError("PORT is missing"); |
| 711 | return; |
| 712 | } |
| 713 | |
| 714 | if (!std::all_of(portStr.begin(), portStr.end(), ::isdigit)) |
| 715 | { |
| 716 | SendSessionI2PError("Port must be numeric"); |
| 717 | return; |
| 718 | } |
| 719 | |
| 720 | uint16_t port = 0; |
| 721 | auto res = std::from_chars(portStr.data(), portStr.data() + portStr.size(), port); |
| 722 | if (res.ec != std::errc()) |
| 723 | { |
| 724 | SendSessionI2PError("Invalid port"); |
| 725 | return; |
| 726 | } |
| 727 | |
| 728 | boost::asio::ip::tcp::endpoint ep; |
| 729 | auto host = params[SAM_PARAM_HOST]; |
| 730 | |
| 731 | if (!host.empty ()) |
| 732 | { |
| 733 | boost::system::error_code ec; |
| 734 | auto addr = boost::asio::ip::make_address(host, ec); |
| 735 | if (ec) |
| 736 | { |
| 737 | SendSessionI2PError("Invalid IP Address in HOST"); |
| 738 | return; |
| 739 | } |
| 740 | ep = boost::asio::ip::tcp::endpoint(addr, port); |
nothing calls this directly
no test coverage detected