From 02cee0e96ec14742d1a87adf2c9660982bfdb531 Mon Sep 17 00:00:00 2001 From: John Sebastian Peterson Date: Mon, 9 Mar 2015 09:35:16 +0100 Subject: [PATCH 1/9] add winrt detection --- include/libtorrent/config.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 825c4363c..78ec62660 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -275,6 +275,14 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_USE_PREADV 1 #define TORRENT_USE_PWRITEV 1 +// ==== WINRT === +#if defined(WINAPI_FAMILY_PARTITION) +# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) \ + && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +# define TORRENT_WINRT +# endif +#endif + // ==== SOLARIS === #elif defined sun || defined __sun #define TORRENT_SOLARIS From cc8a77b363a6cc9f8309f3f0f4e3b189aeefc82b Mon Sep 17 00:00:00 2001 From: John Sebastian Peterson Date: Tue, 10 Mar 2015 01:26:38 +0100 Subject: [PATCH 2/9] use createsemaphore and waitforsingleobject successor to support winrt --- src/thread.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/thread.cpp b/src/thread.cpp index cd148f20a..18dc1136d 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -105,7 +105,7 @@ namespace libtorrent condition_variable::condition_variable() : m_num_waiters(0) { - m_sem = CreateSemaphore(0, 0, INT_MAX, 0); + m_sem = CreateSemaphoreEx(0, 0, INT_MAX, 0, 0, SEMAPHORE_ALL_ACCESS); } condition_variable::~condition_variable() @@ -118,7 +118,7 @@ namespace libtorrent TORRENT_ASSERT(l.locked()); ++m_num_waiters; l.unlock(); - WaitForSingleObject(m_sem, INFINITE); + WaitForSingleObjectEx(m_sem, INFINITE, FALSE); l.lock(); --m_num_waiters; } @@ -128,7 +128,7 @@ namespace libtorrent TORRENT_ASSERT(l.locked()); ++m_num_waiters; l.unlock(); - WaitForSingleObject(m_sem, total_milliseconds(rel_time)); + WaitForSingleObjectEx(m_sem, total_milliseconds(rel_time), FALSE); l.lock(); --m_num_waiters; } From 2bbb238b4b0b54b3aec4d6dbb9d978466ae792eb Mon Sep 17 00:00:00 2001 From: John Sebastian Peterson Date: Mon, 9 Mar 2015 23:39:30 +0100 Subject: [PATCH 3/9] use getfileattributes successor to support winrt --- src/create_torrent.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/create_torrent.cpp b/src/create_torrent.cpp index e069b231d..327a3e3a9 100644 --- a/src/create_torrent.cpp +++ b/src/create_torrent.cpp @@ -65,16 +65,16 @@ namespace libtorrent int get_file_attributes(std::string const& p) { #ifdef TORRENT_WINDOWS - + WIN32_FILE_ATTRIBUTE_DATA attr; #if TORRENT_USE_WSTRING std::wstring path = convert_to_wstring(p); - DWORD attr = GetFileAttributesW(path.c_str()); + GetFileAttributesExW(path.c_str(), GetFileExInfoStandard, &attr); #else std::string path = convert_to_native(p); - DWORD attr = GetFileAttributesA(path.c_str()); + GetFileAttributesExA(path.c_str(), GetFileExInfoStandard, &attr); #endif // TORRENT_USE_WSTRING - if (attr == INVALID_FILE_ATTRIBUTES) return 0; - if (attr & FILE_ATTRIBUTE_HIDDEN) return file_storage::attribute_hidden; + if (attr.dwFileAttributes == INVALID_FILE_ATTRIBUTES) return 0; + if (attr.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) return file_storage::attribute_hidden; return 0; #else struct stat s; From 43c1de33b4a4e562168c8fc27ca6d39573f53075 Mon Sep 17 00:00:00 2001 From: John Sebastian Peterson Date: Tue, 10 Mar 2015 02:23:30 +0100 Subject: [PATCH 4/9] use cryptgenrandom successor in winrt --- ed25519/src/seed.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ed25519/src/seed.cpp b/ed25519/src/seed.cpp index 63da924c0..e6478a293 100644 --- a/ed25519/src/seed.cpp +++ b/ed25519/src/seed.cpp @@ -3,11 +3,18 @@ #include #include +#include "libtorrent/config.hpp" #include "libtorrent/ed25519.hpp" #ifndef ED25519_NO_SEED -#ifdef _WIN32 +#ifdef TORRENT_WINRT +#include +#include +using namespace Windows::Security::Cryptography; +using namespace Windows::Storage::Streams; +using namespace Microsoft::WRL; +#elif defined _WIN32 #include #include #else @@ -15,7 +22,12 @@ #endif void ed25519_create_seed(unsigned char *seed) { -#ifdef _WIN32 +#ifdef TORRENT_WINRT + IBuffer^ seedBuffer = CryptographicBuffer::GenerateRandom(32); + ComPtr bufferByteAccess; + reinterpret_cast(seedBuffer)->QueryInterface(IID_PPV_ARGS(&bufferByteAccess)); + bufferByteAccess->Buffer(&seed); +#elif defined _WIN32 HCRYPTPROV prov; if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { From 7f160e42a5b4ecfe8af5c131d98c9c787bd78def Mon Sep 17 00:00:00 2001 From: John Sebastian Peterson Date: Mon, 9 Mar 2015 23:29:22 +0100 Subject: [PATCH 5/9] fix c++/cx interface name conflict in alerts --- include/libtorrent/alert_types.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 17dc08494..33bce2873 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -56,6 +56,9 @@ POSSIBILITY OF SUCH DAMAGE. #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif +// c++/cx keyword +#undef interface + namespace libtorrent { From e7caa2d20f6e0746140232198ca1207a80c65b1e Mon Sep 17 00:00:00 2001 From: John Sebastian Peterson Date: Tue, 10 Mar 2015 03:14:52 +0100 Subject: [PATCH 6/9] fix winrt compile error in windows.foundation.collections.h(428) --- src/kademlia/dht_tracker.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/kademlia/dht_tracker.cpp b/src/kademlia/dht_tracker.cpp index 0ff731759..61081564c 100644 --- a/src/kademlia/dht_tracker.cpp +++ b/src/kademlia/dht_tracker.cpp @@ -63,7 +63,6 @@ using libtorrent::dht::node; using libtorrent::dht::node_id; using libtorrent::dht::packet_t; using libtorrent::dht::msg; -using namespace libtorrent::detail; enum { @@ -393,7 +392,7 @@ namespace libtorrent { namespace dht entry* n = (entry*)userdata; std::string node; std::back_insert_iterator out(node); - write_endpoint(e.ep(), out); + libtorrent::detail::write_endpoint(e.ep(), out); n->list().push_back(entry(node)); } @@ -412,7 +411,7 @@ namespace libtorrent { namespace dht { std::string node; std::back_insert_iterator out(node); - write_endpoint(i->ep(), out); + libtorrent::detail::write_endpoint(i->ep(), out); nodes.list().push_back(entry(node)); } if (!nodes.list().empty()) From 30142e35ac2634f8f46803ba9ebdc0d8b7c6d323 Mon Sep 17 00:00:00 2001 From: John Sebastian Peterson Date: Sat, 4 Jul 2015 01:42:33 +0200 Subject: [PATCH 7/9] conform crypt api detection to coding standard --- ed25519/src/seed.cpp | 4 ++-- include/libtorrent/config.hpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ed25519/src/seed.cpp b/ed25519/src/seed.cpp index e6478a293..63244cbbd 100644 --- a/ed25519/src/seed.cpp +++ b/ed25519/src/seed.cpp @@ -8,7 +8,7 @@ #ifndef ED25519_NO_SEED -#ifdef TORRENT_WINRT +#if TORRENT_USE_CRYPTOGRAPHIC_BUFFER #include #include using namespace Windows::Security::Cryptography; @@ -22,7 +22,7 @@ using namespace Microsoft::WRL; #endif void ed25519_create_seed(unsigned char *seed) { -#ifdef TORRENT_WINRT +#if TORRENT_USE_CRYPTOGRAPHIC_BUFFER IBuffer^ seedBuffer = CryptographicBuffer::GenerateRandom(32); ComPtr bufferByteAccess; reinterpret_cast(seedBuffer)->QueryInterface(IID_PPV_ARGS(&bufferByteAccess)); diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 78ec62660..d59c6192b 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -280,6 +280,7 @@ POSSIBILITY OF SUCH DAMAGE. # if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) \ && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) # define TORRENT_WINRT +# define TORRENT_USE_CRYPTOGRAPHIC_BUFFER 1 # endif #endif From bb25acd6612351e3beb35580a6e9fe13c4351b5f Mon Sep 17 00:00:00 2001 From: John Sebastian Peterson Date: Sat, 4 Jul 2015 04:33:17 +0200 Subject: [PATCH 8/9] use a better windows.foundation.collections.h(462) conflict fix --- src/kademlia/dht_tracker.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/kademlia/dht_tracker.cpp b/src/kademlia/dht_tracker.cpp index 61081564c..30772d4bb 100644 --- a/src/kademlia/dht_tracker.cpp +++ b/src/kademlia/dht_tracker.cpp @@ -63,6 +63,7 @@ using libtorrent::dht::node; using libtorrent::dht::node_id; using libtorrent::dht::packet_t; using libtorrent::dht::msg; +using libtorrent::detail::write_endpoint; enum { @@ -392,7 +393,7 @@ namespace libtorrent { namespace dht entry* n = (entry*)userdata; std::string node; std::back_insert_iterator out(node); - libtorrent::detail::write_endpoint(e.ep(), out); + write_endpoint(e.ep(), out); n->list().push_back(entry(node)); } @@ -411,7 +412,7 @@ namespace libtorrent { namespace dht { std::string node; std::back_insert_iterator out(node); - libtorrent::detail::write_endpoint(i->ep(), out); + write_endpoint(i->ep(), out); nodes.list().push_back(entry(node)); } if (!nodes.list().empty()) From cc67c60938e5beb3d24ec5513b6e334051fc6b53 Mon Sep 17 00:00:00 2001 From: John Sebastian Peterson Date: Sat, 4 Jul 2015 05:57:04 +0200 Subject: [PATCH 9/9] hide cx keyword from winrt instead of a hacky undef that break the keyword --- include/libtorrent/alert_types.hpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 33bce2873..eb2499489 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -56,9 +56,6 @@ POSSIBILITY OF SUCH DAMAGE. #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif -// c++/cx keyword -#undef interface - namespace libtorrent { @@ -1282,7 +1279,7 @@ namespace libtorrent virtual std::string message() const; TORRENT_NOT_DISCARDABLE -#ifndef TORRENT_NO_DEPRECATE +#if !defined(TORRENT_NO_DEPRECATE) && !defined(TORRENT_WINRT) // the interface libtorrent attempted to listen on std::string interface; #endif