Browse Source

naming lookup through addressbook

pull/113/head
orignal 10 years ago
parent
commit
68c321609d
  1. 18
      AddressBook.cpp
  2. 4
      AddressBook.h
  3. 13
      SAM.cpp
  4. 1
      SAM.h

18
AddressBook.cpp

@ -98,6 +98,11 @@ namespace client @@ -98,6 +98,11 @@ namespace client
delete m_Storage;
}
AddressBookStorage * AddressBook::CreateStorage ()
{
return new AddressBookFilesystemStorage ();
}
bool AddressBook::GetIdentHash (const std::string& address, i2p::data::IdentHash& ident)
{
auto pos = address.find(".b32.i2p");
@ -139,15 +144,24 @@ namespace client @@ -139,15 +144,24 @@ namespace client
{
i2p::data::IdentityEx ident;
ident.FromBase64 (base64);
if (m_Storage) m_Storage->AddAddress (ident);
if (!m_Storage)
m_Storage = CreateStorage ();
m_Storage->AddAddress (ident);
m_Addresses[address] = ident.GetIdentHash ();
LogPrint (address,"->",ident.GetIdentHash ().ToBase32 (), ".b32.i2p added");
}
void AddressBook::InsertAddress (const i2p::data::IdentityEx& address)
{
if (!m_Storage)
m_Storage = CreateStorage ();
m_Storage->AddAddress (address);
}
bool AddressBook::GetAddress (const std::string& address, i2p::data::IdentityEx& identity)
{
if (!m_Storage)
m_Storage = new AddressBookFilesystemStorage ();
m_Storage = CreateStorage ();
auto ident = FindAddress (address);
if (!ident) return false;
return m_Storage->GetAddress (*ident, identity);

4
AddressBook.h

@ -33,7 +33,11 @@ namespace client @@ -33,7 +33,11 @@ namespace client
bool GetAddress (const std::string& address, i2p::data::IdentityEx& identity);
const i2p::data::IdentHash * FindAddress (const std::string& address);
void InsertAddress (const std::string& address, const std::string& base64); // for jump service
void InsertAddress (const i2p::data::IdentityEx& address);
private:
AddressBookStorage * CreateStorage ();
private:

13
SAM.cpp

@ -410,8 +410,11 @@ namespace client @@ -410,8 +410,11 @@ namespace client
ExtractParams (buf, len, params);
std::string& name = params[SAM_PARAM_NAME];
i2p::data::IdentHash ident;
i2p::data::IdentityEx identity;
if (name == "ME")
SendNamingLookupReply (nullptr);
else if (context.GetAddressBook ().GetAddress (name, identity))
SendNamingLookupReply (identity);
else if (m_Session && context.GetAddressBook ().GetIdentHash (name, ident))
{
auto leaseSet = m_Session->localDestination->FindLeaseSet (ident);
@ -437,10 +440,18 @@ namespace client @@ -437,10 +440,18 @@ namespace client
}
void SAMSocket::SendNamingLookupReply (const i2p::data::LeaseSet * leaseSet)
{
const i2p::data::IdentityEx& identity = leaseSet ? leaseSet->GetIdentity () : m_Session->localDestination->GetIdentity ();
if (leaseSet)
// we found LeaseSet for our address, store it to addressbook
context.GetAddressBook ().InsertAddress (identity);
SendNamingLookupReply (identity);
}
void SAMSocket::SendNamingLookupReply (const i2p::data::IdentityEx& identity)
{
uint8_t buf[1024];
char pub[1024];
const i2p::data::IdentityEx& identity = leaseSet ? leaseSet->GetIdentity () : m_Session->localDestination->GetIdentity ();
size_t l = identity.ToBuffer (buf, 1024);
size_t l1 = i2p::data::ByteStreamToBase64 (buf, l, pub, 1024);
pub[l1] = 0;

1
SAM.h

@ -105,6 +105,7 @@ namespace client @@ -105,6 +105,7 @@ namespace client
void HandleStreamDestinationRequestTimer (const boost::system::error_code& ecode, i2p::data::IdentHash ident);
void HandleNamingLookupDestinationRequestTimer (const boost::system::error_code& ecode, i2p::data::IdentHash ident);
void SendNamingLookupReply (const i2p::data::LeaseSet * leaseSet);
void SendNamingLookupReply (const i2p::data::IdentityEx& identity);
void HandleSessionReadinessCheckTimer (const boost::system::error_code& ecode);
void SendSessionCreateReplyOk ();

Loading…
Cancel
Save