From 0a0f61b940e908eb6a512bf991f8ee651dba9c3a Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 1 Apr 2014 12:46:08 -0400 Subject: [PATCH 01/29] some cleanup --- Tunnel.cpp | 17 ----------------- Tunnel.h | 1 - 2 files changed, 18 deletions(-) diff --git a/Tunnel.cpp b/Tunnel.cpp index c32c5e0e..ea81b1f7 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -237,23 +237,6 @@ namespace tunnel } return tunnel; } - - std::vector Tunnels::GetInboundTunnels (int num) const - { - std::vector v; - int i = 0; - for (auto it : m_InboundTunnels) - { - if (i >= num) break; - if (!it.second->IsFailed () && it.second->GetNextIdentHash () != i2p::context.GetRouterInfo ().GetIdentHash ()) - { - // exclude one hop tunnels - v.push_back (it.second); - i++; - } - } - return v; - } OutboundTunnel * Tunnels::GetNextOutboundTunnel () { diff --git a/Tunnel.h b/Tunnel.h index 6711bd3d..58fd3880 100644 --- a/Tunnel.h +++ b/Tunnel.h @@ -114,7 +114,6 @@ namespace tunnel InboundTunnel * GetInboundTunnel (uint32_t tunnelID); Tunnel * GetPendingTunnel (uint32_t replyMsgID); InboundTunnel * GetNextInboundTunnel (); - std::vector GetInboundTunnels (int num) const; OutboundTunnel * GetNextOutboundTunnel (); TransitTunnel * GetTransitTunnel (uint32_t tunnelID); void AddTransitTunnel (TransitTunnel * tunnel); From d7a584f48f7b96421e133d9347ffa25d686120d3 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 1 Apr 2014 12:50:29 -0400 Subject: [PATCH 02/29] some cleanup --- Tunnel.cpp | 44 -------------------------------------------- Tunnel.h | 5 ----- 2 files changed, 49 deletions(-) diff --git a/Tunnel.cpp b/Tunnel.cpp index ea81b1f7..7178e5fd 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -535,49 +535,5 @@ namespace tunnel &i2p::context.GetRouterInfo () })); } - - OutboundTunnel * Tunnels::CreateOneHopOutboundTestTunnel (InboundTunnel * replyTunnel) - { - return CreateTunnel (replyTunnel->GetTunnelConfig ()->Invert ()); - } - - InboundTunnel * Tunnels::CreateOneHopInboundTestTunnel (OutboundTunnel * outboundTunnel) - { - i2p::ntcp::NTCPSession * peer = i2p::transports.GetNextNTCPSession (); - if (peer) - { - const i2p::data::RouterInfo& router = peer->GetRemoteRouterInfo (); - return CreateTunnel ( - new TunnelConfig (std::vector{&router}), - outboundTunnel); - } - else - LogPrint ("No established peers"); - return 0; - } - - OutboundTunnel * Tunnels::CreateTwoHopsOutboundTestTunnel (InboundTunnel * replyTunnel) - { - return CreateTunnel (replyTunnel->GetTunnelConfig ()->Invert ()); - } - - InboundTunnel * Tunnels::CreateTwoHopsInboundTestTunnel (OutboundTunnel * outboundTunnel) - { - i2p::ntcp::NTCPSession * peer = i2p::transports.GetNextNTCPSession (); - if (peer) - { - const i2p::data::RouterInfo& router = peer->GetRemoteRouterInfo (); - return CreateTunnel ( - new TunnelConfig (std::vector - { - &router, - &i2p::context.GetRouterInfo () - }), - outboundTunnel); - } - else - LogPrint ("No established peers"); - return 0; - } } } diff --git a/Tunnel.h b/Tunnel.h index 58fd3880..b964c55e 100644 --- a/Tunnel.h +++ b/Tunnel.h @@ -125,11 +125,6 @@ namespace tunnel TunnelPool * CreateTunnelPool (i2p::data::LocalDestination * localDestination); void DeleteTunnelPool (TunnelPool * pool); - OutboundTunnel * CreateOneHopOutboundTestTunnel (InboundTunnel * replyTunnel); - InboundTunnel * CreateOneHopInboundTestTunnel (OutboundTunnel * outboundTunnel = 0); - OutboundTunnel * CreateTwoHopsOutboundTestTunnel (InboundTunnel * replyTunnel); - InboundTunnel * CreateTwoHopsInboundTestTunnel (OutboundTunnel * outboundTunnel = 0); - private: void Run (); From ee08d6687feb5494ac503705e9da10d8199aa511 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 1 Apr 2014 13:42:04 -0400 Subject: [PATCH 03/29] GetIdentHash for LocalDestination --- Identity.h | 3 ++- RouterContext.h | 7 ++++++- Streaming.h | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Identity.h b/Identity.h index 6b180999..b9763209 100644 --- a/Identity.h +++ b/Identity.h @@ -118,7 +118,8 @@ namespace data { public: - virtual void UpdateLeaseSet () = 0; // LeaseSet must be update + virtual const IdentHash& GetIdentHash () const = 0; + virtual void UpdateLeaseSet () = 0; // LeaseSet must be updated }; } } diff --git a/RouterContext.h b/RouterContext.h index abbc3775..cb30db38 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -4,6 +4,7 @@ #include #include #include +#include "Identity.h" #include "RouterInfo.h" namespace i2p @@ -11,7 +12,7 @@ namespace i2p const char ROUTER_INFO[] = "router.info"; const char ROUTER_KEYS[] = "router.keys"; - class RouterContext + class RouterContext: public i2p::data::LocalDestination { public: @@ -28,6 +29,10 @@ namespace i2p void OverrideNTCPAddress (const char * host, int port); // temporary void UpdateAddress (const char * host); // called from SSU + // implements LocalDestination + void UpdateLeaseSet () {}; + const i2p::data::IdentHash& GetIdentHash () const { return m_RouterInfo.GetIdentHash (); }; + private: void CreateNewRouter (); diff --git a/Streaming.h b/Streaming.h index b25c70a0..cd118f17 100644 --- a/Streaming.h +++ b/Streaming.h @@ -138,6 +138,7 @@ namespace stream // implements LocalDestination void UpdateLeaseSet (); + const i2p::data::IdentHash& GetIdentHash () const { return m_IdentHash; }; private: From 81e06769dca9a6db760dd5f1e5a56c64d0a09149 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 1 Apr 2014 13:55:09 -0400 Subject: [PATCH 04/29] pass LocalDestination by reference --- Streaming.cpp | 4 ++-- Tunnel.cpp | 2 +- Tunnel.h | 2 +- TunnelPool.cpp | 5 ++--- TunnelPool.h | 4 ++-- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Streaming.cpp b/Streaming.cpp index facf68b4..34a24f69 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -347,7 +347,7 @@ namespace stream m_IdentHash = i2p::data::CalculateIdentHash (m_Keys.pub); m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag, CryptoPP::Integer (m_Keys.signingPrivateKey, 20)); - m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (this); + m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this); } StreamingDestination::StreamingDestination (const std::string& fullPath): m_LeaseSet (nullptr) @@ -357,7 +357,7 @@ namespace stream s.read ((char *)&m_Keys, sizeof (m_Keys)); else LogPrint ("Can't open file ", fullPath); - m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (this); + m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this); } StreamingDestination::~StreamingDestination () diff --git a/Tunnel.cpp b/Tunnel.cpp index 7178e5fd..e1804be7 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -255,7 +255,7 @@ namespace tunnel return tunnel; } - TunnelPool * Tunnels::CreateTunnelPool (i2p::data::LocalDestination * localDestination) + TunnelPool * Tunnels::CreateTunnelPool (i2p::data::LocalDestination& localDestination) { auto pool = new TunnelPool (localDestination); m_Pools.push_back (pool); diff --git a/Tunnel.h b/Tunnel.h index b964c55e..d58b1ae6 100644 --- a/Tunnel.h +++ b/Tunnel.h @@ -122,7 +122,7 @@ namespace tunnel void PostTunnelData (I2NPMessage * msg); template TTunnel * CreateTunnel (TunnelConfig * config, OutboundTunnel * outboundTunnel = 0); - TunnelPool * CreateTunnelPool (i2p::data::LocalDestination * localDestination); + TunnelPool * CreateTunnelPool (i2p::data::LocalDestination& localDestination); void DeleteTunnelPool (TunnelPool * pool); private: diff --git a/TunnelPool.cpp b/TunnelPool.cpp index f71a63c3..0b09d352 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -12,7 +12,7 @@ namespace i2p { namespace tunnel { - TunnelPool::TunnelPool (i2p::data::LocalDestination * localDestination, int numTunnels): + TunnelPool::TunnelPool (i2p::data::LocalDestination& localDestination, int numTunnels): m_LocalDestination (localDestination), m_NumTunnels (numTunnels), m_LastOutboundTunnel (nullptr) { CryptoPP::AutoSeededRandomPool rnd; @@ -40,8 +40,7 @@ namespace tunnel expiredTunnel->SetTunnelPool (nullptr); m_InboundTunnels.erase (expiredTunnel); } - if (m_LocalDestination) - m_LocalDestination->UpdateLeaseSet (); + m_LocalDestination.UpdateLeaseSet (); } void TunnelPool::TunnelCreated (OutboundTunnel * createdTunnel) diff --git a/TunnelPool.h b/TunnelPool.h index 8cef8375..16061991 100644 --- a/TunnelPool.h +++ b/TunnelPool.h @@ -22,7 +22,7 @@ namespace tunnel { public: - TunnelPool (i2p::data::LocalDestination * localDestination, int numTunnels = 5); + TunnelPool (i2p::data::LocalDestination& localDestination, int numTunnels = 5); ~TunnelPool (); const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; }; @@ -47,7 +47,7 @@ namespace tunnel private: uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256]; - i2p::data::LocalDestination * m_LocalDestination; + i2p::data::LocalDestination& m_LocalDestination; int m_NumTunnels; std::set m_InboundTunnels; // recent tunnel appears first std::set m_OutboundTunnels; From a10edb4cc54f1bab44fca3ba0c993e3a632c9b70 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 1 Apr 2014 15:08:53 -0400 Subject: [PATCH 05/29] pools per ident hash --- Tunnel.cpp | 15 +++++++++------ Tunnel.h | 2 +- TunnelPool.h | 3 ++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Tunnel.cpp b/Tunnel.cpp index e1804be7..334abee1 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -190,7 +190,7 @@ namespace tunnel m_PendingTunnels.clear (); for (auto& it: m_Pools) - delete it; + delete it.second; m_Pools.clear (); } @@ -258,14 +258,17 @@ namespace tunnel TunnelPool * Tunnels::CreateTunnelPool (i2p::data::LocalDestination& localDestination) { auto pool = new TunnelPool (localDestination); - m_Pools.push_back (pool); + m_Pools[pool->GetIdentHash ()] = pool; return pool; } void Tunnels::DeleteTunnelPool (TunnelPool * pool) { - m_Pools.remove (pool); - delete pool; + if (pool) + { + m_Pools.erase (pool->GetIdentHash ()); + delete pool; + } } void Tunnels::AddTransitTunnel (TransitTunnel * tunnel) @@ -485,8 +488,8 @@ namespace tunnel { for (auto& it: m_Pools) { - it->CreateTunnels (); - it->TestTunnels (); + it.second->CreateTunnels (); + it.second->TestTunnels (); } } diff --git a/Tunnel.h b/Tunnel.h index d58b1ae6..7fffd64d 100644 --- a/Tunnel.h +++ b/Tunnel.h @@ -146,7 +146,7 @@ namespace tunnel std::map m_InboundTunnels; std::list m_OutboundTunnels; std::map m_TransitTunnels; - std::list m_Pools; + std::map m_Pools; i2p::util::Queue m_Queue; public: diff --git a/TunnelPool.h b/TunnelPool.h index 16061991..3a3b67b5 100644 --- a/TunnelPool.h +++ b/TunnelPool.h @@ -35,7 +35,8 @@ namespace tunnel void TunnelExpired (OutboundTunnel * expiredTunnel); std::vector GetInboundTunnels (int num) const; OutboundTunnel * GetNextOutboundTunnel (); - + const i2p::data::IdentHash& GetIdentHash () { return m_LocalDestination.GetIdentHash (); }; + void TestTunnels (); void ProcessDeliveryStatus (I2NPMessage * msg); From aaa14d45644415fc486f3f5cc750462ee1986b8b Mon Sep 17 00:00:00 2001 From: cpubug Date: Tue, 1 Apr 2014 23:18:14 +0400 Subject: [PATCH 06/29] split AddressBook header/source --- AddressBook.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ AddressBook.h | 44 +++-------------------------------- Makefile | 2 +- 3 files changed, 66 insertions(+), 42 deletions(-) create mode 100644 AddressBook.cpp diff --git a/AddressBook.cpp b/AddressBook.cpp new file mode 100644 index 00000000..8bd82d42 --- /dev/null +++ b/AddressBook.cpp @@ -0,0 +1,62 @@ +#include +#include +#include +#include "base64.h" +#include "util.h" +#include "Identity.h" +#include "Log.h" +#include "AddressBook.h" + +namespace i2p +{ +namespace data +{ + +AddressBook::AddressBook (): m_IsLoaded (false) +{ +} + + +const IdentHash * AddressBook::FindAddress (const std::string& address) +{ + if (!m_IsLoaded) + LoadHosts (); + auto it = m_Addresses.find (address); + if (it != m_Addresses.end ()) + return &it->second; + else + return nullptr; +} + + +void AddressBook::LoadHosts () +{ + m_IsLoaded = true; + std::ifstream f (i2p::util::filesystem::GetFullPath ("hosts.txt").c_str (), std::ofstream::in); // in text mode + if (!f.is_open ()) + { + LogPrint ("hosts.txt not found"); + return; + } + int numAddresses = 0; + char str[1024]; + while (!f.eof ()) + { + f.getline (str, 1024); + char * key = strchr (str, '='); + if (key) + { + *key = 0; + key++; + Identity ident; + Base64ToByteStream (key, strlen(key), (uint8_t *)&ident, sizeof (ident)); + m_Addresses[str] = CalculateIdentHash (ident); + numAddresses++; + } + } + LogPrint (numAddresses, " addresses loaded"); +} + +} +} + diff --git a/AddressBook.h b/AddressBook.h index 6d134247..8d255a7a 100644 --- a/AddressBook.h +++ b/AddressBook.h @@ -17,50 +17,12 @@ namespace data { public: - AddressBook (): m_IsLoaded (false) {}; - - const IdentHash * FindAddress (const std::string& address) - { - if (!m_IsLoaded) - LoadHosts (); - auto it = m_Addresses.find (address); - if (it != m_Addresses.end ()) - return &it->second; - else - return nullptr; - } + AddressBook (); + const IdentHash * FindAddress (const std::string& address); private: - void LoadHosts () - { - m_IsLoaded = true; - std::ifstream f (i2p::util::filesystem::GetFullPath ("hosts.txt").c_str (), std::ofstream::in); // in text mode - if (!f.is_open ()) - { - LogPrint ("hosts.txt not found"); - return; - } - int numAddresses = 0; - char str[1024]; - while (!f.eof ()) - { - f.getline (str, 1024); - char * key = strchr (str, '='); - if (key) - { - *key = 0; - key++; - Identity ident; - Base64ToByteStream (key, strlen(key), (uint8_t *)&ident, sizeof (ident)); - m_Addresses[str] = CalculateIdentHash (ident); - numAddresses++; - } - } - LogPrint (numAddresses, " addresses loaded"); - } - - private: + void LoadHosts (); std::map m_Addresses; bool m_IsLoaded; diff --git a/Makefile b/Makefile index d13d41b7..fec4f79d 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ OBJECTS = obj/i2p.o obj/base64.o obj/NTCPSession.o obj/RouterInfo.o obj/Transpor obj/RouterContext.o obj/NetDb.o obj/LeaseSet.o obj/Tunnel.o obj/TunnelEndpoint.o \ obj/TunnelGateway.o obj/TransitTunnel.o obj/I2NPProtocol.o obj/Log.o obj/Garlic.o \ obj/HTTPServer.o obj/Streaming.o obj/Identity.o obj/SSU.o obj/util.o obj/Reseed.o \ - obj/UPnP.o obj/TunnelPool.o obj/HTTPProxy.o + obj/UPnP.o obj/TunnelPool.o obj/HTTPProxy.o obj/AddressBook.o INCFLAGS = LDFLAGS = -Wl,-rpath,/usr/local/lib -lcryptopp -lboost_system -lboost_filesystem -lboost_regex -lboost_program_options -lpthread LIBS = From 0e49d4dcd65b8704bc344694ab04fde5d3e51b1c Mon Sep 17 00:00:00 2001 From: cpubug Date: Wed, 2 Apr 2014 00:27:40 +0400 Subject: [PATCH 07/29] improve hosts.txt loading --- AddressBook.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/AddressBook.cpp b/AddressBook.cpp index 8bd82d42..023e75cf 100644 --- a/AddressBook.cpp +++ b/AddressBook.cpp @@ -39,18 +39,26 @@ void AddressBook::LoadHosts () return; } int numAddresses = 0; - char str[1024]; + + std::string s; + while (!f.eof ()) { - f.getline (str, 1024); - char * key = strchr (str, '='); - if (key) + getline(f, s); + + if (!s.length()) + break; + + size_t pos = s.find('='); + + if (pos != std::string::npos) { - *key = 0; - key++; + std::string name = s.substr(0, pos++); + std::string addr = s.substr(pos); + Identity ident; - Base64ToByteStream (key, strlen(key), (uint8_t *)&ident, sizeof (ident)); - m_Addresses[str] = CalculateIdentHash (ident); + Base64ToByteStream (addr.c_str(), addr.length(), (uint8_t *)&ident, sizeof (ident)); + m_Addresses[name] = CalculateIdentHash (ident); numAddresses++; } } From c600be59b18043d1f0a6391df0bc0fe25100f3b1 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 1 Apr 2014 18:58:47 -0400 Subject: [PATCH 08/29] moved encryption keys from TunnelPool to StreamingDestination --- Identity.h | 2 ++ RouterContext.h | 4 +++- Streaming.cpp | 5 +++++ Streaming.h | 5 ++++- TunnelPool.cpp | 4 ---- TunnelPool.h | 5 ++--- 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Identity.h b/Identity.h index b9763209..2aca019b 100644 --- a/Identity.h +++ b/Identity.h @@ -119,6 +119,8 @@ namespace data public: virtual const IdentHash& GetIdentHash () const = 0; + virtual const uint8_t * GetEncryptionPrivateKey () const = 0; + virtual const uint8_t * GetEncryptionPublicKey () const = 0; virtual void UpdateLeaseSet () = 0; // LeaseSet must be updated }; } diff --git a/RouterContext.h b/RouterContext.h index cb30db38..bd5acd4e 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -32,7 +32,9 @@ namespace i2p // implements LocalDestination void UpdateLeaseSet () {}; const i2p::data::IdentHash& GetIdentHash () const { return m_RouterInfo.GetIdentHash (); }; - + const uint8_t * GetEncryptionPrivateKey () const { return GetPrivateKey (); }; + const uint8_t * GetEncryptionPublicKey () const { return m_Keys.publicKey; }; + private: void CreateNewRouter (); diff --git a/Streaming.cpp b/Streaming.cpp index 34a24f69..9291235a 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include "Log.h" #include "RouterInfo.h" @@ -347,6 +348,8 @@ namespace stream m_IdentHash = i2p::data::CalculateIdentHash (m_Keys.pub); m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag, CryptoPP::Integer (m_Keys.signingPrivateKey, 20)); + CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg); + dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey); m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this); } @@ -357,6 +360,8 @@ namespace stream s.read ((char *)&m_Keys, sizeof (m_Keys)); else LogPrint ("Can't open file ", fullPath); + CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg); + dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey); m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this); } diff --git a/Streaming.h b/Streaming.h index cd118f17..b1706e4a 100644 --- a/Streaming.h +++ b/Streaming.h @@ -139,6 +139,8 @@ namespace stream // implements LocalDestination void UpdateLeaseSet (); const i2p::data::IdentHash& GetIdentHash () const { return m_IdentHash; }; + const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; }; + const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; }; private: @@ -149,7 +151,8 @@ namespace stream std::map m_Streams; i2p::data::PrivateKeys m_Keys; i2p::data::IdentHash m_IdentHash; - + uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256]; + i2p::tunnel::TunnelPool * m_Pool; I2NPMessage * m_LeaseSet; diff --git a/TunnelPool.cpp b/TunnelPool.cpp index 0b09d352..b7c22e2b 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -1,4 +1,3 @@ -#include #include "I2PEndian.h" #include "CryptoConst.h" #include "Tunnel.h" @@ -15,9 +14,6 @@ namespace tunnel TunnelPool::TunnelPool (i2p::data::LocalDestination& localDestination, int numTunnels): m_LocalDestination (localDestination), m_NumTunnels (numTunnels), m_LastOutboundTunnel (nullptr) { - CryptoPP::AutoSeededRandomPool rnd; - CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg); - dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey); } TunnelPool::~TunnelPool () diff --git a/TunnelPool.h b/TunnelPool.h index 3a3b67b5..c780d9b7 100644 --- a/TunnelPool.h +++ b/TunnelPool.h @@ -25,8 +25,8 @@ namespace tunnel TunnelPool (i2p::data::LocalDestination& localDestination, int numTunnels = 5); ~TunnelPool (); - const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; }; - const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; }; + const uint8_t * GetEncryptionPrivateKey () const { return m_LocalDestination.GetEncryptionPrivateKey (); }; + const uint8_t * GetEncryptionPublicKey () const { return m_LocalDestination.GetEncryptionPublicKey (); }; void CreateTunnels (); void TunnelCreated (InboundTunnel * createdTunnel); @@ -47,7 +47,6 @@ namespace tunnel private: - uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256]; i2p::data::LocalDestination& m_LocalDestination; int m_NumTunnels; std::set m_InboundTunnels; // recent tunnel appears first From 4970b4d14e0c6d701a02f55b4e8ae0c9f2e1cd52 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 2 Apr 2014 10:49:16 -0400 Subject: [PATCH 09/29] generic SSU timer --- SSU.cpp | 58 ++++++++++++++++++++++++++++----------------------------- SSU.h | 6 +++--- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/SSU.cpp b/SSU.cpp index b0d351ff..73c42464 100644 --- a/SSU.cpp +++ b/SSU.cpp @@ -14,16 +14,14 @@ namespace i2p namespace ssu { - SSUSession::SSUSession (SSUServer * server, boost::asio::ip::udp::endpoint& remoteEndpoint, + SSUSession::SSUSession (SSUServer& server, boost::asio::ip::udp::endpoint& remoteEndpoint, const i2p::data::RouterInfo * router): m_Server (server), m_RemoteEndpoint (remoteEndpoint), - m_RemoteRouter (router), m_ConnectTimer (nullptr),m_State (eSessionStateUnknown) + m_RemoteRouter (router), m_Timer (m_Server.GetService ()), m_State (eSessionStateUnknown) { } SSUSession::~SSUSession () { - if (m_ConnectTimer) - delete m_ConnectTimer; } void SSUSession::CreateAESandMacKey (uint8_t * pubKey, uint8_t * aesKey, uint8_t * macKey) @@ -110,8 +108,7 @@ namespace ssu case PAYLOAD_TYPE_SESSION_DESTROYED: { LogPrint ("SSU session destroy received"); - if (m_Server) - m_Server->DeleteSession (this); // delete this + m_Server.DeleteSession (this); // delete this break; } case PAYLOAD_TYPE_RELAY_INTRO: @@ -166,7 +163,7 @@ namespace ssu { m_State = eSessionStateCreatedReceived; LogPrint ("Session created received"); - if (m_ConnectTimer) m_ConnectTimer->cancel (); + m_Timer.cancel (); // connect timer uint8_t signedData[532]; // x,y, our IP, our port, remote IP, remote port, relayTag, signed on time uint8_t * payload = buf + sizeof (SSUHeader); uint8_t * y = payload; @@ -245,7 +242,7 @@ namespace ssu FillHeaderAndEncrypt (PAYLOAD_TYPE_SESSION_REQUEST, buf, 304, introKey, iv, introKey); m_State = eSessionStateRequestSent; - m_Server->Send (buf, 304, m_RemoteEndpoint); + m_Server.Send (buf, 304, m_RemoteEndpoint); } void SSUSession::SendRelayRequest (const i2p::data::RouterInfo::Introducer& introducer) @@ -276,7 +273,7 @@ namespace ssu rnd.GenerateBlock (iv, 16); // random iv FillHeaderAndEncrypt (PAYLOAD_TYPE_RELAY_REQUEST, buf, 96, introducer.iKey, iv, introducer.iKey); m_State = eSessionRelayRequestSent; - m_Server->Send (buf, 96, m_RemoteEndpoint); + m_Server.Send (buf, 96, m_RemoteEndpoint); } void SSUSession::SendSessionCreated (const uint8_t * x) @@ -323,7 +320,7 @@ namespace ssu // encrypt message with intro key FillHeaderAndEncrypt (PAYLOAD_TYPE_SESSION_CREATED, buf, 368, introKey, iv, introKey); m_State = eSessionStateCreatedSent; - m_Server->Send (buf, 368, m_RemoteEndpoint); + m_Server.Send (buf, 368, m_RemoteEndpoint); } void SSUSession::SendSessionConfirmed (const uint8_t * y, const uint8_t * ourAddress, uint32_t relayTag) @@ -362,7 +359,7 @@ namespace ssu // encrypt message with session key FillHeaderAndEncrypt (PAYLOAD_TYPE_SESSION_CONFIRMED, buf, 480, m_SessionKey, iv, m_MacKey); m_State = eSessionStateConfirmedSent; - m_Server->Send (buf, 480, m_RemoteEndpoint); + m_Server.Send (buf, 480, m_RemoteEndpoint); } void SSUSession::ProcessRelayResponse (uint8_t * buf, size_t len) @@ -390,7 +387,7 @@ namespace ssu uint16_t remotePort = be16toh (*(uint16_t *)(payload)); payload += 2; boost::asio::ip::udp::endpoint newRemoteEndpoint(remoteIP, remotePort); - m_Server->ReassignSession (m_RemoteEndpoint, newRemoteEndpoint); + m_Server.ReassignSession (m_RemoteEndpoint, newRemoteEndpoint); m_RemoteEndpoint = newRemoteEndpoint; payload++; boost::asio::ip::address_v4 ourIP (be32toh (*(uint32_t* )(payload))); @@ -494,13 +491,10 @@ namespace ssu { if (m_State == eSessionStateUnknown) { - if (m_Server) - { - m_ConnectTimer = new boost::asio::deadline_timer (m_Server->GetService ()); - m_ConnectTimer->expires_from_now (boost::posix_time::seconds(SSU_CONNECT_TIMEOUT)); - m_ConnectTimer->async_wait (boost::bind (&SSUSession::HandleConnectTimer, - this, boost::asio::placeholders::error)); - } + // set connect timer + m_Timer.expires_from_now (boost::posix_time::seconds(SSU_CONNECT_TIMEOUT)); + m_Timer.async_wait (boost::bind (&SSUSession::HandleConnectTimer, + this, boost::asio::placeholders::error)); SendSessionRequest (); } } @@ -516,8 +510,15 @@ namespace ssu } void SSUSession::ConnectThroughIntroducer (const i2p::data::RouterInfo::Introducer& introducer) - { - SendRelayRequest (introducer); + { + if (m_State == eSessionStateUnknown) + { + // set connect timer + m_Timer.expires_from_now (boost::posix_time::seconds(SSU_CONNECT_TIMEOUT)); + m_Timer.async_wait (boost::bind (&SSUSession::HandleConnectTimer, + this, boost::asio::placeholders::error)); + SendRelayRequest (introducer); + } } void SSUSession::Close () @@ -548,8 +549,7 @@ namespace ssu { m_State = eSessionStateFailed; Close (); - if (m_Server) - m_Server->DeleteSession (this); // delete this + m_Server.DeleteSession (this); // delete this } } @@ -692,7 +692,7 @@ namespace ssu rnd.GenerateBlock (iv, 16); // random iv // encrypt message with session key FillHeaderAndEncrypt (PAYLOAD_TYPE_DATA, buf, 48, m_SessionKey, iv, m_MacKey); - m_Server->Send (buf, 48, m_RemoteEndpoint); + m_Server.Send (buf, 48, m_RemoteEndpoint); } void SSUSession::SendSesionDestroyed () @@ -715,7 +715,7 @@ namespace ssu return; } } - m_Server->Send (buf, 48, m_RemoteEndpoint); + m_Server.Send (buf, 48, m_RemoteEndpoint); } void SSUSession::Send (i2p::I2NPMessage * msg) @@ -755,7 +755,7 @@ namespace ssu rnd.GenerateBlock (iv, 16); // random iv // encrypt message with session key FillHeaderAndEncrypt (PAYLOAD_TYPE_DATA, buf, size, m_SessionKey, iv, m_MacKey); - m_Server->Send (buf, size, m_RemoteEndpoint); + m_Server.Send (buf, size, m_RemoteEndpoint); if (!isLast) { @@ -815,7 +815,7 @@ namespace ssu session = it->second; if (!session) { - session = new SSUSession (this, m_SenderEndpoint); + session = new SSUSession (*this, m_SenderEndpoint); m_Sessions[m_SenderEndpoint] = session; LogPrint ("New SSU session from ", m_SenderEndpoint.address ().to_string (), ":", m_SenderEndpoint.port (), " created"); } @@ -856,7 +856,7 @@ namespace ssu if (!router->UsesIntroducer ()) { // connect directly - session = new SSUSession (this, remoteEndpoint, router); + session = new SSUSession (*this, remoteEndpoint, router); m_Sessions[remoteEndpoint] = session; LogPrint ("New SSU session to [", router->GetIdentHashAbbreviation (), "] ", remoteEndpoint.address ().to_string (), ":", remoteEndpoint.port (), " created"); @@ -869,7 +869,7 @@ namespace ssu { auto& introducer = address->introducers[0]; // TODO: boost::asio::ip::udp::endpoint introducerEndpoint (introducer.iHost, introducer.iPort); - session = new SSUSession (this, introducerEndpoint, router); + session = new SSUSession (*this, introducerEndpoint, router); m_Sessions[introducerEndpoint] = session; LogPrint ("New SSU session to [", router->GetIdentHashAbbreviation (), "] through introducer ", introducerEndpoint.address ().to_string (), ":", introducerEndpoint.port ()); diff --git a/SSU.h b/SSU.h index e43fa4ad..40c377c6 100644 --- a/SSU.h +++ b/SSU.h @@ -68,7 +68,7 @@ namespace ssu { public: - SSUSession (SSUServer * server, boost::asio::ip::udp::endpoint& remoteEndpoint, + SSUSession (SSUServer& server, boost::asio::ip::udp::endpoint& remoteEndpoint, const i2p::data::RouterInfo * router = nullptr); void ProcessNextMessage (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint); ~SSUSession (); @@ -109,10 +109,10 @@ namespace ssu private: - SSUServer * m_Server; + SSUServer& m_Server; boost::asio::ip::udp::endpoint m_RemoteEndpoint; const i2p::data::RouterInfo * m_RemoteRouter; - boost::asio::deadline_timer * m_ConnectTimer; + boost::asio::deadline_timer m_Timer; SessionState m_State; CryptoPP::CBC_Mode::Encryption m_Encryption; CryptoPP::CBC_Mode::Decryption m_Decryption; From 489266e7fcde4417e53cbd3f03b7d506068ea9f0 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 2 Apr 2014 13:14:21 -0400 Subject: [PATCH 10/29] exploratory pool added --- HTTPServer.cpp | 2 +- Tunnel.cpp | 2 +- Tunnel.h | 1 + TunnelPool.cpp | 1 - TunnelPool.h | 4 +++- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 27e6f0a1..0befdcda 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -255,7 +255,7 @@ namespace util for (auto it: i2p::tunnel::tunnels.GetInboundTunnels ()) { it.second->GetTunnelConfig ()->Print (s); - if (it.second->GetTunnelPool ()) + if (it.second->GetTunnelPool () && !it.second->GetTunnelPool ()->IsExploratory ()) s << " " << "Pool"; if (it.second->IsFailed ()) s << " " << "Failed"; diff --git a/Tunnel.cpp b/Tunnel.cpp index 334abee1..b85f05aa 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -167,7 +167,7 @@ namespace tunnel Tunnels tunnels; Tunnels::Tunnels (): m_IsRunning (false), m_IsTunnelCreated (false), - m_NextReplyMsgID (555),m_Thread (0) + m_NextReplyMsgID (555), m_Thread (nullptr), m_ExploratoryPool (nullptr) { } diff --git a/Tunnel.h b/Tunnel.h index 7fffd64d..4328ddb3 100644 --- a/Tunnel.h +++ b/Tunnel.h @@ -147,6 +147,7 @@ namespace tunnel std::list m_OutboundTunnels; std::map m_TransitTunnels; std::map m_Pools; + TunnelPool * m_ExploratoryPool; i2p::util::Queue m_Queue; public: diff --git a/TunnelPool.cpp b/TunnelPool.cpp index b7c22e2b..9b552101 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -3,7 +3,6 @@ #include "Tunnel.h" #include "NetDb.h" #include "Timestamp.h" -#include "RouterContext.h" #include "Garlic.h" #include "TunnelPool.h" diff --git a/TunnelPool.h b/TunnelPool.h index c780d9b7..bc71ae24 100644 --- a/TunnelPool.h +++ b/TunnelPool.h @@ -9,6 +9,7 @@ #include "LeaseSet.h" #include "I2NPProtocol.h" #include "TunnelBase.h" +#include "RouterContext.h" namespace i2p { @@ -27,7 +28,8 @@ namespace tunnel const uint8_t * GetEncryptionPrivateKey () const { return m_LocalDestination.GetEncryptionPrivateKey (); }; const uint8_t * GetEncryptionPublicKey () const { return m_LocalDestination.GetEncryptionPublicKey (); }; - + bool IsExploratory () const { return &m_LocalDestination == &i2p::context; }; + void CreateTunnels (); void TunnelCreated (InboundTunnel * createdTunnel); void TunnelExpired (InboundTunnel * expiredTunnel); From 70bf83f127aa0b998974a948521249232ceffc1c Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 2 Apr 2014 20:42:02 -0400 Subject: [PATCH 11/29] move exploratory tunnels to separate pool --- HTTPServer.cpp | 2 +- Tunnel.cpp | 70 ++++++++++++++------------------------------------ TunnelPool.h | 2 +- 3 files changed, 21 insertions(+), 53 deletions(-) diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 0befdcda..f7f15cc1 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -245,7 +245,7 @@ namespace util for (auto it: i2p::tunnel::tunnels.GetOutboundTunnels ()) { it->GetTunnelConfig ()->Print (s); - if (it->GetTunnelPool ()) + if (it->GetTunnelPool () && !it->GetTunnelPool ()->IsExploratory ()) s << " " << "Pool"; if (it->IsFailed ()) s << " " << "Failed"; diff --git a/Tunnel.cpp b/Tunnel.cpp index b85f05aa..9ccf4219 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -384,35 +384,18 @@ namespace tunnel it++; } - if (m_OutboundTunnels.size () < 15) // TODO: store exploratory tunnels explicitly + if (m_OutboundTunnels.size () < 5) { // trying to create one more oubound tunnel - if (m_InboundTunnels.empty ()) return; - InboundTunnel * inboundTunnel = GetNextInboundTunnel (); - if (m_OutboundTunnels.empty () || m_OutboundTunnels.size () < 3) - { - LogPrint ("Creating one hop outbound tunnel..."); - CreateTunnel ( - new TunnelConfig (std::vector - { - i2p::data::netdb.GetRandomRouter () - }, - inboundTunnel->GetTunnelConfig ())); - } - else - { - - LogPrint ("Creating two hops outbound tunnel..."); - auto firstHop = i2p::data::netdb.GetRandomRouter (); - CreateTunnel ( - new TunnelConfig (std::vector - { - firstHop, - i2p::data::netdb.GetRandomRouter (firstHop) - }, - inboundTunnel->GetTunnelConfig ())); - } + if (!inboundTunnel) return; + LogPrint ("Creating one hop outbound tunnel..."); + CreateTunnel ( + new TunnelConfig (std::vector + { + i2p::data::netdb.GetRandomRouter () + }, + inboundTunnel->GetTunnelConfig ())); } } @@ -437,35 +420,20 @@ namespace tunnel { LogPrint ("Creating zero hops inbound tunnel..."); CreateZeroHopsInboundTunnel (); + if (!m_ExploratoryPool) + m_ExploratoryPool = CreateTunnelPool (i2p::context); return; } - if (m_InboundTunnels.size () < 15) // TODO: store exploratory tunnels explicitly + if (m_OutboundTunnels.empty () || m_InboundTunnels.size () < 5) { - // trying to create one more inbound tunnel - if (m_OutboundTunnels.empty () || m_InboundTunnels.size () < 3) - { - LogPrint ("Creating one hop inbound tunnel..."); - CreateTunnel ( - new TunnelConfig (std::vector - { - i2p::data::netdb.GetRandomRouter () - })); - } - else - { - OutboundTunnel * outboundTunnel = GetNextOutboundTunnel (); - LogPrint ("Creating two hops inbound tunnel..."); - auto router = outboundTunnel->GetTunnelConfig ()->GetFirstHop ()->router; - auto firstHop = i2p::data::netdb.GetRandomRouter (outboundTunnel->GetEndpointRouter ()); - CreateTunnel ( - new TunnelConfig (std::vector - { - firstHop, - router != &i2p::context.GetRouterInfo () ? router : i2p::data::netdb.GetRandomRouter (firstHop) - }), - outboundTunnel); - } + // trying to create one more inbound tunnel + LogPrint ("Creating one hop inbound tunnel..."); + CreateTunnel ( + new TunnelConfig (std::vector + { + i2p::data::netdb.GetRandomRouter () + })); } } diff --git a/TunnelPool.h b/TunnelPool.h index bc71ae24..0e18bcd4 100644 --- a/TunnelPool.h +++ b/TunnelPool.h @@ -28,7 +28,7 @@ namespace tunnel const uint8_t * GetEncryptionPrivateKey () const { return m_LocalDestination.GetEncryptionPrivateKey (); }; const uint8_t * GetEncryptionPublicKey () const { return m_LocalDestination.GetEncryptionPublicKey (); }; - bool IsExploratory () const { return &m_LocalDestination == &i2p::context; }; + bool IsExploratory () const { return m_LocalDestination.GetIdentHash () == i2p::context.GetIdentHash (); }; void CreateTunnels (); void TunnelCreated (InboundTunnel * createdTunnel); From feb26692d42f9ef20c47ed53f46308c092bc0af4 Mon Sep 17 00:00:00 2001 From: Meeh Date: Thu, 3 Apr 2014 17:30:29 +0200 Subject: [PATCH 12/29] Adding initial travis file. --- .travis.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..a8ae739d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,34 @@ +language: cpp +matrix: + allow_failures: + - compiler: clang +compiler: + - gcc + - clang +cache: + - apt +branches: + only: + - master +before_install: + - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test # GCC 4.7 + - sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu/ quantal main universe" # Boost 1.50 + - sudo apt-get update -qq + - sudo apt-get install -qq libboost1.50-all-dev libcrypto++9 libcrypto++-dev +script: + - make +notifications: + email: + recipients: + - meeh@sigterm.no + on_success: change + on_failure: change + irc: + channels: + - "irc.freenode.net#i2p-dev" + template: + - "%{repository}/%{branch} (%{commit} - %{author}): %{message}" + on_failure: change + on_success: change + + From 1f85a1199ed9315f00c11fc54521883a820c1fce Mon Sep 17 00:00:00 2001 From: Meeh Date: Thu, 3 Apr 2014 18:15:44 +0200 Subject: [PATCH 13/29] dummy change for triggering travis --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a8ae739d..b38d8bad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,13 +22,13 @@ notifications: recipients: - meeh@sigterm.no on_success: change - on_failure: change + on_failure: always irc: channels: - "irc.freenode.net#i2p-dev" template: - "%{repository}/%{branch} (%{commit} - %{author}): %{message}" - on_failure: change + on_failure: always on_success: change From 646b3f6d7a8a336f7d7e0354bfea6817d4e4df2d Mon Sep 17 00:00:00 2001 From: Meeh Date: Thu, 3 Apr 2014 18:18:56 +0200 Subject: [PATCH 14/29] Adding build status to README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d19a666c..2a393e85 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ on Windows Requires msvs2013, boost 1.46 and higher, crypto++ +[![Build Status](https://travis-ci.org/orignal/i2pd.svg?branch=master)](https://travis-ci.org/orignal/i2pd) + Testing ------- From 92b96d9b15206ee5ab7aa3777947f45ec881c6a0 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 3 Apr 2014 12:19:12 -0400 Subject: [PATCH 15/29] fixed race condition --- Tunnel.cpp | 3 +++ Tunnel.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/Tunnel.cpp b/Tunnel.cpp index 9ccf4219..4b831fbc 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -154,11 +154,14 @@ namespace tunnel else block.deliveryType = eDeliveryTypeLocal; block.data = msg; + + std::unique_lock l(m_SendMutex); m_Gateway.SendTunnelDataMsg (block); } void OutboundTunnel::SendTunnelDataMsg (std::vector msgs) { + std::unique_lock l(m_SendMutex); for (auto& it : msgs) m_Gateway.PutTunnelDataMsg (it); m_Gateway.SendBuffer (); diff --git a/Tunnel.h b/Tunnel.h index 4328ddb3..d1d77fe9 100644 --- a/Tunnel.h +++ b/Tunnel.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include "Queue.h" @@ -83,6 +84,7 @@ namespace tunnel private: + std::mutex m_SendMutex; TunnelGateway m_Gateway; }; From 1612a87810578e50d451a25f66316aab0917814d Mon Sep 17 00:00:00 2001 From: Meeh Date: Thu, 3 Apr 2014 18:20:17 +0200 Subject: [PATCH 16/29] Dropping clang for now. --- .travis.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index b38d8bad..a00511cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,6 @@ language: cpp -matrix: - allow_failures: - - compiler: clang -compiler: - - gcc - - clang -cache: - - apt +compiler: gcc +cache: apt branches: only: - master From 879306b0d45b8bed6a7d8947ef53000fd196a217 Mon Sep 17 00:00:00 2001 From: cpubug Date: Thu, 3 Apr 2014 23:54:24 +0400 Subject: [PATCH 17/29] remove 'build' from .gitignore --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 0e609a70..5d0b3605 100644 --- a/.gitignore +++ b/.gitignore @@ -53,7 +53,6 @@ local.properties [Dd]ebug/ [Rr]elease/ x64/ -build/ [Bb]in/ [Oo]bj/ @@ -200,7 +199,6 @@ $RECYCLE.BIN/ *.egg *.egg-info dist/ -build/ eggs/ parts/ var/ From adbfa688ba5563ab5b62dc5eb62a4095ee40bbde Mon Sep 17 00:00:00 2001 From: cpubug Date: Thu, 3 Apr 2014 23:54:43 +0400 Subject: [PATCH 18/29] CMAKE support added --- build/CMakeLists.txt | 94 ++++++++++++++++++++++++++ build/cmake_modules/FindCryptoPP.cmake | 28 ++++++++ 2 files changed, 122 insertions(+) create mode 100644 build/CMakeLists.txt create mode 100644 build/cmake_modules/FindCryptoPP.cmake diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt new file mode 100644 index 00000000..9a6299ff --- /dev/null +++ b/build/CMakeLists.txt @@ -0,0 +1,94 @@ + +cmake_minimum_required ( VERSION 2.8 ) + +project ( i2pd ) + +set ( SRC_DIR ".." ) +set ( INC_DIR ".." ) + +add_definitions ( "-std=c++0x -Wall" ) + +set ( SOURCES + AddressBook.cpp + Garlic.cpp + HTTPServer.cpp + i2p.cpp + Identity.cpp + Log.cpp + NTCPSession.cpp + RouterContext.cpp + SSU.cpp + TransitTunnel.cpp + Tunnel.cpp + TunnelGateway.cpp + UPnP.cpp + base64.cpp + HTTPProxy.cpp + I2NPProtocol.cpp + LeaseSet.cpp + NetDb.cpp + Reseed.cpp + RouterInfo.cpp + Streaming.cpp + Transports.cpp + TunnelEndpoint.cpp + TunnelPool.cpp + util.cpp +) + +set ( HEADERS + AddressBook.h + Garlic.h + HTTPServer.h + Identity.h + Log.h + NTCPSession.h + RouterContext.h + SSU.h + TransitTunnel.h + Tunnel.h + TunnelGateway.h + UPnP.h + base64.h + HTTPProxy.h + I2NPProtocol.h + LeaseSet.h + NetDb.h + Reseed.h + RouterInfo.h + Streaming.h + Transports.h + TunnelEndpoint.h + TunnelPool.h + util.h +) + +source_group ("Header Files" FILES ${HEADERS}) +source_group ("Source Files" FILES ${SOURCES}) + +find_package ( Threads REQUIRED ) + +find_package ( Boost COMPONENTS system filesystem regex program_options REQUIRED ) + +set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules" ) +find_package ( CryptoPP REQUIRED ) + +include_directories ( ${Boost_INCLUDE_DIRS} ${CryptoPP_INCLUDE_DIRS}) + + +unset ( TMP ) +foreach ( src ${SOURCES} ) + list ( APPEND TMP "${SRC_DIR}/${src}" ) +endforeach () +set ( SOURCES ${TMP} ) + +unset ( TMP ) +foreach ( hdr ${HEADERS} ) + list ( APPEND TMP "${INC_DIR}/${hdr}" ) +endforeach () +set ( HEADERS ${TMP} ) + + +add_executable ( ${PROJECT_NAME} WIN32 ${HEADERS} ${SOURCES} ) + +target_link_libraries( ${PROJECT_NAME} ${Boost_LIBRARIES} ${CryptoPP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ) diff --git a/build/cmake_modules/FindCryptoPP.cmake b/build/cmake_modules/FindCryptoPP.cmake new file mode 100644 index 00000000..68177b98 --- /dev/null +++ b/build/cmake_modules/FindCryptoPP.cmake @@ -0,0 +1,28 @@ +# Find Crypto++ library +# +# Output variables : +# CryptoPP_FOUND +# CryptoPP_INCLUDE_DIRS +# CryptoPP_LIBRARIES +# + + +FIND_PATH( CryptoPP_INCLUDE_DIR cryptopp/dsa.h ) + +FIND_LIBRARY( CryptoPP_LIBRARY NAMES cryptopp ) + +# handle the QUIETLY and REQUIRED arguments and set CRYPTOPP_FOUND to TRUE if +# all listed variables are TRUE +INCLUDE(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(CryptoPP DEFAULT_MSG CryptoPP_LIBRARY CryptoPP_INCLUDE_DIR) + +set ( CryptoPP_FOUND FALSE ) + +if ( ${CRYPTOPP_FOUND} ) + set ( CryptoPP_FOUND TRUE ) + set ( CryptoPP_INCLUDE_DIRS ${CryptoPP_INCLUDE_DIR} ) + set ( CryptoPP_LIBRARIES ${CryptoPP_LIBRARY} ) +endif () + +MARK_AS_ADVANCED(CryptoPP_INCLUDE_DIR CryptoPP_LIBRARY) + From 24f0ff6c00ef0e39e4ba4f2a94b7dcfa452ab4cb Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 3 Apr 2014 16:27:37 -0400 Subject: [PATCH 19/29] pick tunnels from exploratory pool for exploratory --- NetDb.cpp | 5 +++-- Tunnel.h | 1 + TunnelPool.cpp | 17 ++++++++++++++++- TunnelPool.h | 3 +++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/NetDb.cpp b/NetDb.cpp index 57b5029a..1855ac30 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -532,8 +532,9 @@ namespace data void NetDb::Explore () { - auto outbound = i2p::tunnel::tunnels.GetNextOutboundTunnel (); - auto inbound = i2p::tunnel::tunnels.GetNextInboundTunnel (); + auto exploratoryPool = i2p::tunnel::tunnels.GetExploratoryPool (); + auto outbound = exploratoryPool ? exploratoryPool->GetNextOutboundTunnel () : nullptr; + auto inbound = exploratoryPool ? exploratoryPool->GetNextInboundTunnel () : nullptr; if (outbound && inbound) { CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator (); diff --git a/Tunnel.h b/Tunnel.h index d1d77fe9..16ffa9e4 100644 --- a/Tunnel.h +++ b/Tunnel.h @@ -117,6 +117,7 @@ namespace tunnel Tunnel * GetPendingTunnel (uint32_t replyMsgID); InboundTunnel * GetNextInboundTunnel (); OutboundTunnel * GetNextOutboundTunnel (); + TunnelPool * GetExploratoryPool () const { return m_ExploratoryPool; }; TransitTunnel * GetTransitTunnel (uint32_t tunnelID); void AddTransitTunnel (TransitTunnel * tunnel); void AddOutboundTunnel (OutboundTunnel * newTunnel); diff --git a/TunnelPool.cpp b/TunnelPool.cpp index 9b552101..33f6cbda 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -86,7 +86,22 @@ namespace tunnel m_LastOutboundTunnel = tunnel; return tunnel; } - + + InboundTunnel * TunnelPool::GetNextInboundTunnel () + { + return GetNextTunnel (m_InboundTunnels); + } + + template + typename TTunnels::value_type TunnelPool::GetNextTunnel (TTunnels& tunnels) + { + if (tunnels.empty ()) return nullptr; + for (auto it: tunnels) + if (!it->IsFailed ()) + return it; + return nullptr; + } + void TunnelPool::CreateTunnels () { int num = m_InboundTunnels.size (); diff --git a/TunnelPool.h b/TunnelPool.h index 0e18bcd4..1ff66cf3 100644 --- a/TunnelPool.h +++ b/TunnelPool.h @@ -37,6 +37,7 @@ namespace tunnel void TunnelExpired (OutboundTunnel * expiredTunnel); std::vector GetInboundTunnels (int num) const; OutboundTunnel * GetNextOutboundTunnel (); + InboundTunnel * GetNextInboundTunnel (); const i2p::data::IdentHash& GetIdentHash () { return m_LocalDestination.GetIdentHash (); }; void TestTunnels (); @@ -46,6 +47,8 @@ namespace tunnel void CreateInboundTunnel (); void CreateOutboundTunnel (); + template + typename TTunnels::value_type GetNextTunnel (TTunnels& tunnels); private: From e38f7c884c70b4228d070ffda020cd16b29a046e Mon Sep 17 00:00:00 2001 From: Meeh Date: Fri, 4 Apr 2014 01:54:21 +0200 Subject: [PATCH 20/29] Updating cmake so it exit if libraries are missing. Adding FindBoost and upating FindCryptoPP. --- build/CMakeLists.txt | 34 +- build/cmake_modules/FindBoost.cmake | 1181 ++++++++++++++++++++++++ build/cmake_modules/FindCryptoPP.cmake | 51 +- 3 files changed, 1240 insertions(+), 26 deletions(-) create mode 100644 build/cmake_modules/FindBoost.cmake diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index 9a6299ff..1da94f19 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -1,11 +1,12 @@ - cmake_minimum_required ( VERSION 2.8 ) - project ( i2pd ) + + set ( SRC_DIR ".." ) set ( INC_DIR ".." ) + add_definitions ( "-std=c++0x -Wall" ) set ( SOURCES @@ -70,10 +71,35 @@ find_package ( Threads REQUIRED ) find_package ( Boost COMPONENTS system filesystem regex program_options REQUIRED ) +find_package(Crypto++ QUIET) + +# Check for libraries +if(!Boost_FOUND) + message(FATAL_ERROR "Boost is not found, or your boost version was bellow 1.46. Please download Boost!") + return() +else() + # Adding boost directories + INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${Boost_INCLUDE_DIRS}) + LINK_DIRECTORIES(${LINK_DIRECTORIES} ${Boost_LIBRARY_DIRS}) +endif() + +if(!CRYPTO++_FOUND) + message(FATAL_ERROR "Could not find Crypto++. Please download and install it first!") + return() +else() + # Adding Crypto++ directories + INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${CRYPTO++_INCLUDE_DIR}) + LINK_DIRECTORIES(${LINK_DIRECTORIES} ${CRYPTO++_LIBRARIES}) +endif() + + +# End checks + + set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules" ) find_package ( CryptoPP REQUIRED ) -include_directories ( ${Boost_INCLUDE_DIRS} ${CryptoPP_INCLUDE_DIRS}) +include_directories ( ${Boost_INCLUDE_DIRS} ${CRYPTO++_INCLUDE_DIR}) unset ( TMP ) @@ -91,4 +117,4 @@ set ( HEADERS ${TMP} ) add_executable ( ${PROJECT_NAME} WIN32 ${HEADERS} ${SOURCES} ) -target_link_libraries( ${PROJECT_NAME} ${Boost_LIBRARIES} ${CryptoPP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ) +target_link_libraries( ${PROJECT_NAME} ${Boost_LIBRARIES} ${CRYPTO++_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ) diff --git a/build/cmake_modules/FindBoost.cmake b/build/cmake_modules/FindBoost.cmake new file mode 100644 index 00000000..93db9829 --- /dev/null +++ b/build/cmake_modules/FindBoost.cmake @@ -0,0 +1,1181 @@ +# - Find Boost include dirs and libraries +# Use this module by invoking find_package with the form: +# find_package(Boost +# [version] [EXACT] # Minimum or EXACT version e.g. 1.36.0 +# [REQUIRED] # Fail with error if Boost is not found +# [COMPONENTS ...] # Boost libraries by their canonical name +# ) # e.g. "date_time" for "libboost_date_time" +# This module finds headers and requested component libraries OR a CMake +# package configuration file provided by a "Boost CMake" build. For the +# latter case skip to the "Boost CMake" section below. For the former +# case results are reported in variables: +# Boost_FOUND - True if headers and requested libraries were found +# Boost_INCLUDE_DIRS - Boost include directories +# Boost_LIBRARY_DIRS - Link directories for Boost libraries +# Boost_LIBRARIES - Boost component libraries to be linked +# Boost__FOUND - True if component was found ( is upper-case) +# Boost__LIBRARY - Libraries to link for component (may include +# target_link_libraries debug/optimized keywords) +# Boost_VERSION - BOOST_VERSION value from boost/version.hpp +# Boost_LIB_VERSION - Version string appended to library filenames +# Boost_MAJOR_VERSION - Boost major version number (X in X.y.z) +# Boost_MINOR_VERSION - Boost minor version number (Y in x.Y.z) +# Boost_SUBMINOR_VERSION - Boost subminor version number (Z in x.y.Z) +# Boost_LIB_DIAGNOSTIC_DEFINITIONS (Windows) +# - Pass to add_definitions() to have diagnostic +# information about Boost's automatic linking +# displayed during compilation +# +# This module reads hints about search locations from variables: +# BOOST_ROOT - Preferred installation prefix +# (or BOOSTROOT) +# BOOST_INCLUDEDIR - Preferred include directory e.g. /include +# BOOST_LIBRARYDIR - Preferred library directory e.g. /lib +# Boost_NO_SYSTEM_PATHS - Set to ON to disable searching in locations not +# specified by these hint variables. Default is OFF. +# Boost_ADDITIONAL_VERSIONS +# - List of Boost versions not known to this module +# (Boost install locations may contain the version) +# and saves search results persistently in CMake cache entries: +# Boost_INCLUDE_DIR - Directory containing Boost headers +# Boost_LIBRARY_DIR - Directory containing Boost libraries +# Boost__LIBRARY_DEBUG - Component library debug variant +# Boost__LIBRARY_RELEASE - Component library release variant +# Users may set these hints or results as cache entries. Projects should +# not read these entries directly but instead use the above result variables. +# Note that some hint names start in upper-case "BOOST". One may specify +# these as environment variables if they are not specified as CMake variables +# or cache entries. +# +# This module first searches for the Boost header files using the above hint +# variables (excluding BOOST_LIBRARYDIR) and saves the result in +# Boost_INCLUDE_DIR. Then it searches for requested component libraries using +# the above hints (excluding BOOST_INCLUDEDIR and Boost_ADDITIONAL_VERSIONS), +# "lib" directories near Boost_INCLUDE_DIR, and the library name configuration +# settings below. It saves the library directory in Boost_LIBRARY_DIR and +# individual library locations in Boost__LIBRARY_DEBUG and +# Boost__LIBRARY_RELEASE. When one changes settings used by previous +# searches in the same build tree (excluding environment variables) this +# module discards previous search results affected by the changes and searches +# again. +# +# Boost libraries come in many variants encoded in their file name. Users or +# projects may tell this module which variant to find by setting variables: +# Boost_USE_MULTITHREADED - Set to OFF to use the non-multithreaded +# libraries ('mt' tag). Default is ON. +# Boost_USE_STATIC_LIBS - Set to ON to force the use of the static +# libraries. Default is OFF. +# Boost_USE_STATIC_RUNTIME - Set to ON or OFF to specify whether to use +# libraries linked statically to the C++ runtime +# ('s' tag). Default is platform dependent. +# Boost_USE_DEBUG_PYTHON - Set to ON to use libraries compiled with a +# debug Python build ('y' tag). Default is OFF. +# Boost_USE_STLPORT - Set to ON to use libraries compiled with +# STLPort ('p' tag). Default is OFF. +# Boost_USE_STLPORT_DEPRECATED_NATIVE_IOSTREAMS +# - Set to ON to use libraries compiled with +# STLPort deprecated "native iostreams" +# ('n' tag). Default is OFF. +# Boost_COMPILER - Set to the compiler-specific library suffix +# (e.g. "-gcc43"). Default is auto-computed +# for the C++ compiler in use. +# Boost_THREADAPI - Suffix for "thread" component library name, +# such as "pthread" or "win32". Names with +# and without this suffix will both be tried. +# Other variables one may set to control this module are: +# Boost_DEBUG - Set to ON to enable debug output from FindBoost. +# Please enable this before filing any bug report. +# Boost_DETAILED_FAILURE_MSG +# - Set to ON to add detailed information to the +# failure message even when the REQUIRED option +# is not given to the find_package call. +# Boost_REALPATH - Set to ON to resolve symlinks for discovered +# libraries to assist with packaging. For example, +# the "system" component library may be resolved to +# "/usr/lib/libboost_system.so.1.42.0" instead of +# "/usr/lib/libboost_system.so". This does not +# affect linking and should not be enabled unless +# the user needs this information. +# On Visual Studio and Borland compilers Boost headers request automatic +# linking to corresponding libraries. This requires matching libraries to be +# linked explicitly or available in the link library search path. In this +# case setting Boost_USE_STATIC_LIBS to OFF may not achieve dynamic linking. +# Boost automatic linking typically requests static libraries with a few +# exceptions (such as Boost.Python). Use +# add_definitions(${Boost_LIB_DIAGNOSTIC_DEFINITIONS}) +# to ask Boost to report information about automatic linking requests. +# +# Example to find Boost headers only: +# find_package(Boost 1.36.0) +# if(Boost_FOUND) +# include_directories(${Boost_INCLUDE_DIRS}) +# add_executable(foo foo.cc) +# endif() +# Example to find Boost headers and some libraries: +# set(Boost_USE_STATIC_LIBS ON) +# set(Boost_USE_MULTITHREADED ON) +# set(Boost_USE_STATIC_RUNTIME OFF) +# find_package(Boost 1.36.0 COMPONENTS date_time filesystem system ...) +# if(Boost_FOUND) +# include_directories(${Boost_INCLUDE_DIRS}) +# add_executable(foo foo.cc) +# target_link_libraries(foo ${Boost_LIBRARIES}) +# endif() +# +# Boost CMake ---------------------------------------------------------- +# +# If Boost was built using the boost-cmake project it provides a package +# configuration file for use with find_package's Config mode. This module +# looks for the package configuration file called BoostConfig.cmake or +# boost-config.cmake and stores the result in cache entry "Boost_DIR". If +# found, the package configuration file is loaded and this module returns with +# no further action. See documentation of the Boost CMake package +# configuration for details on what it provides. +# +# Set Boost_NO_BOOST_CMAKE to ON to disable the search for boost-cmake. + +#============================================================================= +# Copyright 2006-2012 Kitware, Inc. +# Copyright 2006-2008 Andreas Schneider +# Copyright 2007 Wengo +# Copyright 2007 Mike Jackson +# Copyright 2008 Andreas Pakulat +# Copyright 2008-2012 Philip Lowman +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + + +#------------------------------------------------------------------------------- +# Before we go searching, check whether boost-cmake is available, unless the +# user specifically asked NOT to search for boost-cmake. +# +# If Boost_DIR is set, this behaves as any find_package call would. If not, +# it looks at BOOST_ROOT and BOOSTROOT to find Boost. +# +if (NOT Boost_NO_BOOST_CMAKE) + # If Boost_DIR is not set, look for BOOSTROOT and BOOST_ROOT as alternatives, + # since these are more conventional for Boost. + if ("$ENV{Boost_DIR}" STREQUAL "") + if (NOT "$ENV{BOOST_ROOT}" STREQUAL "") + set(ENV{Boost_DIR} $ENV{BOOST_ROOT}) + elseif (NOT "$ENV{BOOSTROOT}" STREQUAL "") + set(ENV{Boost_DIR} $ENV{BOOSTROOT}) + endif() + endif() + + # Do the same find_package call but look specifically for the CMake version. + # Note that args are passed in the Boost_FIND_xxxxx variables, so there is no + # need to delegate them to this find_package call. + find_package(Boost QUIET NO_MODULE) + mark_as_advanced(Boost_DIR) + + # If we found boost-cmake, then we're done. Print out what we found. + # Otherwise let the rest of the module try to find it. + if (Boost_FOUND) + message("Boost ${Boost_FIND_VERSION} found.") + if (Boost_FIND_COMPONENTS) + message("Found Boost components:") + message(" ${Boost_FIND_COMPONENTS}") + endif() + return() + endif() +endif() + + +#------------------------------------------------------------------------------- +# FindBoost functions & macros +# + +############################################ +# +# Check the existence of the libraries. +# +############################################ +# This macro was taken directly from the FindQt4.cmake file that is included +# with the CMake distribution. This is NOT my work. All work was done by the +# original authors of the FindQt4.cmake file. Only minor modifications were +# made to remove references to Qt and make this file more generally applicable +# And ELSE/ENDIF pairs were removed for readability. +######################################################################### + +macro(_Boost_ADJUST_LIB_VARS basename) + if(Boost_INCLUDE_DIR ) + if(Boost_${basename}_LIBRARY_DEBUG AND Boost_${basename}_LIBRARY_RELEASE) + # if the generator supports configuration types then set + # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value + if(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE) + set(Boost_${basename}_LIBRARY optimized ${Boost_${basename}_LIBRARY_RELEASE} debug ${Boost_${basename}_LIBRARY_DEBUG}) + else() + # if there are no configuration types and CMAKE_BUILD_TYPE has no value + # then just use the release libraries + set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE} ) + endif() + # FIXME: This probably should be set for both cases + set(Boost_${basename}_LIBRARIES optimized ${Boost_${basename}_LIBRARY_RELEASE} debug ${Boost_${basename}_LIBRARY_DEBUG}) + endif() + + # if only the release version was found, set the debug variable also to the release version + if(Boost_${basename}_LIBRARY_RELEASE AND NOT Boost_${basename}_LIBRARY_DEBUG) + set(Boost_${basename}_LIBRARY_DEBUG ${Boost_${basename}_LIBRARY_RELEASE}) + set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE}) + set(Boost_${basename}_LIBRARIES ${Boost_${basename}_LIBRARY_RELEASE}) + endif() + + # if only the debug version was found, set the release variable also to the debug version + if(Boost_${basename}_LIBRARY_DEBUG AND NOT Boost_${basename}_LIBRARY_RELEASE) + set(Boost_${basename}_LIBRARY_RELEASE ${Boost_${basename}_LIBRARY_DEBUG}) + set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_DEBUG}) + set(Boost_${basename}_LIBRARIES ${Boost_${basename}_LIBRARY_DEBUG}) + endif() + + # If the debug & release library ends up being the same, omit the keywords + if(${Boost_${basename}_LIBRARY_RELEASE} STREQUAL ${Boost_${basename}_LIBRARY_DEBUG}) + set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE} ) + set(Boost_${basename}_LIBRARIES ${Boost_${basename}_LIBRARY_RELEASE} ) + endif() + + if(Boost_${basename}_LIBRARY) + set(Boost_${basename}_FOUND ON) + endif() + + endif() + # Make variables changeable to the advanced user + mark_as_advanced( + Boost_${basename}_LIBRARY_RELEASE + Boost_${basename}_LIBRARY_DEBUG + ) +endmacro() + +macro(_Boost_CHANGE_DETECT changed_var) + set(${changed_var} 0) + foreach(v ${ARGN}) + if(DEFINED _Boost_COMPONENTS_SEARCHED) + if(${v}) + if(_${v}_LAST) + string(COMPARE NOTEQUAL "${${v}}" "${_${v}_LAST}" _${v}_CHANGED) + else() + set(_${v}_CHANGED 1) + endif() + elseif(_${v}_LAST) + set(_${v}_CHANGED 1) + endif() + if(_${v}_CHANGED) + set(${changed_var} 1) + endif() + else() + set(_${v}_CHANGED 0) + endif() + endforeach() +endmacro() + +macro(_Boost_FIND_LIBRARY var) + find_library(${var} ${ARGN}) + + # If we found the first library save Boost_LIBRARY_DIR. + if(${var} AND NOT Boost_LIBRARY_DIR) + get_filename_component(_dir "${${var}}" PATH) + set(Boost_LIBRARY_DIR "${_dir}" CACHE PATH "Boost library directory" FORCE) + endif() + + # If Boost_LIBRARY_DIR is known then search only there. + if(Boost_LIBRARY_DIR) + set(_boost_LIBRARY_SEARCH_DIRS ${Boost_LIBRARY_DIR} NO_DEFAULT_PATH) + endif() +endmacro() + +#------------------------------------------------------------------------------- + +# +# Runs compiler with "-dumpversion" and parses major/minor +# version with a regex. +# +function(_Boost_COMPILER_DUMPVERSION _OUTPUT_VERSION) + + exec_program(${CMAKE_CXX_COMPILER} + ARGS ${CMAKE_CXX_COMPILER_ARG1} -dumpversion + OUTPUT_VARIABLE _boost_COMPILER_VERSION + ) + string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2" + _boost_COMPILER_VERSION ${_boost_COMPILER_VERSION}) + + set(${_OUTPUT_VERSION} ${_boost_COMPILER_VERSION} PARENT_SCOPE) +endfunction() + +# +# Take a list of libraries with "thread" in it +# and prepend duplicates with "thread_${Boost_THREADAPI}" +# at the front of the list +# +function(_Boost_PREPEND_LIST_WITH_THREADAPI _output) + set(_orig_libnames ${ARGN}) + string(REPLACE "thread" "thread_${Boost_THREADAPI}" _threadapi_libnames "${_orig_libnames}") + set(${_output} ${_threadapi_libnames} ${_orig_libnames} PARENT_SCOPE) +endfunction() + +# +# If a library is found, replace its cache entry with its REALPATH +# +function(_Boost_SWAP_WITH_REALPATH _library _docstring) + if(${_library}) + get_filename_component(_boost_filepathreal ${${_library}} REALPATH) + unset(${_library} CACHE) + set(${_library} ${_boost_filepathreal} CACHE FILEPATH "${_docstring}") + endif() +endfunction() + +function(_Boost_CHECK_SPELLING _var) + if(${_var}) + string(TOUPPER ${_var} _var_UC) + message(FATAL_ERROR "ERROR: ${_var} is not the correct spelling. The proper spelling is ${_var_UC}.") + endif() +endfunction() + +# Guesses Boost's compiler prefix used in built library names +# Returns the guess by setting the variable pointed to by _ret +function(_Boost_GUESS_COMPILER_PREFIX _ret) + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel" + OR "${CMAKE_CXX_COMPILER}" MATCHES "icl" + OR "${CMAKE_CXX_COMPILER}" MATCHES "icpc") + if(WIN32) + set (_boost_COMPILER "-iw") + else() + set (_boost_COMPILER "-il") + endif() + elseif (MSVC12) + set(_boost_COMPILER "-vc120") + elseif (MSVC11) + set(_boost_COMPILER "-vc110") + elseif (MSVC10) + set(_boost_COMPILER "-vc100") + elseif (MSVC90) + set(_boost_COMPILER "-vc90") + elseif (MSVC80) + set(_boost_COMPILER "-vc80") + elseif (MSVC71) + set(_boost_COMPILER "-vc71") + elseif (MSVC70) # Good luck! + set(_boost_COMPILER "-vc7") # yes, this is correct + elseif (MSVC60) # Good luck! + set(_boost_COMPILER "-vc6") # yes, this is correct + elseif (BORLAND) + set(_boost_COMPILER "-bcb") + elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "SunPro") + set(_boost_COMPILER "-sw") + elseif (MINGW) + if(${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION} VERSION_LESS 1.34) + set(_boost_COMPILER "-mgw") # no GCC version encoding prior to 1.34 + else() + _Boost_COMPILER_DUMPVERSION(_boost_COMPILER_VERSION) + set(_boost_COMPILER "-mgw${_boost_COMPILER_VERSION}") + endif() + elseif (UNIX) + if (CMAKE_COMPILER_IS_GNUCXX) + if(${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION} VERSION_LESS 1.34) + set(_boost_COMPILER "-gcc") # no GCC version encoding prior to 1.34 + else() + _Boost_COMPILER_DUMPVERSION(_boost_COMPILER_VERSION) + # Determine which version of GCC we have. + if(APPLE) + if(Boost_MINOR_VERSION) + if(${Boost_MINOR_VERSION} GREATER 35) + # In Boost 1.36.0 and newer, the mangled compiler name used + # on Mac OS X/Darwin is "xgcc". + set(_boost_COMPILER "-xgcc${_boost_COMPILER_VERSION}") + else() + # In Boost <= 1.35.0, there is no mangled compiler name for + # the Mac OS X/Darwin version of GCC. + set(_boost_COMPILER "") + endif() + else() + # We don't know the Boost version, so assume it's + # pre-1.36.0. + set(_boost_COMPILER "") + endif() + else() + set(_boost_COMPILER "-gcc${_boost_COMPILER_VERSION}") + endif() + endif() + endif () + else() + # TODO at least Boost_DEBUG here? + set(_boost_COMPILER "") + endif() + set(${_ret} ${_boost_COMPILER} PARENT_SCOPE) +endfunction() + +function(_Boost_consider_adding_pthreads _outvar) + # On Unix platforms (excluding cygwin) add pthreads to Boost_LIBRARIES + # if the user is searching for the boost-thread component. + if(UNIX AND NOT CYGWIN) + list(FIND Boost_FIND_COMPONENTS thread _using_boost_thread) + if(_using_boost_thread GREATER -1) + find_library(BOOST_THREAD_LIBRARY NAMES pthread + DOC "The threading library used by boost-thread" + ) + if(BOOST_THREAD_LIBRARY) + set(${_outvar} ${ARGN} ${BOOST_THREAD_LIBRARY} PARENT_SCOPE) + endif() + endif() + endif() +endfunction() + +# +# End functions/macros +# +#------------------------------------------------------------------------------- + +#------------------------------------------------------------------------------- +# main. +#------------------------------------------------------------------------------- + +if(NOT DEFINED Boost_USE_MULTITHREADED) + set(Boost_USE_MULTITHREADED TRUE) +endif() + +# Check the version of Boost against the requested version. +if(Boost_FIND_VERSION AND NOT Boost_FIND_VERSION_MINOR) + message(SEND_ERROR "When requesting a specific version of Boost, you must provide at least the major and minor version numbers, e.g., 1.34") +endif() + +if(Boost_FIND_VERSION_EXACT) + # The version may appear in a directory with or without the patch + # level, even when the patch level is non-zero. + set(_boost_TEST_VERSIONS + "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}.${Boost_FIND_VERSION_PATCH}" + "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}") +else() + # The user has not requested an exact version. Among known + # versions, find those that are acceptable to the user request. + set(_Boost_KNOWN_VERSIONS ${Boost_ADDITIONAL_VERSIONS} + "1.56.0" "1.56" "1.55.0" "1.55" "1.54.0" "1.54" + "1.53.0" "1.53" "1.52.0" "1.52" "1.51.0" "1.51" + "1.50.0" "1.50" "1.49.0" "1.49" "1.48.0" "1.48" "1.47.0" "1.47" "1.46.1" + "1.46.0" "1.46" "1.45.0" "1.45" "1.44.0" "1.44" "1.43.0" "1.43" "1.42.0" "1.42" + "1.41.0" "1.41" "1.40.0" "1.40" "1.39.0" "1.39" "1.38.0" "1.38" "1.37.0" "1.37" + "1.36.1" "1.36.0" "1.36" "1.35.1" "1.35.0" "1.35" "1.34.1" "1.34.0" + "1.34" "1.33.1" "1.33.0" "1.33") + set(_boost_TEST_VERSIONS) + if(Boost_FIND_VERSION) + set(_Boost_FIND_VERSION_SHORT "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}") + # Select acceptable versions. + foreach(version ${_Boost_KNOWN_VERSIONS}) + if(NOT "${version}" VERSION_LESS "${Boost_FIND_VERSION}") + # This version is high enough. + list(APPEND _boost_TEST_VERSIONS "${version}") + elseif("${version}.99" VERSION_EQUAL "${_Boost_FIND_VERSION_SHORT}.99") + # This version is a short-form for the requested version with + # the patch level dropped. + list(APPEND _boost_TEST_VERSIONS "${version}") + endif() + endforeach() + else() + # Any version is acceptable. + set(_boost_TEST_VERSIONS "${_Boost_KNOWN_VERSIONS}") + endif() +endif() + +# The reason that we failed to find Boost. This will be set to a +# user-friendly message when we fail to find some necessary piece of +# Boost. +set(Boost_ERROR_REASON) + +if(Boost_DEBUG) + # Output some of their choices + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "_boost_TEST_VERSIONS = ${_boost_TEST_VERSIONS}") + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "Boost_USE_MULTITHREADED = ${Boost_USE_MULTITHREADED}") + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "Boost_USE_STATIC_LIBS = ${Boost_USE_STATIC_LIBS}") + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "Boost_USE_STATIC_RUNTIME = ${Boost_USE_STATIC_RUNTIME}") + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "Boost_ADDITIONAL_VERSIONS = ${Boost_ADDITIONAL_VERSIONS}") + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "Boost_NO_SYSTEM_PATHS = ${Boost_NO_SYSTEM_PATHS}") +endif() + +if(WIN32) + # In windows, automatic linking is performed, so you do not have + # to specify the libraries. If you are linking to a dynamic + # runtime, then you can choose to link to either a static or a + # dynamic Boost library, the default is to do a static link. You + # can alter this for a specific library "whatever" by defining + # BOOST_WHATEVER_DYN_LINK to force Boost library "whatever" to be + # linked dynamically. Alternatively you can force all Boost + # libraries to dynamic link by defining BOOST_ALL_DYN_LINK. + + # This feature can be disabled for Boost library "whatever" by + # defining BOOST_WHATEVER_NO_LIB, or for all of Boost by defining + # BOOST_ALL_NO_LIB. + + # If you want to observe which libraries are being linked against + # then defining BOOST_LIB_DIAGNOSTIC will cause the auto-linking + # code to emit a #pragma message each time a library is selected + # for linking. + set(Boost_LIB_DIAGNOSTIC_DEFINITIONS "-DBOOST_LIB_DIAGNOSTIC") +endif() + +_Boost_CHECK_SPELLING(Boost_ROOT) +_Boost_CHECK_SPELLING(Boost_LIBRARYDIR) +_Boost_CHECK_SPELLING(Boost_INCLUDEDIR) + +# Collect environment variable inputs as hints. Do not consider changes. +foreach(v BOOSTROOT BOOST_ROOT BOOST_INCLUDEDIR BOOST_LIBRARYDIR) + set(_env $ENV{${v}}) + if(_env) + file(TO_CMAKE_PATH "${_env}" _ENV_${v}) + else() + set(_ENV_${v} "") + endif() +endforeach() +if(NOT _ENV_BOOST_ROOT AND _ENV_BOOSTROOT) + set(_ENV_BOOST_ROOT "${_ENV_BOOSTROOT}") +endif() + +# Collect inputs and cached results. Detect changes since the last run. +if(NOT BOOST_ROOT AND BOOSTROOT) + set(BOOST_ROOT "${BOOSTROOT}") +endif() +set(_Boost_VARS_DIR + BOOST_ROOT + Boost_NO_SYSTEM_PATHS + ) + +if(Boost_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "Declared as CMake or Environmental Variables:") + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + " BOOST_ROOT = ${BOOST_ROOT}") + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + " BOOST_INCLUDEDIR = ${BOOST_INCLUDEDIR}") + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + " BOOST_LIBRARYDIR = ${BOOST_LIBRARYDIR}") + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "_boost_TEST_VERSIONS = ${_boost_TEST_VERSIONS}") +endif() + +# ------------------------------------------------------------------------ +# Search for Boost include DIR +# ------------------------------------------------------------------------ + +set(_Boost_VARS_INC BOOST_INCLUDEDIR Boost_INCLUDE_DIR Boost_ADDITIONAL_VERSIONS) +_Boost_CHANGE_DETECT(_Boost_CHANGE_INCDIR ${_Boost_VARS_DIR} ${_Boost_VARS_INC}) +# Clear Boost_INCLUDE_DIR if it did not change but other input affecting the +# location did. We will find a new one based on the new inputs. +if(_Boost_CHANGE_INCDIR AND NOT _Boost_INCLUDE_DIR_CHANGED) + unset(Boost_INCLUDE_DIR CACHE) +endif() + +if(NOT Boost_INCLUDE_DIR) + set(_boost_INCLUDE_SEARCH_DIRS "") + if(BOOST_INCLUDEDIR) + list(APPEND _boost_INCLUDE_SEARCH_DIRS ${BOOST_INCLUDEDIR}) + elseif(_ENV_BOOST_INCLUDEDIR) + list(APPEND _boost_INCLUDE_SEARCH_DIRS ${_ENV_BOOST_INCLUDEDIR}) + endif() + + if( BOOST_ROOT ) + list(APPEND _boost_INCLUDE_SEARCH_DIRS ${BOOST_ROOT}/include ${BOOST_ROOT}) + elseif( _ENV_BOOST_ROOT ) + list(APPEND _boost_INCLUDE_SEARCH_DIRS ${_ENV_BOOST_ROOT}/include ${_ENV_BOOST_ROOT}) + endif() + + if( Boost_NO_SYSTEM_PATHS) + list(APPEND _boost_INCLUDE_SEARCH_DIRS NO_CMAKE_SYSTEM_PATH) + else() + list(APPEND _boost_INCLUDE_SEARCH_DIRS PATHS + C:/boost/include + C:/boost + /sw/local/include + ) + endif() + + # Try to find Boost by stepping backwards through the Boost versions + # we know about. + # Build a list of path suffixes for each version. + set(_boost_PATH_SUFFIXES) + foreach(_boost_VER ${_boost_TEST_VERSIONS}) + # Add in a path suffix, based on the required version, ideally + # we could read this from version.hpp, but for that to work we'd + # need to know the include dir already + set(_boost_BOOSTIFIED_VERSION) + + # Transform 1.35 => 1_35 and 1.36.0 => 1_36_0 + if(_boost_VER MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+") + string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1_\\2_\\3" + _boost_BOOSTIFIED_VERSION ${_boost_VER}) + elseif(_boost_VER MATCHES "[0-9]+\\.[0-9]+") + string(REGEX REPLACE "([0-9]+)\\.([0-9]+)" "\\1_\\2" + _boost_BOOSTIFIED_VERSION ${_boost_VER}) + endif() + + list(APPEND _boost_PATH_SUFFIXES + "boost-${_boost_BOOSTIFIED_VERSION}" + "boost_${_boost_BOOSTIFIED_VERSION}" + "boost/boost-${_boost_BOOSTIFIED_VERSION}" + "boost/boost_${_boost_BOOSTIFIED_VERSION}" + ) + + endforeach() + + if(Boost_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "Include debugging info:") + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + " _boost_INCLUDE_SEARCH_DIRS = ${_boost_INCLUDE_SEARCH_DIRS}") + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + " _boost_PATH_SUFFIXES = ${_boost_PATH_SUFFIXES}") + endif() + + # Look for a standard boost header file. + find_path(Boost_INCLUDE_DIR + NAMES boost/config.hpp + HINTS ${_boost_INCLUDE_SEARCH_DIRS} + PATH_SUFFIXES ${_boost_PATH_SUFFIXES} + ) +endif() + +# ------------------------------------------------------------------------ +# Extract version information from version.hpp +# ------------------------------------------------------------------------ + +# Set Boost_FOUND based only on header location and version. +# It will be updated below for component libraries. +if(Boost_INCLUDE_DIR) + if(Boost_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "location of version.hpp: ${Boost_INCLUDE_DIR}/boost/version.hpp") + endif() + + # Extract Boost_VERSION and Boost_LIB_VERSION from version.hpp + set(Boost_VERSION 0) + set(Boost_LIB_VERSION "") + file(STRINGS "${Boost_INCLUDE_DIR}/boost/version.hpp" _boost_VERSION_HPP_CONTENTS REGEX "#define BOOST_(LIB_)?VERSION ") + set(_Boost_VERSION_REGEX "([0-9]+)") + set(_Boost_LIB_VERSION_REGEX "\"([0-9_]+)\"") + foreach(v VERSION LIB_VERSION) + if("${_boost_VERSION_HPP_CONTENTS}" MATCHES ".*#define BOOST_${v} ${_Boost_${v}_REGEX}.*") + set(Boost_${v} "${CMAKE_MATCH_1}") + endif() + endforeach() + unset(_boost_VERSION_HPP_CONTENTS) + + math(EXPR Boost_MAJOR_VERSION "${Boost_VERSION} / 100000") + math(EXPR Boost_MINOR_VERSION "${Boost_VERSION} / 100 % 1000") + math(EXPR Boost_SUBMINOR_VERSION "${Boost_VERSION} % 100") + + set(Boost_ERROR_REASON + "${Boost_ERROR_REASON}Boost version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}\nBoost include path: ${Boost_INCLUDE_DIR}") + if(Boost_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "version.hpp reveals boost " + "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}") + endif() + + if(Boost_FIND_VERSION) + # Set Boost_FOUND based on requested version. + set(_Boost_VERSION "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}") + if("${_Boost_VERSION}" VERSION_LESS "${Boost_FIND_VERSION}") + set(Boost_FOUND 0) + set(_Boost_VERSION_AGE "old") + elseif(Boost_FIND_VERSION_EXACT AND + NOT "${_Boost_VERSION}" VERSION_EQUAL "${Boost_FIND_VERSION}") + set(Boost_FOUND 0) + set(_Boost_VERSION_AGE "new") + else() + set(Boost_FOUND 1) + endif() + if(NOT Boost_FOUND) + # State that we found a version of Boost that is too new or too old. + set(Boost_ERROR_REASON + "${Boost_ERROR_REASON}\nDetected version of Boost is too ${_Boost_VERSION_AGE}. Requested version was ${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}") + if (Boost_FIND_VERSION_PATCH) + set(Boost_ERROR_REASON + "${Boost_ERROR_REASON}.${Boost_FIND_VERSION_PATCH}") + endif () + if (NOT Boost_FIND_VERSION_EXACT) + set(Boost_ERROR_REASON "${Boost_ERROR_REASON} (or newer)") + endif () + set(Boost_ERROR_REASON "${Boost_ERROR_REASON}.") + endif () + else() + # Caller will accept any Boost version. + set(Boost_FOUND 1) + endif() +else() + set(Boost_FOUND 0) + set(Boost_ERROR_REASON + "${Boost_ERROR_REASON}Unable to find the Boost header files. Please set BOOST_ROOT to the root directory containing Boost or BOOST_INCLUDEDIR to the directory containing Boost's headers.") +endif() + +# ------------------------------------------------------------------------ +# Suffix initialization and compiler suffix detection. +# ------------------------------------------------------------------------ + +set(_Boost_VARS_NAME + Boost_COMPILER + Boost_THREADAPI + Boost_USE_DEBUG_PYTHON + Boost_USE_MULTITHREADED + Boost_USE_STATIC_LIBS + Boost_USE_STATIC_RUNTIME + Boost_USE_STLPORT + Boost_USE_STLPORT_DEPRECATED_NATIVE_IOSTREAMS + ) +_Boost_CHANGE_DETECT(_Boost_CHANGE_LIBNAME ${_Boost_VARS_NAME}) + +# Setting some more suffixes for the library +set(Boost_LIB_PREFIX "") +if ( WIN32 AND Boost_USE_STATIC_LIBS AND NOT CYGWIN) + set(Boost_LIB_PREFIX "lib") +endif() + +if (Boost_COMPILER) + set(_boost_COMPILER ${Boost_COMPILER}) + if(Boost_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "using user-specified Boost_COMPILER = ${_boost_COMPILER}") + endif() +else() + # Attempt to guess the compiler suffix + # NOTE: this is not perfect yet, if you experience any issues + # please report them and use the Boost_COMPILER variable + # to work around the problems. + _Boost_GUESS_COMPILER_PREFIX(_boost_COMPILER) + if(Boost_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "guessed _boost_COMPILER = ${_boost_COMPILER}") + endif() +endif() + +set (_boost_MULTITHREADED "-mt") +if( NOT Boost_USE_MULTITHREADED ) + set (_boost_MULTITHREADED "") +endif() +if(Boost_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "_boost_MULTITHREADED = ${_boost_MULTITHREADED}") +endif() + +#====================== +# Systematically build up the Boost ABI tag +# http://boost.org/doc/libs/1_41_0/more/getting_started/windows.html#library-naming +set( _boost_RELEASE_ABI_TAG "-") +set( _boost_DEBUG_ABI_TAG "-") +# Key Use this library when: +# s linking statically to the C++ standard library and +# compiler runtime support libraries. +if(Boost_USE_STATIC_RUNTIME) + set( _boost_RELEASE_ABI_TAG "${_boost_RELEASE_ABI_TAG}s") + set( _boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}s") +endif() +# g using debug versions of the standard and runtime +# support libraries +if(WIN32) + if(MSVC OR "${CMAKE_CXX_COMPILER}" MATCHES "icl" + OR "${CMAKE_CXX_COMPILER}" MATCHES "icpc") + set(_boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}g") + endif() +endif() +# y using special debug build of python +if(Boost_USE_DEBUG_PYTHON) + set(_boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}y") +endif() +# d using a debug version of your code +set(_boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}d") +# p using the STLport standard library rather than the +# default one supplied with your compiler +if(Boost_USE_STLPORT) + set( _boost_RELEASE_ABI_TAG "${_boost_RELEASE_ABI_TAG}p") + set( _boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}p") +endif() +# n using the STLport deprecated "native iostreams" feature +if(Boost_USE_STLPORT_DEPRECATED_NATIVE_IOSTREAMS) + set( _boost_RELEASE_ABI_TAG "${_boost_RELEASE_ABI_TAG}n") + set( _boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}n") +endif() + +if(Boost_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "_boost_RELEASE_ABI_TAG = ${_boost_RELEASE_ABI_TAG}") + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "_boost_DEBUG_ABI_TAG = ${_boost_DEBUG_ABI_TAG}") +endif() + +# ------------------------------------------------------------------------ +# Begin finding boost libraries +# ------------------------------------------------------------------------ +set(_Boost_VARS_LIB BOOST_LIBRARYDIR Boost_LIBRARY_DIR) +_Boost_CHANGE_DETECT(_Boost_CHANGE_LIBDIR ${_Boost_VARS_DIR} ${_Boost_VARS_LIB} Boost_INCLUDE_DIR) +# Clear Boost_LIBRARY_DIR if it did not change but other input affecting the +# location did. We will find a new one based on the new inputs. +if(_Boost_CHANGE_LIBDIR AND NOT _Boost_LIBRARY_DIR_CHANGED) + unset(Boost_LIBRARY_DIR CACHE) +endif() + +if(Boost_LIBRARY_DIR) + set(_boost_LIBRARY_SEARCH_DIRS ${Boost_LIBRARY_DIR} NO_DEFAULT_PATH) +else() + set(_boost_LIBRARY_SEARCH_DIRS "") + if(BOOST_LIBRARYDIR) + list(APPEND _boost_LIBRARY_SEARCH_DIRS ${BOOST_LIBRARYDIR}) + elseif(_ENV_BOOST_LIBRARYDIR) + list(APPEND _boost_LIBRARY_SEARCH_DIRS ${_ENV_BOOST_LIBRARYDIR}) + endif() + + if(BOOST_ROOT) + list(APPEND _boost_LIBRARY_SEARCH_DIRS ${BOOST_ROOT}/lib ${BOOST_ROOT}/stage/lib) + elseif(_ENV_BOOST_ROOT) + list(APPEND _boost_LIBRARY_SEARCH_DIRS ${_ENV_BOOST_ROOT}/lib ${_ENV_BOOST_ROOT}/stage/lib) + endif() + + list(APPEND _boost_LIBRARY_SEARCH_DIRS + ${Boost_INCLUDE_DIR}/lib + ${Boost_INCLUDE_DIR}/../lib + ${Boost_INCLUDE_DIR}/stage/lib + ) + if( Boost_NO_SYSTEM_PATHS ) + list(APPEND _boost_LIBRARY_SEARCH_DIRS NO_CMAKE_SYSTEM_PATH) + else() + list(APPEND _boost_LIBRARY_SEARCH_DIRS PATHS + C:/boost/lib + C:/boost + /sw/local/lib + ) + endif() +endif() + +if(Boost_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "_boost_LIBRARY_SEARCH_DIRS = ${_boost_LIBRARY_SEARCH_DIRS}") +endif() + +# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES +if( Boost_USE_STATIC_LIBS ) + set( _boost_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) + if(WIN32) + set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) + else() + set(CMAKE_FIND_LIBRARY_SUFFIXES .a ) + endif() +endif() + +# We want to use the tag inline below without risking double dashes +if(_boost_RELEASE_ABI_TAG) + if(${_boost_RELEASE_ABI_TAG} STREQUAL "-") + set(_boost_RELEASE_ABI_TAG "") + endif() +endif() +if(_boost_DEBUG_ABI_TAG) + if(${_boost_DEBUG_ABI_TAG} STREQUAL "-") + set(_boost_DEBUG_ABI_TAG "") + endif() +endif() + +# The previous behavior of FindBoost when Boost_USE_STATIC_LIBS was enabled +# on WIN32 was to: +# 1. Search for static libs compiled against a SHARED C++ standard runtime library (use if found) +# 2. Search for static libs compiled against a STATIC C++ standard runtime library (use if found) +# We maintain this behavior since changing it could break people's builds. +# To disable the ambiguous behavior, the user need only +# set Boost_USE_STATIC_RUNTIME either ON or OFF. +set(_boost_STATIC_RUNTIME_WORKAROUND false) +if(WIN32 AND Boost_USE_STATIC_LIBS) + if(NOT DEFINED Boost_USE_STATIC_RUNTIME) + set(_boost_STATIC_RUNTIME_WORKAROUND true) + endif() +endif() + +# On versions < 1.35, remove the System library from the considered list +# since it wasn't added until 1.35. +if(Boost_VERSION AND Boost_FIND_COMPONENTS) + if(Boost_VERSION LESS 103500) + list(REMOVE_ITEM Boost_FIND_COMPONENTS system) + endif() +endif() + +# If the user changed any of our control inputs flush previous results. +if(_Boost_CHANGE_LIBDIR OR _Boost_CHANGE_LIBNAME) + foreach(COMPONENT ${_Boost_COMPONENTS_SEARCHED}) + string(TOUPPER ${COMPONENT} UPPERCOMPONENT) + foreach(c DEBUG RELEASE) + set(_var Boost_${UPPERCOMPONENT}_LIBRARY_${c}) + unset(${_var} CACHE) + set(${_var} "${_var}-NOTFOUND") + endforeach() + endforeach() + set(_Boost_COMPONENTS_SEARCHED "") +endif() + +foreach(COMPONENT ${Boost_FIND_COMPONENTS}) + string(TOUPPER ${COMPONENT} UPPERCOMPONENT) + + set( _boost_docstring_release "Boost ${COMPONENT} library (release)") + set( _boost_docstring_debug "Boost ${COMPONENT} library (debug)") + + # + # Find RELEASE libraries + # + set(_boost_RELEASE_NAMES + ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG} + ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG} + ${Boost_LIB_PREFIX}boost_${COMPONENT} ) + if(_boost_STATIC_RUNTIME_WORKAROUND) + set(_boost_RELEASE_STATIC_ABI_TAG "-s${_boost_RELEASE_ABI_TAG}") + list(APPEND _boost_RELEASE_NAMES + ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG} + ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG} ) + endif() + if(Boost_THREADAPI AND ${COMPONENT} STREQUAL "thread") + _Boost_PREPEND_LIST_WITH_THREADAPI(_boost_RELEASE_NAMES ${_boost_RELEASE_NAMES}) + endif() + if(Boost_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "Searching for ${UPPERCOMPONENT}_LIBRARY_RELEASE: ${_boost_RELEASE_NAMES}") + endif() + + # Avoid passing backslashes to _Boost_FIND_LIBRARY due to macro re-parsing. + string(REPLACE "\\" "/" _boost_LIBRARY_SEARCH_DIRS_tmp "${_boost_LIBRARY_SEARCH_DIRS}") + + _Boost_FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE + NAMES ${_boost_RELEASE_NAMES} + HINTS ${_boost_LIBRARY_SEARCH_DIRS_tmp} + NAMES_PER_DIR + DOC "${_boost_docstring_release}" + ) + + # + # Find DEBUG libraries + # + set(_boost_DEBUG_NAMES + ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG} + ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG} + ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED} + ${Boost_LIB_PREFIX}boost_${COMPONENT} ) + if(_boost_STATIC_RUNTIME_WORKAROUND) + set(_boost_DEBUG_STATIC_ABI_TAG "-s${_boost_DEBUG_ABI_TAG}") + list(APPEND _boost_DEBUG_NAMES + ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG} + ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG} ) + endif() + if(Boost_THREADAPI AND ${COMPONENT} STREQUAL "thread") + _Boost_PREPEND_LIST_WITH_THREADAPI(_boost_DEBUG_NAMES ${_boost_DEBUG_NAMES}) + endif() + if(Boost_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "Searching for ${UPPERCOMPONENT}_LIBRARY_DEBUG: ${_boost_DEBUG_NAMES}") + endif() + + # Avoid passing backslashes to _Boost_FIND_LIBRARY due to macro re-parsing. + string(REPLACE "\\" "/" _boost_LIBRARY_SEARCH_DIRS_tmp "${_boost_LIBRARY_SEARCH_DIRS}") + + _Boost_FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG + NAMES ${_boost_DEBUG_NAMES} + HINTS ${_boost_LIBRARY_SEARCH_DIRS_tmp} + NAMES_PER_DIR + DOC "${_boost_docstring_debug}" + ) + + if(Boost_REALPATH) + _Boost_SWAP_WITH_REALPATH(Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE "${_boost_docstring_release}") + _Boost_SWAP_WITH_REALPATH(Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG "${_boost_docstring_debug}" ) + endif() + + _Boost_ADJUST_LIB_VARS(${UPPERCOMPONENT}) + +endforeach() + +# Restore the original find library ordering +if( Boost_USE_STATIC_LIBS ) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${_boost_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) +endif() + +# ------------------------------------------------------------------------ +# End finding boost libraries +# ------------------------------------------------------------------------ + +set(Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIR}) +set(Boost_LIBRARY_DIRS ${Boost_LIBRARY_DIR}) + +# The above setting of Boost_FOUND was based only on the header files. +# Update it for the requested component libraries. +if(Boost_FOUND) + # The headers were found. Check for requested component libs. + set(_boost_CHECKED_COMPONENT FALSE) + set(_Boost_MISSING_COMPONENTS "") + foreach(COMPONENT ${Boost_FIND_COMPONENTS}) + string(TOUPPER ${COMPONENT} COMPONENT) + set(_boost_CHECKED_COMPONENT TRUE) + if(NOT Boost_${COMPONENT}_FOUND) + string(TOLOWER ${COMPONENT} COMPONENT) + list(APPEND _Boost_MISSING_COMPONENTS ${COMPONENT}) + endif() + endforeach() + + if(Boost_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] Boost_FOUND = ${Boost_FOUND}") + endif() + + if (_Boost_MISSING_COMPONENTS) + set(Boost_FOUND 0) + # We were unable to find some libraries, so generate a sensible + # error message that lists the libraries we were unable to find. + set(Boost_ERROR_REASON + "${Boost_ERROR_REASON}\nCould not find the following") + if(Boost_USE_STATIC_LIBS) + set(Boost_ERROR_REASON "${Boost_ERROR_REASON} static") + endif() + set(Boost_ERROR_REASON + "${Boost_ERROR_REASON} Boost libraries:\n") + foreach(COMPONENT ${_Boost_MISSING_COMPONENTS}) + set(Boost_ERROR_REASON + "${Boost_ERROR_REASON} boost_${COMPONENT}\n") + endforeach() + + list(LENGTH Boost_FIND_COMPONENTS Boost_NUM_COMPONENTS_WANTED) + list(LENGTH _Boost_MISSING_COMPONENTS Boost_NUM_MISSING_COMPONENTS) + if (${Boost_NUM_COMPONENTS_WANTED} EQUAL ${Boost_NUM_MISSING_COMPONENTS}) + set(Boost_ERROR_REASON + "${Boost_ERROR_REASON}No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.") + else () + set(Boost_ERROR_REASON + "${Boost_ERROR_REASON}Some (but not all) of the required Boost libraries were found. You may need to install these additional Boost libraries. Alternatively, set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.") + endif () + endif () + + if( NOT Boost_LIBRARY_DIRS AND NOT _boost_CHECKED_COMPONENT ) + # Compatibility Code for backwards compatibility with CMake + # 2.4's FindBoost module. + + # Look for the boost library path. + # Note that the user may not have installed any libraries + # so it is quite possible the Boost_LIBRARY_DIRS may not exist. + set(_boost_LIB_DIR ${Boost_INCLUDE_DIR}) + + if("${_boost_LIB_DIR}" MATCHES "boost-[0-9]+") + get_filename_component(_boost_LIB_DIR ${_boost_LIB_DIR} PATH) + endif() + + if("${_boost_LIB_DIR}" MATCHES "/include$") + # Strip off the trailing "/include" in the path. + get_filename_component(_boost_LIB_DIR ${_boost_LIB_DIR} PATH) + endif() + + if(EXISTS "${_boost_LIB_DIR}/lib") + set(_boost_LIB_DIR ${_boost_LIB_DIR}/lib) + else() + if(EXISTS "${_boost_LIB_DIR}/stage/lib") + set(_boost_LIB_DIR ${_boost_LIB_DIR}/stage/lib) + else() + set(_boost_LIB_DIR "") + endif() + endif() + + if(_boost_LIB_DIR AND EXISTS "${_boost_LIB_DIR}") + set(Boost_LIBRARY_DIRS ${_boost_LIB_DIR}) + endif() + + endif() +else() + # Boost headers were not found so no components were found. + foreach(COMPONENT ${Boost_FIND_COMPONENTS}) + string(TOUPPER ${COMPONENT} UPPERCOMPONENT) + set(Boost_${UPPERCOMPONENT}_FOUND 0) + endforeach() +endif() + +# ------------------------------------------------------------------------ +# Notification to end user about what was found +# ------------------------------------------------------------------------ + +set(Boost_LIBRARIES "") +if(Boost_FOUND) + if(NOT Boost_FIND_QUIETLY) + message(STATUS "Boost version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}") + if(Boost_FIND_COMPONENTS) + message(STATUS "Found the following Boost libraries:") + endif() + endif() + foreach( COMPONENT ${Boost_FIND_COMPONENTS} ) + string( TOUPPER ${COMPONENT} UPPERCOMPONENT ) + if( Boost_${UPPERCOMPONENT}_FOUND ) + if(NOT Boost_FIND_QUIETLY) + message (STATUS " ${COMPONENT}") + endif() + list(APPEND Boost_LIBRARIES ${Boost_${UPPERCOMPONENT}_LIBRARY}) + endif() + endforeach() + + # Add pthread library on UNIX if thread component was found + _Boost_consider_adding_pthreads(Boost_LIBRARIES ${Boost_LIBRARIES}) +else() + if(Boost_FIND_REQUIRED) + message(SEND_ERROR "Unable to find the requested Boost libraries.\n${Boost_ERROR_REASON}") + else() + if(NOT Boost_FIND_QUIETLY) + # we opt not to automatically output Boost_ERROR_REASON here as + # it could be quite lengthy and somewhat imposing in its requests + # Since Boost is not always a required dependency we'll leave this + # up to the end-user. + if(Boost_DEBUG OR Boost_DETAILED_FAILURE_MSG) + message(STATUS "Could NOT find Boost\n${Boost_ERROR_REASON}") + else() + message(STATUS "Could NOT find Boost") + endif() + endif() + endif() +endif() + +# Configure display of cache entries in GUI. +foreach(v BOOSTROOT BOOST_ROOT ${_Boost_VARS_INC} ${_Boost_VARS_LIB}) + get_property(_type CACHE ${v} PROPERTY TYPE) + if(_type) + set_property(CACHE ${v} PROPERTY ADVANCED 1) + if("x${_type}" STREQUAL "xUNINITIALIZED") + if("x${v}" STREQUAL "xBoost_ADDITIONAL_VERSIONS") + set_property(CACHE ${v} PROPERTY TYPE STRING) + else() + set_property(CACHE ${v} PROPERTY TYPE PATH) + endif() + endif() + endif() +endforeach() + +# Record last used values of input variables so we can +# detect on the next run if the user changed them. +foreach(v + ${_Boost_VARS_INC} ${_Boost_VARS_LIB} + ${_Boost_VARS_DIR} ${_Boost_VARS_NAME} + ) + if(DEFINED ${v}) + set(_${v}_LAST "${${v}}" CACHE INTERNAL "Last used ${v} value.") + else() + unset(_${v}_LAST CACHE) + endif() +endforeach() + +# Maintain a persistent list of components requested anywhere since +# the last flush. +set(_Boost_COMPONENTS_SEARCHED "${_Boost_COMPONENTS_SEARCHED}") +list(APPEND _Boost_COMPONENTS_SEARCHED ${Boost_FIND_COMPONENTS}) +list(REMOVE_DUPLICATES _Boost_COMPONENTS_SEARCHED) +list(SORT _Boost_COMPONENTS_SEARCHED) +set(_Boost_COMPONENTS_SEARCHED "${_Boost_COMPONENTS_SEARCHED}" + CACHE INTERNAL "Components requested for this build tree.") diff --git a/build/cmake_modules/FindCryptoPP.cmake b/build/cmake_modules/FindCryptoPP.cmake index 68177b98..7a8ac317 100644 --- a/build/cmake_modules/FindCryptoPP.cmake +++ b/build/cmake_modules/FindCryptoPP.cmake @@ -1,28 +1,35 @@ -# Find Crypto++ library -# -# Output variables : -# CryptoPP_FOUND -# CryptoPP_INCLUDE_DIRS -# CryptoPP_LIBRARIES -# +# - Find Crypto++ +if(CRYPTO++_INCLUDE_DIR AND CRYPTO++_LIBRARIES) + set(CRYPTO++_FOUND TRUE) -FIND_PATH( CryptoPP_INCLUDE_DIR cryptopp/dsa.h ) +else(CRYPTO++_INCLUDE_DIR AND CRYPTO++_LIBRARIES) + find_path(CRYPTO++_INCLUDE_DIR cryptlib.h + /usr/include/crypto++ + /usr/include/cryptopp + /usr/local/include/crypto++ + /usr/local/include/cryptopp + /opt/local/include/crypto++ + /opt/local/include/cryptopp + $ENV{SystemDrive}/Crypto++/include + ) -FIND_LIBRARY( CryptoPP_LIBRARY NAMES cryptopp ) + find_library(CRYPTO++_LIBRARIES NAMES cryptopp + PATHS + /usr/lib + /usr/local/lib + /opt/local/lib + $ENV{SystemDrive}/Crypto++/lib + ) -# handle the QUIETLY and REQUIRED arguments and set CRYPTOPP_FOUND to TRUE if -# all listed variables are TRUE -INCLUDE(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(CryptoPP DEFAULT_MSG CryptoPP_LIBRARY CryptoPP_INCLUDE_DIR) + if(CRYPTO++_INCLUDE_DIR AND CRYPTO++_LIBRARIES) + set(CRYPTO++_FOUND TRUE) + message(STATUS "Found Crypto++: ${CRYPTO++_INCLUDE_DIR}, ${CRYPTO++_LIBRARIES}") + else(CRYPTO++_INCLUDE_DIR AND CRYPTO++_LIBRARIES) + set(CRYPTO++_FOUND FALSE) + message(STATUS "Crypto++ not found.") + endif(CRYPTO++_INCLUDE_DIR AND CRYPTO++_LIBRARIES) -set ( CryptoPP_FOUND FALSE ) - -if ( ${CRYPTOPP_FOUND} ) - set ( CryptoPP_FOUND TRUE ) - set ( CryptoPP_INCLUDE_DIRS ${CryptoPP_INCLUDE_DIR} ) - set ( CryptoPP_LIBRARIES ${CryptoPP_LIBRARY} ) -endif () - -MARK_AS_ADVANCED(CryptoPP_INCLUDE_DIR CryptoPP_LIBRARY) + mark_as_advanced(CRYPTO++_INCLUDE_DIR CRYPTO++_LIBRARIES) +endif(CRYPTO++_INCLUDE_DIR AND CRYPTO++_LIBRARIES) From 15299aa42de7e7513b90776b60c8cdd702b50348 Mon Sep 17 00:00:00 2001 From: Meeh Date: Fri, 4 Apr 2014 02:08:39 +0200 Subject: [PATCH 21/29] Setting debug as default build mode. --- build/CMakeLists.txt | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index 1da94f19..c4c6d334 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -1,7 +1,9 @@ cmake_minimum_required ( VERSION 2.8 ) project ( i2pd ) - +# Default build is Debug +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall") +#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall") set ( SRC_DIR ".." ) set ( INC_DIR ".." ) @@ -77,19 +79,11 @@ find_package(Crypto++ QUIET) if(!Boost_FOUND) message(FATAL_ERROR "Boost is not found, or your boost version was bellow 1.46. Please download Boost!") return() -else() - # Adding boost directories - INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${Boost_INCLUDE_DIRS}) - LINK_DIRECTORIES(${LINK_DIRECTORIES} ${Boost_LIBRARY_DIRS}) endif() if(!CRYPTO++_FOUND) message(FATAL_ERROR "Could not find Crypto++. Please download and install it first!") return() -else() - # Adding Crypto++ directories - INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${CRYPTO++_INCLUDE_DIR}) - LINK_DIRECTORIES(${LINK_DIRECTORIES} ${CRYPTO++_LIBRARIES}) endif() From 7bdf52a7747c3a7e8da332d7bdcd1965ff96d47d Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 4 Apr 2014 13:30:13 -0400 Subject: [PATCH 22/29] generate DH keys pair per NTCP session --- Identity.cpp | 8 ++++++++ Identity.h | 7 +++++++ NTCPSession.cpp | 14 ++++++++++---- NTCPSession.h | 4 +++- Transports.cpp | 7 +++++++ Transports.h | 2 ++ 6 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Identity.cpp b/Identity.cpp index eb107ca3..387eef50 100644 --- a/Identity.cpp +++ b/Identity.cpp @@ -53,6 +53,14 @@ namespace data return keys; } + void CreateRandomDHKeysPair (DHKeysPair * keys) + { + if (!keys) return; + CryptoPP::AutoSeededRandomPool rnd; + CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg); + dh.GenerateKeyPair(rnd, keys->privateKey, keys->publicKey); + } + RoutingKey CreateRoutingKey (const IdentHash& ident) { uint8_t buf[41]; // ident + yyyymmdd diff --git a/Identity.h b/Identity.h index 2aca019b..1dafdef4 100644 --- a/Identity.h +++ b/Identity.h @@ -11,6 +11,12 @@ namespace data { #pragma pack(1) + struct DHKeysPair // transient keys for transport sessions + { + uint8_t publicKey[256]; + uint8_t privateKey[256]; + }; + struct Keys { uint8_t privateKey[256]; @@ -71,6 +77,7 @@ namespace data IdentHash CalculateIdentHash (const Identity& identity); Keys CreateRandomKeys (); + void CreateRandomDHKeysPair (DHKeysPair * keys); // for transport sessions // kademlia struct RoutingKey diff --git a/NTCPSession.cpp b/NTCPSession.cpp index 1a72fdbc..7eb1614a 100644 --- a/NTCPSession.cpp +++ b/NTCPSession.cpp @@ -24,13 +24,19 @@ namespace ntcp m_Socket (service), m_TerminationTimer (service), m_IsEstablished (false), m_RemoteRouterInfo (in_RemoteRouterInfo), m_ReceiveBufferOffset (0), m_NextMessage (nullptr) { + m_DHKeysPair = i2p::transports.GetNextDHKeysPair (); } + NTCPSession::~NTCPSession () + { + delete m_DHKeysPair; + } + void NTCPSession::CreateAESKey (uint8_t * pubKey, uint8_t * aesKey) { CryptoPP::DH dh (elgp, elgg); CryptoPP::SecByteBlock secretKey(dh.AgreedValueLength()); - if (!dh.Agree (secretKey, i2p::context.GetPrivateKey (), pubKey)) + if (!dh.Agree (secretKey, m_DHKeysPair->privateKey, pubKey)) { LogPrint ("Couldn't create shared key"); Terminate (); @@ -78,7 +84,7 @@ namespace ntcp void NTCPSession::ClientLogin () { // send Phase1 - const uint8_t * x = i2p::context.GetRouterIdentity ().publicKey; + const uint8_t * x = m_DHKeysPair->publicKey; memcpy (m_Phase1.pubKey, x, 256); CryptoPP::SHA256().CalculateDigest(m_Phase1.HXxorHI, x, 256); const uint8_t * ident = m_RemoteRouterInfo.GetIdentHash (); @@ -143,7 +149,7 @@ namespace ntcp void NTCPSession::SendPhase2 () { - const uint8_t * y = i2p::context.GetRouterIdentity ().publicKey; + const uint8_t * y = m_DHKeysPair->publicKey; memcpy (m_Phase2.pubKey, y, 256); uint8_t xy[512]; memcpy (xy, m_Phase1.pubKey, 256); @@ -200,7 +206,7 @@ namespace ntcp m_Decryption.ProcessData((uint8_t *)&m_Phase2.encrypted, (uint8_t *)&m_Phase2.encrypted, sizeof(m_Phase2.encrypted)); // verify uint8_t xy[512], hxy[32]; - memcpy (xy, i2p::context.GetRouterIdentity ().publicKey, 256); + memcpy (xy, m_DHKeysPair->publicKey, 256); memcpy (xy + 256, m_Phase2.pubKey, 256); CryptoPP::SHA256().CalculateDigest(hxy, xy, 512); if (memcmp (hxy, m_Phase2.encrypted.hxy, 32)) diff --git a/NTCPSession.h b/NTCPSession.h index eb31951d..4202c5c9 100644 --- a/NTCPSession.h +++ b/NTCPSession.h @@ -7,6 +7,7 @@ #include #include #include +#include "Identity.h" #include "RouterInfo.h" #include "I2NPProtocol.h" @@ -66,7 +67,7 @@ namespace ntcp public: NTCPSession (boost::asio::io_service& service, i2p::data::RouterInfo& in_RemoteRouterInfo); - virtual ~NTCPSession () {}; + virtual ~NTCPSession (); boost::asio::ip::tcp::socket& GetSocket () { return m_Socket; }; bool IsEstablished () const { return m_IsEstablished; }; @@ -120,6 +121,7 @@ namespace ntcp boost::asio::ip::tcp::socket m_Socket; boost::asio::deadline_timer m_TerminationTimer; bool m_IsEstablished; + i2p::data::DHKeysPair * m_DHKeysPair; // X - for client and Y - for server CryptoPP::CBC_Mode::Decryption m_Decryption; CryptoPP::CBC_Mode::Encryption m_Encryption; diff --git a/Transports.cpp b/Transports.cpp index 60de2710..48462ae3 100644 --- a/Transports.cpp +++ b/Transports.cpp @@ -221,4 +221,11 @@ namespace i2p } } + i2p::data::DHKeysPair * Transports::GetNextDHKeysPair () + { + // TODO: use supplier with separate thread + i2p::data::DHKeysPair * pair = new i2p::data::DHKeysPair (); + i2p::data::CreateRandomDHKeysPair (pair); + return pair; + } } diff --git a/Transports.h b/Transports.h index aedd51b2..ed75cd60 100644 --- a/Transports.h +++ b/Transports.h @@ -10,6 +10,7 @@ #include "SSU.h" #include "RouterInfo.h" #include "I2NPProtocol.h" +#include "Identity.h" namespace i2p { @@ -24,6 +25,7 @@ namespace i2p void Stop (); boost::asio::io_service& GetService () { return m_Service; }; + i2p::data::DHKeysPair * GetNextDHKeysPair (); void AddNTCPSession (i2p::ntcp::NTCPSession * session); void RemoveNTCPSession (i2p::ntcp::NTCPSession * session); From fb350d30dd20d0b56a68565d8231b5b668555e76 Mon Sep 17 00:00:00 2001 From: Meeh Date: Fri, 4 Apr 2014 20:13:27 +0200 Subject: [PATCH 23/29] Removing FindBoost since it's apparently shipped with default cmake. --- build/cmake_modules/FindBoost.cmake | 1181 --------------------------- 1 file changed, 1181 deletions(-) delete mode 100644 build/cmake_modules/FindBoost.cmake diff --git a/build/cmake_modules/FindBoost.cmake b/build/cmake_modules/FindBoost.cmake deleted file mode 100644 index 93db9829..00000000 --- a/build/cmake_modules/FindBoost.cmake +++ /dev/null @@ -1,1181 +0,0 @@ -# - Find Boost include dirs and libraries -# Use this module by invoking find_package with the form: -# find_package(Boost -# [version] [EXACT] # Minimum or EXACT version e.g. 1.36.0 -# [REQUIRED] # Fail with error if Boost is not found -# [COMPONENTS ...] # Boost libraries by their canonical name -# ) # e.g. "date_time" for "libboost_date_time" -# This module finds headers and requested component libraries OR a CMake -# package configuration file provided by a "Boost CMake" build. For the -# latter case skip to the "Boost CMake" section below. For the former -# case results are reported in variables: -# Boost_FOUND - True if headers and requested libraries were found -# Boost_INCLUDE_DIRS - Boost include directories -# Boost_LIBRARY_DIRS - Link directories for Boost libraries -# Boost_LIBRARIES - Boost component libraries to be linked -# Boost__FOUND - True if component was found ( is upper-case) -# Boost__LIBRARY - Libraries to link for component (may include -# target_link_libraries debug/optimized keywords) -# Boost_VERSION - BOOST_VERSION value from boost/version.hpp -# Boost_LIB_VERSION - Version string appended to library filenames -# Boost_MAJOR_VERSION - Boost major version number (X in X.y.z) -# Boost_MINOR_VERSION - Boost minor version number (Y in x.Y.z) -# Boost_SUBMINOR_VERSION - Boost subminor version number (Z in x.y.Z) -# Boost_LIB_DIAGNOSTIC_DEFINITIONS (Windows) -# - Pass to add_definitions() to have diagnostic -# information about Boost's automatic linking -# displayed during compilation -# -# This module reads hints about search locations from variables: -# BOOST_ROOT - Preferred installation prefix -# (or BOOSTROOT) -# BOOST_INCLUDEDIR - Preferred include directory e.g. /include -# BOOST_LIBRARYDIR - Preferred library directory e.g. /lib -# Boost_NO_SYSTEM_PATHS - Set to ON to disable searching in locations not -# specified by these hint variables. Default is OFF. -# Boost_ADDITIONAL_VERSIONS -# - List of Boost versions not known to this module -# (Boost install locations may contain the version) -# and saves search results persistently in CMake cache entries: -# Boost_INCLUDE_DIR - Directory containing Boost headers -# Boost_LIBRARY_DIR - Directory containing Boost libraries -# Boost__LIBRARY_DEBUG - Component library debug variant -# Boost__LIBRARY_RELEASE - Component library release variant -# Users may set these hints or results as cache entries. Projects should -# not read these entries directly but instead use the above result variables. -# Note that some hint names start in upper-case "BOOST". One may specify -# these as environment variables if they are not specified as CMake variables -# or cache entries. -# -# This module first searches for the Boost header files using the above hint -# variables (excluding BOOST_LIBRARYDIR) and saves the result in -# Boost_INCLUDE_DIR. Then it searches for requested component libraries using -# the above hints (excluding BOOST_INCLUDEDIR and Boost_ADDITIONAL_VERSIONS), -# "lib" directories near Boost_INCLUDE_DIR, and the library name configuration -# settings below. It saves the library directory in Boost_LIBRARY_DIR and -# individual library locations in Boost__LIBRARY_DEBUG and -# Boost__LIBRARY_RELEASE. When one changes settings used by previous -# searches in the same build tree (excluding environment variables) this -# module discards previous search results affected by the changes and searches -# again. -# -# Boost libraries come in many variants encoded in their file name. Users or -# projects may tell this module which variant to find by setting variables: -# Boost_USE_MULTITHREADED - Set to OFF to use the non-multithreaded -# libraries ('mt' tag). Default is ON. -# Boost_USE_STATIC_LIBS - Set to ON to force the use of the static -# libraries. Default is OFF. -# Boost_USE_STATIC_RUNTIME - Set to ON or OFF to specify whether to use -# libraries linked statically to the C++ runtime -# ('s' tag). Default is platform dependent. -# Boost_USE_DEBUG_PYTHON - Set to ON to use libraries compiled with a -# debug Python build ('y' tag). Default is OFF. -# Boost_USE_STLPORT - Set to ON to use libraries compiled with -# STLPort ('p' tag). Default is OFF. -# Boost_USE_STLPORT_DEPRECATED_NATIVE_IOSTREAMS -# - Set to ON to use libraries compiled with -# STLPort deprecated "native iostreams" -# ('n' tag). Default is OFF. -# Boost_COMPILER - Set to the compiler-specific library suffix -# (e.g. "-gcc43"). Default is auto-computed -# for the C++ compiler in use. -# Boost_THREADAPI - Suffix for "thread" component library name, -# such as "pthread" or "win32". Names with -# and without this suffix will both be tried. -# Other variables one may set to control this module are: -# Boost_DEBUG - Set to ON to enable debug output from FindBoost. -# Please enable this before filing any bug report. -# Boost_DETAILED_FAILURE_MSG -# - Set to ON to add detailed information to the -# failure message even when the REQUIRED option -# is not given to the find_package call. -# Boost_REALPATH - Set to ON to resolve symlinks for discovered -# libraries to assist with packaging. For example, -# the "system" component library may be resolved to -# "/usr/lib/libboost_system.so.1.42.0" instead of -# "/usr/lib/libboost_system.so". This does not -# affect linking and should not be enabled unless -# the user needs this information. -# On Visual Studio and Borland compilers Boost headers request automatic -# linking to corresponding libraries. This requires matching libraries to be -# linked explicitly or available in the link library search path. In this -# case setting Boost_USE_STATIC_LIBS to OFF may not achieve dynamic linking. -# Boost automatic linking typically requests static libraries with a few -# exceptions (such as Boost.Python). Use -# add_definitions(${Boost_LIB_DIAGNOSTIC_DEFINITIONS}) -# to ask Boost to report information about automatic linking requests. -# -# Example to find Boost headers only: -# find_package(Boost 1.36.0) -# if(Boost_FOUND) -# include_directories(${Boost_INCLUDE_DIRS}) -# add_executable(foo foo.cc) -# endif() -# Example to find Boost headers and some libraries: -# set(Boost_USE_STATIC_LIBS ON) -# set(Boost_USE_MULTITHREADED ON) -# set(Boost_USE_STATIC_RUNTIME OFF) -# find_package(Boost 1.36.0 COMPONENTS date_time filesystem system ...) -# if(Boost_FOUND) -# include_directories(${Boost_INCLUDE_DIRS}) -# add_executable(foo foo.cc) -# target_link_libraries(foo ${Boost_LIBRARIES}) -# endif() -# -# Boost CMake ---------------------------------------------------------- -# -# If Boost was built using the boost-cmake project it provides a package -# configuration file for use with find_package's Config mode. This module -# looks for the package configuration file called BoostConfig.cmake or -# boost-config.cmake and stores the result in cache entry "Boost_DIR". If -# found, the package configuration file is loaded and this module returns with -# no further action. See documentation of the Boost CMake package -# configuration for details on what it provides. -# -# Set Boost_NO_BOOST_CMAKE to ON to disable the search for boost-cmake. - -#============================================================================= -# Copyright 2006-2012 Kitware, Inc. -# Copyright 2006-2008 Andreas Schneider -# Copyright 2007 Wengo -# Copyright 2007 Mike Jackson -# Copyright 2008 Andreas Pakulat -# Copyright 2008-2012 Philip Lowman -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - - -#------------------------------------------------------------------------------- -# Before we go searching, check whether boost-cmake is available, unless the -# user specifically asked NOT to search for boost-cmake. -# -# If Boost_DIR is set, this behaves as any find_package call would. If not, -# it looks at BOOST_ROOT and BOOSTROOT to find Boost. -# -if (NOT Boost_NO_BOOST_CMAKE) - # If Boost_DIR is not set, look for BOOSTROOT and BOOST_ROOT as alternatives, - # since these are more conventional for Boost. - if ("$ENV{Boost_DIR}" STREQUAL "") - if (NOT "$ENV{BOOST_ROOT}" STREQUAL "") - set(ENV{Boost_DIR} $ENV{BOOST_ROOT}) - elseif (NOT "$ENV{BOOSTROOT}" STREQUAL "") - set(ENV{Boost_DIR} $ENV{BOOSTROOT}) - endif() - endif() - - # Do the same find_package call but look specifically for the CMake version. - # Note that args are passed in the Boost_FIND_xxxxx variables, so there is no - # need to delegate them to this find_package call. - find_package(Boost QUIET NO_MODULE) - mark_as_advanced(Boost_DIR) - - # If we found boost-cmake, then we're done. Print out what we found. - # Otherwise let the rest of the module try to find it. - if (Boost_FOUND) - message("Boost ${Boost_FIND_VERSION} found.") - if (Boost_FIND_COMPONENTS) - message("Found Boost components:") - message(" ${Boost_FIND_COMPONENTS}") - endif() - return() - endif() -endif() - - -#------------------------------------------------------------------------------- -# FindBoost functions & macros -# - -############################################ -# -# Check the existence of the libraries. -# -############################################ -# This macro was taken directly from the FindQt4.cmake file that is included -# with the CMake distribution. This is NOT my work. All work was done by the -# original authors of the FindQt4.cmake file. Only minor modifications were -# made to remove references to Qt and make this file more generally applicable -# And ELSE/ENDIF pairs were removed for readability. -######################################################################### - -macro(_Boost_ADJUST_LIB_VARS basename) - if(Boost_INCLUDE_DIR ) - if(Boost_${basename}_LIBRARY_DEBUG AND Boost_${basename}_LIBRARY_RELEASE) - # if the generator supports configuration types then set - # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value - if(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE) - set(Boost_${basename}_LIBRARY optimized ${Boost_${basename}_LIBRARY_RELEASE} debug ${Boost_${basename}_LIBRARY_DEBUG}) - else() - # if there are no configuration types and CMAKE_BUILD_TYPE has no value - # then just use the release libraries - set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE} ) - endif() - # FIXME: This probably should be set for both cases - set(Boost_${basename}_LIBRARIES optimized ${Boost_${basename}_LIBRARY_RELEASE} debug ${Boost_${basename}_LIBRARY_DEBUG}) - endif() - - # if only the release version was found, set the debug variable also to the release version - if(Boost_${basename}_LIBRARY_RELEASE AND NOT Boost_${basename}_LIBRARY_DEBUG) - set(Boost_${basename}_LIBRARY_DEBUG ${Boost_${basename}_LIBRARY_RELEASE}) - set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE}) - set(Boost_${basename}_LIBRARIES ${Boost_${basename}_LIBRARY_RELEASE}) - endif() - - # if only the debug version was found, set the release variable also to the debug version - if(Boost_${basename}_LIBRARY_DEBUG AND NOT Boost_${basename}_LIBRARY_RELEASE) - set(Boost_${basename}_LIBRARY_RELEASE ${Boost_${basename}_LIBRARY_DEBUG}) - set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_DEBUG}) - set(Boost_${basename}_LIBRARIES ${Boost_${basename}_LIBRARY_DEBUG}) - endif() - - # If the debug & release library ends up being the same, omit the keywords - if(${Boost_${basename}_LIBRARY_RELEASE} STREQUAL ${Boost_${basename}_LIBRARY_DEBUG}) - set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE} ) - set(Boost_${basename}_LIBRARIES ${Boost_${basename}_LIBRARY_RELEASE} ) - endif() - - if(Boost_${basename}_LIBRARY) - set(Boost_${basename}_FOUND ON) - endif() - - endif() - # Make variables changeable to the advanced user - mark_as_advanced( - Boost_${basename}_LIBRARY_RELEASE - Boost_${basename}_LIBRARY_DEBUG - ) -endmacro() - -macro(_Boost_CHANGE_DETECT changed_var) - set(${changed_var} 0) - foreach(v ${ARGN}) - if(DEFINED _Boost_COMPONENTS_SEARCHED) - if(${v}) - if(_${v}_LAST) - string(COMPARE NOTEQUAL "${${v}}" "${_${v}_LAST}" _${v}_CHANGED) - else() - set(_${v}_CHANGED 1) - endif() - elseif(_${v}_LAST) - set(_${v}_CHANGED 1) - endif() - if(_${v}_CHANGED) - set(${changed_var} 1) - endif() - else() - set(_${v}_CHANGED 0) - endif() - endforeach() -endmacro() - -macro(_Boost_FIND_LIBRARY var) - find_library(${var} ${ARGN}) - - # If we found the first library save Boost_LIBRARY_DIR. - if(${var} AND NOT Boost_LIBRARY_DIR) - get_filename_component(_dir "${${var}}" PATH) - set(Boost_LIBRARY_DIR "${_dir}" CACHE PATH "Boost library directory" FORCE) - endif() - - # If Boost_LIBRARY_DIR is known then search only there. - if(Boost_LIBRARY_DIR) - set(_boost_LIBRARY_SEARCH_DIRS ${Boost_LIBRARY_DIR} NO_DEFAULT_PATH) - endif() -endmacro() - -#------------------------------------------------------------------------------- - -# -# Runs compiler with "-dumpversion" and parses major/minor -# version with a regex. -# -function(_Boost_COMPILER_DUMPVERSION _OUTPUT_VERSION) - - exec_program(${CMAKE_CXX_COMPILER} - ARGS ${CMAKE_CXX_COMPILER_ARG1} -dumpversion - OUTPUT_VARIABLE _boost_COMPILER_VERSION - ) - string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2" - _boost_COMPILER_VERSION ${_boost_COMPILER_VERSION}) - - set(${_OUTPUT_VERSION} ${_boost_COMPILER_VERSION} PARENT_SCOPE) -endfunction() - -# -# Take a list of libraries with "thread" in it -# and prepend duplicates with "thread_${Boost_THREADAPI}" -# at the front of the list -# -function(_Boost_PREPEND_LIST_WITH_THREADAPI _output) - set(_orig_libnames ${ARGN}) - string(REPLACE "thread" "thread_${Boost_THREADAPI}" _threadapi_libnames "${_orig_libnames}") - set(${_output} ${_threadapi_libnames} ${_orig_libnames} PARENT_SCOPE) -endfunction() - -# -# If a library is found, replace its cache entry with its REALPATH -# -function(_Boost_SWAP_WITH_REALPATH _library _docstring) - if(${_library}) - get_filename_component(_boost_filepathreal ${${_library}} REALPATH) - unset(${_library} CACHE) - set(${_library} ${_boost_filepathreal} CACHE FILEPATH "${_docstring}") - endif() -endfunction() - -function(_Boost_CHECK_SPELLING _var) - if(${_var}) - string(TOUPPER ${_var} _var_UC) - message(FATAL_ERROR "ERROR: ${_var} is not the correct spelling. The proper spelling is ${_var_UC}.") - endif() -endfunction() - -# Guesses Boost's compiler prefix used in built library names -# Returns the guess by setting the variable pointed to by _ret -function(_Boost_GUESS_COMPILER_PREFIX _ret) - if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel" - OR "${CMAKE_CXX_COMPILER}" MATCHES "icl" - OR "${CMAKE_CXX_COMPILER}" MATCHES "icpc") - if(WIN32) - set (_boost_COMPILER "-iw") - else() - set (_boost_COMPILER "-il") - endif() - elseif (MSVC12) - set(_boost_COMPILER "-vc120") - elseif (MSVC11) - set(_boost_COMPILER "-vc110") - elseif (MSVC10) - set(_boost_COMPILER "-vc100") - elseif (MSVC90) - set(_boost_COMPILER "-vc90") - elseif (MSVC80) - set(_boost_COMPILER "-vc80") - elseif (MSVC71) - set(_boost_COMPILER "-vc71") - elseif (MSVC70) # Good luck! - set(_boost_COMPILER "-vc7") # yes, this is correct - elseif (MSVC60) # Good luck! - set(_boost_COMPILER "-vc6") # yes, this is correct - elseif (BORLAND) - set(_boost_COMPILER "-bcb") - elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "SunPro") - set(_boost_COMPILER "-sw") - elseif (MINGW) - if(${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION} VERSION_LESS 1.34) - set(_boost_COMPILER "-mgw") # no GCC version encoding prior to 1.34 - else() - _Boost_COMPILER_DUMPVERSION(_boost_COMPILER_VERSION) - set(_boost_COMPILER "-mgw${_boost_COMPILER_VERSION}") - endif() - elseif (UNIX) - if (CMAKE_COMPILER_IS_GNUCXX) - if(${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION} VERSION_LESS 1.34) - set(_boost_COMPILER "-gcc") # no GCC version encoding prior to 1.34 - else() - _Boost_COMPILER_DUMPVERSION(_boost_COMPILER_VERSION) - # Determine which version of GCC we have. - if(APPLE) - if(Boost_MINOR_VERSION) - if(${Boost_MINOR_VERSION} GREATER 35) - # In Boost 1.36.0 and newer, the mangled compiler name used - # on Mac OS X/Darwin is "xgcc". - set(_boost_COMPILER "-xgcc${_boost_COMPILER_VERSION}") - else() - # In Boost <= 1.35.0, there is no mangled compiler name for - # the Mac OS X/Darwin version of GCC. - set(_boost_COMPILER "") - endif() - else() - # We don't know the Boost version, so assume it's - # pre-1.36.0. - set(_boost_COMPILER "") - endif() - else() - set(_boost_COMPILER "-gcc${_boost_COMPILER_VERSION}") - endif() - endif() - endif () - else() - # TODO at least Boost_DEBUG here? - set(_boost_COMPILER "") - endif() - set(${_ret} ${_boost_COMPILER} PARENT_SCOPE) -endfunction() - -function(_Boost_consider_adding_pthreads _outvar) - # On Unix platforms (excluding cygwin) add pthreads to Boost_LIBRARIES - # if the user is searching for the boost-thread component. - if(UNIX AND NOT CYGWIN) - list(FIND Boost_FIND_COMPONENTS thread _using_boost_thread) - if(_using_boost_thread GREATER -1) - find_library(BOOST_THREAD_LIBRARY NAMES pthread - DOC "The threading library used by boost-thread" - ) - if(BOOST_THREAD_LIBRARY) - set(${_outvar} ${ARGN} ${BOOST_THREAD_LIBRARY} PARENT_SCOPE) - endif() - endif() - endif() -endfunction() - -# -# End functions/macros -# -#------------------------------------------------------------------------------- - -#------------------------------------------------------------------------------- -# main. -#------------------------------------------------------------------------------- - -if(NOT DEFINED Boost_USE_MULTITHREADED) - set(Boost_USE_MULTITHREADED TRUE) -endif() - -# Check the version of Boost against the requested version. -if(Boost_FIND_VERSION AND NOT Boost_FIND_VERSION_MINOR) - message(SEND_ERROR "When requesting a specific version of Boost, you must provide at least the major and minor version numbers, e.g., 1.34") -endif() - -if(Boost_FIND_VERSION_EXACT) - # The version may appear in a directory with or without the patch - # level, even when the patch level is non-zero. - set(_boost_TEST_VERSIONS - "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}.${Boost_FIND_VERSION_PATCH}" - "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}") -else() - # The user has not requested an exact version. Among known - # versions, find those that are acceptable to the user request. - set(_Boost_KNOWN_VERSIONS ${Boost_ADDITIONAL_VERSIONS} - "1.56.0" "1.56" "1.55.0" "1.55" "1.54.0" "1.54" - "1.53.0" "1.53" "1.52.0" "1.52" "1.51.0" "1.51" - "1.50.0" "1.50" "1.49.0" "1.49" "1.48.0" "1.48" "1.47.0" "1.47" "1.46.1" - "1.46.0" "1.46" "1.45.0" "1.45" "1.44.0" "1.44" "1.43.0" "1.43" "1.42.0" "1.42" - "1.41.0" "1.41" "1.40.0" "1.40" "1.39.0" "1.39" "1.38.0" "1.38" "1.37.0" "1.37" - "1.36.1" "1.36.0" "1.36" "1.35.1" "1.35.0" "1.35" "1.34.1" "1.34.0" - "1.34" "1.33.1" "1.33.0" "1.33") - set(_boost_TEST_VERSIONS) - if(Boost_FIND_VERSION) - set(_Boost_FIND_VERSION_SHORT "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}") - # Select acceptable versions. - foreach(version ${_Boost_KNOWN_VERSIONS}) - if(NOT "${version}" VERSION_LESS "${Boost_FIND_VERSION}") - # This version is high enough. - list(APPEND _boost_TEST_VERSIONS "${version}") - elseif("${version}.99" VERSION_EQUAL "${_Boost_FIND_VERSION_SHORT}.99") - # This version is a short-form for the requested version with - # the patch level dropped. - list(APPEND _boost_TEST_VERSIONS "${version}") - endif() - endforeach() - else() - # Any version is acceptable. - set(_boost_TEST_VERSIONS "${_Boost_KNOWN_VERSIONS}") - endif() -endif() - -# The reason that we failed to find Boost. This will be set to a -# user-friendly message when we fail to find some necessary piece of -# Boost. -set(Boost_ERROR_REASON) - -if(Boost_DEBUG) - # Output some of their choices - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "_boost_TEST_VERSIONS = ${_boost_TEST_VERSIONS}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "Boost_USE_MULTITHREADED = ${Boost_USE_MULTITHREADED}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "Boost_USE_STATIC_LIBS = ${Boost_USE_STATIC_LIBS}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "Boost_USE_STATIC_RUNTIME = ${Boost_USE_STATIC_RUNTIME}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "Boost_ADDITIONAL_VERSIONS = ${Boost_ADDITIONAL_VERSIONS}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "Boost_NO_SYSTEM_PATHS = ${Boost_NO_SYSTEM_PATHS}") -endif() - -if(WIN32) - # In windows, automatic linking is performed, so you do not have - # to specify the libraries. If you are linking to a dynamic - # runtime, then you can choose to link to either a static or a - # dynamic Boost library, the default is to do a static link. You - # can alter this for a specific library "whatever" by defining - # BOOST_WHATEVER_DYN_LINK to force Boost library "whatever" to be - # linked dynamically. Alternatively you can force all Boost - # libraries to dynamic link by defining BOOST_ALL_DYN_LINK. - - # This feature can be disabled for Boost library "whatever" by - # defining BOOST_WHATEVER_NO_LIB, or for all of Boost by defining - # BOOST_ALL_NO_LIB. - - # If you want to observe which libraries are being linked against - # then defining BOOST_LIB_DIAGNOSTIC will cause the auto-linking - # code to emit a #pragma message each time a library is selected - # for linking. - set(Boost_LIB_DIAGNOSTIC_DEFINITIONS "-DBOOST_LIB_DIAGNOSTIC") -endif() - -_Boost_CHECK_SPELLING(Boost_ROOT) -_Boost_CHECK_SPELLING(Boost_LIBRARYDIR) -_Boost_CHECK_SPELLING(Boost_INCLUDEDIR) - -# Collect environment variable inputs as hints. Do not consider changes. -foreach(v BOOSTROOT BOOST_ROOT BOOST_INCLUDEDIR BOOST_LIBRARYDIR) - set(_env $ENV{${v}}) - if(_env) - file(TO_CMAKE_PATH "${_env}" _ENV_${v}) - else() - set(_ENV_${v} "") - endif() -endforeach() -if(NOT _ENV_BOOST_ROOT AND _ENV_BOOSTROOT) - set(_ENV_BOOST_ROOT "${_ENV_BOOSTROOT}") -endif() - -# Collect inputs and cached results. Detect changes since the last run. -if(NOT BOOST_ROOT AND BOOSTROOT) - set(BOOST_ROOT "${BOOSTROOT}") -endif() -set(_Boost_VARS_DIR - BOOST_ROOT - Boost_NO_SYSTEM_PATHS - ) - -if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "Declared as CMake or Environmental Variables:") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - " BOOST_ROOT = ${BOOST_ROOT}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - " BOOST_INCLUDEDIR = ${BOOST_INCLUDEDIR}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - " BOOST_LIBRARYDIR = ${BOOST_LIBRARYDIR}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "_boost_TEST_VERSIONS = ${_boost_TEST_VERSIONS}") -endif() - -# ------------------------------------------------------------------------ -# Search for Boost include DIR -# ------------------------------------------------------------------------ - -set(_Boost_VARS_INC BOOST_INCLUDEDIR Boost_INCLUDE_DIR Boost_ADDITIONAL_VERSIONS) -_Boost_CHANGE_DETECT(_Boost_CHANGE_INCDIR ${_Boost_VARS_DIR} ${_Boost_VARS_INC}) -# Clear Boost_INCLUDE_DIR if it did not change but other input affecting the -# location did. We will find a new one based on the new inputs. -if(_Boost_CHANGE_INCDIR AND NOT _Boost_INCLUDE_DIR_CHANGED) - unset(Boost_INCLUDE_DIR CACHE) -endif() - -if(NOT Boost_INCLUDE_DIR) - set(_boost_INCLUDE_SEARCH_DIRS "") - if(BOOST_INCLUDEDIR) - list(APPEND _boost_INCLUDE_SEARCH_DIRS ${BOOST_INCLUDEDIR}) - elseif(_ENV_BOOST_INCLUDEDIR) - list(APPEND _boost_INCLUDE_SEARCH_DIRS ${_ENV_BOOST_INCLUDEDIR}) - endif() - - if( BOOST_ROOT ) - list(APPEND _boost_INCLUDE_SEARCH_DIRS ${BOOST_ROOT}/include ${BOOST_ROOT}) - elseif( _ENV_BOOST_ROOT ) - list(APPEND _boost_INCLUDE_SEARCH_DIRS ${_ENV_BOOST_ROOT}/include ${_ENV_BOOST_ROOT}) - endif() - - if( Boost_NO_SYSTEM_PATHS) - list(APPEND _boost_INCLUDE_SEARCH_DIRS NO_CMAKE_SYSTEM_PATH) - else() - list(APPEND _boost_INCLUDE_SEARCH_DIRS PATHS - C:/boost/include - C:/boost - /sw/local/include - ) - endif() - - # Try to find Boost by stepping backwards through the Boost versions - # we know about. - # Build a list of path suffixes for each version. - set(_boost_PATH_SUFFIXES) - foreach(_boost_VER ${_boost_TEST_VERSIONS}) - # Add in a path suffix, based on the required version, ideally - # we could read this from version.hpp, but for that to work we'd - # need to know the include dir already - set(_boost_BOOSTIFIED_VERSION) - - # Transform 1.35 => 1_35 and 1.36.0 => 1_36_0 - if(_boost_VER MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+") - string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1_\\2_\\3" - _boost_BOOSTIFIED_VERSION ${_boost_VER}) - elseif(_boost_VER MATCHES "[0-9]+\\.[0-9]+") - string(REGEX REPLACE "([0-9]+)\\.([0-9]+)" "\\1_\\2" - _boost_BOOSTIFIED_VERSION ${_boost_VER}) - endif() - - list(APPEND _boost_PATH_SUFFIXES - "boost-${_boost_BOOSTIFIED_VERSION}" - "boost_${_boost_BOOSTIFIED_VERSION}" - "boost/boost-${_boost_BOOSTIFIED_VERSION}" - "boost/boost_${_boost_BOOSTIFIED_VERSION}" - ) - - endforeach() - - if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "Include debugging info:") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - " _boost_INCLUDE_SEARCH_DIRS = ${_boost_INCLUDE_SEARCH_DIRS}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - " _boost_PATH_SUFFIXES = ${_boost_PATH_SUFFIXES}") - endif() - - # Look for a standard boost header file. - find_path(Boost_INCLUDE_DIR - NAMES boost/config.hpp - HINTS ${_boost_INCLUDE_SEARCH_DIRS} - PATH_SUFFIXES ${_boost_PATH_SUFFIXES} - ) -endif() - -# ------------------------------------------------------------------------ -# Extract version information from version.hpp -# ------------------------------------------------------------------------ - -# Set Boost_FOUND based only on header location and version. -# It will be updated below for component libraries. -if(Boost_INCLUDE_DIR) - if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "location of version.hpp: ${Boost_INCLUDE_DIR}/boost/version.hpp") - endif() - - # Extract Boost_VERSION and Boost_LIB_VERSION from version.hpp - set(Boost_VERSION 0) - set(Boost_LIB_VERSION "") - file(STRINGS "${Boost_INCLUDE_DIR}/boost/version.hpp" _boost_VERSION_HPP_CONTENTS REGEX "#define BOOST_(LIB_)?VERSION ") - set(_Boost_VERSION_REGEX "([0-9]+)") - set(_Boost_LIB_VERSION_REGEX "\"([0-9_]+)\"") - foreach(v VERSION LIB_VERSION) - if("${_boost_VERSION_HPP_CONTENTS}" MATCHES ".*#define BOOST_${v} ${_Boost_${v}_REGEX}.*") - set(Boost_${v} "${CMAKE_MATCH_1}") - endif() - endforeach() - unset(_boost_VERSION_HPP_CONTENTS) - - math(EXPR Boost_MAJOR_VERSION "${Boost_VERSION} / 100000") - math(EXPR Boost_MINOR_VERSION "${Boost_VERSION} / 100 % 1000") - math(EXPR Boost_SUBMINOR_VERSION "${Boost_VERSION} % 100") - - set(Boost_ERROR_REASON - "${Boost_ERROR_REASON}Boost version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}\nBoost include path: ${Boost_INCLUDE_DIR}") - if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "version.hpp reveals boost " - "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}") - endif() - - if(Boost_FIND_VERSION) - # Set Boost_FOUND based on requested version. - set(_Boost_VERSION "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}") - if("${_Boost_VERSION}" VERSION_LESS "${Boost_FIND_VERSION}") - set(Boost_FOUND 0) - set(_Boost_VERSION_AGE "old") - elseif(Boost_FIND_VERSION_EXACT AND - NOT "${_Boost_VERSION}" VERSION_EQUAL "${Boost_FIND_VERSION}") - set(Boost_FOUND 0) - set(_Boost_VERSION_AGE "new") - else() - set(Boost_FOUND 1) - endif() - if(NOT Boost_FOUND) - # State that we found a version of Boost that is too new or too old. - set(Boost_ERROR_REASON - "${Boost_ERROR_REASON}\nDetected version of Boost is too ${_Boost_VERSION_AGE}. Requested version was ${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}") - if (Boost_FIND_VERSION_PATCH) - set(Boost_ERROR_REASON - "${Boost_ERROR_REASON}.${Boost_FIND_VERSION_PATCH}") - endif () - if (NOT Boost_FIND_VERSION_EXACT) - set(Boost_ERROR_REASON "${Boost_ERROR_REASON} (or newer)") - endif () - set(Boost_ERROR_REASON "${Boost_ERROR_REASON}.") - endif () - else() - # Caller will accept any Boost version. - set(Boost_FOUND 1) - endif() -else() - set(Boost_FOUND 0) - set(Boost_ERROR_REASON - "${Boost_ERROR_REASON}Unable to find the Boost header files. Please set BOOST_ROOT to the root directory containing Boost or BOOST_INCLUDEDIR to the directory containing Boost's headers.") -endif() - -# ------------------------------------------------------------------------ -# Suffix initialization and compiler suffix detection. -# ------------------------------------------------------------------------ - -set(_Boost_VARS_NAME - Boost_COMPILER - Boost_THREADAPI - Boost_USE_DEBUG_PYTHON - Boost_USE_MULTITHREADED - Boost_USE_STATIC_LIBS - Boost_USE_STATIC_RUNTIME - Boost_USE_STLPORT - Boost_USE_STLPORT_DEPRECATED_NATIVE_IOSTREAMS - ) -_Boost_CHANGE_DETECT(_Boost_CHANGE_LIBNAME ${_Boost_VARS_NAME}) - -# Setting some more suffixes for the library -set(Boost_LIB_PREFIX "") -if ( WIN32 AND Boost_USE_STATIC_LIBS AND NOT CYGWIN) - set(Boost_LIB_PREFIX "lib") -endif() - -if (Boost_COMPILER) - set(_boost_COMPILER ${Boost_COMPILER}) - if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "using user-specified Boost_COMPILER = ${_boost_COMPILER}") - endif() -else() - # Attempt to guess the compiler suffix - # NOTE: this is not perfect yet, if you experience any issues - # please report them and use the Boost_COMPILER variable - # to work around the problems. - _Boost_GUESS_COMPILER_PREFIX(_boost_COMPILER) - if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "guessed _boost_COMPILER = ${_boost_COMPILER}") - endif() -endif() - -set (_boost_MULTITHREADED "-mt") -if( NOT Boost_USE_MULTITHREADED ) - set (_boost_MULTITHREADED "") -endif() -if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "_boost_MULTITHREADED = ${_boost_MULTITHREADED}") -endif() - -#====================== -# Systematically build up the Boost ABI tag -# http://boost.org/doc/libs/1_41_0/more/getting_started/windows.html#library-naming -set( _boost_RELEASE_ABI_TAG "-") -set( _boost_DEBUG_ABI_TAG "-") -# Key Use this library when: -# s linking statically to the C++ standard library and -# compiler runtime support libraries. -if(Boost_USE_STATIC_RUNTIME) - set( _boost_RELEASE_ABI_TAG "${_boost_RELEASE_ABI_TAG}s") - set( _boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}s") -endif() -# g using debug versions of the standard and runtime -# support libraries -if(WIN32) - if(MSVC OR "${CMAKE_CXX_COMPILER}" MATCHES "icl" - OR "${CMAKE_CXX_COMPILER}" MATCHES "icpc") - set(_boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}g") - endif() -endif() -# y using special debug build of python -if(Boost_USE_DEBUG_PYTHON) - set(_boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}y") -endif() -# d using a debug version of your code -set(_boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}d") -# p using the STLport standard library rather than the -# default one supplied with your compiler -if(Boost_USE_STLPORT) - set( _boost_RELEASE_ABI_TAG "${_boost_RELEASE_ABI_TAG}p") - set( _boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}p") -endif() -# n using the STLport deprecated "native iostreams" feature -if(Boost_USE_STLPORT_DEPRECATED_NATIVE_IOSTREAMS) - set( _boost_RELEASE_ABI_TAG "${_boost_RELEASE_ABI_TAG}n") - set( _boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}n") -endif() - -if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "_boost_RELEASE_ABI_TAG = ${_boost_RELEASE_ABI_TAG}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "_boost_DEBUG_ABI_TAG = ${_boost_DEBUG_ABI_TAG}") -endif() - -# ------------------------------------------------------------------------ -# Begin finding boost libraries -# ------------------------------------------------------------------------ -set(_Boost_VARS_LIB BOOST_LIBRARYDIR Boost_LIBRARY_DIR) -_Boost_CHANGE_DETECT(_Boost_CHANGE_LIBDIR ${_Boost_VARS_DIR} ${_Boost_VARS_LIB} Boost_INCLUDE_DIR) -# Clear Boost_LIBRARY_DIR if it did not change but other input affecting the -# location did. We will find a new one based on the new inputs. -if(_Boost_CHANGE_LIBDIR AND NOT _Boost_LIBRARY_DIR_CHANGED) - unset(Boost_LIBRARY_DIR CACHE) -endif() - -if(Boost_LIBRARY_DIR) - set(_boost_LIBRARY_SEARCH_DIRS ${Boost_LIBRARY_DIR} NO_DEFAULT_PATH) -else() - set(_boost_LIBRARY_SEARCH_DIRS "") - if(BOOST_LIBRARYDIR) - list(APPEND _boost_LIBRARY_SEARCH_DIRS ${BOOST_LIBRARYDIR}) - elseif(_ENV_BOOST_LIBRARYDIR) - list(APPEND _boost_LIBRARY_SEARCH_DIRS ${_ENV_BOOST_LIBRARYDIR}) - endif() - - if(BOOST_ROOT) - list(APPEND _boost_LIBRARY_SEARCH_DIRS ${BOOST_ROOT}/lib ${BOOST_ROOT}/stage/lib) - elseif(_ENV_BOOST_ROOT) - list(APPEND _boost_LIBRARY_SEARCH_DIRS ${_ENV_BOOST_ROOT}/lib ${_ENV_BOOST_ROOT}/stage/lib) - endif() - - list(APPEND _boost_LIBRARY_SEARCH_DIRS - ${Boost_INCLUDE_DIR}/lib - ${Boost_INCLUDE_DIR}/../lib - ${Boost_INCLUDE_DIR}/stage/lib - ) - if( Boost_NO_SYSTEM_PATHS ) - list(APPEND _boost_LIBRARY_SEARCH_DIRS NO_CMAKE_SYSTEM_PATH) - else() - list(APPEND _boost_LIBRARY_SEARCH_DIRS PATHS - C:/boost/lib - C:/boost - /sw/local/lib - ) - endif() -endif() - -if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "_boost_LIBRARY_SEARCH_DIRS = ${_boost_LIBRARY_SEARCH_DIRS}") -endif() - -# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES -if( Boost_USE_STATIC_LIBS ) - set( _boost_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) - if(WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) - else() - set(CMAKE_FIND_LIBRARY_SUFFIXES .a ) - endif() -endif() - -# We want to use the tag inline below without risking double dashes -if(_boost_RELEASE_ABI_TAG) - if(${_boost_RELEASE_ABI_TAG} STREQUAL "-") - set(_boost_RELEASE_ABI_TAG "") - endif() -endif() -if(_boost_DEBUG_ABI_TAG) - if(${_boost_DEBUG_ABI_TAG} STREQUAL "-") - set(_boost_DEBUG_ABI_TAG "") - endif() -endif() - -# The previous behavior of FindBoost when Boost_USE_STATIC_LIBS was enabled -# on WIN32 was to: -# 1. Search for static libs compiled against a SHARED C++ standard runtime library (use if found) -# 2. Search for static libs compiled against a STATIC C++ standard runtime library (use if found) -# We maintain this behavior since changing it could break people's builds. -# To disable the ambiguous behavior, the user need only -# set Boost_USE_STATIC_RUNTIME either ON or OFF. -set(_boost_STATIC_RUNTIME_WORKAROUND false) -if(WIN32 AND Boost_USE_STATIC_LIBS) - if(NOT DEFINED Boost_USE_STATIC_RUNTIME) - set(_boost_STATIC_RUNTIME_WORKAROUND true) - endif() -endif() - -# On versions < 1.35, remove the System library from the considered list -# since it wasn't added until 1.35. -if(Boost_VERSION AND Boost_FIND_COMPONENTS) - if(Boost_VERSION LESS 103500) - list(REMOVE_ITEM Boost_FIND_COMPONENTS system) - endif() -endif() - -# If the user changed any of our control inputs flush previous results. -if(_Boost_CHANGE_LIBDIR OR _Boost_CHANGE_LIBNAME) - foreach(COMPONENT ${_Boost_COMPONENTS_SEARCHED}) - string(TOUPPER ${COMPONENT} UPPERCOMPONENT) - foreach(c DEBUG RELEASE) - set(_var Boost_${UPPERCOMPONENT}_LIBRARY_${c}) - unset(${_var} CACHE) - set(${_var} "${_var}-NOTFOUND") - endforeach() - endforeach() - set(_Boost_COMPONENTS_SEARCHED "") -endif() - -foreach(COMPONENT ${Boost_FIND_COMPONENTS}) - string(TOUPPER ${COMPONENT} UPPERCOMPONENT) - - set( _boost_docstring_release "Boost ${COMPONENT} library (release)") - set( _boost_docstring_debug "Boost ${COMPONENT} library (debug)") - - # - # Find RELEASE libraries - # - set(_boost_RELEASE_NAMES - ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}-${Boost_LIB_VERSION} - ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG} - ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}-${Boost_LIB_VERSION} - ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG} - ${Boost_LIB_PREFIX}boost_${COMPONENT} ) - if(_boost_STATIC_RUNTIME_WORKAROUND) - set(_boost_RELEASE_STATIC_ABI_TAG "-s${_boost_RELEASE_ABI_TAG}") - list(APPEND _boost_RELEASE_NAMES - ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}-${Boost_LIB_VERSION} - ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG} - ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}-${Boost_LIB_VERSION} - ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG} ) - endif() - if(Boost_THREADAPI AND ${COMPONENT} STREQUAL "thread") - _Boost_PREPEND_LIST_WITH_THREADAPI(_boost_RELEASE_NAMES ${_boost_RELEASE_NAMES}) - endif() - if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "Searching for ${UPPERCOMPONENT}_LIBRARY_RELEASE: ${_boost_RELEASE_NAMES}") - endif() - - # Avoid passing backslashes to _Boost_FIND_LIBRARY due to macro re-parsing. - string(REPLACE "\\" "/" _boost_LIBRARY_SEARCH_DIRS_tmp "${_boost_LIBRARY_SEARCH_DIRS}") - - _Boost_FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE - NAMES ${_boost_RELEASE_NAMES} - HINTS ${_boost_LIBRARY_SEARCH_DIRS_tmp} - NAMES_PER_DIR - DOC "${_boost_docstring_release}" - ) - - # - # Find DEBUG libraries - # - set(_boost_DEBUG_NAMES - ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}-${Boost_LIB_VERSION} - ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG} - ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}-${Boost_LIB_VERSION} - ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG} - ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED} - ${Boost_LIB_PREFIX}boost_${COMPONENT} ) - if(_boost_STATIC_RUNTIME_WORKAROUND) - set(_boost_DEBUG_STATIC_ABI_TAG "-s${_boost_DEBUG_ABI_TAG}") - list(APPEND _boost_DEBUG_NAMES - ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}-${Boost_LIB_VERSION} - ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG} - ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}-${Boost_LIB_VERSION} - ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG} ) - endif() - if(Boost_THREADAPI AND ${COMPONENT} STREQUAL "thread") - _Boost_PREPEND_LIST_WITH_THREADAPI(_boost_DEBUG_NAMES ${_boost_DEBUG_NAMES}) - endif() - if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "Searching for ${UPPERCOMPONENT}_LIBRARY_DEBUG: ${_boost_DEBUG_NAMES}") - endif() - - # Avoid passing backslashes to _Boost_FIND_LIBRARY due to macro re-parsing. - string(REPLACE "\\" "/" _boost_LIBRARY_SEARCH_DIRS_tmp "${_boost_LIBRARY_SEARCH_DIRS}") - - _Boost_FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG - NAMES ${_boost_DEBUG_NAMES} - HINTS ${_boost_LIBRARY_SEARCH_DIRS_tmp} - NAMES_PER_DIR - DOC "${_boost_docstring_debug}" - ) - - if(Boost_REALPATH) - _Boost_SWAP_WITH_REALPATH(Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE "${_boost_docstring_release}") - _Boost_SWAP_WITH_REALPATH(Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG "${_boost_docstring_debug}" ) - endif() - - _Boost_ADJUST_LIB_VARS(${UPPERCOMPONENT}) - -endforeach() - -# Restore the original find library ordering -if( Boost_USE_STATIC_LIBS ) - set(CMAKE_FIND_LIBRARY_SUFFIXES ${_boost_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) -endif() - -# ------------------------------------------------------------------------ -# End finding boost libraries -# ------------------------------------------------------------------------ - -set(Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIR}) -set(Boost_LIBRARY_DIRS ${Boost_LIBRARY_DIR}) - -# The above setting of Boost_FOUND was based only on the header files. -# Update it for the requested component libraries. -if(Boost_FOUND) - # The headers were found. Check for requested component libs. - set(_boost_CHECKED_COMPONENT FALSE) - set(_Boost_MISSING_COMPONENTS "") - foreach(COMPONENT ${Boost_FIND_COMPONENTS}) - string(TOUPPER ${COMPONENT} COMPONENT) - set(_boost_CHECKED_COMPONENT TRUE) - if(NOT Boost_${COMPONENT}_FOUND) - string(TOLOWER ${COMPONENT} COMPONENT) - list(APPEND _Boost_MISSING_COMPONENTS ${COMPONENT}) - endif() - endforeach() - - if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] Boost_FOUND = ${Boost_FOUND}") - endif() - - if (_Boost_MISSING_COMPONENTS) - set(Boost_FOUND 0) - # We were unable to find some libraries, so generate a sensible - # error message that lists the libraries we were unable to find. - set(Boost_ERROR_REASON - "${Boost_ERROR_REASON}\nCould not find the following") - if(Boost_USE_STATIC_LIBS) - set(Boost_ERROR_REASON "${Boost_ERROR_REASON} static") - endif() - set(Boost_ERROR_REASON - "${Boost_ERROR_REASON} Boost libraries:\n") - foreach(COMPONENT ${_Boost_MISSING_COMPONENTS}) - set(Boost_ERROR_REASON - "${Boost_ERROR_REASON} boost_${COMPONENT}\n") - endforeach() - - list(LENGTH Boost_FIND_COMPONENTS Boost_NUM_COMPONENTS_WANTED) - list(LENGTH _Boost_MISSING_COMPONENTS Boost_NUM_MISSING_COMPONENTS) - if (${Boost_NUM_COMPONENTS_WANTED} EQUAL ${Boost_NUM_MISSING_COMPONENTS}) - set(Boost_ERROR_REASON - "${Boost_ERROR_REASON}No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.") - else () - set(Boost_ERROR_REASON - "${Boost_ERROR_REASON}Some (but not all) of the required Boost libraries were found. You may need to install these additional Boost libraries. Alternatively, set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.") - endif () - endif () - - if( NOT Boost_LIBRARY_DIRS AND NOT _boost_CHECKED_COMPONENT ) - # Compatibility Code for backwards compatibility with CMake - # 2.4's FindBoost module. - - # Look for the boost library path. - # Note that the user may not have installed any libraries - # so it is quite possible the Boost_LIBRARY_DIRS may not exist. - set(_boost_LIB_DIR ${Boost_INCLUDE_DIR}) - - if("${_boost_LIB_DIR}" MATCHES "boost-[0-9]+") - get_filename_component(_boost_LIB_DIR ${_boost_LIB_DIR} PATH) - endif() - - if("${_boost_LIB_DIR}" MATCHES "/include$") - # Strip off the trailing "/include" in the path. - get_filename_component(_boost_LIB_DIR ${_boost_LIB_DIR} PATH) - endif() - - if(EXISTS "${_boost_LIB_DIR}/lib") - set(_boost_LIB_DIR ${_boost_LIB_DIR}/lib) - else() - if(EXISTS "${_boost_LIB_DIR}/stage/lib") - set(_boost_LIB_DIR ${_boost_LIB_DIR}/stage/lib) - else() - set(_boost_LIB_DIR "") - endif() - endif() - - if(_boost_LIB_DIR AND EXISTS "${_boost_LIB_DIR}") - set(Boost_LIBRARY_DIRS ${_boost_LIB_DIR}) - endif() - - endif() -else() - # Boost headers were not found so no components were found. - foreach(COMPONENT ${Boost_FIND_COMPONENTS}) - string(TOUPPER ${COMPONENT} UPPERCOMPONENT) - set(Boost_${UPPERCOMPONENT}_FOUND 0) - endforeach() -endif() - -# ------------------------------------------------------------------------ -# Notification to end user about what was found -# ------------------------------------------------------------------------ - -set(Boost_LIBRARIES "") -if(Boost_FOUND) - if(NOT Boost_FIND_QUIETLY) - message(STATUS "Boost version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}") - if(Boost_FIND_COMPONENTS) - message(STATUS "Found the following Boost libraries:") - endif() - endif() - foreach( COMPONENT ${Boost_FIND_COMPONENTS} ) - string( TOUPPER ${COMPONENT} UPPERCOMPONENT ) - if( Boost_${UPPERCOMPONENT}_FOUND ) - if(NOT Boost_FIND_QUIETLY) - message (STATUS " ${COMPONENT}") - endif() - list(APPEND Boost_LIBRARIES ${Boost_${UPPERCOMPONENT}_LIBRARY}) - endif() - endforeach() - - # Add pthread library on UNIX if thread component was found - _Boost_consider_adding_pthreads(Boost_LIBRARIES ${Boost_LIBRARIES}) -else() - if(Boost_FIND_REQUIRED) - message(SEND_ERROR "Unable to find the requested Boost libraries.\n${Boost_ERROR_REASON}") - else() - if(NOT Boost_FIND_QUIETLY) - # we opt not to automatically output Boost_ERROR_REASON here as - # it could be quite lengthy and somewhat imposing in its requests - # Since Boost is not always a required dependency we'll leave this - # up to the end-user. - if(Boost_DEBUG OR Boost_DETAILED_FAILURE_MSG) - message(STATUS "Could NOT find Boost\n${Boost_ERROR_REASON}") - else() - message(STATUS "Could NOT find Boost") - endif() - endif() - endif() -endif() - -# Configure display of cache entries in GUI. -foreach(v BOOSTROOT BOOST_ROOT ${_Boost_VARS_INC} ${_Boost_VARS_LIB}) - get_property(_type CACHE ${v} PROPERTY TYPE) - if(_type) - set_property(CACHE ${v} PROPERTY ADVANCED 1) - if("x${_type}" STREQUAL "xUNINITIALIZED") - if("x${v}" STREQUAL "xBoost_ADDITIONAL_VERSIONS") - set_property(CACHE ${v} PROPERTY TYPE STRING) - else() - set_property(CACHE ${v} PROPERTY TYPE PATH) - endif() - endif() - endif() -endforeach() - -# Record last used values of input variables so we can -# detect on the next run if the user changed them. -foreach(v - ${_Boost_VARS_INC} ${_Boost_VARS_LIB} - ${_Boost_VARS_DIR} ${_Boost_VARS_NAME} - ) - if(DEFINED ${v}) - set(_${v}_LAST "${${v}}" CACHE INTERNAL "Last used ${v} value.") - else() - unset(_${v}_LAST CACHE) - endif() -endforeach() - -# Maintain a persistent list of components requested anywhere since -# the last flush. -set(_Boost_COMPONENTS_SEARCHED "${_Boost_COMPONENTS_SEARCHED}") -list(APPEND _Boost_COMPONENTS_SEARCHED ${Boost_FIND_COMPONENTS}) -list(REMOVE_DUPLICATES _Boost_COMPONENTS_SEARCHED) -list(SORT _Boost_COMPONENTS_SEARCHED) -set(_Boost_COMPONENTS_SEARCHED "${_Boost_COMPONENTS_SEARCHED}" - CACHE INTERNAL "Components requested for this build tree.") From 7f357e285fecc11c2001e8226f65dd7485f0a163 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 4 Apr 2014 14:56:46 -0400 Subject: [PATCH 24/29] generate DH keys pair per SSU session --- SSU.cpp | 13 ++++++++----- SSU.h | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/SSU.cpp b/SSU.cpp index 73c42464..a43e04f6 100644 --- a/SSU.cpp +++ b/SSU.cpp @@ -6,6 +6,7 @@ #include "Log.h" #include "Timestamp.h" #include "RouterContext.h" +#include "Transports.h" #include "hmac.h" #include "SSU.h" @@ -18,17 +19,19 @@ namespace ssu const i2p::data::RouterInfo * router): m_Server (server), m_RemoteEndpoint (remoteEndpoint), m_RemoteRouter (router), m_Timer (m_Server.GetService ()), m_State (eSessionStateUnknown) { + m_DHKeysPair = i2p::transports.GetNextDHKeysPair (); } SSUSession::~SSUSession () { + delete m_DHKeysPair; } void SSUSession::CreateAESandMacKey (uint8_t * pubKey, uint8_t * aesKey, uint8_t * macKey) { CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg); CryptoPP::SecByteBlock secretKey(dh.AgreedValueLength()); - if (!dh.Agree (secretKey, i2p::context.GetPrivateKey (), pubKey)) + if (!dh.Agree (secretKey, m_DHKeysPair->privateKey, pubKey)) { LogPrint ("Couldn't create shared key"); return; @@ -167,7 +170,7 @@ namespace ssu uint8_t signedData[532]; // x,y, our IP, our port, remote IP, remote port, relayTag, signed on time uint8_t * payload = buf + sizeof (SSUHeader); uint8_t * y = payload; - memcpy (signedData, i2p::context.GetRouterIdentity ().publicKey, 256); // x + memcpy (signedData, m_DHKeysPair->publicKey, 256); // x memcpy (signedData + 256, y, 256); // y payload += 256; payload += 1; // size, assume 4 @@ -232,7 +235,7 @@ namespace ssu uint8_t buf[304 + 18]; // 304 bytes for ipv4 (320 for ipv6) uint8_t * payload = buf + sizeof (SSUHeader); - memcpy (payload, i2p::context.GetRouterIdentity ().publicKey, 256); + memcpy (payload, m_DHKeysPair->publicKey, 256); // x payload[256] = 4; // we assume ipv4 *(uint32_t *)(payload + 257) = htobe32 (m_RemoteEndpoint.address ().to_v4 ().to_ulong ()); @@ -290,7 +293,7 @@ namespace ssu uint8_t buf[368 + 18]; uint8_t * payload = buf + sizeof (SSUHeader); - memcpy (payload, i2p::context.GetRouterIdentity ().publicKey, 256); + memcpy (payload, m_DHKeysPair->publicKey, 256); memcpy (signedData + 256, payload, 256); // y payload += 256; *payload = 4; // we assume ipv4 @@ -344,7 +347,7 @@ namespace ssu // signature uint8_t signedData[532]; // x,y, our IP, our port, remote IP, remote port, relayTag, our signed on time - memcpy (signedData, i2p::context.GetRouterIdentity ().publicKey, 256); // x + memcpy (signedData, m_DHKeysPair->publicKey, 256); // x memcpy (signedData + 256, y, 256); // y memcpy (signedData + 512, ourAddress, 6); // our address/port as seem by party *(uint32_t *)(signedData + 518) = htobe32 (m_RemoteEndpoint.address ().to_v4 ().to_ulong ()); // remote IP diff --git a/SSU.h b/SSU.h index 40c377c6..e528d30b 100644 --- a/SSU.h +++ b/SSU.h @@ -8,6 +8,7 @@ #include #include #include "I2PEndian.h" +#include "Identity.h" #include "RouterInfo.h" #include "I2NPProtocol.h" @@ -113,6 +114,7 @@ namespace ssu boost::asio::ip::udp::endpoint m_RemoteEndpoint; const i2p::data::RouterInfo * m_RemoteRouter; boost::asio::deadline_timer m_Timer; + i2p::data::DHKeysPair * m_DHKeysPair; // X - for client and Y - for server SessionState m_State; CryptoPP::CBC_Mode::Encryption m_Encryption; CryptoPP::CBC_Mode::Decryption m_Decryption; From 93ff88bcb8512a1273f5382282b5c2229f226b81 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 4 Apr 2014 16:29:40 -0400 Subject: [PATCH 25/29] DH keys supplier --- Transports.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++++---- Transports.h | 31 +++++++++++++++++++++ 2 files changed, 101 insertions(+), 5 deletions(-) diff --git a/Transports.cpp b/Transports.cpp index 48462ae3..6c326e72 100644 --- a/Transports.cpp +++ b/Transports.cpp @@ -9,10 +9,76 @@ using namespace i2p::data; namespace i2p { + DHKeysPairSupplier::~DHKeysPairSupplier () + { + Stop (); + } + + void DHKeysPairSupplier::Start () + { + m_IsRunning = true; + m_Thread = new std::thread (std::bind (&DHKeysPairSupplier::Run, this)); + } + + void DHKeysPairSupplier::Stop () + { + m_IsRunning = false; + m_Acquired.notify_one (); + if (m_Thread) + { + m_Thread->join (); + delete m_Thread; + m_Thread = 0; + } + } + + void DHKeysPairSupplier::Run () + { + while (m_IsRunning) + { + int num; + while ((num = m_QueueSize - m_Queue.size ()) > 0) + CreateDHKeysPairs (num); + std::unique_lock l(m_AcquiredMutex); + m_Acquired.wait (l); // wait for element gets aquired + } + } + + void DHKeysPairSupplier::CreateDHKeysPairs (int num) + { + if (num > 0) + { + for (int i = 0; i < num; i++) + { + i2p::data::DHKeysPair * pair = new i2p::data::DHKeysPair (); + i2p::data::CreateRandomDHKeysPair (pair); + m_Queue.push (pair); + } + } + } + + i2p::data::DHKeysPair * DHKeysPairSupplier::Acquire () + { + if (!m_Queue.empty ()) + { + auto pair = m_Queue.front (); + m_Queue.pop (); + m_Acquired.notify_one (); + return pair; + } + else // queue is empty, create new + { + i2p::data::DHKeysPair * pair = new i2p::data::DHKeysPair (); + i2p::data::CreateRandomDHKeysPair (pair); + return pair; + } + } + Transports transports; Transports::Transports (): - m_Thread (nullptr), m_Work (m_Service),m_NTCPAcceptor (nullptr), m_SSUServer (nullptr) + m_Thread (nullptr), m_Work (m_Service), m_NTCPAcceptor (nullptr), + m_SSUServer (nullptr), m_DHKeysPairSupplier (5) // 5 pre-generated keys { } @@ -23,6 +89,7 @@ namespace i2p void Transports::Start () { + m_DHKeysPairSupplier.Start (); m_IsRunning = true; m_Thread = new std::thread (std::bind (&Transports::Run, this)); m_Timer = new boost::asio::deadline_timer (m_Service); @@ -74,6 +141,7 @@ namespace i2p delete m_SSUServer; } + m_DHKeysPairSupplier.Stop (); m_IsRunning = false; m_Service.stop (); if (m_Thread) @@ -223,9 +291,6 @@ namespace i2p i2p::data::DHKeysPair * Transports::GetNextDHKeysPair () { - // TODO: use supplier with separate thread - i2p::data::DHKeysPair * pair = new i2p::data::DHKeysPair (); - i2p::data::CreateRandomDHKeysPair (pair); - return pair; + return m_DHKeysPairSupplier.Acquire (); } } diff --git a/Transports.h b/Transports.h index ed75cd60..bcec7690 100644 --- a/Transports.h +++ b/Transports.h @@ -2,8 +2,11 @@ #define TRANSPORTS_H__ #include +#include +#include #include #include +#include #include #include #include "NTCPSession.h" @@ -14,6 +17,32 @@ namespace i2p { + class DHKeysPairSupplier + { + public: + + DHKeysPairSupplier (int size): m_QueueSize (size), m_IsRunning (false), m_Thread (nullptr) {}; + ~DHKeysPairSupplier (); + void Start (); + void Stop (); + i2p::data::DHKeysPair * Acquire (); + + private: + + void Run (); + void CreateDHKeysPairs (int num); + + private: + + int m_QueueSize; + std::queue m_Queue; + + bool m_IsRunning; + std::thread * m_Thread; + std::condition_variable m_Acquired; + std::mutex m_AcquiredMutex; + }; + class Transports { public: @@ -56,6 +85,8 @@ namespace i2p i2p::ssu::SSUServer * m_SSUServer; boost::asio::deadline_timer * m_Timer; + DHKeysPairSupplier m_DHKeysPairSupplier; + public: // for HTTP only From fb2a89cbead019bf3a57c69b330bf3e1c1dd1e01 Mon Sep 17 00:00:00 2001 From: Meeh Date: Sat, 5 Apr 2014 01:52:40 +0200 Subject: [PATCH 26/29] Use paths for verification instead of bool variables in CMake. --- build/CMakeLists.txt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index c4c6d334..5541301f 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -69,19 +69,21 @@ set ( HEADERS source_group ("Header Files" FILES ${HEADERS}) source_group ("Source Files" FILES ${SOURCES}) +set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules" ) + find_package ( Threads REQUIRED ) find_package ( Boost COMPONENTS system filesystem regex program_options REQUIRED ) -find_package(Crypto++ QUIET) +find_package ( CryptoPP REQUIRED ) # Check for libraries -if(!Boost_FOUND) +if(NOT DEFINED Boost_INCLUDE_DIRS) message(FATAL_ERROR "Boost is not found, or your boost version was bellow 1.46. Please download Boost!") return() endif() -if(!CRYPTO++_FOUND) +if(NOT DEFINED CRYPTO++_INCLUDE_DIR) message(FATAL_ERROR "Could not find Crypto++. Please download and install it first!") return() endif() @@ -90,9 +92,6 @@ endif() # End checks -set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules" ) -find_package ( CryptoPP REQUIRED ) - include_directories ( ${Boost_INCLUDE_DIRS} ${CRYPTO++_INCLUDE_DIR}) From ff9f14d7a67b525bd926b13b083990768823577c Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 5 Apr 2014 15:44:12 -0400 Subject: [PATCH 27/29] if NTCP failed, try to send through SSU --- NTCPSession.cpp | 17 +++++++++++++---- Transports.cpp | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/NTCPSession.cpp b/NTCPSession.cpp index 7eb1614a..e21e8d18 100644 --- a/NTCPSession.cpp +++ b/NTCPSession.cpp @@ -56,11 +56,19 @@ namespace ntcp { m_IsEstablished = false; m_Socket.close (); - for (auto it :m_DelayedMessages) - delete it; - m_DelayedMessages.clear (); - // TODO: notify tunnels i2p::transports.RemoveNTCPSession (this); + int numDelayed = 0; + for (auto it :m_DelayedMessages) + { + // try to send them again + i2p::transports.SendMessage (m_RemoteRouterInfo.GetIdentHash (), it); + numDelayed++; + } + m_DelayedMessages.clear (); + if (numDelayed > 0) + LogPrint ("NTCP session ", numDelayed, " not sent"); + // TODO: notify tunnels + delete this; LogPrint ("NTCP session terminated"); } @@ -327,6 +335,7 @@ namespace ntcp if (ecode) { LogPrint ("Phase 4 read error: ", ecode.message ()); + GetRemoteRouterInfo ().SetUnreachable (true); // this router doesn't like us Terminate (); } else diff --git a/Transports.cpp b/Transports.cpp index 6c326e72..10c27afd 100644 --- a/Transports.cpp +++ b/Transports.cpp @@ -239,7 +239,7 @@ namespace i2p // existing session not found. create new // try NTCP first auto address = r->GetNTCPAddress (); - if (address) + if (address && !r->IsUnreachable ()) { auto s = new i2p::ntcp::NTCPClient (m_Service, address->host, address->port, *r); AddNTCPSession (s); From 8d3fcff5c521ea76cccdb102a6125ffb6814bc59 Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 5 Apr 2014 19:51:05 -0400 Subject: [PATCH 28/29] endian.h for different platforms --- I2PEndian.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/I2PEndian.h b/I2PEndian.h index 01ba73e8..661179cb 100644 --- a/I2PEndian.h +++ b/I2PEndian.h @@ -1,8 +1,12 @@ #ifndef I2PENDIAN_H__ #define I2PENDIAN_H__ -#ifndef _WIN32 +#ifdef __linux__ #include +#elif __FreeBSD__ +#include +#elif __MACH__ // Mac OS X +#include #else #include From 1862896532782566db0cb71c7a48ed3e12ee5ef1 Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 5 Apr 2014 21:25:54 -0400 Subject: [PATCH 29/29] request RouterInfo if outdated --- NetDb.cpp | 6 ++++-- Transports.cpp | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/NetDb.cpp b/NetDb.cpp index 1855ac30..553ee52b 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -442,9 +442,11 @@ namespace data if (dest->IsExploratory ()) { - if (!FindRouter (router)) // router with ident not found + auto r = FindRouter (router); + if (!r || i2p::util::GetMillisecondsSinceEpoch () > r->GetTimestamp () + 3600*1000LL) { - LogPrint ("Found new router. Requesting RouterInfo ..."); + // router with ident not found or too old (1 hour) + LogPrint ("Found new/outdated router. Requesting RouterInfo ..."); if (outbound && inbound) { RequestedDestination * d1 = CreateRequestedDestination (router, false, false); diff --git a/Transports.cpp b/Transports.cpp index 10c27afd..9d86d605 100644 --- a/Transports.cpp +++ b/Transports.cpp @@ -239,7 +239,7 @@ namespace i2p // existing session not found. create new // try NTCP first auto address = r->GetNTCPAddress (); - if (address && !r->IsUnreachable ()) + if (address && !r->UsesIntroducer () && !r->IsUnreachable ()) { auto s = new i2p::ntcp::NTCPClient (m_Service, address->host, address->port, *r); AddNTCPSession (s);