From fd08dc72bd70a19f531b60ef67b9ada270c2a092 Mon Sep 17 00:00:00 2001 From: chertov Date: Fri, 18 Apr 2014 00:27:11 +0400 Subject: [PATCH] Add *.b32.i2p address detection --- HTTPServer.cpp | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/HTTPServer.cpp b/HTTPServer.cpp index f7f15cc1..b92c786e 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -311,28 +311,41 @@ namespace util { i2p::data::IdentHash destination; std::string fullAddress; - if (address.find (".i2p") != std::string::npos) - { - auto addr = i2p::data::netdb.FindAddress(address); - if (!addr) + 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 ("Unknown address ", address); - SendReply ("" + itoopieImage + "
Unknown address " + address + ""); + LogPrint ("Invalid Base32 address ", address); + SendReply ("" + itoopieImage + "
Invalid Base32 address"); return; - } - destination = *addr; + } fullAddress = address; } else - { - if (i2p::data::Base32ToByteStream (address.c_str (), address.length (), (uint8_t *)destination, 32) != 32) + { + if (address.find(".i2p") != std::string::npos) { - LogPrint ("Invalid Base32 address ", address); - SendReply ("" + itoopieImage + "
Invalid Base32 address"); - return; + auto addr = i2p::data::netdb.FindAddress(address); + if (!addr) + { + LogPrint ("Unknown address ", address); + SendReply ("" + itoopieImage + "
Unknown address " + address + ""); + return; + } + destination = *addr; + fullAddress = address; } - fullAddress = address + ".b32.i2p"; - } + else + { + if (i2p::data::Base32ToByteStream(address.c_str(), address.length(), (uint8_t *)destination, 32) != 32) + { + LogPrint("Invalid Base32 address ", address); + SendReply("" + itoopieImage + "
Invalid Base32 address"); + return; + } + fullAddress = address + ".b32.i2p"; + } + } auto leaseSet = i2p::data::netdb.FindLeaseSet (destination); if (!leaseSet || !leaseSet->HasNonExpiredLeases ())