Browse Source

store SAM destinations if address book

pull/113/head
orignal 10 years ago
parent
commit
8350f16b20
  1. 12
      AddressBook.cpp
  2. 35
      SAM.cpp
  3. 1
      SAM.h

12
AddressBook.cpp

@ -151,7 +151,11 @@ namespace client @@ -151,7 +151,11 @@ namespace client
AddressBook::~AddressBook ()
{
delete m_Storage;
if (m_Storage)
{
m_Storage->Save (m_Addresses);
delete m_Storage;
}
}
AddressBookStorage * AddressBook::CreateStorage ()
@ -218,9 +222,9 @@ namespace client @@ -218,9 +222,9 @@ namespace client
{
if (!m_Storage)
m_Storage = CreateStorage ();
auto ident = FindAddress (address);
if (!ident) return false;
return m_Storage->GetAddress (*ident, identity);
i2p::data::IdentHash ident;
if (!GetIdentHash (address, ident)) return false;
return m_Storage->GetAddress (ident, identity);
}
void AddressBook::LoadHostsFromI2P ()

35
SAM.cpp

@ -291,6 +291,7 @@ namespace client @@ -291,6 +291,7 @@ namespace client
size_t l = i2p::data::Base64ToByteStream (destination.c_str (), destination.length (), ident, 1024);
i2p::data::IdentityEx dest;
dest.FromBuffer (ident, l);
context.GetAddressBook ().InsertAddress (dest);
auto leaseSet = i2p::data::netdb.FindLeaseSet (dest.GetIdentHash ());
if (leaseSet)
Connect (*leaseSet);
@ -331,26 +332,6 @@ namespace client @@ -331,26 +332,6 @@ namespace client
}
}
void SAMSocket::HandleNamingLookupDestinationRequestTimer (const boost::system::error_code& ecode, i2p::data::IdentHash ident)
{
if (!ecode) // timeout expired
{
auto leaseSet = m_Session->localDestination->FindLeaseSet (ident);
if (leaseSet)
SendNamingLookupReply (leaseSet);
else
{
LogPrint ("SAM name destination not found");
#ifdef _MSC_VER
size_t len = sprintf_s (m_Buffer, SAM_SOCKET_BUFFER_SIZE, SAM_NAMING_REPLY_KEY_NOT_FOUND, (ident.ToBase32 () + ".b32.i2p").c_str ());
#else
size_t len = snprintf (m_Buffer, SAM_SOCKET_BUFFER_SIZE, SAM_NAMING_REPLY_KEY_NOT_FOUND, (ident.ToBase32 () + ".b32.i2p").c_str ());
#endif
SendMessageReply (m_Buffer, len, false);
}
}
}
void SAMSocket::ProcessStreamAccept (char * buf, size_t len)
{
LogPrint ("SAM stream accept: ", buf);
@ -415,19 +396,6 @@ namespace client @@ -415,19 +396,6 @@ namespace client
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);
if (leaseSet)
SendNamingLookupReply (leaseSet);
else
{
i2p::data::netdb.RequestDestination (ident, true, m_Session->localDestination->GetTunnelPool ());
m_Timer.expires_from_now (boost::posix_time::seconds(SAM_NAMING_LOOKUP_TIMEOUT));
m_Timer.async_wait (std::bind (&SAMSocket::HandleNamingLookupDestinationRequestTimer,
shared_from_this (), std::placeholders::_1, ident));
}
}
else
{
#ifdef _MSC_VER
@ -547,6 +515,7 @@ namespace client @@ -547,6 +515,7 @@ namespace client
{
LogPrint ("SAM incoming I2P connection for session ", m_ID);
m_Stream = stream;
context.GetAddressBook ().InsertAddress (stream->GetRemoteIdentity ());
auto session = m_Owner.FindSession (m_ID);
if (session)
session->localDestination->StopAcceptingStreams ();

1
SAM.h

@ -103,7 +103,6 @@ namespace client @@ -103,7 +103,6 @@ namespace client
void Connect (const i2p::data::LeaseSet& remote);
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);

Loading…
Cancel
Save