Browse Source

address lookup

pull/509/merge
orignal 9 years ago
parent
commit
aa6bc8042a
  1. 34
      I2CP.cpp

34
I2CP.cpp

@ -13,6 +13,7 @@
#include "Log.h" #include "Log.h"
#include "Timestamp.h" #include "Timestamp.h"
#include "LeaseSet.h" #include "LeaseSet.h"
#include "ClientContext.h"
#include "I2CP.h" #include "I2CP.h"
namespace i2p namespace i2p
@ -390,17 +391,38 @@ namespace client
{ {
uint32_t requestID = bufbe32toh (buf + 2); uint32_t requestID = bufbe32toh (buf + 2);
//uint32_t timeout = bufbe32toh (buf + 6); //uint32_t timeout = bufbe32toh (buf + 6);
if (!buf[10]) // request type = 0 (hash) i2p::data::IdentHash ident;
switch (buf[10])
{ {
case 0: // hash
ident = i2p::data::IdentHash (buf + 11);
break;
case 1: // address
{
auto name = ExtractString (buf + 11, len - 11);
if (!i2p::client::context.GetAddressBook ().GetIdentHash (name, ident))
{
LogPrint (eLogError, "I2CP: address ", name, " not found");
SendHostReplyMessage (requestID, nullptr);
return;
}
break;
}
default:
LogPrint (eLogError, "I2CP: request type ", (int)buf[10], " is not supported");
SendHostReplyMessage (requestID, nullptr);
return;
}
if (m_Destination) if (m_Destination)
{ {
auto ls = m_Destination->FindLeaseSet (buf + 11); auto ls = m_Destination->FindLeaseSet (ident);
if (ls) if (ls)
SendHostReplyMessage (requestID, ls->GetIdentity ()); SendHostReplyMessage (requestID, ls->GetIdentity ());
else else
{ {
auto s = shared_from_this (); auto s = shared_from_this ();
m_Destination->RequestDestination (buf + 11, m_Destination->RequestDestination (ident,
[s, requestID](std::shared_ptr<i2p::data::LeaseSet> leaseSet) [s, requestID](std::shared_ptr<i2p::data::LeaseSet> leaseSet)
{ {
s->SendHostReplyMessage (requestID, leaseSet ? leaseSet->GetIdentity () : nullptr); s->SendHostReplyMessage (requestID, leaseSet ? leaseSet->GetIdentity () : nullptr);
@ -410,12 +432,6 @@ namespace client
else else
SendHostReplyMessage (requestID, nullptr); SendHostReplyMessage (requestID, nullptr);
} }
else
{
LogPrint (eLogError, "I2CP: request type ", (int)buf[8], " is not supported");
SendHostReplyMessage (requestID, nullptr);
}
}
else else
LogPrint (eLogError, "I2CP: unexpected sessionID ", sessionID); LogPrint (eLogError, "I2CP: unexpected sessionID ", sessionID);
} }

Loading…
Cancel
Save