mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 13:27:17 +01:00
naming lookup through addressbook
This commit is contained in:
parent
fae01f61d2
commit
68c321609d
|
@ -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
|
|||
{
|
||||
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);
|
||||
|
|
|
@ -33,10 +33,14 @@ 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:
|
||||
|
||||
void LoadHosts ();
|
||||
void LoadHostsFromI2P ();
|
||||
|
||||
|
|
13
SAM.cpp
13
SAM.cpp
|
@ -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
|
|||
}
|
||||
|
||||
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
1
SAM.h
|
@ -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…
Reference in a new issue