From e51cca826339d7b73f95b5671ef830bec3259e02 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 23 Sep 2014 15:38:56 -0400 Subject: [PATCH] jump service --- AddressBook.cpp | 8 ++++++++ AddressBook.h | 1 + HTTPProxy.cpp | 14 ++++++++++++++ NetDb.h | 1 + 4 files changed, 24 insertions(+) diff --git a/AddressBook.cpp b/AddressBook.cpp index 948d7a0c..b08f946a 100644 --- a/AddressBook.cpp +++ b/AddressBook.cpp @@ -32,6 +32,14 @@ namespace data return nullptr; } + void AddressBook::InsertAddress (const std::string& address, const std::string& base64) + { + IdentityEx ident; + ident.FromBase64 (base64); + m_Addresses[address] = ident.GetIdentHash (); + LogPrint (address,"->",ident.GetIdentHash ().ToBase32 (), ".b32.i2p added"); + } + void AddressBook::LoadHostsFromI2P () { std::string content; diff --git a/AddressBook.h b/AddressBook.h index c5a0a48a..22875d04 100644 --- a/AddressBook.h +++ b/AddressBook.h @@ -19,6 +19,7 @@ namespace data AddressBook (); const IdentHash * FindAddress (const std::string& address); + void InsertAddress (const std::string& address, const std::string& base64); // for jump service private: diff --git a/HTTPProxy.cpp b/HTTPProxy.cpp index 52917cb3..d7a77a4d 100644 --- a/HTTPProxy.cpp +++ b/HTTPProxy.cpp @@ -1,6 +1,7 @@ #include #include +#include "NetDb.h" #include "HTTPProxy.h" namespace i2p @@ -63,6 +64,19 @@ namespace proxy request r; ExtractRequest(r); parseHeaders(m_Buffer, r.headers); + size_t addressHelperPos = r.uri.find ("i2paddresshelper"); + if (addressHelperPos != std::string::npos) + { + // jump service + size_t addressPos = r.uri.find ("=", addressHelperPos); + if (addressPos != std::string::npos) + { + LogPrint ("Jump service for ", r.host, " found. Inserting to address book"); + auto base64 = r.uri.substr (addressPos + 1); + i2p::data::netdb.InsertAddress (r.host, base64); + } + } + LogPrint("Requesting ", r.host, " with path ", r.uri, " and method ", r.method); SendToAddress (r.host, m_Buffer, m_BufferLen); } diff --git a/NetDb.h b/NetDb.h index 6ee065d4..35cc7aa6 100644 --- a/NetDb.h +++ b/NetDb.h @@ -67,6 +67,7 @@ namespace data RouterInfo * FindRouter (const IdentHash& ident) const; LeaseSet * FindLeaseSet (const IdentHash& destination) const; const IdentHash * FindAddress (const std::string& address) { return m_AddressBook.FindAddress (address); }; // TODO: move AddressBook away from NetDb + void InsertAddress (const std::string& address, const std::string& base64) { m_AddressBook.InsertAddress (address, base64); }; void Subscribe (const IdentHash& ident, i2p::tunnel::TunnelPool * pool = nullptr); // keep LeaseSets upto date void Unsubscribe (const IdentHash& ident);