i2pd/AddressBook.h

60 lines
1.5 KiB
C
Raw Normal View History

2014-03-13 19:22:32 +01:00
#ifndef ADDRESS_BOOK_H__
#define ADDRESS_BOOK_H__
#include <string.h>
#include <string>
#include <map>
#include "base64.h"
#include "util.h"
#include "Identity.h"
#include "Log.h"
namespace i2p
{
2014-10-24 21:22:36 +02:00
namespace client
2014-03-13 19:22:32 +01:00
{
2014-11-26 22:19:36 +01:00
class AddressBookStorage // interface for storage
{
public:
virtual ~AddressBookStorage () {};
2014-11-28 15:40:27 +01:00
virtual bool GetAddress (const i2p::data::IdentHash& ident, i2p::data::IdentityEx& address) const = 0;
2014-11-26 22:19:36 +01:00
virtual void AddAddress (const i2p::data::IdentityEx& address) = 0;
virtual void RemoveAddress (const i2p::data::IdentHash& ident) = 0;
2014-11-27 22:26:55 +01:00
2014-11-28 15:40:27 +01:00
virtual int Load (std::map<std::string, i2p::data::IdentHash>& addresses) = 0;
virtual int Save (const std::map<std::string, i2p::data::IdentHash>& addresses) = 0;
2014-11-26 22:19:36 +01:00
};
2014-03-13 19:22:32 +01:00
class AddressBook
{
public:
2014-04-01 21:18:14 +02:00
AddressBook ();
2014-11-26 22:19:36 +01:00
~AddressBook ();
2014-10-24 21:22:36 +02:00
bool GetIdentHash (const std::string& address, i2p::data::IdentHash& ident);
2014-11-26 22:19:36 +01:00
bool GetAddress (const std::string& address, i2p::data::IdentityEx& identity);
2014-10-24 21:22:36 +02:00
const i2p::data::IdentHash * FindAddress (const std::string& address);
2014-09-23 21:38:56 +02:00
void InsertAddress (const std::string& address, const std::string& base64); // for jump service
2014-11-26 22:51:36 +01:00
void InsertAddress (const i2p::data::IdentityEx& address);
2014-03-13 19:22:32 +01:00
private:
2014-11-26 22:51:36 +01:00
AddressBookStorage * CreateStorage ();
private:
2014-04-01 21:18:14 +02:00
void LoadHosts ();
void LoadHostsFromI2P ();
2014-03-13 19:22:32 +01:00
2014-10-24 21:22:36 +02:00
std::map<std::string, i2p::data::IdentHash> m_Addresses;
2014-11-26 22:19:36 +01:00
AddressBookStorage * m_Storage;
bool m_IsLoaded, m_IsDowloading;
2014-03-13 19:22:32 +01:00
};
}
}
#endif