Browse Source

naming lookup of .b32 address through LeaseSet request

pull/151/head
orignal 10 years ago
parent
commit
588c613043
  1. 48
      SAM.cpp
  2. 4
      SAM.h

48
SAM.cpp

@ -326,7 +326,7 @@ namespace client
else else
{ {
m_Session->localDestination->RequestDestination (dest.GetIdentHash (), m_Session->localDestination->RequestDestination (dest.GetIdentHash (),
std::bind (&SAMSocket::HandleLeaseSetRequestComplete, std::bind (&SAMSocket::HandleConnectLeaseSetRequestComplete,
shared_from_this (), std::placeholders::_1, dest.GetIdentHash ())); shared_from_this (), std::placeholders::_1, dest.GetIdentHash ()));
} }
} }
@ -344,7 +344,7 @@ namespace client
SendMessageReply (SAM_STREAM_STATUS_OK, strlen(SAM_STREAM_STATUS_OK), false); SendMessageReply (SAM_STREAM_STATUS_OK, strlen(SAM_STREAM_STATUS_OK), false);
} }
void SAMSocket::HandleLeaseSetRequestComplete (bool success, i2p::data::IdentHash ident) void SAMSocket::HandleConnectLeaseSetRequestComplete (bool success, i2p::data::IdentHash ident)
{ {
const i2p::data::LeaseSet * leaseSet = nullptr; const i2p::data::LeaseSet * leaseSet = nullptr;
if (success) // timeout expired if (success) // timeout expired
@ -409,14 +409,25 @@ namespace client
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];
i2p::data::IdentHash ident;
i2p::data::IdentityEx identity; i2p::data::IdentityEx identity;
i2p::data::IdentHash ident;
if (name == "ME") if (name == "ME")
SendNamingLookupReply (nullptr); SendNamingLookupReply (m_Session->localDestination->GetIdentity ());
else if (context.GetAddressBook ().GetAddress (name, identity)) else if (context.GetAddressBook ().GetAddress (name, identity))
SendNamingLookupReply (identity); SendNamingLookupReply (identity);
else if (context.GetAddressBook ().GetIdentHash (name, ident))
{
auto leaseSet = i2p::data::netdb.FindLeaseSet (ident);
if (leaseSet)
SendNamingLookupReply (leaseSet->GetIdentity ());
else
m_Session->localDestination->RequestDestination (ident,
std::bind (&SAMSocket::HandleNamingLookupLeaseSetRequestComplete,
shared_from_this (), std::placeholders::_1, ident));
}
else else
{ {
LogPrint ("SAM naming failed. Unknown address ", name);
#ifdef _MSC_VER #ifdef _MSC_VER
size_t len = sprintf_s (m_Buffer, SAM_SOCKET_BUFFER_SIZE, SAM_NAMING_REPLY_INVALID_KEY, name.c_str()); size_t len = sprintf_s (m_Buffer, SAM_SOCKET_BUFFER_SIZE, SAM_NAMING_REPLY_INVALID_KEY, name.c_str());
#else #else
@ -426,15 +437,30 @@ namespace client
} }
} }
void SAMSocket::SendNamingLookupReply (const i2p::data::LeaseSet * leaseSet) void SAMSocket::HandleNamingLookupLeaseSetRequestComplete (bool success, i2p::data::IdentHash ident)
{ {
const i2p::data::IdentityEx& identity = leaseSet ? leaseSet->GetIdentity () : m_Session->localDestination->GetIdentity (); const i2p::data::LeaseSet * leaseSet = nullptr;
if (success)
leaseSet = m_Session->localDestination->FindLeaseSet (ident);
if (leaseSet) if (leaseSet)
// we found LeaseSet for our address, store it to addressbook {
context.GetAddressBook ().InsertAddress (identity); context.GetAddressBook ().InsertAddress (leaseSet->GetIdentity ());
SendNamingLookupReply (identity); SendNamingLookupReply (leaseSet->GetIdentity ());
} }
else
{
LogPrint (eLogInfo, "SAM naming lookup failed. LeaseSet for ", ident.ToBase32 (), " not found");
#ifdef _MSC_VER
size_t len = sprintf_s (m_Buffer, SAM_SOCKET_BUFFER_SIZE, SAM_NAMING_REPLY_INVALID_KEY,
context.GetAddressBook ().ToAddress (ident).c_str());
#else
size_t len = snprintf (m_Buffer, SAM_SOCKET_BUFFER_SIZE, SAM_NAMING_REPLY_INVALID_KEY,
context.GetAddressBook ().ToAddress (ident).c_str());
#endif
SendMessageReply (m_Buffer, len, false);
}
}
void SAMSocket::SendNamingLookupReply (const i2p::data::IdentityEx& identity) void SAMSocket::SendNamingLookupReply (const i2p::data::IdentityEx& identity)
{ {
auto base64 = identity.ToBase64 (); auto base64 = identity.ToBase64 ();

4
SAM.h

@ -105,9 +105,9 @@ namespace client
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); void Connect (const i2p::data::LeaseSet& remote);
void HandleLeaseSetRequestComplete (bool success, i2p::data::IdentHash ident); void HandleConnectLeaseSetRequestComplete (bool success, i2p::data::IdentHash ident);
void SendNamingLookupReply (const i2p::data::LeaseSet * leaseSet);
void SendNamingLookupReply (const i2p::data::IdentityEx& identity); void SendNamingLookupReply (const i2p::data::IdentityEx& identity);
void HandleNamingLookupLeaseSetRequestComplete (bool success, i2p::data::IdentHash ident);
void HandleSessionReadinessCheckTimer (const boost::system::error_code& ecode); void HandleSessionReadinessCheckTimer (const boost::system::error_code& ecode);
void SendSessionCreateReplyOk (); void SendSessionCreateReplyOk ();

Loading…
Cancel
Save