Browse Source

moved AddressBook to ClientContext

pull/105/head
orignal 10 years ago
parent
commit
af997473b2
  1. 10
      AddressBook.cpp
  2. 8
      AddressBook.h
  3. 5
      ClientContext.h
  4. 4
      HTTPProxy.cpp
  5. 2
      HTTPServer.cpp
  6. 4
      I2PTunnel.cpp
  7. 3
      NetDb.h
  8. 2
      SAM.cpp

10
AddressBook.cpp

@ -11,14 +11,14 @@
namespace i2p namespace i2p
{ {
namespace data namespace client
{ {
AddressBook::AddressBook (): m_IsLoaded (false), m_IsDowloading (false) 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"); auto pos = address.find(".b32.i2p");
if (pos != std::string::npos) if (pos != std::string::npos)
@ -42,7 +42,7 @@ namespace data
return false; return false;
} }
const IdentHash * AddressBook::FindAddress (const std::string& address) const i2p::data::IdentHash * AddressBook::FindAddress (const std::string& address)
{ {
if (!m_IsLoaded) if (!m_IsLoaded)
LoadHosts (); LoadHosts ();
@ -57,7 +57,7 @@ namespace data
void AddressBook::InsertAddress (const std::string& address, const std::string& base64) void AddressBook::InsertAddress (const std::string& address, const std::string& base64)
{ {
IdentityEx ident; i2p::data::IdentityEx ident;
ident.FromBase64 (base64); ident.FromBase64 (base64);
m_Addresses[address] = ident.GetIdentHash (); m_Addresses[address] = ident.GetIdentHash ();
LogPrint (address,"->",ident.GetIdentHash ().ToBase32 (), ".b32.i2p added"); LogPrint (address,"->",ident.GetIdentHash ().ToBase32 (), ".b32.i2p added");
@ -118,7 +118,7 @@ namespace data
std::string name = s.substr(0, pos++); std::string name = s.substr(0, pos++);
std::string addr = s.substr(pos); std::string addr = s.substr(pos);
IdentityEx ident; i2p::data::IdentityEx ident;
ident.FromBase64(addr); ident.FromBase64(addr);
m_Addresses[name] = ident.GetIdentHash (); m_Addresses[name] = ident.GetIdentHash ();
numAddresses++; numAddresses++;

8
AddressBook.h

@ -11,15 +11,15 @@
namespace i2p namespace i2p
{ {
namespace data namespace client
{ {
class AddressBook class AddressBook
{ {
public: public:
AddressBook (); AddressBook ();
bool GetIdentHash (const std::string& address, IdentHash& ident); bool GetIdentHash (const std::string& address, i2p::data::IdentHash& ident);
const IdentHash * FindAddress (const std::string& address); 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 std::string& address, const std::string& base64); // for jump service
private: private:
@ -27,7 +27,7 @@ namespace data
void LoadHosts (); void LoadHosts ();
void LoadHostsFromI2P (); void LoadHostsFromI2P ();
std::map<std::string, IdentHash> m_Addresses; std::map<std::string, i2p::data::IdentHash> m_Addresses;
bool m_IsLoaded, m_IsDowloading; bool m_IsLoaded, m_IsDowloading;
}; };
} }

5
ClientContext.h

@ -7,6 +7,7 @@
#include "SOCKS.h" #include "SOCKS.h"
#include "I2PTunnel.h" #include "I2PTunnel.h"
#include "SAM.h" #include "SAM.h"
#include "AddressBook.h"
namespace i2p namespace i2p
{ {
@ -29,6 +30,8 @@ namespace client
ClientDestination * FindLocalDestination (const i2p::data::IdentHash& destination) const; ClientDestination * FindLocalDestination (const i2p::data::IdentHash& destination) const;
ClientDestination * LoadLocalDestination (const std::string& filename, bool isPublic); ClientDestination * LoadLocalDestination (const std::string& filename, bool isPublic);
AddressBook& GetAddressBook () { return m_AddressBook; };
private: private:
void LoadLocalDestinations (); void LoadLocalDestinations ();
@ -39,6 +42,8 @@ namespace client
std::map<i2p::data::IdentHash, ClientDestination *> m_Destinations; std::map<i2p::data::IdentHash, ClientDestination *> m_Destinations;
ClientDestination * m_SharedLocalDestination; ClientDestination * m_SharedLocalDestination;
AddressBook m_AddressBook;
i2p::proxy::HTTPProxy * m_HttpProxy; i2p::proxy::HTTPProxy * m_HttpProxy;
i2p::proxy::SOCKSProxy * m_SocksProxy; i2p::proxy::SOCKSProxy * m_SocksProxy;
I2PClientTunnel * m_IrcTunnel; I2PClientTunnel * m_IrcTunnel;

4
HTTPProxy.cpp

@ -1,7 +1,7 @@
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/regex.hpp> #include <boost/regex.hpp>
#include "NetDb.h" #include "ClientContext.h"
#include "HTTPProxy.h" #include "HTTPProxy.h"
namespace i2p namespace i2p
@ -74,7 +74,7 @@ namespace proxy
{ {
LogPrint ("Jump service for ", r.host, " found. Inserting to address book"); LogPrint ("Jump service for ", r.host, " found. Inserting to address book");
auto base64 = r.uri.substr (addressPos + 1); auto base64 = r.uri.substr (addressPos + 1);
i2p::data::netdb.GetAddressBook ().InsertAddress (r.host, base64); i2p::client::context.GetAddressBook ().InsertAddress (r.host, base64);
} }
} }

2
HTTPServer.cpp

@ -845,7 +845,7 @@ namespace util
void HTTPConnection::SendToAddress (const std::string& address, int port, const char * buf, size_t len) void HTTPConnection::SendToAddress (const std::string& address, int port, const char * buf, size_t len)
{ {
i2p::data::IdentHash destination; i2p::data::IdentHash destination;
if (!i2p::data::netdb.GetAddressBook ().GetIdentHash (address, destination)) if (!i2p::client::context.GetAddressBook ().GetIdentHash (address, destination))
{ {
LogPrint ("Unknown address ", address); LogPrint ("Unknown address ", address);
SendReply ("<html>" + itoopieImage + "<br>Unknown address " + address + "</html>", 404); SendReply ("<html>" + itoopieImage + "<br>Unknown address " + address + "</html>", 404);

4
I2PTunnel.cpp

@ -162,7 +162,7 @@ namespace client
void I2PClientTunnel::Start () void I2PClientTunnel::Start ()
{ {
i2p::data::IdentHash identHash; 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); m_DestinationIdentHash = new i2p::data::IdentHash (identHash);
if (!m_DestinationIdentHash) if (!m_DestinationIdentHash)
LogPrint ("I2PTunnel unknown destination ", m_Destination); LogPrint ("I2PTunnel unknown destination ", m_Destination);
@ -192,7 +192,7 @@ namespace client
if (!m_DestinationIdentHash) if (!m_DestinationIdentHash)
{ {
i2p::data::IdentHash identHash; 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); m_DestinationIdentHash = new i2p::data::IdentHash (identHash);
} }
if (m_DestinationIdentHash) if (m_DestinationIdentHash)

3
NetDb.h

@ -15,7 +15,6 @@
#include "LeaseSet.h" #include "LeaseSet.h"
#include "Tunnel.h" #include "Tunnel.h"
#include "TunnelPool.h" #include "TunnelPool.h"
#include "AddressBook.h"
namespace i2p namespace i2p
{ {
@ -67,7 +66,6 @@ namespace data
void AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len, i2p::tunnel::InboundTunnel * from); void AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len, i2p::tunnel::InboundTunnel * from);
RouterInfo * FindRouter (const IdentHash& ident) const; RouterInfo * FindRouter (const IdentHash& ident) const;
LeaseSet * FindLeaseSet (const IdentHash& destination) 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 PublishLeaseSet (const LeaseSet * leaseSet, i2p::tunnel::TunnelPool * pool);
void RequestDestination (const IdentHash& destination, bool isLeaseSet = false, void RequestDestination (const IdentHash& destination, bool isLeaseSet = false,
@ -120,7 +118,6 @@ namespace data
int m_ReseedRetries; int m_ReseedRetries;
std::thread * m_Thread; std::thread * m_Thread;
i2p::util::Queue<I2NPMessage> m_Queue; // of I2NPDatabaseStoreMsg i2p::util::Queue<I2NPMessage> m_Queue; // of I2NPDatabaseStoreMsg
AddressBook m_AddressBook;
static const char m_NetDbPath[]; static const char m_NetDbPath[];
}; };

2
SAM.cpp

@ -401,7 +401,7 @@ namespace client
i2p::data::IdentHash ident; i2p::data::IdentHash ident;
if (name == "ME") if (name == "ME")
SendNamingLookupReply (nullptr); 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); auto leaseSet = m_Session->localDestination->FindLeaseSet (ident);
if (leaseSet) if (leaseSet)

Loading…
Cancel
Save