Browse Source

handle NAMING LOOKUP

pull/102/head
orignal 10 years ago
parent
commit
6e905c8f5c
  1. 32
      SAM.cpp
  2. 3
      SAM.h

32
SAM.cpp

@ -13,7 +13,8 @@ namespace stream
{ {
SAMSocket::SAMSocket (SAMBridge& owner): SAMSocket::SAMSocket (SAMBridge& owner):
m_Owner (owner), m_Socket (m_Owner.GetService ()), m_Timer (m_Owner.GetService ()), m_Owner (owner), m_Socket (m_Owner.GetService ()), m_Timer (m_Owner.GetService ()),
m_SocketType (eSAMSocketTypeUnknown), m_IsSilent (false), m_Stream (nullptr) m_SocketType (eSAMSocketTypeUnknown), m_IsSilent (false), m_Stream (nullptr),
m_Session (nullptr)
{ {
} }
@ -212,17 +213,17 @@ namespace stream
SendMessageReply (SAM_SESSION_CREATE_DUPLICATED_ID, strlen(SAM_SESSION_CREATE_DUPLICATED_ID), true); SendMessageReply (SAM_SESSION_CREATE_DUPLICATED_ID, strlen(SAM_SESSION_CREATE_DUPLICATED_ID), true);
return; return;
} }
auto session = m_Owner.CreateSession (id, destination == SAM_VALUE_TRANSIENT ? "" : destination); m_Session = m_Owner.CreateSession (id, destination == SAM_VALUE_TRANSIENT ? "" : destination);
if (session) if (m_Session)
{ {
m_SocketType = eSAMSocketTypeSession; m_SocketType = eSAMSocketTypeSession;
size_t l = strlen (SAM_SESSION_CREATE_REPLY_OK); uint8_t buf[1024];
memcpy (m_Buffer, SAM_SESSION_CREATE_REPLY_OK, l); char priv[1024];
uint8_t ident[1024]; size_t l = m_Session->localDestination->GetPrivateKeys ().ToBuffer (buf, 1024);
size_t l1 = session->localDestination->GetPrivateKeys ().ToBuffer (ident, 1024); size_t l1 = i2p::data::ByteStreamToBase64 (buf, l, priv, 1024);
size_t l2 = i2p::data::ByteStreamToBase64 (ident, l1, m_Buffer + l, SAM_SOCKET_BUFFER_SIZE - l); priv[l1] = 0;
m_Buffer[l + l2] = '\n'; size_t l2 = snprintf (m_Buffer, SAM_SOCKET_BUFFER_SIZE, SAM_SESSION_CREATE_REPLY_OK, priv);
SendMessageReply (m_Buffer, l + l2 + 1, false); SendMessageReply (m_Buffer, l2, false);
} }
else else
SendMessageReply (SAM_SESSION_CREATE_DUPLICATED_DEST, strlen(SAM_SESSION_CREATE_DUPLICATED_DEST), true); SendMessageReply (SAM_SESSION_CREATE_DUPLICATED_DEST, strlen(SAM_SESSION_CREATE_DUPLICATED_DEST), true);
@ -339,14 +340,15 @@ 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& name = params[SAM_PARAM_NAME]; std::string& name = params[SAM_PARAM_NAME];
if (name == "ME") if (name == "ME" && m_Session)
{ {
/*uint8_t buf[1024]; uint8_t buf[1024];
char pub[1024]; char pub[1024];
size_t l = localDestination->GetIdentity ().ToBuffer (buf, 1024); size_t l = m_Session->localDestination->GetIdentity ().ToBuffer (buf, 1024);
size_t l1 = i2p::data::ByteStreamToBase64 (buf, l, pub, 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); pub[l1] = 0;
SendMessageReply (m_Buffer, len, false);*/ size_t l2 = snprintf (m_Buffer, SAM_SOCKET_BUFFER_SIZE, SAM_NAMING_REPLY, pub);
SendMessageReply (m_Buffer, l2, false);
} }
else else
{ {

3
SAM.h

@ -21,7 +21,7 @@ namespace stream
const char SAM_HANDSHAKE[] = "HELLO VERSION"; const char SAM_HANDSHAKE[] = "HELLO VERSION";
const char SAM_HANDSHAKE_REPLY[] = "HELLO REPLY RESULT=OK VERSION=3.1\n"; const char SAM_HANDSHAKE_REPLY[] = "HELLO REPLY RESULT=OK VERSION=3.1\n";
const char SAM_SESSION_CREATE[] = "SESSION CREATE"; const char SAM_SESSION_CREATE[] = "SESSION CREATE";
const char SAM_SESSION_CREATE_REPLY_OK[] = "SESSION STATUS RESULT=OK DESTINATION="; const char SAM_SESSION_CREATE_REPLY_OK[] = "SESSION STATUS RESULT=OK DESTINATION=%s\n";
const char SAM_SESSION_CREATE_DUPLICATED_ID[] = "SESSION STATUS RESULT=DUPLICATED_ID\n"; const char SAM_SESSION_CREATE_DUPLICATED_ID[] = "SESSION STATUS RESULT=DUPLICATED_ID\n";
const char SAM_SESSION_CREATE_DUPLICATED_DEST[] = "SESSION STATUS RESULT=DUPLICATED_DEST\n"; const char SAM_SESSION_CREATE_DUPLICATED_DEST[] = "SESSION STATUS RESULT=DUPLICATED_DEST\n";
const char SAM_STREAM_CONNECT[] = "STREAM CONNECT"; const char SAM_STREAM_CONNECT[] = "STREAM CONNECT";
@ -102,6 +102,7 @@ namespace stream
std::string m_ID; // nickname std::string m_ID; // nickname
bool m_IsSilent; bool m_IsSilent;
Stream * m_Stream; Stream * m_Stream;
SAMSession * m_Session;
}; };
struct SAMSession struct SAMSession

Loading…
Cancel
Save