mirror of https://github.com/PurpleI2P/i2pd.git
I2P: End-to-End encrypted and anonymous Internet
https://i2pd.website/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
3.9 KiB
111 lines
3.9 KiB
11 years ago
|
#ifndef ADDRESS_BOOK_H__
|
||
|
#define ADDRESS_BOOK_H__
|
||
|
|
||
|
#include <string.h>
|
||
|
#include <string>
|
||
|
#include <map>
|
||
10 years ago
|
#include <vector>
|
||
10 years ago
|
#include <iostream>
|
||
10 years ago
|
#include <mutex>
|
||
10 years ago
|
#include <boost/asio.hpp>
|
||
9 years ago
|
#include "util/base64.h"
|
||
9 years ago
|
#include "util/util.h"
|
||
11 years ago
|
#include "Identity.h"
|
||
9 years ago
|
#include "util/Log.h"
|
||
11 years ago
|
|
||
|
namespace i2p
|
||
|
{
|
||
10 years ago
|
namespace client
|
||
11 years ago
|
{
|
||
10 years ago
|
const char DEFAULT_SUBSCRIPTION_ADDRESS[] = "http://udhdrtrcetjm5sxzskjyr5ztpeszydbh4dpl3pl4utgqqw2v4jna.b32.i2p/hosts.txt";
|
||
|
const int INITIAL_SUBSCRIPTION_UPDATE_TIMEOUT = 3; // in minutes
|
||
|
const int INITIAL_SUBSCRIPTION_RETRY_TIMEOUT = 1; // in minutes
|
||
|
const int CONTINIOUS_SUBSCRIPTION_UPDATE_TIMEOUT = 720; // in minutes (12 hours)
|
||
|
const int CONTINIOUS_SUBSCRIPTION_RETRY_TIMEOUT = 5; // in minutes
|
||
|
const int SUBSCRIPTION_REQUEST_TIMEOUT = 60; //in second
|
||
|
|
||
|
inline std::string GetB32Address(const i2p::data::IdentHash& ident) { return ident.ToBase32().append(".b32.i2p"); }
|
||
|
|
||
|
class AddressBookStorage // interface for storage
|
||
|
{
|
||
|
public:
|
||
|
|
||
|
virtual ~AddressBookStorage () {};
|
||
|
virtual bool GetAddress (const i2p::data::IdentHash& ident, i2p::data::IdentityEx& address) const = 0;
|
||
|
virtual void AddAddress (const i2p::data::IdentityEx& address) = 0;
|
||
|
virtual void RemoveAddress (const i2p::data::IdentHash& ident) = 0;
|
||
|
|
||
|
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;
|
||
|
};
|
||
|
|
||
9 years ago
|
class ClientDestination;
|
||
10 years ago
|
class AddressBookSubscription;
|
||
|
class AddressBook
|
||
|
{
|
||
|
public:
|
||
|
|
||
|
AddressBook ();
|
||
|
~AddressBook ();
|
||
9 years ago
|
void Start (ClientDestination* local_destination);
|
||
10 years ago
|
void Stop ();
|
||
|
bool GetIdentHash (const std::string& address, i2p::data::IdentHash& ident);
|
||
|
bool GetAddress (const std::string& address, i2p::data::IdentityEx& identity);
|
||
|
const i2p::data::IdentHash * FindAddress (const std::string& address);
|
||
9 years ago
|
|
||
|
ClientDestination* getSharedLocalDestination() const;
|
||
|
|
||
10 years ago
|
void InsertAddress (const std::string& address, const std::string& base64); // for jump service
|
||
|
void InsertAddress (const i2p::data::IdentityEx& address);
|
||
|
|
||
|
void LoadHostsFromStream (std::istream& f);
|
||
|
void DownloadComplete (bool success);
|
||
|
//This method returns the ".b32.i2p" address
|
||
|
std::string ToAddress(const i2p::data::IdentHash& ident) { return GetB32Address(ident); }
|
||
|
std::string ToAddress(const i2p::data::IdentityEx& ident) { return ToAddress(ident.GetIdentHash ()); }
|
||
|
private:
|
||
|
|
||
|
void StartSubscriptions ();
|
||
|
void StopSubscriptions ();
|
||
|
|
||
|
AddressBookStorage * CreateStorage ();
|
||
|
void LoadHosts ();
|
||
|
void LoadSubscriptions ();
|
||
|
|
||
|
void HandleSubscriptionsUpdateTimer (const boost::system::error_code& ecode);
|
||
|
|
||
|
private:
|
||
|
|
||
|
std::mutex m_AddressBookMutex;
|
||
|
std::map<std::string, i2p::data::IdentHash> m_Addresses;
|
||
|
AddressBookStorage * m_Storage;
|
||
|
volatile bool m_IsLoaded, m_IsDownloading;
|
||
|
std::vector<AddressBookSubscription *> m_Subscriptions;
|
||
|
AddressBookSubscription * m_DefaultSubscription; // in case if we don't know any addresses yet
|
||
|
boost::asio::deadline_timer * m_SubscriptionsUpdateTimer;
|
||
9 years ago
|
ClientDestination* m_SharedLocalDestination;
|
||
10 years ago
|
};
|
||
|
|
||
|
class AddressBookSubscription
|
||
|
{
|
||
|
public:
|
||
|
|
||
|
AddressBookSubscription (AddressBook& book, const std::string& link);
|
||
|
void CheckSubscription ();
|
||
|
|
||
|
private:
|
||
|
|
||
|
void Request ();
|
||
|
|
||
|
private:
|
||
|
|
||
|
AddressBook& m_Book;
|
||
|
std::string m_Link, m_Etag, m_LastModified;
|
||
|
};
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
|
#endif
|
||
|
|
||
|
|