mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
split AddressBook header/source
This commit is contained in:
parent
81e06769dc
commit
aaa14d4564
62
AddressBook.cpp
Normal file
62
AddressBook.cpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
#include <string.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "base64.h"
|
||||
#include "util.h"
|
||||
#include "Identity.h"
|
||||
#include "Log.h"
|
||||
#include "AddressBook.h"
|
||||
|
||||
namespace i2p
|
||||
{
|
||||
namespace data
|
||||
{
|
||||
|
||||
AddressBook::AddressBook (): m_IsLoaded (false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
const IdentHash * AddressBook::FindAddress (const std::string& address)
|
||||
{
|
||||
if (!m_IsLoaded)
|
||||
LoadHosts ();
|
||||
auto it = m_Addresses.find (address);
|
||||
if (it != m_Addresses.end ())
|
||||
return &it->second;
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
void AddressBook::LoadHosts ()
|
||||
{
|
||||
m_IsLoaded = true;
|
||||
std::ifstream f (i2p::util::filesystem::GetFullPath ("hosts.txt").c_str (), std::ofstream::in); // in text mode
|
||||
if (!f.is_open ())
|
||||
{
|
||||
LogPrint ("hosts.txt not found");
|
||||
return;
|
||||
}
|
||||
int numAddresses = 0;
|
||||
char str[1024];
|
||||
while (!f.eof ())
|
||||
{
|
||||
f.getline (str, 1024);
|
||||
char * key = strchr (str, '=');
|
||||
if (key)
|
||||
{
|
||||
*key = 0;
|
||||
key++;
|
||||
Identity ident;
|
||||
Base64ToByteStream (key, strlen(key), (uint8_t *)&ident, sizeof (ident));
|
||||
m_Addresses[str] = CalculateIdentHash (ident);
|
||||
numAddresses++;
|
||||
}
|
||||
}
|
||||
LogPrint (numAddresses, " addresses loaded");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -17,50 +17,12 @@ namespace data
|
|||
{
|
||||
public:
|
||||
|
||||
AddressBook (): m_IsLoaded (false) {};
|
||||
|
||||
const IdentHash * FindAddress (const std::string& address)
|
||||
{
|
||||
if (!m_IsLoaded)
|
||||
LoadHosts ();
|
||||
auto it = m_Addresses.find (address);
|
||||
if (it != m_Addresses.end ())
|
||||
return &it->second;
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
AddressBook ();
|
||||
const IdentHash * FindAddress (const std::string& address);
|
||||
|
||||
private:
|
||||
|
||||
void LoadHosts ()
|
||||
{
|
||||
m_IsLoaded = true;
|
||||
std::ifstream f (i2p::util::filesystem::GetFullPath ("hosts.txt").c_str (), std::ofstream::in); // in text mode
|
||||
if (!f.is_open ())
|
||||
{
|
||||
LogPrint ("hosts.txt not found");
|
||||
return;
|
||||
}
|
||||
int numAddresses = 0;
|
||||
char str[1024];
|
||||
while (!f.eof ())
|
||||
{
|
||||
f.getline (str, 1024);
|
||||
char * key = strchr (str, '=');
|
||||
if (key)
|
||||
{
|
||||
*key = 0;
|
||||
key++;
|
||||
Identity ident;
|
||||
Base64ToByteStream (key, strlen(key), (uint8_t *)&ident, sizeof (ident));
|
||||
m_Addresses[str] = CalculateIdentHash (ident);
|
||||
numAddresses++;
|
||||
}
|
||||
}
|
||||
LogPrint (numAddresses, " addresses loaded");
|
||||
}
|
||||
|
||||
private:
|
||||
void LoadHosts ();
|
||||
|
||||
std::map<std::string, IdentHash> m_Addresses;
|
||||
bool m_IsLoaded;
|
||||
|
|
2
Makefile
2
Makefile
|
@ -5,7 +5,7 @@ OBJECTS = obj/i2p.o obj/base64.o obj/NTCPSession.o obj/RouterInfo.o obj/Transpor
|
|||
obj/RouterContext.o obj/NetDb.o obj/LeaseSet.o obj/Tunnel.o obj/TunnelEndpoint.o \
|
||||
obj/TunnelGateway.o obj/TransitTunnel.o obj/I2NPProtocol.o obj/Log.o obj/Garlic.o \
|
||||
obj/HTTPServer.o obj/Streaming.o obj/Identity.o obj/SSU.o obj/util.o obj/Reseed.o \
|
||||
obj/UPnP.o obj/TunnelPool.o obj/HTTPProxy.o
|
||||
obj/UPnP.o obj/TunnelPool.o obj/HTTPProxy.o obj/AddressBook.o
|
||||
INCFLAGS =
|
||||
LDFLAGS = -Wl,-rpath,/usr/local/lib -lcryptopp -lboost_system -lboost_filesystem -lboost_regex -lboost_program_options -lpthread
|
||||
LIBS =
|
||||
|
|
Loading…
Reference in a new issue