diff --git a/AddressBook.cpp b/AddressBook.cpp index b993f456..705d4e6f 100644 --- a/AddressBook.cpp +++ b/AddressBook.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "Base.h" #include "util.h" #include "Identity.h" @@ -15,6 +16,7 @@ #include "NetDb.h" #include "ClientContext.h" #include "AddressBook.h" +#include "Config.h" namespace i2p { @@ -205,7 +207,7 @@ namespace client //--------------------------------------------------------------------- AddressBook::AddressBook (): m_Storage(nullptr), m_IsLoaded (false), m_IsDownloading (false), - m_DefaultSubscription (nullptr), m_SubscriptionsUpdateTimer (nullptr) + m_SubscriptionsUpdateTimer (nullptr) { } @@ -259,7 +261,6 @@ namespace client delete m_Storage; m_Storage = nullptr; } - m_DefaultSubscription = nullptr; m_Subscriptions.clear (); } @@ -404,9 +405,21 @@ namespace client m_Subscriptions.push_back (std::make_shared (*this, s)); } LogPrint (eLogInfo, "Addressbook: ", m_Subscriptions.size (), " subscriptions urls loaded"); + LogPrint (eLogWarning, "Addressbook: subscriptions.txt usage is deprecated, use config file instead"); } else - LogPrint (eLogWarning, "Addressbook: subscriptions.txt not found in datadir"); + { + // using config file items + std::string subscriptionURLs; i2p::config::GetOption("addressbook.subscriptions", subscriptionURLs); + std::vector subsList; + boost::split(subsList, subscriptionURLs, boost::is_any_of(","), boost::token_compress_on); + + for (size_t i = 0; i < subsList.size (); i++) + { + m_Subscriptions.push_back (std::make_shared (*this, subsList[i])); + } + LogPrint (eLogInfo, "Addressbook: ", m_Subscriptions.size (), " subscriptions urls loaded"); + } } else LogPrint (eLogError, "Addressbook: subscriptions already loaded"); @@ -460,7 +473,6 @@ namespace client int nextUpdateTimeout = CONTINIOUS_SUBSCRIPTION_RETRY_TIMEOUT; if (success) { - if (m_DefaultSubscription) m_DefaultSubscription = nullptr; if (m_IsLoaded) nextUpdateTimeout = CONTINIOUS_SUBSCRIPTION_UPDATE_TIMEOUT; else @@ -509,17 +521,7 @@ namespace client } if (!m_IsDownloading && dest->IsReady ()) { - if (!m_IsLoaded) - { - // download it from http://i2p-projekt.i2p/hosts.txt - LogPrint (eLogInfo, "Addressbook: trying to download it from default subscription."); - if (!m_DefaultSubscription) - m_DefaultSubscription = std::make_shared(*this, DEFAULT_SUBSCRIPTION_ADDRESS); - m_IsDownloading = true; - std::thread load_hosts(std::bind (&AddressBookSubscription::CheckUpdates, m_DefaultSubscription)); - load_hosts.detach(); // TODO: use join - } - else if (!m_Subscriptions.empty ()) + if (m_IsLoaded && !m_Subscriptions.empty ()) { // pick random subscription auto ind = rand () % m_Subscriptions.size(); diff --git a/AddressBook.h b/AddressBook.h index 7f559cd0..e09d3661 100644 --- a/AddressBook.h +++ b/AddressBook.h @@ -18,11 +18,6 @@ namespace i2p { namespace client { -#ifdef MESHNET - const char DEFAULT_SUBSCRIPTION_ADDRESS[] = "http://i42ofzetmgicvui5sshinfckpijix2udewbam4sjo6x5fbukltia.b32.i2p/hosts.txt"; -#else - const char DEFAULT_SUBSCRIPTION_ADDRESS[] = "http://joajgazyztfssty4w2on5oaqksz6tqoxbduy553y34mf4byv6gpq.b32.i2p/export/alive-hosts.txt"; -#endif 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) @@ -103,7 +98,6 @@ namespace client AddressBookStorage * m_Storage; volatile bool m_IsLoaded, m_IsDownloading; std::vector > m_Subscriptions; - std::shared_ptr m_DefaultSubscription; // in case if we don't know any addresses yet boost::asio::deadline_timer * m_SubscriptionsUpdateTimer; }; diff --git a/Config.cpp b/Config.cpp index 84633532..c0c4aa45 100644 --- a/Config.cpp +++ b/Config.cpp @@ -176,6 +176,12 @@ namespace config { ("trust.family", value()->default_value(""), "Router Familiy to trust for first hops") ("trust.hidden", value()->default_value(false), "should we hide our router from other routers?"); + options_description addressbook("AddressBook options"); + addressbook.add_options() + ("addressbook.subscriptions", value()->default_value( + "http://joajgazyztfssty4w2on5oaqksz6tqoxbduy553y34mf4byv6gpq.b32.i2p/export/alive-hosts.txt" + ), "AddressBook subscriptions URLs, separated by comma"); + m_OptionsDesc .add(general) .add(limits) @@ -190,6 +196,7 @@ namespace config { .add(precomputation) .add(reseed) .add(trust) + .add(addressbook) ; } diff --git a/docs/configuration.md b/docs/configuration.md index 31082dc2..13b2063b 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -74,6 +74,7 @@ All options below still possible in cmdline, but better write it in config file: * --precomputation.elgamal= - Use ElGamal precomputated tables. false for x64 and true for other platforms by default * --reseed.file - Full path to SU3 file to reseed from * --reseed.urls - Reseed URLs, separated by comma +* --addressbook.subscriptions - AddressBook subscriptions URLs, separated by comma * --limits.transittunnels= - Override maximum number of transit tunnels. 2500 by default diff --git a/docs/i2pd.conf b/docs/i2pd.conf index 94287bd0..6bc5cbfe 100644 --- a/docs/i2pd.conf +++ b/docs/i2pd.conf @@ -92,8 +92,16 @@ ipv6 = false # name = I2Pd [reseed] -## Path to reseed .su3 file (if ) -# file = +## URLs to request reseed data from, separated by comma +## Default: "mainline" I2P Network reseeds +# urls = https://reseed.i2p-projekt.de/,https://i2p.mooo.com/netDb/,https://netdb.i2p2.no/ +## Path to reseed data file (.su3) for manual reseeding +# file = /path/to/i2pseeds.su3 + +[addressbook] +## AddressBook subscriptions URLs, separated by comma +## Default: inr.i2p at "mainline" I2P Network +# subscriptions = http://joajgazyztfssty4w2on5oaqksz6tqoxbduy553y34mf4byv6gpq.b32.i2p/export/alive-hosts.txt [http] ## Uncomment and set to 'false' to disable Web Console diff --git a/docs/index.rst b/docs/index.rst index 5507b075..8cfddb24 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -32,7 +32,9 @@ Contents: build_requirements build_notes_unix build_notes_windows + build_notes_cross build_notes_android + build_notes_ios configuration family usage