diff --git a/Destination.cpp b/Destination.cpp index 491a9f29..f3cb9af8 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -844,6 +844,12 @@ namespace client return false; } + void ClientDestination::AcceptOnce (const i2p::stream::StreamingDestination::Acceptor& acceptor) + { + if (m_StreamingDestination) + m_StreamingDestination->AcceptOnce (acceptor); + } + std::shared_ptr ClientDestination::CreateStreamingDestination (int port, bool gzip) { auto dest = std::make_shared (GetSharedFromThis (), port, gzip); diff --git a/Destination.h b/Destination.h index 1ccb0a9c..7a4e0b64 100644 --- a/Destination.h +++ b/Destination.h @@ -186,7 +186,8 @@ namespace client void AcceptStreams (const i2p::stream::StreamingDestination::Acceptor& acceptor); void StopAcceptingStreams (); bool IsAcceptingStreams () const; - + void AcceptOnce (const i2p::stream::StreamingDestination::Acceptor& acceptor); + // datagram i2p::datagram::DatagramDestination * GetDatagramDestination () const { return m_DatagramDestination; }; i2p::datagram::DatagramDestination * CreateDatagramDestination (); diff --git a/SAM.cpp b/SAM.cpp index cb843685..aa7de1c8 100644 --- a/SAM.cpp +++ b/SAM.cpp @@ -405,7 +405,8 @@ namespace client { m_SocketType = eSAMSocketTypeAcceptor; m_Session->AddSocket (shared_from_this ()); - m_Session->localDestination->AcceptStreams (std::bind (&SAMSocket::HandleI2PAccept, shared_from_this (), std::placeholders::_1)); + if (!m_Session->localDestination->IsAcceptingStreams ()) + m_Session->localDestination->AcceptOnce (std::bind (&SAMSocket::HandleI2PAccept, shared_from_this (), std::placeholders::_1)); SendMessageReply (SAM_STREAM_STATUS_OK, strlen(SAM_STREAM_STATUS_OK), false); } else @@ -657,12 +658,20 @@ namespace client if (stream) { LogPrint (eLogDebug, "SAM: incoming I2P connection for session ", m_ID); + m_SocketType = eSAMSocketTypeStream; m_Stream = stream; context.GetAddressBook ().InsertAddress (stream->GetRemoteIdentity ()); auto session = m_Owner.FindSession (m_ID); - if (session) - session->localDestination->StopAcceptingStreams (); - m_SocketType = eSAMSocketTypeStream; + if (session) + { + // find more pending acceptors + for (auto it: session->ListSockets ()) + if (it->m_SocketType == eSAMSocketTypeAcceptor) + { + session->localDestination->AcceptOnce (std::bind (&SAMSocket::HandleI2PAccept, shared_from_this (), std::placeholders::_1)); + break; + } + } if (!m_IsSilent) { // get remote peer address