diff --git a/AddressBook.cpp b/AddressBook.cpp index 2d0d2624..7fc39841 100644 --- a/AddressBook.cpp +++ b/AddressBook.cpp @@ -11,14 +11,14 @@ namespace i2p { -namespace data +namespace client { AddressBook::AddressBook (): m_IsLoaded (false), m_IsDowloading (false) { } - bool AddressBook::GetIdentHash (const std::string& address, IdentHash& ident) + bool AddressBook::GetIdentHash (const std::string& address, i2p::data::IdentHash& ident) { auto pos = address.find(".b32.i2p"); if (pos != std::string::npos) @@ -42,7 +42,7 @@ namespace data return false; } - const IdentHash * AddressBook::FindAddress (const std::string& address) + const i2p::data::IdentHash * AddressBook::FindAddress (const std::string& address) { if (!m_IsLoaded) LoadHosts (); @@ -57,7 +57,7 @@ namespace data void AddressBook::InsertAddress (const std::string& address, const std::string& base64) { - IdentityEx ident; + i2p::data::IdentityEx ident; ident.FromBase64 (base64); m_Addresses[address] = ident.GetIdentHash (); LogPrint (address,"->",ident.GetIdentHash ().ToBase32 (), ".b32.i2p added"); @@ -118,7 +118,7 @@ namespace data std::string name = s.substr(0, pos++); std::string addr = s.substr(pos); - IdentityEx ident; + i2p::data::IdentityEx ident; ident.FromBase64(addr); m_Addresses[name] = ident.GetIdentHash (); numAddresses++; diff --git a/AddressBook.h b/AddressBook.h index db9d2319..8131a032 100644 --- a/AddressBook.h +++ b/AddressBook.h @@ -11,15 +11,15 @@ namespace i2p { -namespace data +namespace client { class AddressBook { public: AddressBook (); - bool GetIdentHash (const std::string& address, IdentHash& ident); - const IdentHash * FindAddress (const std::string& address); + bool GetIdentHash (const std::string& address, i2p::data::IdentHash& ident); + const i2p::data::IdentHash * FindAddress (const std::string& address); void InsertAddress (const std::string& address, const std::string& base64); // for jump service private: @@ -27,7 +27,7 @@ namespace data void LoadHosts (); void LoadHostsFromI2P (); - std::map m_Addresses; + std::map m_Addresses; bool m_IsLoaded, m_IsDowloading; }; } diff --git a/ClientContext.h b/ClientContext.h index 58c2cf36..da65f3f8 100644 --- a/ClientContext.h +++ b/ClientContext.h @@ -7,6 +7,7 @@ #include "SOCKS.h" #include "I2PTunnel.h" #include "SAM.h" +#include "AddressBook.h" namespace i2p { @@ -29,6 +30,8 @@ namespace client ClientDestination * FindLocalDestination (const i2p::data::IdentHash& destination) const; ClientDestination * LoadLocalDestination (const std::string& filename, bool isPublic); + AddressBook& GetAddressBook () { return m_AddressBook; }; + private: void LoadLocalDestinations (); @@ -39,6 +42,8 @@ namespace client std::map m_Destinations; ClientDestination * m_SharedLocalDestination; + AddressBook m_AddressBook; + i2p::proxy::HTTPProxy * m_HttpProxy; i2p::proxy::SOCKSProxy * m_SocksProxy; I2PClientTunnel * m_IrcTunnel; diff --git a/HTTPProxy.cpp b/HTTPProxy.cpp index a3d95842..ae644b6a 100644 --- a/HTTPProxy.cpp +++ b/HTTPProxy.cpp @@ -1,7 +1,7 @@ #include #include -#include "NetDb.h" +#include "ClientContext.h" #include "HTTPProxy.h" namespace i2p @@ -74,7 +74,7 @@ namespace proxy { LogPrint ("Jump service for ", r.host, " found. Inserting to address book"); auto base64 = r.uri.substr (addressPos + 1); - i2p::data::netdb.GetAddressBook ().InsertAddress (r.host, base64); + i2p::client::context.GetAddressBook ().InsertAddress (r.host, base64); } } diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 3a0aedc9..3f385af6 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -845,7 +845,7 @@ namespace util void HTTPConnection::SendToAddress (const std::string& address, int port, const char * buf, size_t len) { i2p::data::IdentHash destination; - if (!i2p::data::netdb.GetAddressBook ().GetIdentHash (address, destination)) + if (!i2p::client::context.GetAddressBook ().GetIdentHash (address, destination)) { LogPrint ("Unknown address ", address); SendReply ("" + itoopieImage + "
Unknown address " + address + "", 404); diff --git a/I2PTunnel.cpp b/I2PTunnel.cpp index a8193bdd..8dadabae 100644 --- a/I2PTunnel.cpp +++ b/I2PTunnel.cpp @@ -162,7 +162,7 @@ namespace client void I2PClientTunnel::Start () { i2p::data::IdentHash identHash; - if (i2p::data::netdb.GetAddressBook ().GetIdentHash (m_Destination, identHash)) + if (i2p::client::context.GetAddressBook ().GetIdentHash (m_Destination, identHash)) m_DestinationIdentHash = new i2p::data::IdentHash (identHash); if (!m_DestinationIdentHash) LogPrint ("I2PTunnel unknown destination ", m_Destination); @@ -192,7 +192,7 @@ namespace client if (!m_DestinationIdentHash) { i2p::data::IdentHash identHash; - if (i2p::data::netdb.GetAddressBook ().GetIdentHash (m_Destination, identHash)) + if (i2p::client::context.GetAddressBook ().GetIdentHash (m_Destination, identHash)) m_DestinationIdentHash = new i2p::data::IdentHash (identHash); } if (m_DestinationIdentHash) diff --git a/NetDb.h b/NetDb.h index ca62163c..384d1c80 100644 --- a/NetDb.h +++ b/NetDb.h @@ -15,7 +15,6 @@ #include "LeaseSet.h" #include "Tunnel.h" #include "TunnelPool.h" -#include "AddressBook.h" namespace i2p { @@ -67,7 +66,6 @@ namespace data void AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len, i2p::tunnel::InboundTunnel * from); RouterInfo * FindRouter (const IdentHash& ident) const; LeaseSet * FindLeaseSet (const IdentHash& destination) const; - AddressBook& GetAddressBook () { return m_AddressBook; };// TODO: move AddressBook away from NetDb void PublishLeaseSet (const LeaseSet * leaseSet, i2p::tunnel::TunnelPool * pool); void RequestDestination (const IdentHash& destination, bool isLeaseSet = false, @@ -120,7 +118,6 @@ namespace data int m_ReseedRetries; std::thread * m_Thread; i2p::util::Queue m_Queue; // of I2NPDatabaseStoreMsg - AddressBook m_AddressBook; static const char m_NetDbPath[]; }; diff --git a/SAM.cpp b/SAM.cpp index 7f9f4b9f..cd976aa4 100644 --- a/SAM.cpp +++ b/SAM.cpp @@ -401,7 +401,7 @@ namespace client i2p::data::IdentHash ident; if (name == "ME") SendNamingLookupReply (nullptr); - else if (m_Session && i2p::data::netdb.GetAddressBook ().GetIdentHash (name, ident)) + else if (m_Session && context.GetAddressBook ().GetIdentHash (name, ident)) { auto leaseSet = m_Session->localDestination->FindLeaseSet (ident); if (leaseSet)