| 631 | } |
| 632 | |
| 633 | void SAMSocket::ProcessStreamAccept (std::string_view buf) |
| 634 | { |
| 635 | LogPrint (eLogDebug, "SAM: Stream accept: ", buf); |
| 636 | if ( m_SocketType != SAMSocketType::eSAMSocketTypeUnknown) |
| 637 | { |
| 638 | SendSessionI2PError ("Socket already in use"); |
| 639 | return; |
| 640 | } |
| 641 | auto params = ExtractParams (buf); |
| 642 | std::string_view id = params[SAM_PARAM_ID]; |
| 643 | std::string_view silent = params[SAM_PARAM_SILENT]; |
| 644 | if (silent == SAM_VALUE_TRUE) m_IsSilent = true; |
| 645 | m_ID = id; |
| 646 | auto session = m_Owner.FindSession (id); |
| 647 | if (session) |
| 648 | { |
| 649 | m_SocketType = SAMSocketType::eSAMSocketTypeAcceptor; |
| 650 | if (!session->GetLocalDestination ()->IsAcceptingStreams ()) |
| 651 | { |
| 652 | m_IsAccepting = true; |
| 653 | SendMessageReply (SAM_STREAM_STATUS_OK, false); |
| 654 | session->GetLocalDestination ()->AcceptOnce (std::bind (&SAMSocket::HandleI2PAccept, shared_from_this (), std::placeholders::_1)); |
| 655 | } |
| 656 | else |
| 657 | { |
| 658 | auto ts = i2p::util::GetSecondsSinceEpoch (); |
| 659 | while (!session->acceptQueue.empty () && session->acceptQueue.front ().second + SAM_SESSION_MAX_ACCEPT_INTERVAL > ts) |
| 660 | { |
| 661 | auto socket = session->acceptQueue.front ().first; |
| 662 | session->acceptQueue.pop_front (); |
| 663 | if (socket) |
| 664 | boost::asio::post (m_Owner.GetService (), std::bind(&SAMSocket::TerminateClose, socket)); |
| 665 | } |
| 666 | if (session->acceptQueue.size () < SAM_SESSION_MAX_ACCEPT_QUEUE_SIZE) |
| 667 | { |
| 668 | // already accepting, queue up |
| 669 | SendMessageReply (SAM_STREAM_STATUS_OK, false); |
| 670 | session->acceptQueue.push_back (std::make_pair(shared_from_this(), ts)); |
| 671 | } |
| 672 | else |
| 673 | { |
| 674 | LogPrint (eLogInfo, "SAM: Session ", m_ID, " accept queue is full ", session->acceptQueue.size ()); |
| 675 | SendStreamI2PError ("Already accepting"); |
| 676 | } |
| 677 | } |
| 678 | } |
| 679 | else |
| 680 | SendMessageReply (SAM_STREAM_STATUS_INVALID_ID, true); |
| 681 | } |
| 682 | |
| 683 | void SAMSocket::ProcessStreamForward (std::string_view buf) |
| 684 | { |
nothing calls this directly
no test coverage detected