Browse Source

Merge pull request #210 from mlt/fixes

Few fixes
pull/213/head
orignal 10 years ago
parent
commit
d07c68bd9a
  1. 3
      DaemonLinux.cpp
  2. 2
      HTTPProxy.cpp
  3. 42
      NetDb.cpp
  4. 4
      NetDb.h
  5. 5
      RouterInfo.cpp
  6. 6
      SAM.cpp

3
DaemonLinux.cpp

@ -62,7 +62,8 @@ namespace i2p
LogPrint("Error, could not create process group."); LogPrint("Error, could not create process group.");
return false; return false;
} }
chdir(i2p::util::filesystem::GetDataDir().string().c_str()); std::string d(i2p::util::filesystem::GetDataDir()); // make a copy
chdir(d.c_str());
// close stdin/stdout/stderr descriptors // close stdin/stdout/stderr descriptors
::close (0); ::close (0);

2
HTTPProxy.cpp

@ -90,7 +90,7 @@ namespace proxy
//TODO: handle this apropriately //TODO: handle this apropriately
void HTTPProxyHandler::HTTPRequestFailed(/*HTTPProxyHandler::errTypes error*/) void HTTPProxyHandler::HTTPRequestFailed(/*HTTPProxyHandler::errTypes error*/)
{ {
std::string response = "HTTP/1.0 500 Internal Server Error\r\nContent-type: text/html\r\nContent-length: 0\r\n"; static std::string response = "HTTP/1.0 500 Internal Server Error\r\nContent-type: text/html\r\nContent-length: 0\r\n";
boost::asio::async_write(*m_sock, boost::asio::buffer(response,response.size()), boost::asio::async_write(*m_sock, boost::asio::buffer(response,response.size()),
std::bind(&HTTPProxyHandler::SentHTTPFailed, shared_from_this(), std::placeholders::_1)); std::bind(&HTTPProxyHandler::SentHTTPFailed, shared_from_this(), std::placeholders::_1));
} }

42
NetDb.cpp

@ -21,11 +21,7 @@ namespace i2p
{ {
namespace data namespace data
{ {
#ifndef _WIN32 const char NetDb::m_NetDbPath[] = "netDb";
const char NetDb::m_NetDbPath[] = "/netDb";
#else
const char NetDb::m_NetDbPath[] = "\\netDb";
#endif
NetDb netdb; NetDb netdb;
NetDb::NetDb (): m_IsRunning (false), m_Thread (nullptr), m_Reseeder (nullptr) NetDb::NetDb (): m_IsRunning (false), m_Thread (nullptr), m_Reseeder (nullptr)
@ -40,7 +36,7 @@ namespace data
void NetDb::Start () void NetDb::Start ()
{ {
Load (m_NetDbPath); Load ();
if (m_RouterInfos.size () < 25) // reseed if # of router less than 50 if (m_RouterInfos.size () < 25) // reseed if # of router less than 50
{ {
// try SU3 first // try SU3 first
@ -55,7 +51,7 @@ namespace data
{ {
m_Reseeder->reseedNow(); m_Reseeder->reseedNow();
reseedRetries++; reseedRetries++;
Load (m_NetDbPath); Load ();
} }
} }
} }
@ -133,7 +129,7 @@ namespace data
{ {
if (lastSave) if (lastSave)
{ {
SaveUpdated (m_NetDbPath); SaveUpdated ();
ManageLeaseSets (); ManageLeaseSets ();
} }
lastSave = ts; lastSave = ts;
@ -295,10 +291,9 @@ namespace data
LogPrint (eLogWarning, "Failed to reseed after 10 attempts"); LogPrint (eLogWarning, "Failed to reseed after 10 attempts");
} }
void NetDb::Load (const char * directory) void NetDb::Load ()
{ {
boost::filesystem::path p (i2p::util::filesystem::GetDataDir()); boost::filesystem::path p(i2p::util::filesystem::GetDataDir() / m_NetDbPath);
p /= (directory);
if (!boost::filesystem::exists (p)) if (!boost::filesystem::exists (p))
{ {
// seems netDb doesn't exist yet // seems netDb doesn't exist yet
@ -345,27 +340,15 @@ namespace data
LogPrint (m_Floodfills.size (), " floodfills loaded"); LogPrint (m_Floodfills.size (), " floodfills loaded");
} }
void NetDb::SaveUpdated (const char * directory) void NetDb::SaveUpdated ()
{ {
auto GetFilePath = [](const char * directory, const RouterInfo * routerInfo) auto GetFilePath = [](const boost::filesystem::path& directory, const RouterInfo * routerInfo)
{ {
#ifndef _WIN32 std::string s(routerInfo->GetIdentHashBase64());
return std::string (directory) + "/r" + return directory / (std::string("r") + s[0]) / ("routerInfo-" + s + ".dat");
routerInfo->GetIdentHashBase64 ()[0] + "/routerInfo-" +
#else
return std::string (directory) + "\\r" +
routerInfo->GetIdentHashBase64 ()[0] + "\\routerInfo-" +
#endif
routerInfo->GetIdentHashBase64 () + ".dat";
}; };
boost::filesystem::path p (i2p::util::filesystem::GetDataDir()); boost::filesystem::path fullDirectory (i2p::util::filesystem::GetDataDir() / m_NetDbPath);
p /= (directory);
#if BOOST_VERSION > 10500
const char * fullDirectory = p.string().c_str ();
#else
const char * fullDirectory = p.c_str ();
#endif
int count = 0, deletedCount = 0; int count = 0, deletedCount = 0;
auto total = m_RouterInfos.size (); auto total = m_RouterInfos.size ();
uint64_t ts = i2p::util::GetMillisecondsSinceEpoch (); uint64_t ts = i2p::util::GetMillisecondsSinceEpoch ();
@ -373,7 +356,8 @@ namespace data
{ {
if (it.second->IsUpdated ()) if (it.second->IsUpdated ())
{ {
it.second->SaveToFile (GetFilePath(fullDirectory, it.second.get ())); std::string f = GetFilePath(fullDirectory, it.second.get()).string();
it.second->SaveToFile (f);
it.second->SetUpdated (false); it.second->SetUpdated (false);
it.second->SetUnreachable (false); it.second->SetUnreachable (false);
it.second->DeleteBuffer (); it.second->DeleteBuffer ();

4
NetDb.h

@ -68,8 +68,8 @@ namespace data
private: private:
bool CreateNetDb(boost::filesystem::path directory); bool CreateNetDb(boost::filesystem::path directory);
void Load (const char * directory); void Load ();
void SaveUpdated (const char * directory); void SaveUpdated ();
void Run (); // exploratory thread void Run (); // exploratory thread
void Explore (int numDestinations); void Explore (int numDestinations);
void Publish (); void Publish ();

5
RouterInfo.cpp

@ -447,10 +447,13 @@ namespace data
if (m_Buffer) if (m_Buffer)
{ {
std::ofstream f (fullPath, std::ofstream::binary | std::ofstream::out); std::ofstream f (fullPath, std::ofstream::binary | std::ofstream::out);
if (f.is_open ())
f.write ((char *)m_Buffer, m_BufferLen); f.write ((char *)m_Buffer, m_BufferLen);
else
LogPrint(eLogError, "Can't save RouterInfo to ", fullPath);
} }
else else
LogPrint (eLogError, "Can't save to file"); LogPrint (eLogError, "Can't save RouterInfo m_Buffer==NULL");
} }
size_t RouterInfo::ReadString (char * str, std::istream& s) size_t RouterInfo::ReadString (char * str, std::istream& s)

6
SAM.cpp

@ -85,6 +85,9 @@ namespace client
else else
{ {
m_Buffer[bytes_transferred] = 0; m_Buffer[bytes_transferred] = 0;
char * eol = (char *)memchr (m_Buffer, '\n', bytes_transferred);
if (eol)
*eol = 0;
LogPrint ("SAM handshake ", m_Buffer); LogPrint ("SAM handshake ", m_Buffer);
char * separator = strchr (m_Buffer, ' '); char * separator = strchr (m_Buffer, ' ');
if (separator) if (separator)
@ -101,9 +104,6 @@ namespace client
if (separator) if (separator)
{ {
separator++; separator++;
char *eol = strchr (separator, '\n');
if (eol)
*eol = 0;
std::map<std::string, std::string> params; std::map<std::string, std::string> params;
ExtractParams (separator, params); ExtractParams (separator, params);
auto it = params.find (SAM_PARAM_MAX); auto it = params.find (SAM_PARAM_MAX);

Loading…
Cancel
Save