forked from PurpleI2P/i2pd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cpubug
committed
Apr 1, 2014
1 parent
81e0676
commit aaa14d4
Showing
3 changed files
with
66 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters