From 84bb740e6236eb14a75460c04d5878ef75cf9314 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 15 Jul 2016 13:52:55 -0400 Subject: [PATCH] clean up code --- Destination.cpp | 2 +- HTTPServer.cpp | 110 +++++++++++++++++++++++----------------------- NetDb.cpp | 20 ++++----- NetDb.h | 14 +++--- RouterContext.cpp | 6 +-- 5 files changed, 76 insertions(+), 76 deletions(-) diff --git a/Destination.cpp b/Destination.cpp index 6e6d880f..2df14a9f 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -459,7 +459,7 @@ namespace client // "this" added due to bug in gcc 4.7-4.8 [s,this](std::shared_ptr leaseSet) { - if (leaseSet) + if (leaseSet && s->m_LeaseSet) { // we got latest LeasetSet LogPrint (eLogDebug, "Destination: published LeaseSet verified for ", GetIdentHash().ToBase32()); diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 7da308cc..566ad53e 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -72,7 +72,7 @@ namespace http { const char HTTP_PAGE_SAM_SESSION[] = "sam_session"; const char HTTP_PAGE_I2P_TUNNELS[] = "i2p_tunnels"; const char HTTP_PAGE_COMMANDS[] = "commands"; - const char HTTP_PAGE_LEASESETS[] = "leasesets"; + const char HTTP_PAGE_LEASESETS[] = "leasesets"; const char HTTP_COMMAND_ENABLE_TRANSIT[] = "enable_transit"; const char HTTP_COMMAND_DISABLE_TRANSIT[] = "disable_transit"; const char HTTP_COMMAND_SHUTDOWN_START[] = "shutdown_start"; @@ -141,7 +141,7 @@ namespace http { " Main page
\r\n
\r\n" " Router commands
\r\n" " Local destinations
\r\n" - " Lease Sets
\r\n" + " Lease Sets
\r\n" " Tunnels
\r\n" " Transit tunnels
\r\n" " Transports
\r\n" @@ -329,57 +329,57 @@ namespace http { } } - void ShowLeasesSets(std::stringstream& s) - { - s << "
LeaseSets

"; - // for each lease set - i2p::data::netdb.VisitLeaseSets( - [&s](const i2p::data::IdentHash dest, std::shared_ptr leaseSet) - { - // create copy of lease set so we extract leases - i2p::data::LeaseSet ls(leaseSet->GetBuffer(), leaseSet->GetBufferLen()); - // begin lease set entry - s << "
"; - // invalid ? - if (!ls.IsValid()) - s << "
!! Invalid !!
"; - // ident - s << "
" << dest.ToBase32() << "
"; - // LeaseSet time - s << "
expires: " << ls.GetExpirationTime() << "
"; - // get non expired leases - auto leases = ls.GetNonExpiredLeases(); - // show non expired leases - s << "
Non Expired Leases: " << leases.size() << "
"; - // for each lease - s << "
"; - for ( auto & l : leases ) - { - // begin lease - s << "
"; - // gateway - s << "
Gateway: " << l->tunnelGateway.ToBase64() << "
"; - // tunnel id - s << "
TunnelID: " << l->tunnelID << "
"; - // end date - s << "
EndDate: " << l->endDate << "
"; - // end lease - s << "
"; - } - // end for each lease - s << "
"; - // end lease set entry - s << "
"; - // linebreak - s << "
"; - } - ); - // end for each lease set - } - + void ShowLeasesSets(std::stringstream& s) + { + s << "
LeaseSets

"; + // for each lease set + i2p::data::netdb.VisitLeaseSets( + [&s](const i2p::data::IdentHash dest, std::shared_ptr leaseSet) + { + // create copy of lease set so we extract leases + i2p::data::LeaseSet ls(leaseSet->GetBuffer(), leaseSet->GetBufferLen()); + // begin lease set entry + s << "
"; + // invalid ? + if (!ls.IsValid()) + s << "
!! Invalid !!
"; + // ident + s << "
" << dest.ToBase32() << "
"; + // LeaseSet time + s << "
expires: " << ls.GetExpirationTime() << "
"; + // get non expired leases + auto leases = ls.GetNonExpiredLeases(); + // show non expired leases + s << "
Non Expired Leases: " << leases.size() << "
"; + // for each lease + s << "
"; + for ( auto & l : leases ) + { + // begin lease + s << "
"; + // gateway + s << "
Gateway: " << l->tunnelGateway.ToBase64() << "
"; + // tunnel id + s << "
TunnelID: " << l->tunnelID << "
"; + // end date + s << "
EndDate: " << l->endDate << "
"; + // end lease + s << "
"; + } + // end for each lease + s << "
"; + // end lease set entry + s << "
"; + // linebreak + s << "
"; + } + ); + // end for each lease set + } + void ShowTunnels (std::stringstream& s) { s << "Queue size: " << i2p::tunnel::tunnels.GetQueueSize () << "
\r\n"; @@ -692,8 +692,8 @@ namespace http { ShowSAMSession (s, params["sam_id"]); else if (page == HTTP_PAGE_I2P_TUNNELS) ShowI2PTunnels (s); - else if (page == HTTP_PAGE_LEASESETS) - ShowLeasesSets(s); + else if (page == HTTP_PAGE_LEASESETS) + ShowLeasesSets(s); else { res.code = 400; ShowError(s, "Unknown page: " + page); diff --git a/NetDb.cpp b/NetDb.cpp index 645bc85f..1710b73a 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -213,7 +213,7 @@ namespace data bool NetDb::AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len, std::shared_ptr from) { - std::unique_lock lock(m_LeaseSetsMutex); + std::unique_lock lock(m_LeaseSetsMutex); bool updated = false; if (!from) // unsolicited LS must be received directly { @@ -265,7 +265,7 @@ namespace data std::shared_ptr NetDb::FindLeaseSet (const IdentHash& destination) const { - std::unique_lock lock(m_LeaseSetsMutex); + std::unique_lock lock(m_LeaseSetsMutex); auto it = m_LeaseSets.find (destination); if (it != m_LeaseSets.end ()) return it->second; @@ -320,13 +320,13 @@ namespace data return true; } - void NetDb::VisitLeaseSets(LeaseSetVisitor v) - { - std::unique_lock lock(m_LeaseSetsMutex); - for ( auto & entry : m_LeaseSets) - v(entry.first, entry.second); - } - + void NetDb::VisitLeaseSets(LeaseSetVisitor v) + { + std::unique_lock lock(m_LeaseSetsMutex); + for ( auto & entry : m_LeaseSets) + v(entry.first, entry.second); + } + void NetDb::Load () { // make sure we cleanup netDb from previous attempts @@ -750,7 +750,7 @@ namespace data const uint8_t numTags = excluded[32]; if (numTags) { - const i2p::garlic::SessionTag sessionTag(excluded + 33); // take first tag + const i2p::garlic::SessionTag sessionTag(excluded + 33); // take first tag i2p::garlic::GarlicRoutingSession garlic (sessionKey, sessionTag); replyMsg = garlic.WrapSingleMessage (replyMsg); if(replyMsg == nullptr) LogPrint(eLogError, "NetDb: failed to wrap message"); diff --git a/NetDb.h b/NetDb.h index c7371407..43b069b9 100644 --- a/NetDb.h +++ b/NetDb.h @@ -33,9 +33,9 @@ namespace data const int NETDB_MAX_EXPIRATION_TIMEOUT = 27*60*60; // 27 hours const int NETDB_PUBLISH_INTERVAL = 60*40; - /** function for visiting a leaseset stored in a floodfill */ - typedef std::function)> LeaseSetVisitor; - + /** function for visiting a leaseset stored in a floodfill */ + typedef std::function)> LeaseSetVisitor; + class NetDb { public: @@ -84,9 +84,9 @@ namespace data int GetNumFloodfills () const { return m_Floodfills.size (); }; int GetNumLeaseSets () const { return m_LeaseSets.size (); }; - /** visit all lease sets we currently store */ - void VisitLeaseSets(LeaseSetVisitor v); - + /** visit all lease sets we currently store */ + void VisitLeaseSets(LeaseSetVisitor v); + private: void Load (); @@ -104,7 +104,7 @@ namespace data private: - mutable std::mutex m_LeaseSetsMutex; + mutable std::mutex m_LeaseSetsMutex; std::map > m_LeaseSets; mutable std::mutex m_RouterInfosMutex; std::map > m_RouterInfos; diff --git a/RouterContext.cpp b/RouterContext.cpp index 44b967e8..b2d4f073 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -49,10 +49,10 @@ namespace i2p uint16_t port; i2p::config::GetOption("port", port); if (!port) port = rand () % (30777 - 9111) + 9111; // I2P network ports range - bool ipv4; i2p::config::GetOption("ipv4", ipv4); - bool ipv6; i2p::config::GetOption("ipv6", ipv6); + bool ipv4; i2p::config::GetOption("ipv4", ipv4); + bool ipv6; i2p::config::GetOption("ipv6", ipv6); std::string host = i2p::util::config::GetHost(ipv4, ipv6); - routerInfo.AddSSUAddress (host.c_str(), port, routerInfo.GetIdentHash ()); + routerInfo.AddSSUAddress (host.c_str(), port, routerInfo.GetIdentHash ()); routerInfo.AddNTCPAddress (host.c_str(), port); routerInfo.SetCaps (i2p::data::RouterInfo::eReachable | i2p::data::RouterInfo::eSSUTesting | i2p::data::RouterInfo::eSSUIntroducer); // LR, BC