Browse Source

store SAM destinations if address book

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

12
AddressBook.cpp

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

37
SAM.cpp

@ -291,6 +291,7 @@ namespace client
size_t l = i2p::data::Base64ToByteStream (destination.c_str (), destination.length (), ident, 1024); size_t l = i2p::data::Base64ToByteStream (destination.c_str (), destination.length (), ident, 1024);
i2p::data::IdentityEx dest; i2p::data::IdentityEx dest;
dest.FromBuffer (ident, l); dest.FromBuffer (ident, l);
context.GetAddressBook ().InsertAddress (dest);
auto leaseSet = i2p::data::netdb.FindLeaseSet (dest.GetIdentHash ()); auto leaseSet = i2p::data::netdb.FindLeaseSet (dest.GetIdentHash ());
if (leaseSet) if (leaseSet)
Connect (*leaseSet); Connect (*leaseSet);
@ -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) void SAMSocket::ProcessStreamAccept (char * buf, size_t len)
{ {
LogPrint ("SAM stream accept: ", buf); LogPrint ("SAM stream accept: ", buf);
@ -415,20 +396,7 @@ namespace client
SendNamingLookupReply (nullptr); SendNamingLookupReply (nullptr);
else if (context.GetAddressBook ().GetAddress (name, identity)) else if (context.GetAddressBook ().GetAddress (name, identity))
SendNamingLookupReply (identity); SendNamingLookupReply (identity);
else if (m_Session && context.GetAddressBook ().GetIdentHash (name, ident)) else
{
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 #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());
@ -547,6 +515,7 @@ namespace client
{ {
LogPrint ("SAM incoming I2P connection for session ", m_ID); LogPrint ("SAM incoming I2P connection for session ", m_ID);
m_Stream = stream; m_Stream = stream;
context.GetAddressBook ().InsertAddress (stream->GetRemoteIdentity ());
auto session = m_Owner.FindSession (m_ID); auto session = m_Owner.FindSession (m_ID);
if (session) if (session)
session->localDestination->StopAcceptingStreams (); session->localDestination->StopAcceptingStreams ();

1
SAM.h

@ -103,7 +103,6 @@ namespace client
void Connect (const i2p::data::LeaseSet& remote); void Connect (const i2p::data::LeaseSet& remote);
void HandleStreamDestinationRequestTimer (const boost::system::error_code& ecode, i2p::data::IdentHash ident); 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::LeaseSet * leaseSet);
void SendNamingLookupReply (const i2p::data::IdentityEx& identity); void SendNamingLookupReply (const i2p::data::IdentityEx& identity);
void HandleSessionReadinessCheckTimer (const boost::system::error_code& ecode); void HandleSessionReadinessCheckTimer (const boost::system::error_code& ecode);

Loading…
Cancel
Save