mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 08:14:15 +00:00
handle NAMING LOOKUP
This commit is contained in:
parent
6a8c18f2fc
commit
18f177ee19
28
SAM.cpp
28
SAM.cpp
@ -176,6 +176,8 @@ namespace stream
|
|||||||
ProcessStreamAccept (separator + 1, bytes_transferred - (separator - m_Buffer) - 1);
|
ProcessStreamAccept (separator + 1, bytes_transferred - (separator - m_Buffer) - 1);
|
||||||
else if (!strcmp (m_Buffer, SAM_DEST_GENERATE))
|
else if (!strcmp (m_Buffer, SAM_DEST_GENERATE))
|
||||||
ProcessDestGenerate ();
|
ProcessDestGenerate ();
|
||||||
|
else if (!strcmp (m_Buffer, SAM_NAMING_LOOKUP))
|
||||||
|
ProcessNamingLookup (separator + 1, bytes_transferred - (separator - m_Buffer) - 1);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogPrint ("SAM unexpected message ", m_Buffer);
|
LogPrint ("SAM unexpected message ", m_Buffer);
|
||||||
@ -331,6 +333,28 @@ namespace stream
|
|||||||
SendMessageReply (SAM_DEST_REPLY_I2P_ERROR, strlen(SAM_DEST_REPLY_I2P_ERROR), true);
|
SendMessageReply (SAM_DEST_REPLY_I2P_ERROR, strlen(SAM_DEST_REPLY_I2P_ERROR), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SAMSocket::ProcessNamingLookup (char * buf, size_t len)
|
||||||
|
{
|
||||||
|
LogPrint ("SAM naming lookup: ", buf);
|
||||||
|
std::map<std::string, std::string> params;
|
||||||
|
ExtractParams (buf, len, params);
|
||||||
|
std::string& name = params[SAM_PARAM_NAME];
|
||||||
|
if (name == "ME")
|
||||||
|
{
|
||||||
|
/*uint8_t buf[1024];
|
||||||
|
char pub[1024];
|
||||||
|
size_t l = localDestination->GetIdentity ().ToBuffer (buf, 1024);
|
||||||
|
size_t l1 = i2p::data::ByteStreamToBase64 (buf, l, pub, 1024);
|
||||||
|
size_t len = snprintf (m_Buffer, SAM_SOCKET_BUFFER_SIZE, SAM_NAMING_REPLY, pub);
|
||||||
|
SendMessageReply (m_Buffer, len, false);*/
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size_t len = snprintf (m_Buffer, SAM_SOCKET_BUFFER_SIZE, SAM_NAMING_REPLY_INVALID_KEY, name.c_str());
|
||||||
|
SendMessageReply (m_Buffer, len, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SAMSocket::ExtractParams (char * buf, size_t len, std::map<std::string, std::string>& params)
|
void SAMSocket::ExtractParams (char * buf, size_t len, std::map<std::string, std::string>& params)
|
||||||
{
|
{
|
||||||
while (char * separator = strchr (buf, ' '))
|
while (char * separator = strchr (buf, ' '))
|
||||||
@ -350,8 +374,8 @@ namespace stream
|
|||||||
void SAMSocket::Receive ()
|
void SAMSocket::Receive ()
|
||||||
{
|
{
|
||||||
m_Socket.async_read_some (boost::asio::buffer(m_Buffer, SAM_SOCKET_BUFFER_SIZE),
|
m_Socket.async_read_some (boost::asio::buffer(m_Buffer, SAM_SOCKET_BUFFER_SIZE),
|
||||||
boost::bind(&SAMSocket::HandleReceived, this,
|
boost::bind((m_SocketType == eSAMSocketTypeSession) ? &SAMSocket::HandleMessage : &SAMSocket::HandleReceived,
|
||||||
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
|
this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SAMSocket::HandleReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred)
|
void SAMSocket::HandleReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred)
|
||||||
|
5
SAM.h
5
SAM.h
@ -33,10 +33,14 @@ namespace stream
|
|||||||
const char SAM_DEST_GENERATE[] = "DEST GENERATE";
|
const char SAM_DEST_GENERATE[] = "DEST GENERATE";
|
||||||
const char SAM_DEST_REPLY[] = "DEST REPLY PUB=%s PRIV=%s\n";
|
const char SAM_DEST_REPLY[] = "DEST REPLY PUB=%s PRIV=%s\n";
|
||||||
const char SAM_DEST_REPLY_I2P_ERROR[] = "DEST REPLY RESULT=I2P_ERROR\n";
|
const char SAM_DEST_REPLY_I2P_ERROR[] = "DEST REPLY RESULT=I2P_ERROR\n";
|
||||||
|
const char SAM_NAMING_LOOKUP[] = "NAMING LOOKUP";
|
||||||
|
const char SAM_NAMING_REPLY[] = "NAMING REPLY RESULT=OK NAME=ME VALUE=%s\n";
|
||||||
|
const char SAM_NAMING_REPLY_INVALID_KEY[] = "NAMING REPLY RESULT=INVALID_KEY NAME=%s\n";
|
||||||
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_SILENT[] = "SILENT";
|
||||||
const char SAM_PARAM_DESTINATION[] = "DESTINATION";
|
const char SAM_PARAM_DESTINATION[] = "DESTINATION";
|
||||||
|
const char SAM_PARAM_NAME[] = "NAME";
|
||||||
const char SAM_VALUE_TRANSIENT[] = "TRANSIENT";
|
const char SAM_VALUE_TRANSIENT[] = "TRANSIENT";
|
||||||
const char SAM_VALUE_TRUE[] = "true";
|
const char SAM_VALUE_TRUE[] = "true";
|
||||||
const char SAM_VALUE_FALSE[] = "false";
|
const char SAM_VALUE_FALSE[] = "false";
|
||||||
@ -81,6 +85,7 @@ namespace stream
|
|||||||
void ProcessStreamConnect (char * buf, size_t len);
|
void ProcessStreamConnect (char * buf, size_t len);
|
||||||
void ProcessStreamAccept (char * buf, size_t len);
|
void ProcessStreamAccept (char * buf, size_t len);
|
||||||
void ProcessDestGenerate ();
|
void ProcessDestGenerate ();
|
||||||
|
void ProcessNamingLookup (char * buf, size_t len);
|
||||||
void ExtractParams (char * buf, size_t len, std::map<std::string, std::string>& params);
|
void ExtractParams (char * buf, size_t len, std::map<std::string, std::string>& params);
|
||||||
|
|
||||||
void Connect (const i2p::data::LeaseSet& remote, SAMSession * session);
|
void Connect (const i2p::data::LeaseSet& remote, SAMSession * session);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user