From a78caa2976d3d96f8ac2defb7622c48e456e0630 Mon Sep 17 00:00:00 2001 From: weekendi2p Date: Wed, 27 Apr 2016 00:31:33 +0200 Subject: [PATCH 1/6] added SetFamilyString(); GetFamilyString() and shows family in webiface --- HTTPServer.cpp | 1 + RouterContext.cpp | 12 ++++++++++++ RouterContext.h | 2 ++ 3 files changed, 15 insertions(+) diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 6c2c6112..08b67e22 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -417,6 +417,7 @@ namespace util default: s << "Unknown"; } s << "
\r\n"; + s << "Family: " << i2p::context.GetFamilyString() << "
\r\n"; s << "Tunnel creation success rate: " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate () << "%
\r\n"; s << "Received: "; s << std::fixed << std::setprecision(2); diff --git a/RouterContext.cpp b/RouterContext.cpp index f35d8426..4cdf13fe 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -149,11 +149,23 @@ namespace i2p UpdateRouterInfo (); } + std::string RouterContext::GetFamilyString () const + { + return m_FamilyString; + } + void RouterContext::SetFamily (const std::string& family) { + + m_FamilyString = family; + if (m_FamilyString.length() == 0) + m_FamilyString = "<undefined>"; + std::string signature; if (family.length () > 0) + { signature = i2p::data::CreateFamilySignature (family, GetIdentHash ()); + } if (signature.length () > 0) { m_RouterInfo.SetProperty (i2p::data::ROUTER_INFO_PROPERTY_FAMILY, family); diff --git a/RouterContext.h b/RouterContext.h index 9766c66e..1b0f7ed2 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -59,6 +59,7 @@ namespace i2p bool IsFloodfill () const { return m_IsFloodfill; }; void SetFloodfill (bool floodfill); void SetFamily (const std::string& family); + std::string GetFamilyString () const; void SetBandwidth (int limit); /* in kilobytes */ void SetBandwidth (char L); /* by letter */ bool AcceptsTunnels () const { return m_AcceptsTunnels; }; @@ -100,6 +101,7 @@ namespace i2p i2p::data::PrivateKeys m_Keys; uint64_t m_LastUpdateTime; bool m_AcceptsTunnels, m_IsFloodfill; + std::string m_FamilyString; uint64_t m_StartupTime; // in seconds since epoch uint32_t m_BandwidthLimit; // allowed bandwidth RouterStatus m_Status; From 61e8becd38e2b1af4948fa56333f8ee82d66040b Mon Sep 17 00:00:00 2001 From: weekendi2p Date: Wed, 27 Apr 2016 00:48:23 +0200 Subject: [PATCH 2/6] wrong file version --- Daemon.cpp | 1 + RouterContext.cpp | 14 ++++++++------ RouterContext.h | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Daemon.cpp b/Daemon.cpp index 81bbcdd5..2a32ff04 100644 --- a/Daemon.cpp +++ b/Daemon.cpp @@ -189,6 +189,7 @@ namespace i2p std::string family; i2p::config::GetOption("family", family); i2p::context.SetFamily (family); + i2p::context.SetFamilyString (family); if (family.length () > 0) LogPrint(eLogInfo, "Daemon: family set to ", family); diff --git a/RouterContext.cpp b/RouterContext.cpp index 4cdf13fe..bc1f3fc1 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -149,6 +149,14 @@ namespace i2p UpdateRouterInfo (); } + void RouterContext::SetFamilyString (const std::string& family) + { + if (family.length() > 0) + m_FamilyString = family; + else + m_FamilyString = "<undefined>"; + } + std::string RouterContext::GetFamilyString () const { return m_FamilyString; @@ -157,15 +165,9 @@ namespace i2p void RouterContext::SetFamily (const std::string& family) { - m_FamilyString = family; - if (m_FamilyString.length() == 0) - m_FamilyString = "<undefined>"; - std::string signature; if (family.length () > 0) - { signature = i2p::data::CreateFamilySignature (family, GetIdentHash ()); - } if (signature.length () > 0) { m_RouterInfo.SetProperty (i2p::data::ROUTER_INFO_PROPERTY_FAMILY, family); diff --git a/RouterContext.h b/RouterContext.h index 1b0f7ed2..def89383 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -59,6 +59,7 @@ namespace i2p bool IsFloodfill () const { return m_IsFloodfill; }; void SetFloodfill (bool floodfill); void SetFamily (const std::string& family); + void SetFamilyString (const std::string& family); std::string GetFamilyString () const; void SetBandwidth (int limit); /* in kilobytes */ void SetBandwidth (char L); /* by letter */ From ebee94fb11b436add295ae791cb1fe53c6e99d7d Mon Sep 17 00:00:00 2001 From: weekendi2p Date: Wed, 27 Apr 2016 01:19:27 +0200 Subject: [PATCH 3/6] removed 1 blank line.. --- RouterContext.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/RouterContext.cpp b/RouterContext.cpp index bc1f3fc1..29891169 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -164,7 +164,6 @@ namespace i2p void RouterContext::SetFamily (const std::string& family) { - std::string signature; if (family.length () > 0) signature = i2p::data::CreateFamilySignature (family, GetIdentHash ()); From 2373b94d3e7794dc19a95322a0c407fddf6ae8d9 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Wed, 27 Apr 2016 12:08:08 -0400 Subject: [PATCH 4/6] try fixing issue #482 --- Destination.cpp | 25 ++++++++++++++----------- util.h | 14 ++++++++++++++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/Destination.cpp b/Destination.cpp index 5893caff..1534cbf9 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -9,6 +9,7 @@ #include "Timestamp.h" #include "NetDb.h" #include "Destination.h" +#include "util.h" namespace i2p { @@ -35,28 +36,30 @@ namespace client { auto it = params->find (I2CP_PARAM_INBOUND_TUNNEL_LENGTH); if (it != params->end ()) - { - int len = boost::lexical_cast(it->second); + { + + int len = i2p::util::lexical_cast(it->second, inboundTunnelLen); if (len > 0) { - inboundTunnelLen = len; - LogPrint (eLogInfo, "Destination: Inbound tunnel length set to ", len); + inboundTunnelLen = len; } + LogPrint (eLogInfo, "Destination: Inbound tunnel length set to ", inboundTunnelLen); } it = params->find (I2CP_PARAM_OUTBOUND_TUNNEL_LENGTH); if (it != params->end ()) { - int len = boost::lexical_cast(it->second); + + int len = i2p::util::lexical_cast(it->second, outboundTunnelLen); if (len > 0) { - outboundTunnelLen = len; - LogPrint (eLogInfo, "Destination: Outbound tunnel length set to ", len); + outboundTunnelLen = len; } + LogPrint (eLogInfo, "Destination: Outbound tunnel length set to ", outboundTunnelLen); } it = params->find (I2CP_PARAM_INBOUND_TUNNELS_QUANTITY); if (it != params->end ()) { - int quantity = boost::lexical_cast(it->second); + int quantity = i2p::util::lexical_cast(it->second, inboundTunnelsQuantity); if (quantity > 0) { inboundTunnelsQuantity = quantity; @@ -66,7 +69,7 @@ namespace client it = params->find (I2CP_PARAM_OUTBOUND_TUNNELS_QUANTITY); if (it != params->end ()) { - int quantity = boost::lexical_cast(it->second); + int quantity = i2p::util::lexical_cast(it->second, outboundTunnelsQuantity); if (quantity > 0) { outboundTunnelsQuantity = quantity; @@ -76,11 +79,11 @@ namespace client it = params->find (I2CP_PARAM_TAGS_TO_SEND); if (it != params->end ()) { - int tagsToSend = boost::lexical_cast(it->second); + int tagsToSend = i2p::util::lexical_cast(it->second, numTags); if (tagsToSend > 0) { numTags = tagsToSend; - LogPrint (eLogInfo, "Destination: Tags to send set to ", tagsToSend); + LogPrint (eLogInfo, "Destination: Tags to send set to ", tagsToSend); } } it = params->find (I2CP_PARAM_EXPLICIT_PEERS); diff --git a/util.h b/util.h index 13200591..f5dbc9aa 100644 --- a/util.h +++ b/util.h @@ -5,11 +5,25 @@ #include #include #include +#include namespace i2p { namespace util { + + /** + wrapper arround boost::lexical_cast that "never" fails + */ + template + T lexical_cast(const std::string & str, const T fallback) { + try { + return boost::lexical_cast(str); + } catch ( ... ) { + return fallback; + } + } + namespace http { // in (lower case) From 5e2dc14dd5564fda8f6458db0de38485edd9d6de Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 28 Apr 2016 18:16:11 -0400 Subject: [PATCH 5/6] get family string from local RouterInfo --- Daemon.cpp | 1 - HTTPServer.cpp | 4 +++- RouterContext.cpp | 12 ++---------- RouterContext.h | 4 +--- RouterInfo.cpp | 8 ++++++++ RouterInfo.h | 1 + 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Daemon.cpp b/Daemon.cpp index 2a32ff04..81bbcdd5 100644 --- a/Daemon.cpp +++ b/Daemon.cpp @@ -189,7 +189,6 @@ namespace i2p std::string family; i2p::config::GetOption("family", family); i2p::context.SetFamily (family); - i2p::context.SetFamilyString (family); if (family.length () > 0) LogPrint(eLogInfo, "Daemon: family set to ", family); diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 08b67e22..458a717f 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -417,7 +417,9 @@ namespace util default: s << "Unknown"; } s << "
\r\n"; - s << "Family: " << i2p::context.GetFamilyString() << "
\r\n"; + auto family = i2p::context.GetFamily (); + if (family.length () > 0) + s << "Family: " << family << "
\r\n"; s << "Tunnel creation success rate: " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate () << "%
\r\n"; s << "Received: "; s << std::fixed << std::setprecision(2); diff --git a/RouterContext.cpp b/RouterContext.cpp index 29891169..5fa32a13 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -149,17 +149,9 @@ namespace i2p UpdateRouterInfo (); } - void RouterContext::SetFamilyString (const std::string& family) + std::string RouterContext::GetFamily () const { - if (family.length() > 0) - m_FamilyString = family; - else - m_FamilyString = "<undefined>"; - } - - std::string RouterContext::GetFamilyString () const - { - return m_FamilyString; + return m_RouterInfo.GetProperty (i2p::data::ROUTER_INFO_PROPERTY_FAMILY); } void RouterContext::SetFamily (const std::string& family) diff --git a/RouterContext.h b/RouterContext.h index def89383..5a72ad58 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -59,8 +59,7 @@ namespace i2p bool IsFloodfill () const { return m_IsFloodfill; }; void SetFloodfill (bool floodfill); void SetFamily (const std::string& family); - void SetFamilyString (const std::string& family); - std::string GetFamilyString () const; + std::string GetFamily () const; void SetBandwidth (int limit); /* in kilobytes */ void SetBandwidth (char L); /* by letter */ bool AcceptsTunnels () const { return m_AcceptsTunnels; }; @@ -102,7 +101,6 @@ namespace i2p i2p::data::PrivateKeys m_Keys; uint64_t m_LastUpdateTime; bool m_AcceptsTunnels, m_IsFloodfill; - std::string m_FamilyString; uint64_t m_StartupTime; // in seconds since epoch uint32_t m_BandwidthLimit; // allowed bandwidth RouterStatus m_Status; diff --git a/RouterInfo.cpp b/RouterInfo.cpp index c27f8754..2e76127c 100644 --- a/RouterInfo.cpp +++ b/RouterInfo.cpp @@ -636,6 +636,14 @@ namespace data m_Properties.erase (key); } + std::string RouterInfo::GetProperty (const std::string& key) const + { + auto it = m_Properties.find (key); + if (it != m_Properties.end ()) + return it->second; + return ""; + } + bool RouterInfo::IsNTCP (bool v4only) const { if (v4only) diff --git a/RouterInfo.h b/RouterInfo.h index c9881dd2..a55924a8 100644 --- a/RouterInfo.h +++ b/RouterInfo.h @@ -128,6 +128,7 @@ namespace data bool RemoveIntroducer (const boost::asio::ip::udp::endpoint& e); void SetProperty (const std::string& key, const std::string& value); // called from RouterContext only void DeleteProperty (const std::string& key); // called from RouterContext only + std::string GetProperty (const std::string& key) const; // called from RouterContext only void ClearProperties () { m_Properties.clear (); }; bool IsFloodfill () const { return m_Caps & Caps::eFloodfill; }; bool IsReachable () const { return m_Caps & Caps::eReachable; }; From 00cfdc7d9257cfdb0ada151b77bf14b52c4da729 Mon Sep 17 00:00:00 2001 From: Jeff Date: Wed, 4 May 2016 12:12:24 -0400 Subject: [PATCH 6/6] fix mac brew, use libressl and homebrew --- Makefile | 2 +- Makefile.homebrew | 29 +++++++++++++++++++++++++++++ docs/build_notes_unix.md | 15 +++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 Makefile.homebrew diff --git a/Makefile b/Makefile index ae49ae4f..db6da2df 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ USE_STATIC := no ifeq ($(UNAME),Darwin) DAEMON_SRC += DaemonLinux.cpp - include Makefile.osx + include Makefile.homebrew else ifeq ($(shell echo $(UNAME) | $(GREP) -c FreeBSD),1) DAEMON_SRC += DaemonLinux.cpp include Makefile.bsd diff --git a/Makefile.homebrew b/Makefile.homebrew new file mode 100644 index 00000000..163b7950 --- /dev/null +++ b/Makefile.homebrew @@ -0,0 +1,29 @@ +# root directory holding homebrew +BREWROOT = /usr/local/ +BOOSTROOT = ${BREWROOT}/opt/boost +SSLROOT = ${BREWROOT}/opt/libressl +CXX = clang++ +CXXFLAGS = -g -Wall -std=c++11 -DMAC_OSX +INCFLAGS = -I${SSLROOT}/include -I${BOOSTROOT}/include +LDFLAGS = -L${SSLROOT}/lib -L${BOOSTROOT}/lib +LDLIBS = -lz -lcrypto -lssl -lboost_system -lboost_date_time -lboost_filesystem -lboost_regex -lboost_program_options -lpthread + +ifeq ($(USE_UPNP),1) + LDFLAGS += -ldl + CXXFLAGS += -DUSE_UPNP +endif + +# OSX Notes +# http://www.hutsby.net/2011/08/macs-with-aes-ni.html +# Seems like all recent Mac's have AES-NI, after firmware upgrade 2.2 +# Found no good way to detect it from command line. TODO: Might be some osx sysinfo magic +# note from psi: 2009 macbook does not have aesni +#ifeq ($(USE_AESNI),yes) +# CXXFLAGS += -maes -DAESNI +#endif + +# Disabled, since it will be the default make rule. I think its better +# to define the default rule in Makefile and not Makefile. - torkel +#install: all +# test -d ${PREFIX} || mkdir -p ${PREFIX}/ +# cp -r i2p ${PREFIX}/ diff --git a/docs/build_notes_unix.md b/docs/build_notes_unix.md index d02eb5df..d173d4ae 100644 --- a/docs/build_notes_unix.md +++ b/docs/build_notes_unix.md @@ -93,6 +93,21 @@ If you need UPnP support (don't forget to run CMake with `WITH_UPNP=ON`) miniupn miniupnpc-devel ``` +MAC OS X +-------- + +Requires homebrew + +```bash +brew install libressl boost +``` + +Then build: +```bash +make +``` + + FreeBSD -------