1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-01-23 13:24:20 +00:00

clean up code

This commit is contained in:
Jeff Becker 2016-07-15 13:52:55 -04:00
parent d37482ada1
commit 84bb740e62
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B
5 changed files with 76 additions and 76 deletions

View File

@ -459,7 +459,7 @@ namespace client
// "this" added due to bug in gcc 4.7-4.8 // "this" added due to bug in gcc 4.7-4.8
[s,this](std::shared_ptr<i2p::data::LeaseSet> leaseSet) [s,this](std::shared_ptr<i2p::data::LeaseSet> leaseSet)
{ {
if (leaseSet) if (leaseSet && s->m_LeaseSet)
{ {
// we got latest LeasetSet // we got latest LeasetSet
LogPrint (eLogDebug, "Destination: published LeaseSet verified for ", GetIdentHash().ToBase32()); LogPrint (eLogDebug, "Destination: published LeaseSet verified for ", GetIdentHash().ToBase32());

View File

@ -72,7 +72,7 @@ namespace http {
const char HTTP_PAGE_SAM_SESSION[] = "sam_session"; const char HTTP_PAGE_SAM_SESSION[] = "sam_session";
const char HTTP_PAGE_I2P_TUNNELS[] = "i2p_tunnels"; const char HTTP_PAGE_I2P_TUNNELS[] = "i2p_tunnels";
const char HTTP_PAGE_COMMANDS[] = "commands"; 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_ENABLE_TRANSIT[] = "enable_transit";
const char HTTP_COMMAND_DISABLE_TRANSIT[] = "disable_transit"; const char HTTP_COMMAND_DISABLE_TRANSIT[] = "disable_transit";
const char HTTP_COMMAND_SHUTDOWN_START[] = "shutdown_start"; const char HTTP_COMMAND_SHUTDOWN_START[] = "shutdown_start";
@ -141,7 +141,7 @@ namespace http {
" <a href=\"/\">Main page</a><br>\r\n<br>\r\n" " <a href=\"/\">Main page</a><br>\r\n<br>\r\n"
" <a href=\"/?page=" << HTTP_PAGE_COMMANDS << "\">Router commands</a><br>\r\n" " <a href=\"/?page=" << HTTP_PAGE_COMMANDS << "\">Router commands</a><br>\r\n"
" <a href=\"/?page=" << HTTP_PAGE_LOCAL_DESTINATIONS << "\">Local destinations</a><br>\r\n" " <a href=\"/?page=" << HTTP_PAGE_LOCAL_DESTINATIONS << "\">Local destinations</a><br>\r\n"
" <a href=\"/?page=" << HTTP_PAGE_LEASESETS << "\">Lease Sets</a><br>\r\n" " <a href=\"/?page=" << HTTP_PAGE_LEASESETS << "\">Lease Sets</a><br>\r\n"
" <a href=\"/?page=" << HTTP_PAGE_TUNNELS << "\">Tunnels</a><br>\r\n" " <a href=\"/?page=" << HTTP_PAGE_TUNNELS << "\">Tunnels</a><br>\r\n"
" <a href=\"/?page=" << HTTP_PAGE_TRANSIT_TUNNELS << "\">Transit tunnels</a><br>\r\n" " <a href=\"/?page=" << HTTP_PAGE_TRANSIT_TUNNELS << "\">Transit tunnels</a><br>\r\n"
" <a href=\"/?page=" << HTTP_PAGE_TRANSPORTS << "\">Transports</a><br>\r\n" " <a href=\"/?page=" << HTTP_PAGE_TRANSPORTS << "\">Transports</a><br>\r\n"
@ -329,57 +329,57 @@ namespace http {
} }
} }
void ShowLeasesSets(std::stringstream& s) void ShowLeasesSets(std::stringstream& s)
{ {
s << "<div id='leasesets'>LeaseSets</div><br>"; s << "<div id='leasesets'>LeaseSets</div><br>";
// for each lease set // for each lease set
i2p::data::netdb.VisitLeaseSets( i2p::data::netdb.VisitLeaseSets(
[&s](const i2p::data::IdentHash dest, std::shared_ptr<i2p::data::LeaseSet> leaseSet) [&s](const i2p::data::IdentHash dest, std::shared_ptr<i2p::data::LeaseSet> leaseSet)
{ {
// create copy of lease set so we extract leases // create copy of lease set so we extract leases
i2p::data::LeaseSet ls(leaseSet->GetBuffer(), leaseSet->GetBufferLen()); i2p::data::LeaseSet ls(leaseSet->GetBuffer(), leaseSet->GetBufferLen());
// begin lease set entry // begin lease set entry
s << "<div class='leaseset"; s << "<div class='leaseset";
if (ls.IsExpired()) if (ls.IsExpired())
s << " expired"; // additional css class for expired s << " expired"; // additional css class for expired
s << "'>"; s << "'>";
// invalid ? // invalid ?
if (!ls.IsValid()) if (!ls.IsValid())
s << "<div class='invalid'>!! Invalid !! </div>"; s << "<div class='invalid'>!! Invalid !! </div>";
// ident // ident
s << "<div class='ident'>" << dest.ToBase32() << "</div>"; s << "<div class='ident'>" << dest.ToBase32() << "</div>";
// LeaseSet time // LeaseSet time
s << "<div class='expires'>expires: " << ls.GetExpirationTime() << "</div>"; s << "<div class='expires'>expires: " << ls.GetExpirationTime() << "</div>";
// get non expired leases // get non expired leases
auto leases = ls.GetNonExpiredLeases(); auto leases = ls.GetNonExpiredLeases();
// show non expired leases // show non expired leases
s << "<div class='leasecount'>Non Expired Leases: " << leases.size() << "</div>"; s << "<div class='leasecount'>Non Expired Leases: " << leases.size() << "</div>";
// for each lease // for each lease
s << "<div class='leases'>"; s << "<div class='leases'>";
for ( auto & l : leases ) for ( auto & l : leases )
{ {
// begin lease // begin lease
s << "<div class='lease'>"; s << "<div class='lease'>";
// gateway // gateway
s << "<div class='gateway'>Gateway: " << l->tunnelGateway.ToBase64() << "</div>"; s << "<div class='gateway'>Gateway: " << l->tunnelGateway.ToBase64() << "</div>";
// tunnel id // tunnel id
s << "<div class='tunnelID'>TunnelID: " << l->tunnelID << "</div>"; s << "<div class='tunnelID'>TunnelID: " << l->tunnelID << "</div>";
// end date // end date
s << "<div class='endDate'>EndDate: " << l->endDate << "</div>"; s << "<div class='endDate'>EndDate: " << l->endDate << "</div>";
// end lease // end lease
s << "</div>"; s << "</div>";
} }
// end for each lease // end for each lease
s << "</div>"; s << "</div>";
// end lease set entry // end lease set entry
s << "</div>"; s << "</div>";
// linebreak // linebreak
s << "<br>"; s << "<br>";
} }
); );
// end for each lease set // end for each lease set
} }
void ShowTunnels (std::stringstream& s) void ShowTunnels (std::stringstream& s)
{ {
s << "<b>Queue size:</b> " << i2p::tunnel::tunnels.GetQueueSize () << "<br>\r\n"; s << "<b>Queue size:</b> " << i2p::tunnel::tunnels.GetQueueSize () << "<br>\r\n";
@ -692,8 +692,8 @@ namespace http {
ShowSAMSession (s, params["sam_id"]); ShowSAMSession (s, params["sam_id"]);
else if (page == HTTP_PAGE_I2P_TUNNELS) else if (page == HTTP_PAGE_I2P_TUNNELS)
ShowI2PTunnels (s); ShowI2PTunnels (s);
else if (page == HTTP_PAGE_LEASESETS) else if (page == HTTP_PAGE_LEASESETS)
ShowLeasesSets(s); ShowLeasesSets(s);
else { else {
res.code = 400; res.code = 400;
ShowError(s, "Unknown page: " + page); ShowError(s, "Unknown page: " + page);

View File

@ -213,7 +213,7 @@ namespace data
bool NetDb::AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len, bool NetDb::AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len,
std::shared_ptr<i2p::tunnel::InboundTunnel> from) std::shared_ptr<i2p::tunnel::InboundTunnel> from)
{ {
std::unique_lock<std::mutex> lock(m_LeaseSetsMutex); std::unique_lock<std::mutex> lock(m_LeaseSetsMutex);
bool updated = false; bool updated = false;
if (!from) // unsolicited LS must be received directly if (!from) // unsolicited LS must be received directly
{ {
@ -265,7 +265,7 @@ namespace data
std::shared_ptr<LeaseSet> NetDb::FindLeaseSet (const IdentHash& destination) const std::shared_ptr<LeaseSet> NetDb::FindLeaseSet (const IdentHash& destination) const
{ {
std::unique_lock<std::mutex> lock(m_LeaseSetsMutex); std::unique_lock<std::mutex> lock(m_LeaseSetsMutex);
auto it = m_LeaseSets.find (destination); auto it = m_LeaseSets.find (destination);
if (it != m_LeaseSets.end ()) if (it != m_LeaseSets.end ())
return it->second; return it->second;
@ -320,13 +320,13 @@ namespace data
return true; return true;
} }
void NetDb::VisitLeaseSets(LeaseSetVisitor v) void NetDb::VisitLeaseSets(LeaseSetVisitor v)
{ {
std::unique_lock<std::mutex> lock(m_LeaseSetsMutex); std::unique_lock<std::mutex> lock(m_LeaseSetsMutex);
for ( auto & entry : m_LeaseSets) for ( auto & entry : m_LeaseSets)
v(entry.first, entry.second); v(entry.first, entry.second);
} }
void NetDb::Load () void NetDb::Load ()
{ {
// make sure we cleanup netDb from previous attempts // make sure we cleanup netDb from previous attempts
@ -750,7 +750,7 @@ namespace data
const uint8_t numTags = excluded[32]; const uint8_t numTags = excluded[32];
if (numTags) 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); i2p::garlic::GarlicRoutingSession garlic (sessionKey, sessionTag);
replyMsg = garlic.WrapSingleMessage (replyMsg); replyMsg = garlic.WrapSingleMessage (replyMsg);
if(replyMsg == nullptr) LogPrint(eLogError, "NetDb: failed to wrap message"); if(replyMsg == nullptr) LogPrint(eLogError, "NetDb: failed to wrap message");

14
NetDb.h
View File

@ -33,9 +33,9 @@ namespace data
const int NETDB_MAX_EXPIRATION_TIMEOUT = 27*60*60; // 27 hours const int NETDB_MAX_EXPIRATION_TIMEOUT = 27*60*60; // 27 hours
const int NETDB_PUBLISH_INTERVAL = 60*40; const int NETDB_PUBLISH_INTERVAL = 60*40;
/** function for visiting a leaseset stored in a floodfill */ /** function for visiting a leaseset stored in a floodfill */
typedef std::function<void(const IdentHash, std::shared_ptr<LeaseSet>)> LeaseSetVisitor; typedef std::function<void(const IdentHash, std::shared_ptr<LeaseSet>)> LeaseSetVisitor;
class NetDb class NetDb
{ {
public: public:
@ -84,9 +84,9 @@ namespace data
int GetNumFloodfills () const { return m_Floodfills.size (); }; int GetNumFloodfills () const { return m_Floodfills.size (); };
int GetNumLeaseSets () const { return m_LeaseSets.size (); }; int GetNumLeaseSets () const { return m_LeaseSets.size (); };
/** visit all lease sets we currently store */ /** visit all lease sets we currently store */
void VisitLeaseSets(LeaseSetVisitor v); void VisitLeaseSets(LeaseSetVisitor v);
private: private:
void Load (); void Load ();
@ -104,7 +104,7 @@ namespace data
private: private:
mutable std::mutex m_LeaseSetsMutex; mutable std::mutex m_LeaseSetsMutex;
std::map<IdentHash, std::shared_ptr<LeaseSet> > m_LeaseSets; std::map<IdentHash, std::shared_ptr<LeaseSet> > m_LeaseSets;
mutable std::mutex m_RouterInfosMutex; mutable std::mutex m_RouterInfosMutex;
std::map<IdentHash, std::shared_ptr<RouterInfo> > m_RouterInfos; std::map<IdentHash, std::shared_ptr<RouterInfo> > m_RouterInfos;

View File

@ -49,10 +49,10 @@ namespace i2p
uint16_t port; i2p::config::GetOption("port", port); uint16_t port; i2p::config::GetOption("port", port);
if (!port) if (!port)
port = rand () % (30777 - 9111) + 9111; // I2P network ports range port = rand () % (30777 - 9111) + 9111; // I2P network ports range
bool ipv4; i2p::config::GetOption("ipv4", ipv4); bool ipv4; i2p::config::GetOption("ipv4", ipv4);
bool ipv6; i2p::config::GetOption("ipv6", ipv6); bool ipv6; i2p::config::GetOption("ipv6", ipv6);
std::string host = i2p::util::config::GetHost(ipv4, 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.AddNTCPAddress (host.c_str(), port);
routerInfo.SetCaps (i2p::data::RouterInfo::eReachable | routerInfo.SetCaps (i2p::data::RouterInfo::eReachable |
i2p::data::RouterInfo::eSSUTesting | i2p::data::RouterInfo::eSSUIntroducer); // LR, BC i2p::data::RouterInfo::eSSUTesting | i2p::data::RouterInfo::eSSUIntroducer); // LR, BC