mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-08 18:47:52 +00:00
handle SILENT flag
This commit is contained in:
parent
b13c9d924f
commit
8feabe8a6e
26
SAM.cpp
26
SAM.cpp
@ -12,7 +12,7 @@ namespace stream
|
|||||||
{
|
{
|
||||||
SAMSocket::SAMSocket (SAMBridge& owner):
|
SAMSocket::SAMSocket (SAMBridge& owner):
|
||||||
m_Owner (owner), m_Socket (m_Owner.GetService ()), m_SocketType (eSAMSocketTypeUnknown),
|
m_Owner (owner), m_Socket (m_Owner.GetService ()), m_SocketType (eSAMSocketTypeUnknown),
|
||||||
m_Stream (nullptr)
|
m_IsSilent (false), m_Stream (nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,9 +113,17 @@ namespace stream
|
|||||||
|
|
||||||
void SAMSocket::SendMessageReply (const char * msg, size_t len, bool close)
|
void SAMSocket::SendMessageReply (const char * msg, size_t len, bool close)
|
||||||
{
|
{
|
||||||
|
if (!m_IsSilent || m_SocketType == eSAMSocketTypeAcceptor)
|
||||||
boost::asio::async_write (m_Socket, boost::asio::buffer (msg, len), boost::asio::transfer_all (),
|
boost::asio::async_write (m_Socket, boost::asio::buffer (msg, len), boost::asio::transfer_all (),
|
||||||
boost::bind(&SAMSocket::HandleMessageReplySent, this,
|
boost::bind(&SAMSocket::HandleMessageReplySent, this,
|
||||||
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, close));
|
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, close));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (close)
|
||||||
|
Terminate ();
|
||||||
|
else
|
||||||
|
Receive ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SAMSocket::HandleMessageReplySent (const boost::system::error_code& ecode, std::size_t bytes_transferred, bool close)
|
void SAMSocket::HandleMessageReplySent (const boost::system::error_code& ecode, std::size_t bytes_transferred, bool close)
|
||||||
@ -213,6 +221,8 @@ namespace stream
|
|||||||
ExtractParams (buf, len, params);
|
ExtractParams (buf, len, params);
|
||||||
std::string& id = params[SAM_PARAM_ID];
|
std::string& id = params[SAM_PARAM_ID];
|
||||||
std::string& destination = params[SAM_PARAM_DESTINATION];
|
std::string& destination = params[SAM_PARAM_DESTINATION];
|
||||||
|
std::string& silent = params[SAM_PARAM_SILENT];
|
||||||
|
if (silent == SAM_VALUE_TRUE) m_IsSilent = true;
|
||||||
m_ID = id;
|
m_ID = id;
|
||||||
auto session = m_Owner.FindSession (id);
|
auto session = m_Owner.FindSession (id);
|
||||||
if (session)
|
if (session)
|
||||||
@ -247,6 +257,8 @@ namespace stream
|
|||||||
std::map<std::string, std::string> params;
|
std::map<std::string, std::string> params;
|
||||||
ExtractParams (buf, len, params);
|
ExtractParams (buf, len, params);
|
||||||
std::string& id = params[SAM_PARAM_ID];
|
std::string& id = params[SAM_PARAM_ID];
|
||||||
|
std::string& silent = params[SAM_PARAM_SILENT];
|
||||||
|
if (silent == SAM_VALUE_TRUE) m_IsSilent = true;
|
||||||
m_ID = id;
|
m_ID = id;
|
||||||
auto session = m_Owner.FindSession (id);
|
auto session = m_Owner.FindSession (id);
|
||||||
if (session)
|
if (session)
|
||||||
@ -340,13 +352,25 @@ namespace stream
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SAMSocket::HandleI2PAccept (i2p::stream::Stream * stream)
|
void SAMSocket::HandleI2PAccept (i2p::stream::Stream * stream)
|
||||||
|
{
|
||||||
|
if (stream)
|
||||||
{
|
{
|
||||||
m_Stream = stream;
|
m_Stream = stream;
|
||||||
auto session = m_Owner.FindSession (m_ID);
|
auto session = m_Owner.FindSession (m_ID);
|
||||||
if (session)
|
if (session)
|
||||||
session->localDestination->ResetAcceptor ();
|
session->localDestination->ResetAcceptor ();
|
||||||
|
if (!m_IsSilent)
|
||||||
|
{
|
||||||
|
// send remote peer address
|
||||||
|
uint8_t ident[1024];
|
||||||
|
size_t l = stream->GetRemoteIdentity ().ToBuffer (ident, 1024);
|
||||||
|
size_t l1 = i2p::data::ByteStreamToBase64 (ident, l, m_Buffer, SAM_SOCKET_BUFFER_SIZE);
|
||||||
|
m_Buffer[l1] = '\n';
|
||||||
|
SendMessageReply (m_Buffer, l1 + 1, false);
|
||||||
|
}
|
||||||
I2PReceive ();
|
I2PReceive ();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SAMBridge::SAMBridge (int port):
|
SAMBridge::SAMBridge (int port):
|
||||||
m_IsRunning (false), m_Thread (nullptr),
|
m_IsRunning (false), m_Thread (nullptr),
|
||||||
|
4
SAM.h
4
SAM.h
@ -28,8 +28,11 @@ namespace stream
|
|||||||
const char SAM_STREAM_ACCEPT[] = "STREAM ACCEPT";
|
const char SAM_STREAM_ACCEPT[] = "STREAM ACCEPT";
|
||||||
const char SAM_PARAM_STYLE[] = "STYLE";
|
const char SAM_PARAM_STYLE[] = "STYLE";
|
||||||
const char SAM_PARAM_ID[] = "ID";
|
const char SAM_PARAM_ID[] = "ID";
|
||||||
|
const char SAM_PARAM_SILENT[] = "SILENT";
|
||||||
const char SAM_PARAM_DESTINATION[] = "DESTINATION";
|
const char SAM_PARAM_DESTINATION[] = "DESTINATION";
|
||||||
const char SAM_VALUE_TRANSIENT[] = "TRANSIENT";
|
const char SAM_VALUE_TRANSIENT[] = "TRANSIENT";
|
||||||
|
const char SAM_VALUE_TRUE[] = "true";
|
||||||
|
const char SAM_VALUE_FALSE[] = "false";
|
||||||
|
|
||||||
enum SAMSocketType
|
enum SAMSocketType
|
||||||
{
|
{
|
||||||
@ -79,6 +82,7 @@ namespace stream
|
|||||||
uint8_t m_StreamBuffer[SAM_SOCKET_BUFFER_SIZE];
|
uint8_t m_StreamBuffer[SAM_SOCKET_BUFFER_SIZE];
|
||||||
SAMSocketType m_SocketType;
|
SAMSocketType m_SocketType;
|
||||||
std::string m_ID; // nickname
|
std::string m_ID; // nickname
|
||||||
|
bool m_IsSilent;
|
||||||
Stream * m_Stream;
|
Stream * m_Stream;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -86,6 +86,7 @@ namespace stream
|
|||||||
uint32_t GetSendStreamID () const { return m_SendStreamID; };
|
uint32_t GetSendStreamID () const { return m_SendStreamID; };
|
||||||
uint32_t GetRecvStreamID () const { return m_RecvStreamID; };
|
uint32_t GetRecvStreamID () const { return m_RecvStreamID; };
|
||||||
const i2p::data::LeaseSet * GetRemoteLeaseSet () const { return m_RemoteLeaseSet; };
|
const i2p::data::LeaseSet * GetRemoteLeaseSet () const { return m_RemoteLeaseSet; };
|
||||||
|
const i2p::data::IdentityEx& GetRemoteIdentity () const { return m_RemoteIdentity; };
|
||||||
bool IsOpen () const { return m_IsOpen; };
|
bool IsOpen () const { return m_IsOpen; };
|
||||||
bool IsEstablished () const { return m_SendStreamID; };
|
bool IsEstablished () const { return m_SendStreamID; };
|
||||||
StreamingDestination * GetLocalDestination () { return m_LocalDestination; };
|
StreamingDestination * GetLocalDestination () { return m_LocalDestination; };
|
||||||
|
Loading…
Reference in New Issue
Block a user