Browse Source

parse address in AddressBook

pull/102/head
orignal 10 years ago
parent
commit
07654212f8
  1. 23
      AddressBook.cpp
  2. 1
      AddressBook.h
  3. 2
      HTTPProxy.cpp
  4. 24
      HTTPServer.cpp
  5. 26
      I2PTunnel.cpp
  6. 3
      NetDb.h

23
AddressBook.cpp

@ -18,6 +18,29 @@ namespace data @@ -18,6 +18,29 @@ namespace data
{
}
bool AddressBook::GetIdentHash (const std::string& address, IdentHash& ident)
{
auto pos = address.find(".b32.i2p");
if (pos != std::string::npos)
{
Base32ToByteStream (address.c_str(), pos, ident, 32);
return true;
}
else
{
pos = address.find (".i2p");
if (pos != std::string::npos)
{
auto identHash = FindAddress (address);
if (identHash)
{
ident = *identHash;
return true;
}
}
}
return false;
}
const IdentHash * AddressBook::FindAddress (const std::string& address)
{

1
AddressBook.h

@ -18,6 +18,7 @@ namespace data @@ -18,6 +18,7 @@ namespace data
public:
AddressBook ();
bool GetIdentHash (const std::string& address, IdentHash& ident);
const IdentHash * FindAddress (const std::string& address);
void InsertAddress (const std::string& address, const std::string& base64); // for jump service

2
HTTPProxy.cpp

@ -73,7 +73,7 @@ namespace proxy @@ -73,7 +73,7 @@ namespace proxy
{
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);
i2p::data::netdb.GetAddressBook ().InsertAddress (r.host, base64);
}
}

24
HTTPServer.cpp

@ -829,34 +829,12 @@ namespace util @@ -829,34 +829,12 @@ namespace util
void HTTPConnection::SendToAddress (const std::string& address, const char * buf, size_t len)
{
i2p::data::IdentHash destination;
if (address.find(".b32.i2p") != std::string::npos)
{
if (i2p::data::Base32ToByteStream(address.c_str(), address.length() - strlen(".b32.i2p"), (uint8_t *)destination, 32) != 32)
{
LogPrint ("Invalid Base32 address ", address);
SendReply ("<html>" + itoopieImage + "<br>Invalid Base32 address</html>", 400);
return;
}
}
else
{
if (address.find(".i2p") != std::string::npos)
{
auto addr = i2p::data::netdb.FindAddress(address);
if (!addr)
if (!i2p::data::netdb.GetAddressBook ().GetIdentHash (address, destination))
{
LogPrint ("Unknown address ", address);
SendReply ("<html>" + itoopieImage + "<br>Unknown address " + address + "</html>", 404);
return;
}
destination = *addr;
}
else
{
SendReply ("<html>Unexpected address " + address + "</html>", 404);
return;
}
}
SendToDestination (destination, buf, len);
}

26
I2PTunnel.cpp

@ -153,23 +153,9 @@ namespace stream @@ -153,23 +153,9 @@ namespace stream
void I2PClientTunnel::Start ()
{
auto pos = m_Destination.find(".b32.i2p");
if (pos != std::string::npos)
{
uint8_t hash[32];
i2p::data::Base32ToByteStream (m_Destination.c_str(), pos, hash, 32);
m_DestinationIdentHash = new i2p::data::IdentHash (hash);
}
else
{
pos = m_Destination.find (".i2p");
if (pos != std::string::npos)
{
auto identHash = i2p::data::netdb.FindAddress (m_Destination);
if (identHash)
m_DestinationIdentHash = new i2p::data::IdentHash (*identHash);
}
}
i2p::data::IdentHash identHash;
if (i2p::data::netdb.GetAddressBook ().GetIdentHash (m_Destination, identHash))
m_DestinationIdentHash = new i2p::data::IdentHash (identHash);
if (m_DestinationIdentHash)
{
i2p::data::netdb.Subscribe (*m_DestinationIdentHash, GetLocalDestination ()->GetTunnelPool ());
@ -206,10 +192,10 @@ namespace stream @@ -206,10 +192,10 @@ namespace stream
m_RemoteLeaseSet = i2p::data::netdb.FindLeaseSet (*m_DestinationIdentHash);
else
{
auto identHash = i2p::data::netdb.FindAddress (m_Destination);
if (identHash)
i2p::data::IdentHash identHash;
if (i2p::data::netdb.GetAddressBook ().GetIdentHash (m_Destination, identHash))
{
m_DestinationIdentHash = new i2p::data::IdentHash (*identHash);
m_DestinationIdentHash = new i2p::data::IdentHash (identHash);
i2p::data::netdb.Subscribe (*m_DestinationIdentHash, GetSharedLocalDestination ()->GetTunnelPool ());
}
}

3
NetDb.h

@ -66,8 +66,7 @@ namespace data @@ -66,8 +66,7 @@ namespace data
void AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len);
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); };
AddressBook& GetAddressBook () { return m_AddressBook; };// TODO: move AddressBook away from NetDb
void Subscribe (const IdentHash& ident, i2p::tunnel::TunnelPool * pool = nullptr); // keep LeaseSets upto date
void Unsubscribe (const IdentHash& ident);

Loading…
Cancel
Save