From 55392ce78376979faedd84b7385b37164372f941 Mon Sep 17 00:00:00 2001 From: mikhail4021 Date: Thu, 9 Jan 2014 23:56:07 +0400 Subject: [PATCH 1/2] ms visual studio 2013 support not full support --- Garlic.cpp | 2 +- I2NPProtocol.cpp | 2 +- I2PEndian.cpp | 81 +++++++++++++++ I2PEndian.h | 19 ++++ Identity.h | 4 + LittleBigEndian.h | 242 +++++++++++++++++++++++++++++++++++++++++++ NTCPSession.cpp | 2 +- NetDb.cpp | 8 +- RouterInfo.cpp | 2 +- Streaming.cpp | 2 +- Timestamp.h | 2 +- TransitTunnel.cpp | 2 +- Tunnel.cpp | 13 +-- TunnelEndpoint.cpp | 2 +- TunnelGateway.cpp | 2 +- i2p.cpp | 3 +- i2pd.sln | 22 ++++ i2pd.vcxproj | 127 +++++++++++++++++++++++ i2pd.vcxproj.filters | 153 +++++++++++++++++++++++++++ 19 files changed, 670 insertions(+), 20 deletions(-) create mode 100644 I2PEndian.cpp create mode 100644 I2PEndian.h create mode 100644 LittleBigEndian.h create mode 100644 i2pd.sln create mode 100644 i2pd.vcxproj create mode 100644 i2pd.vcxproj.filters diff --git a/Garlic.cpp b/Garlic.cpp index 50da90a35b0..ecaed829f35 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -1,5 +1,5 @@ #include -#include +#include "I2PEndian.h" #include #include #include "ElGamal.h" diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index 58622fb8293..87fced42aa1 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -1,5 +1,5 @@ #include -#include +#include "I2PEndian.h" #include #include #include diff --git a/I2PEndian.cpp b/I2PEndian.cpp new file mode 100644 index 00000000000..1fccf47fd1f --- /dev/null +++ b/I2PEndian.cpp @@ -0,0 +1,81 @@ +#include "I2PEndian.h" + +// http://habrahabr.ru/post/121811/ +// http://codepad.org/2ycmkz2y + +#include "LittleBigEndian.h" + +uint16_t htobe16(uint16_t int16) +{ + BigEndian u16(int16); + return u16.raw_value; +} + +uint32_t htobe32(uint32_t int32) +{ + BigEndian u32(int32); + return u32.raw_value; +} + +uint64_t htobe64(uint64_t int64) +{ + BigEndian u64(int64); + return u64.raw_value; +} + +uint16_t be16toh(uint16_t big16) +{ + LittleEndian u16(big16); + return u16.raw_value; +} + +uint32_t be32toh(uint32_t big32) +{ + LittleEndian u32(big32); + return u32.raw_value; +} + +uint64_t be64toh(uint64_t big64) +{ + LittleEndian u64(big64); + return u64.raw_value; +} + +/* it can be used in Windows 8 +#include + +uint16_t htobe16(uint16_t int16) +{ + return htons(int16); +} + +uint32_t htobe32(uint32_t int32) +{ + return htonl(int32); +} + +uint64_t htobe64(uint64_t int64) +{ + // http://msdn.microsoft.com/en-us/library/windows/desktop/jj710199%28v=vs.85%29.aspx + //return htonll(int64); + return 0; +} + + +uint16_t be16toh(uint16_t big16) +{ + return ntohs(big16); +} + +uint32_t be32toh(uint32_t big32) +{ + return ntohl(big32); +} + +uint64_t be64toh(uint64_t big64) +{ + // http://msdn.microsoft.com/en-us/library/windows/desktop/jj710199%28v=vs.85%29.aspx + //return ntohll(big64); + return 0; +} +*/ \ No newline at end of file diff --git a/I2PEndian.h b/I2PEndian.h new file mode 100644 index 00000000000..01ba73e89d5 --- /dev/null +++ b/I2PEndian.h @@ -0,0 +1,19 @@ +#ifndef I2PENDIAN_H__ +#define I2PENDIAN_H__ + +#ifndef _WIN32 +#include +#else +#include + +uint16_t htobe16(uint16_t int16); +uint32_t htobe32(uint32_t int32); +uint64_t htobe64(uint64_t int64); + +uint16_t be16toh(uint16_t big16); +uint32_t be32toh(uint32_t big32); +uint64_t be64toh(uint64_t big64); + +#endif + +#endif // I2PENDIAN_H__ \ No newline at end of file diff --git a/Identity.h b/Identity.h index 09af9332e7d..05a317e58b9 100644 --- a/Identity.h +++ b/Identity.h @@ -33,11 +33,15 @@ namespace data IdentHash (const uint8_t * hash) { memcpy (m_Hash, hash, 32); }; IdentHash (const IdentHash& ) = default; +#ifndef _WIN32 // FIXME!!! msvs 2013 can't compile it IdentHash (IdentHash&& ) = default; +#endif IdentHash () = default; IdentHash& operator= (const IdentHash& ) = default; +#ifndef _WIN32 IdentHash& operator= (IdentHash&& ) = default; +#endif uint8_t * operator()() { return m_Hash; }; const uint8_t * operator()() const { return m_Hash; }; diff --git a/LittleBigEndian.h b/LittleBigEndian.h new file mode 100644 index 00000000000..ea879729567 --- /dev/null +++ b/LittleBigEndian.h @@ -0,0 +1,242 @@ +// LittleBigEndian.h fixed for 64-bits added union +// + +#ifndef LITTLEBIGENDIAN_H +#define LITTLEBIGENDIAN_H + +// Determine Little-Endian or Big-Endian + +#define CURRENT_BYTE_ORDER (*(int *)"\x01\x02\x03\x04") +#define LITTLE_ENDIAN_BYTE_ORDER 0x04030201 +#define BIG_ENDIAN_BYTE_ORDER 0x01020304 +#define PDP_ENDIAN_BYTE_ORDER 0x02010403 + +#define IS_LITTLE_ENDIAN (CURRENT_BYTE_ORDER == LITTLE_ENDIAN_BYTE_ORDER) +#define IS_BIG_ENDIAN (CURRENT_BYTE_ORDER == BIG_ENDIAN_BYTE_ORDER) +#define IS_PDP_ENDIAN (CURRENT_BYTE_ORDER == PDP_ENDIAN_BYTE_ORDER) + +// Forward declaration + +template +struct LittleEndian; + +template +struct BigEndian; + +// Little-Endian template + +#pragma pack(push,1) +template +struct LittleEndian +{ + union + { + unsigned char bytes[sizeof(T)]; + T raw_value; + }; + + LittleEndian(T t = T()) + { + operator =(t); + } + + LittleEndian(const LittleEndian & t) + { + raw_value = t.raw_value; + } + + LittleEndian(const BigEndian & t) + { + for (unsigned i = 0; i < sizeof(T); i++) + bytes[i] = t.bytes[sizeof(T)-1-i]; + } + + operator const T() const + { + T t = T(); + for (unsigned i = 0; i < sizeof(T); i++) + t |= T(bytes[i]) << (i << 3); + return t; + } + + const T operator = (const T t) + { + for (unsigned i = 0; i < sizeof(T); i++) + bytes[i] = t >> (i << 3); + return t; + } + + // operators + + const T operator += (const T t) + { + return (*this = *this + t); + } + + const T operator -= (const T t) + { + return (*this = *this - t); + } + + const T operator *= (const T t) + { + return (*this = *this * t); + } + + const T operator /= (const T t) + { + return (*this = *this / t); + } + + const T operator %= (const T t) + { + return (*this = *this % t); + } + + LittleEndian operator ++ (int) + { + LittleEndian tmp(*this); + operator ++ (); + return tmp; + } + + LittleEndian & operator ++ () + { + for (unsigned i = 0; i < sizeof(T); i++) + { + ++bytes[i]; + if (bytes[i] != 0) + break; + } + return (*this); + } + + LittleEndian operator -- (int) + { + LittleEndian tmp(*this); + operator -- (); + return tmp; + } + + LittleEndian & operator -- () + { + for (unsigned i = 0; i < sizeof(T); i++) + { + --bytes[i]; + if (bytes[i] != (T)(-1)) + break; + } + return (*this); + } +}; +#pragma pack(pop) + +// Big-Endian template + +#pragma pack(push,1) +template +struct BigEndian +{ + union + { + unsigned char bytes[sizeof(T)]; + T raw_value; + }; + + BigEndian(T t = T()) + { + operator =(t); + } + + BigEndian(const BigEndian & t) + { + raw_value = t.raw_value; + } + + BigEndian(const LittleEndian & t) + { + for (unsigned i = 0; i < sizeof(T); i++) + bytes[i] = t.bytes[sizeof(T)-1-i]; + } + + operator const T() const + { + T t = T(); + for (unsigned i = 0; i < sizeof(T); i++) + t |= T(bytes[sizeof(T) - 1 - i]) << (i << 3); + return t; + } + + const T operator = (const T t) + { + for (unsigned i = 0; i < sizeof(T); i++) + bytes[sizeof(T) - 1 - i] = t >> (i << 3); + return t; + } + + // operators + + const T operator += (const T t) + { + return (*this = *this + t); + } + + const T operator -= (const T t) + { + return (*this = *this - t); + } + + const T operator *= (const T t) + { + return (*this = *this * t); + } + + const T operator /= (const T t) + { + return (*this = *this / t); + } + + const T operator %= (const T t) + { + return (*this = *this % t); + } + + BigEndian operator ++ (int) + { + BigEndian tmp(*this); + operator ++ (); + return tmp; + } + + BigEndian & operator ++ () + { + for (unsigned i = 0; i < sizeof(T); i++) + { + ++bytes[sizeof(T) - 1 - i]; + if (bytes[sizeof(T) - 1 - i] != 0) + break; + } + return (*this); + } + + BigEndian operator -- (int) + { + BigEndian tmp(*this); + operator -- (); + return tmp; + } + + BigEndian & operator -- () + { + for (unsigned i = 0; i < sizeof(T); i++) + { + --bytes[sizeof(T) - 1 - i]; + if (bytes[sizeof(T) - 1 - i] != (T)(-1)) + break; + } + return (*this); + } +}; +#pragma pack(pop) + +#endif // LITTLEBIGENDIAN_H \ No newline at end of file diff --git a/NTCPSession.cpp b/NTCPSession.cpp index b52a6223532..f8f481006ae 100644 --- a/NTCPSession.cpp +++ b/NTCPSession.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include "I2PEndian.h" #include #include #include diff --git a/NetDb.cpp b/NetDb.cpp index 41440582433..33ad940af14 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -1,4 +1,4 @@ -#include +#include "I2PEndian.h" #include #include #include @@ -78,7 +78,7 @@ namespace data else // if no new DatabaseStore coming, explore it Explore (); - uint32_t ts = i2p::util::GetSecondsSinceEpoch (); + uint64_t ts = i2p::util::GetSecondsSinceEpoch (); if (ts - lastTs >= 60) // save routers every minute { if (lastTs) @@ -142,7 +142,7 @@ namespace data { for (boost::filesystem::directory_iterator it1 (it->path ()); it1 != end; ++it1) { - RouterInfo * r = new RouterInfo (it1->path ().c_str ()); + RouterInfo * r = new RouterInfo (it1->path ().c_str ()); // FIXME!!! path::value_type != char in boost 1_55 on Windows. How to solve? m_RouterInfos[r->GetIdentHash ()] = r; numRouters++; } @@ -222,7 +222,7 @@ namespace data decompressor.Put (buf + offset, size); decompressor.MessageEnd(); uint8_t uncompressed[2048]; - int uncomressedSize = decompressor.MaxRetrievable (); + size_t uncomressedSize = decompressor.MaxRetrievable (); decompressor.Get (uncompressed, uncomressedSize); AddRouterInfo (uncompressed, uncomressedSize); } diff --git a/RouterInfo.cpp b/RouterInfo.cpp index c6666dfd37d..1f3f8feea05 100644 --- a/RouterInfo.cpp +++ b/RouterInfo.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include "I2PEndian.h" #include #include #include diff --git a/Streaming.cpp b/Streaming.cpp index 7a8c18ef4c1..c718c0cf62d 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -1,4 +1,4 @@ -#include +#include "I2PEndian.h" #include #include #include "Log.h" diff --git a/Timestamp.h b/Timestamp.h index f70bb97f1b3..d48cb1642ed 100644 --- a/Timestamp.h +++ b/Timestamp.h @@ -20,7 +20,7 @@ namespace util std::chrono::system_clock::now().time_since_epoch()).count (); } - inline uint32_t GetSecondsSinceEpoch () + inline uint64_t GetSecondsSinceEpoch () { return std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch()).count (); diff --git a/TransitTunnel.cpp b/TransitTunnel.cpp index 5771c38511a..3bb3295af3f 100644 --- a/TransitTunnel.cpp +++ b/TransitTunnel.cpp @@ -1,5 +1,5 @@ #include -#include +#include "I2PEndian.h" #include "Log.h" #include "RouterContext.h" #include "I2NPProtocol.h" diff --git a/Tunnel.cpp b/Tunnel.cpp index f45ba1d43ad..26b4dab3b17 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -1,4 +1,5 @@ -#include +#include "I2PEndian.h" +#include #include #include "RouterContext.h" #include "Log.h" @@ -255,9 +256,9 @@ namespace tunnel void Tunnels::Run () { - sleep (1); // wait for other parts are ready + boost::this_thread::sleep(boost::posix_time::seconds(1)); // wait for other parts are ready - uint32_t lastTs = 0; + uint64_t lastTs = 0; while (m_IsRunning) { try @@ -283,7 +284,7 @@ namespace tunnel msg = m_Queue.Get (); } - uint32_t ts = i2p::util::GetSecondsSinceEpoch (); + uint64_t ts = i2p::util::GetSecondsSinceEpoch (); if (ts - lastTs >= 15) // manage tunnels every 15 seconds { ManageTunnels (); @@ -326,7 +327,7 @@ namespace tunnel void Tunnels::ManageOutboundTunnels () { - uint32_t ts = i2p::util::GetSecondsSinceEpoch (); + uint64_t ts = i2p::util::GetSecondsSinceEpoch (); for (auto it = m_OutboundTunnels.begin (); it != m_OutboundTunnels.end ();) { if (ts > (*it)->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) @@ -366,7 +367,7 @@ namespace tunnel void Tunnels::ManageInboundTunnels () { - uint32_t ts = i2p::util::GetSecondsSinceEpoch (); + uint64_t ts = i2p::util::GetSecondsSinceEpoch (); for (auto it = m_InboundTunnels.begin (); it != m_InboundTunnels.end ();) { if (ts > it->second->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) diff --git a/TunnelEndpoint.cpp b/TunnelEndpoint.cpp index 1d856e4a827..a53be1263a1 100644 --- a/TunnelEndpoint.cpp +++ b/TunnelEndpoint.cpp @@ -1,4 +1,4 @@ -#include +#include "I2PEndian.h" #include #include "Log.h" #include "I2NPProtocol.h" diff --git a/TunnelGateway.cpp b/TunnelGateway.cpp index d70763e6754..7bff2cba736 100644 --- a/TunnelGateway.cpp +++ b/TunnelGateway.cpp @@ -1,5 +1,5 @@ #include -#include +#include "I2PEndian.h" #include #include "Log.h" #include "RouterContext.h" diff --git a/i2p.cpp b/i2p.cpp index 884bdbc91d4..be007d1579a 100644 --- a/i2p.cpp +++ b/i2p.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "Log.h" #include "base64.h" #include "Transports.h" @@ -19,7 +20,7 @@ int main( int, char** ) i2p::transports.Start (); i2p::tunnel::tunnels.Start (); - sleep (1000); + boost::this_thread::sleep(boost::posix_time::seconds(1000)); i2p::tunnel::tunnels.Stop (); i2p::transports.Stop (); i2p::data::netdb.Stop (); diff --git a/i2pd.sln b/i2pd.sln new file mode 100644 index 00000000000..af0c8110748 --- /dev/null +++ b/i2pd.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "i2pd", "i2pd.vcxproj", "{930568EC-31C9-406A-AD1C-9636DF5D8FAA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {930568EC-31C9-406A-AD1C-9636DF5D8FAA}.Debug|Win32.ActiveCfg = Debug|Win32 + {930568EC-31C9-406A-AD1C-9636DF5D8FAA}.Debug|Win32.Build.0 = Debug|Win32 + {930568EC-31C9-406A-AD1C-9636DF5D8FAA}.Release|Win32.ActiveCfg = Release|Win32 + {930568EC-31C9-406A-AD1C-9636DF5D8FAA}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/i2pd.vcxproj b/i2pd.vcxproj new file mode 100644 index 00000000000..2c04ff5888d --- /dev/null +++ b/i2pd.vcxproj @@ -0,0 +1,127 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {930568EC-31C9-406A-AD1C-9636DF5D8FAA} + i2pd + + + + Application + true + v120 + MultiByte + + + Application + false + v120 + true + MultiByte + + + + + + + + + + + + + $(BOOST);$(CRYPTOPP);$(IncludePath) + $(BOOST)\stage\lib;$(CRYPTOPP)\cryptopp\Win32\Output\$(Configuration)\;$(LibraryPath) + + + .\boost;.\cryptopp;$(IncludePath) + .\stage-x86\lib;$(LibraryPath) + + + + Level3 + Disabled + true + MultiThreadedDebugDLL + _MBCS;_WIN32_WINNT=0x0501;%(PreprocessorDefinitions) + + + true + cryptlib.lib;%(AdditionalDependencies) + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/i2pd.vcxproj.filters b/i2pd.vcxproj.filters new file mode 100644 index 00000000000..99d5e78f3d5 --- /dev/null +++ b/i2pd.vcxproj.filters @@ -0,0 +1,153 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 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 From 8185c8048d16e4bc2508cabcf7d340a68da375f4 Mon Sep 17 00:00:00 2001 From: mikhail4021 Date: Thu, 9 Jan 2014 23:59:35 +0400 Subject: [PATCH 2/2] readme updated --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index dc64c4a5d42..ab64cb4d795 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,7 @@ i2pd i2p router for Linux written on C++ Requires gcc 4.6 and higher, boost 1.46 and higher, crypto++ + +on Windows + +Requires msvs2013, boost 1.46 and higher, crypto++