From fcddf9843d8ddec82664035947a57a9de246ddb7 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 9 Jan 2014 17:55:53 -0500 Subject: [PATCH 1/5] fixed Linux build --- NetDb.cpp | 2 +- Streaming.cpp | 2 +- Tunnel.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NetDb.cpp b/NetDb.cpp index c5956dd8..870027e7 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -169,7 +169,7 @@ namespace data { for (boost::filesystem::directory_iterator it1 (it->path ()); it1 != end; ++it1) { -#ifdef BOOST_VERSION > 10500 +#if BOOST_VERSION > 10500 RouterInfo * r = new RouterInfo (it1->path().string().c_str ()); #else RouterInfo * r = new RouterInfo(it1->path().c_str()); diff --git a/Streaming.cpp b/Streaming.cpp index 4ca4b49b..79feedeb 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -124,7 +124,7 @@ namespace stream void StreamingDestination::HandleNextPacket (const uint8_t * buf, size_t len) { - uint32_t sendStreamID = *(uint32_t *)(buf); + uint32_t sendStreamID = be32toh (*(uint32_t *)(buf)); auto it = m_Streams.find (sendStreamID); if (it != m_Streams.end ()) it->second->HandleNextPacket (buf, len); diff --git a/Tunnel.cpp b/Tunnel.cpp index 4e43e70d..2a87a939 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -1,5 +1,5 @@ #include "I2PEndian.h" -#include +#include #include #include "RouterContext.h" #include "Log.h" @@ -260,7 +260,7 @@ namespace tunnel void Tunnels::Run () { - boost::this_thread::sleep(boost::posix_time::seconds(1)); // wait for other parts are ready + std::this_thread::sleep_for (std::chrono::seconds(1)); // wait for other parts are ready uint64_t lastTs = 0; while (m_IsRunning) From b02b88627b8f7b0aac7a72fe1d9a1a0141bf89c3 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 9 Jan 2014 21:42:07 -0500 Subject: [PATCH 2/5] implemented delivery type tunnel for garlic --- Garlic.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/Garlic.cpp b/Garlic.cpp index 7a9585a8..1a2b7108 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -312,17 +312,27 @@ namespace garlic LogPrint ("Unexpected I2NP garlic message ", (int)header->typeID); break; } - case eGarlicDeliveryTypeRouter: - LogPrint ("Garlic type router not implemented"); - // TODO: implement - buf += 32; - break; case eGarlicDeliveryTypeTunnel: - LogPrint ("Garlic type tunnel not implemented"); - // TODO: implement + { + LogPrint ("Garlic type tunnel"); + uint32_t gwTunnel = be32toh (*(uint32_t *)buf); buf += 4; + uint8_t * gwHash = buf; + buf += 32; + auto tunnel = i2p::tunnel::tunnels.GetNextOutboundTunnel (); + if (tunnel) // we have send it through an outbound tunnel + { + I2NPMessage * msg = CreateI2NPMessage (buf, len - 36); + tunnel->SendTunnelDataMsg (gwHash, gwTunnel, msg); + } + else + LogPrint ("No outbound tunnels available for garlic clove"); + break; + } + case eGarlicDeliveryTypeRouter: + LogPrint ("Garlic type router not supported"); buf += 32; - break; + break; default: LogPrint ("Unknow garlic delivery type ", (int)deliveryType); } From 991a80428d10370d78dfa8686a2cf24009f79908 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 9 Jan 2014 22:26:30 -0500 Subject: [PATCH 3/5] fixed few small issues --- NTCPSession.cpp | 6 +++--- RouterInfo.h | 2 +- Streaming.cpp | 12 +++++++----- Streaming.h | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/NTCPSession.cpp b/NTCPSession.cpp index 3174e4f5..61e7944f 100644 --- a/NTCPSession.cpp +++ b/NTCPSession.cpp @@ -1,13 +1,13 @@ #include #include #include "I2PEndian.h" -#include #include #include #include #include #include "base64.h" #include "Log.h" +#include "Timestamp.h" #include "CryptoConst.h" #include "I2NPProtocol.h" #include "RouterContext.h" @@ -149,7 +149,7 @@ namespace ntcp memcpy (xy, m_Phase1.pubKey, 256); memcpy (xy + 256, y, 256); CryptoPP::SHA256().CalculateDigest(m_Phase2.encrypted.hxy, xy, 512); - uint32_t tsB = htobe32 (time(0)); + uint32_t tsB = htobe32 (i2p::util::GetSecondsSinceEpoch ()); m_Phase2.encrypted.timestamp = tsB; // TODO: fill filler @@ -217,7 +217,7 @@ namespace ntcp { m_Phase3.size = htons (sizeof (m_Phase3.ident)); memcpy (&m_Phase3.ident, &i2p::context.GetRouterIdentity (), sizeof (m_Phase3.ident)); - uint32_t tsA = htobe32 (time(0)); + uint32_t tsA = htobe32 (i2p::util::GetSecondsSinceEpoch ()); m_Phase3.timestamp = tsA; SignedData s; diff --git a/RouterInfo.h b/RouterInfo.h index ceda10cb..a8d59adf 100644 --- a/RouterInfo.h +++ b/RouterInfo.h @@ -7,7 +7,7 @@ #include #include #include -#include "LeaseSet.h" +#include "Identity.h" namespace i2p { diff --git a/Streaming.cpp b/Streaming.cpp index 79feedeb..fc746ebc 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -24,7 +24,9 @@ namespace stream { const uint8_t * end = buf + len; buf += 4; // sendStreamID - buf += 4; // receiveStreamID + if (!m_SendStreamID) + m_SendStreamID = be32toh (*(uint32_t *)buf); + buf += 4; // receiveStreamID buf += 4; // sequenceNum buf += 4; // ackThrough int nackCount = buf[0]; @@ -150,10 +152,10 @@ namespace stream I2NPMessage * StreamingDestination::GetLeaseSet () { - if (!m_LeaseSet) - m_LeaseSet = CreateLeaseSet (); - else - FillI2NPMessageHeader (m_LeaseSet, eI2NPDatabaseStore); // refresh msgID + if (m_LeaseSet) // temporary always create new LeaseSet + DeleteI2NPMessage (m_LeaseSet); + m_LeaseSet = CreateLeaseSet (); + return m_LeaseSet; } diff --git a/Streaming.h b/Streaming.h index 86aeac31..26e84e3a 100644 --- a/Streaming.h +++ b/Streaming.h @@ -35,7 +35,7 @@ namespace stream uint32_t GetSendStreamID () const { return m_SendStreamID; }; uint32_t GetRecvStreamID () const { return m_RecvStreamID; }; const i2p::data::LeaseSet * GetRemoteLeaseSet () const { return m_RemoteLeaseSet; }; - bool IsEstablished () const { return !m_SendStreamID; }; + bool IsEstablished () const { return m_SendStreamID; }; void HandleNextPacket (const uint8_t * buf, size_t len); size_t Send (uint8_t * buf, size_t len, int timeout); // timeout in seconds From ebc6811e7172d744fd1eb5e7c5a7703ec0503ff0 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 9 Jan 2014 22:51:33 -0500 Subject: [PATCH 4/5] support of multiple incoming garlic sessions --- Garlic.cpp | 18 ++++++++++-------- Garlic.h | 6 ++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Garlic.cpp b/Garlic.cpp index 1a2b7108..1db02493 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -232,14 +232,17 @@ namespace garlic uint32_t length = be32toh (*(uint32_t *)buf); buf += 4; std::string sessionTag((const char *)buf, 32); - if (m_SessionTags.count (sessionTag) > 0) + auto it = m_SessionTags.find (sessionTag); + if (it != m_SessionTags.end ()) { // existing session + std::string sessionKey (it->second); + m_SessionTags.erase (it); // tag might be used only once uint8_t iv[32]; // IV is first 16 bytes CryptoPP::SHA256().CalculateDigest(iv, buf, 32); - m_Decryption.SetKeyWithIV (m_SessionKey, 32, iv); + m_Decryption.SetKeyWithIV ((uint8_t *)sessionKey.c_str (), 32, iv); // tag is mapped to 32 bytes key m_Decryption.ProcessData(buf + 32, buf + 32, length - 32); - HandleAESBlock (buf + 32, length - 32); + HandleAESBlock (buf + 32, length - 32, (uint8_t *)sessionKey.c_str ()); } else { @@ -248,22 +251,21 @@ namespace garlic i2p::crypto::ElGamalDecrypt ( isFromTunnel ? i2p::context.GetLeaseSetPrivateKey () : i2p::context.GetPrivateKey (), buf, (uint8_t *)&elGamal, true); - memcpy (m_SessionKey, elGamal.sessionKey, 32); uint8_t iv[32]; // IV is first 16 bytes CryptoPP::SHA256().CalculateDigest(iv, elGamal.preIV, 32); - m_Decryption.SetKeyWithIV (m_SessionKey, 32, iv); + m_Decryption.SetKeyWithIV (elGamal.sessionKey, 32, iv); m_Decryption.ProcessData(buf + 514, buf + 514, length - 514); - HandleAESBlock (buf + 514, length - 514); + HandleAESBlock (buf + 514, length - 514, elGamal.sessionKey); } } - void GarlicRouting::HandleAESBlock (uint8_t * buf, size_t len) + void GarlicRouting::HandleAESBlock (uint8_t * buf, size_t len, uint8_t * sessionKey) { uint16_t tagCount = be16toh (*(uint16_t *)buf); buf += 2; for (int i = 0; i < tagCount; i++) - m_SessionTags.insert (std::string ((const char *)(buf + i*32), 32)); + m_SessionTags[std::string ((const char *)(buf + i*32), 32)] = std::string ((const char *)sessionKey, 32); buf += tagCount*32; uint32_t payloadSize = be32toh (*(uint32_t *)buf); buf += 4; diff --git a/Garlic.h b/Garlic.h index 81675fa9..89f6bd90 100644 --- a/Garlic.h +++ b/Garlic.h @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -75,7 +74,7 @@ namespace garlic private: - void HandleAESBlock (uint8_t * buf, size_t len); + void HandleAESBlock (uint8_t * buf, size_t len, uint8_t * sessionKey); void HandleGarlicPayload (uint8_t * buf, size_t len); private: @@ -83,8 +82,7 @@ namespace garlic // outgoing sessions std::map m_Sessions; // incoming session - uint8_t m_SessionKey[32]; - std::set m_SessionTags; + std::map m_SessionTags; // tag -> key CryptoPP::CBC_Mode::Decryption m_Decryption; }; From 810ddb267e2af92a7b63be451b355e6b524494fa Mon Sep 17 00:00:00 2001 From: mikhail4021 Date: Fri, 10 Jan 2014 20:35:47 +0400 Subject: [PATCH 5/5] folder structure updated --- .gitignore | 215 ++++++++++++++++++ i2pd.sln => Win32/i2pd.sln | 0 i2pd.vcxproj => Win32/i2pd.vcxproj | 99 ++++---- .../i2pd.vcxproj.filters | 168 +++++++------- 4 files changed, 349 insertions(+), 133 deletions(-) create mode 100644 .gitignore rename i2pd.sln => Win32/i2pd.sln (100%) rename i2pd.vcxproj => Win32/i2pd.vcxproj (65%) rename i2pd.vcxproj.filters => Win32/i2pd.vcxproj.filters (63%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..b9d6bd92 --- /dev/null +++ b/.gitignore @@ -0,0 +1,215 @@ +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml +*.pubxml + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +#packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + +############# +## Windows detritus +############# + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac crap +.DS_Store + + +############# +## Python +############# + +*.py[co] + +# Packages +*.egg +*.egg-info +dist/ +build/ +eggs/ +parts/ +var/ +sdist/ +develop-eggs/ +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg diff --git a/i2pd.sln b/Win32/i2pd.sln similarity index 100% rename from i2pd.sln rename to Win32/i2pd.sln diff --git a/i2pd.vcxproj b/Win32/i2pd.vcxproj similarity index 65% rename from i2pd.vcxproj rename to Win32/i2pd.vcxproj index 2c04ff58..a98c7449 100644 --- a/i2pd.vcxproj +++ b/Win32/i2pd.vcxproj @@ -10,6 +10,54 @@ Win32 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {930568EC-31C9-406A-AD1C-9636DF5D8FAA} i2pd @@ -39,8 +87,9 @@ - $(BOOST);$(CRYPTOPP);$(IncludePath) + ./..;$(BOOST);$(CRYPTOPP);$(IncludePath) $(BOOST)\stage\lib;$(CRYPTOPP)\cryptopp\Win32\Output\$(Configuration)\;$(LibraryPath) + ./..;$(VC_SourcePath); .\boost;.\cryptopp;$(IncludePath) @@ -73,54 +122,6 @@ true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/i2pd.vcxproj.filters b/Win32/i2pd.vcxproj.filters similarity index 63% rename from i2pd.vcxproj.filters rename to Win32/i2pd.vcxproj.filters index 99d5e78f..39abceab 100644 --- a/i2pd.vcxproj.filters +++ b/Win32/i2pd.vcxproj.filters @@ -15,139 +15,139 @@ - + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - \ No newline at end of file