From e201dec90727e4bbb1d7c2d5cc916f7abfdb4d25 Mon Sep 17 00:00:00 2001 From: Emil Axelsson Date: Mon, 6 Nov 2017 19:07:52 +0100 Subject: [PATCH] Start work on TorrentSynchronization --- .gitmodules | 4 +- apps/Launcher/CMakeLists.txt | 21 +--- apps/Launcher/syncwidget.cpp | 10 +- assets/missions/newhorizons/spice/spice.asset | 8 ++ assets/newhorizons.asset | 2 + include/openspace/scene/asset.h | 1 - include/openspace/scene/assetloader.h | 9 +- include/openspace/scripting/scriptscheduler.h | 2 +- .../openspace/util/resourcesynchronization.h | 9 +- modules/sync/CMakeLists.txt | 30 +++++- .../Launcher => modules/sync}/ext/libtorrent | 0 modules/sync/syncmodule.cpp | 51 +++++++-- modules/sync/syncmodule.h | 17 ++- modules/sync/syncs/httpsynchronization.cpp | 19 +++- modules/sync/syncs/httpsynchronization.h | 2 + modules/sync/syncs/torrentsynchronization.cpp | 71 ++++++++++++ modules/sync/syncs/torrentsynchronization.h | 24 +++++ modules/sync/torrentclient.cpp | 101 ++++++++++++++++++ modules/sync/torrentclient.h | 55 ++++++++++ src/engine/openspaceengine.cpp | 16 +-- src/scene/asset.cpp | 13 --- src/scene/assetloader.cpp | 9 +- src/util/resourcesynchronization.cpp | 11 +- 23 files changed, 377 insertions(+), 108 deletions(-) create mode 100644 assets/missions/newhorizons/spice/spice.asset create mode 100644 assets/newhorizons.asset rename {apps/Launcher => modules/sync}/ext/libtorrent (100%) create mode 100644 modules/sync/torrentclient.cpp create mode 100644 modules/sync/torrentclient.h diff --git a/.gitmodules b/.gitmodules index dab3c8a7c5..8d23c60cda 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,6 +13,6 @@ [submodule "modules/touch/ext/libTUIO11"] path = modules/touch/ext/libTUIO11 url = https://github.com/mkalten/TUIO11_CPP -[submodule "apps/Launcher/ext/libtorrent"] - path = apps/Launcher/ext/libtorrent +[submodule "modules/sync/ext/libtorrent"] + path = modules/sync/ext/libtorrent url = https://github.com/OpenSpace/libtorrent.git diff --git a/apps/Launcher/CMakeLists.txt b/apps/Launcher/CMakeLists.txt index a103345d17..84c062f2d2 100644 --- a/apps/Launcher/CMakeLists.txt +++ b/apps/Launcher/CMakeLists.txt @@ -60,23 +60,4 @@ target_link_libraries( libOpenSpace Qt5::Widgets Qt5::Network -) - -##### -# Libtorrent -##### -set(Boost_USE_STATIC_LIBS ON) -set(Boost_USE_MULTITHREADED ON) -SET(LIBTORRENT_encryption OFF CACHE BOOL "Use OpenSSL Encryption" FORCE) -SET(LIBTORRENT_shared OFF CACHE BOOL "Use Libtorrent as shared library" FORCE) - -include_external_library( - Launcher - torrent-rasterbar - ${CMAKE_CURRENT_SOURCE_DIR}/ext/libtorrent -) -target_include_directories( - Launcher - SYSTEM PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/ext/libtorrent/include -) +) \ No newline at end of file diff --git a/apps/Launcher/syncwidget.cpp b/apps/Launcher/syncwidget.cpp index b58511ea23..9c0bf60abf 100644 --- a/apps/Launcher/syncwidget.cpp +++ b/apps/Launcher/syncwidget.cpp @@ -51,11 +51,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include diff --git a/assets/missions/newhorizons/spice/spice.asset b/assets/missions/newhorizons/spice/spice.asset new file mode 100644 index 0000000000..60eb057390 --- /dev/null +++ b/assets/missions/newhorizons/spice/spice.asset @@ -0,0 +1,8 @@ +--local assetHelper = asset.import('assethelper') + +local kernelsPath = asset.syncedResource({ + Type = "TorrentSynchronization", + TorrentFile = asset.localResource("new_horizons_kernels.torrent") +}) + +--AssetHelper.registerSpiceKernels(asset, kernels) \ No newline at end of file diff --git a/assets/newhorizons.asset b/assets/newhorizons.asset new file mode 100644 index 0000000000..bb536d3d08 --- /dev/null +++ b/assets/newhorizons.asset @@ -0,0 +1,2 @@ +asset.import('solarsystem') +asset.import('missions/newhorizons/spice/spice') \ No newline at end of file diff --git a/include/openspace/scene/asset.h b/include/openspace/scene/asset.h index 94da0d425c..d4e8d48ba2 100644 --- a/include/openspace/scene/asset.h +++ b/include/openspace/scene/asset.h @@ -65,7 +65,6 @@ public: std::string assetDirectory() const; std::string assetName() const; AssetLoader* loader() const; - std::string syncDirectory() const; ReadyState readyState() const; void addSynchronization(std::shared_ptr synchronization); diff --git a/include/openspace/scene/assetloader.h b/include/openspace/scene/assetloader.h index e9af168fc0..41aea6eb5e 100644 --- a/include/openspace/scene/assetloader.h +++ b/include/openspace/scene/assetloader.h @@ -63,8 +63,7 @@ public: */ AssetLoader( ghoul::lua::LuaState& luaState, - std::string assetRoot, - ResourceSynchronizationOptions syncOptions + std::string assetRoot ); /** @@ -121,11 +120,6 @@ public: */ std::shared_ptr rootAsset() const; - /** - * Return the sync root directory - */ - const std::string& syncRootDirectory(); - /** * Return the asset root directory */ @@ -178,7 +172,6 @@ private: AssetSynchronizer* _assetSynchronizer; std::string _assetRootDirectory; - ResourceSynchronizationOptions _synchronizationOptions; ghoul::lua::LuaState* _luaState; // References to lua values diff --git a/include/openspace/scripting/scriptscheduler.h b/include/openspace/scripting/scriptscheduler.h index 5db048fa85..6dc00bab10 100644 --- a/include/openspace/scripting/scriptscheduler.h +++ b/include/openspace/scripting/scriptscheduler.h @@ -117,7 +117,7 @@ private: std::vector _backwardScripts; int _currentIndex = 0; - double _currentTime; + double _currentTime = 0; }; diff --git a/include/openspace/util/resourcesynchronization.h b/include/openspace/util/resourcesynchronization.h index f17c0b6b61..09a03b55dd 100644 --- a/include/openspace/util/resourcesynchronization.h +++ b/include/openspace/util/resourcesynchronization.h @@ -34,10 +34,7 @@ namespace openspace { -struct ResourceSynchronizationOptions { - std::vector httpSynchronizationRepositories; - std::string synchronizationRoot; -}; +class TorrentClient; class ResourceSynchronization; @@ -67,15 +64,13 @@ public: virtual void synchronize() = 0; virtual std::string directory() = 0; - void setSynchronizationOptions(ResourceSynchronizationOptions opt); void wait(); bool isResolved(); void resolve(); float progress(); void updateProgress(float t); std::shared_ptr job(); -protected: - ResourceSynchronizationOptions _synchronizationOptions; + private: std::shared_ptr _job; std::atomic _started; diff --git a/modules/sync/CMakeLists.txt b/modules/sync/CMakeLists.txt index ae617ec6b9..2b3a3a413d 100644 --- a/modules/sync/CMakeLists.txt +++ b/modules/sync/CMakeLists.txt @@ -25,16 +25,18 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake) set(HEADER_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/syncmodule.h + ${CMAKE_CURRENT_SOURCE_DIR}/torrentclient.h ${CMAKE_CURRENT_SOURCE_DIR}/syncs/httpsynchronization.h - # ${CMAKE_CURRENT_SOURCE_DIR}/syncs/resourcesynchronization.h - # ${CMAKE_CURRENT_SOURCE_DIR}/syncs/torrentsynchronization.h + ${CMAKE_CURRENT_SOURCE_DIR}/syncs/torrentsynchronization.h ) source_group("Header Files" FILES ${HEADER_FILES}) set(SOURCE_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/syncmodule.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/torrentclient.cpp ${CMAKE_CURRENT_SOURCE_DIR}/syncs/httpsynchronization.cpp - # ${CMAKE_CURRENT_SOURCE_DIR}/syncs/resourcesynchronization.cpp - # ${CMAKE_CURRENT_SOURCE_DIR}/syncs/torrentsynchronization.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/syncs/torrentsynchronization.cpp ) source_group("Source Files" FILES ${SOURCE_FILES}) @@ -54,3 +56,23 @@ create_new_module( sync_module ${HEADER_FILES} ${SOURCE_FILES} ) + +##### +# Libtorrent +##### +set(Boost_USE_STATIC_LIBS ON) +set(Boost_USE_MULTITHREADED ON) +SET(LIBTORRENT_encryption OFF CACHE BOOL "Use OpenSSL Encryption" FORCE) +SET(LIBTORRENT_shared OFF CACHE BOOL "Use Libtorrent as shared library" FORCE) + +include_external_library( + ${sync_module} + torrent-rasterbar + ${CMAKE_CURRENT_SOURCE_DIR}/ext/libtorrent +) +target_include_directories( + ${sync_module} + SYSTEM PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/ext/libtorrent/include +) + diff --git a/apps/Launcher/ext/libtorrent b/modules/sync/ext/libtorrent similarity index 100% rename from apps/Launcher/ext/libtorrent rename to modules/sync/ext/libtorrent diff --git a/modules/sync/syncmodule.cpp b/modules/sync/syncmodule.cpp index 1fde400c18..d328f963c4 100644 --- a/modules/sync/syncmodule.cpp +++ b/modules/sync/syncmodule.cpp @@ -24,18 +24,20 @@ #include +#include +#include + +#include +#include #include #include #include #include - -#include - #include -#include -//#include -//#include +#include +#include +#include namespace openspace { @@ -48,14 +50,45 @@ void SyncModule::internalInitialize() { ghoul_assert(fSynchronization, "ResourceSynchronization factory was not created"); fSynchronization->registerClass("HttpSynchronization"); + fSynchronization->registerClass("TorrentSynchronization"); + + _synchronizationRoot = FileSys.absPath("${SYNC}"); + _torrentClient.initialize(); + + if (!OsEng.configurationManager().hasKey( + ConfigurationManager::KeyHttpSynchronizationRepositories)) + { + return; + } + + ghoul::Dictionary dictionary = OsEng.configurationManager().value( + ConfigurationManager::KeyHttpSynchronizationRepositories + ); + for (std::string key : dictionary.keys()) { + _httpSynchronizationRepositories.push_back( + dictionary.value(key) + ); + } } std::vector SyncModule::documentations() const { return { - HttpSynchronization::Documentation() - //ResourceSynchronization::Documentation(), - //TorrentSynchronization::Documentation() + HttpSynchronization::Documentation(), + TorrentSynchronization::Documentation() }; } +std::string SyncModule::synchronizationRoot() const +{ + return _synchronizationRoot; +} + +std::vector SyncModule::httpSynchronizationRepositories() const { + return _httpSynchronizationRepositories; +} + +TorrentClient* SyncModule::torrentClient() { + return &_torrentClient; +} + } // namespace openspace diff --git a/modules/sync/syncmodule.h b/modules/sync/syncmodule.h index 1e98290b96..5466a4df86 100644 --- a/modules/sync/syncmodule.h +++ b/modules/sync/syncmodule.h @@ -22,25 +22,32 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef __OPENSPACE_MODULE_SPACE___SYNCMODULE___H__ -#define __OPENSPACE_MODULE_SPACE___SYNCMODULE___H__ +#ifndef __OPENSPACE_MODULE_SYNC___SYNCMODULE___H__ +#define __OPENSPACE_MODULE_SYNC___SYNCMODULE___H__ #include +#include + namespace openspace { class SyncModule : public OpenSpaceModule { public: constexpr static const char* Name = "Sync"; - SyncModule(); virtual ~SyncModule() = default; std::vector documentations() const override; - + std::string synchronizationRoot() const; + std::vector httpSynchronizationRepositories() const; + TorrentClient* torrentClient(); protected: void internalInitialize() override; +private: + TorrentClient _torrentClient; + std::vector _httpSynchronizationRepositories; + std::string _synchronizationRoot; }; } // namespace openspace -#endif // __OPENSPACE_MODULE_SPACE___SYNCMODULE___H__ \ No newline at end of file +#endif // __OPENSPACE_MODULE_SYNC___SYNCMODULE___H__ diff --git a/modules/sync/syncs/httpsynchronization.cpp b/modules/sync/syncs/httpsynchronization.cpp index 6be8ac4e5c..539ef6c8aa 100644 --- a/modules/sync/syncs/httpsynchronization.cpp +++ b/modules/sync/syncs/httpsynchronization.cpp @@ -24,7 +24,12 @@ #include "httpsynchronization.h" +#include + +#include +#include #include + #include #include #include @@ -56,6 +61,13 @@ HttpSynchronization::HttpSynchronization(const ghoul::Dictionary& dict) _identifier = dict.value(KeyIdentifier); _version = static_cast(dict.value(KeyVersion)); + + // Configure synchronization based on global settings in SyncModule + // TODO: For testability and decreaing deps, make it possible to inject this instead. + // For example, allow this configuration to be done by the TemplateFactory. + const SyncModule* syncModule = OsEng.moduleEngine().module(); + _synchronizationRoot = syncModule->synchronizationRoot(); + _synchronizationRepositories = syncModule->httpSynchronizationRepositories(); } documentation::Documentation HttpSynchronization::Documentation() { @@ -82,7 +94,7 @@ documentation::Documentation HttpSynchronization::Documentation() { std::string HttpSynchronization::directory() { ghoul::filesystem::Directory d( - _synchronizationOptions.synchronizationRoot + + _synchronizationRoot + ghoul::filesystem::FileSystem::PathSeparator + "http" + ghoul::filesystem::FileSystem::PathSeparator + @@ -115,7 +127,7 @@ std::vector HttpSynchronization::fileListUrls() { "&" + QueryKeyApplicationVersion + "=" + std::to_string(ApplicationVersion); std::vector urls; - for (const auto& repoUrl : _synchronizationOptions.httpSynchronizationRepositories) { + for (const auto& repoUrl : _synchronizationRepositories) { urls.push_back(repoUrl + query); } @@ -141,7 +153,8 @@ bool HttpSynchronization::trySyncFromUrl(std::string listUrl) { std::vector downloadThreads; std::string line = ""; while (fileList >> line) { - std::string filename = ghoul::filesystem::File(line, ghoul::filesystem::File::RawPath::Yes).filename(); + size_t lastSlash = line.find_last_of('/'); + std::string filename = line.substr(lastSlash + 1); std::string fileDestination = directory() + ghoul::filesystem::FileSystem::PathSeparator + diff --git a/modules/sync/syncs/httpsynchronization.h b/modules/sync/syncs/httpsynchronization.h index 9bc269a767..d58c3ae0c9 100644 --- a/modules/sync/syncs/httpsynchronization.h +++ b/modules/sync/syncs/httpsynchronization.h @@ -50,6 +50,8 @@ private: std::string _identifier; int _version; + std::string _synchronizationRoot; + std::vector _synchronizationRepositories; }; } // namespace openspace diff --git a/modules/sync/syncs/torrentsynchronization.cpp b/modules/sync/syncs/torrentsynchronization.cpp index f6a4cabf01..570f59bef0 100644 --- a/modules/sync/syncs/torrentsynchronization.cpp +++ b/modules/sync/syncs/torrentsynchronization.cpp @@ -24,8 +24,79 @@ #include "torrentsynchronization.h" +#include + +#include +#include +#include + + +#include +#include + + +namespace { + const char* _loggerCat = "TorrentSynchronization"; + + const char* KeyTorrentFile = "TorrentFile"; +} + namespace openspace { +TorrentSynchronization::TorrentSynchronization(const ghoul::Dictionary& dict) + : openspace::ResourceSynchronization() +{ + documentation::testSpecificationAndThrow( + Documentation(), + dict, + "TorrentSynchroniztion" + ); + _torrentFilePath = dict.value(KeyTorrentFile); + + // Configure synchronization based on global settings in SyncModule + // TODO: For testability and decreaing deps, make it possible to inject this instead. + // For example, allow this configuration to be done by the TemplateFactory. + SyncModule* syncModule = OsEng.moduleEngine().module(); + _synchronizationRoot = syncModule->synchronizationRoot(); + _torrentClient = syncModule->torrentClient(); +} + +documentation::Documentation TorrentSynchronization::Documentation() { + using namespace openspace::documentation; + return { + "TorrentSynchronization", + "torrent_synchronization", + { + { + KeyTorrentFile, + new StringVerifier, + Optional::No, + "An absolute path to a torrent file" + }, + } + }; +} + +std::string TorrentSynchronization::directory() { + ghoul::filesystem::Directory d( + _synchronizationRoot + + ghoul::filesystem::FileSystem::PathSeparator + + "torrent" + + ghoul::filesystem::FileSystem::PathSeparator + + "test" + ); + + return FileSys.absPath(d); +} + +void TorrentSynchronization::synchronize() { + _torrentClient->addTorrent(_torrentFilePath, directory()); + + + + resolve(); + return; +} } // namespace openspace diff --git a/modules/sync/syncs/torrentsynchronization.h b/modules/sync/syncs/torrentsynchronization.h index 12d88fbc1e..f37555e6a7 100644 --- a/modules/sync/syncs/torrentsynchronization.h +++ b/modules/sync/syncs/torrentsynchronization.h @@ -25,9 +25,33 @@ #ifndef __OPENSPACE_MODULE_SYNC___TORRENTSYNCHRONIZATION___H__ #define __OPENSPACE_MODULE_SYNC___TORRENTSYNCHRONIZATION___H__ +#include +#include + +#include + +namespace libtorrent { + class session; + struct torrent_handle; +} + namespace openspace { +class TorrentSynchronizationJob; +class TorrentSynchronization : public ResourceSynchronization { +public: + TorrentSynchronization(const ghoul::Dictionary& dict); + static documentation::Documentation Documentation(); + + std::string directory() override; + void synchronize() override; + +private: + std::string _torrentFilePath; + std::string _synchronizationRoot; + TorrentClient* _torrentClient; +}; } // namespace openspace diff --git a/modules/sync/torrentclient.cpp b/modules/sync/torrentclient.cpp new file mode 100644 index 0000000000..f4e101869b --- /dev/null +++ b/modules/sync/torrentclient.cpp @@ -0,0 +1,101 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2017 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include "torrentclient.h" + +#include +#include +#include +#include +#include + +#include + +#include + +namespace { + const char* _loggerCat = "TorrentClient"; +} + +namespace openspace { + +TorrentClient::TorrentClient() {} + +TorrentClient::~TorrentClient() {} + +void TorrentClient::initialize() { + libtorrent::settings_pack settings; + + _session = std::make_unique(); + + settings.set_str(libtorrent::settings_pack::user_agent, "OpenSpace/" + + std::to_string(openspace::OPENSPACE_VERSION_MAJOR) + "." + + std::to_string(openspace::OPENSPACE_VERSION_MINOR) + "." + + std::to_string(openspace::OPENSPACE_VERSION_PATCH)); + + settings.set_bool(libtorrent::settings_pack::allow_multiple_connections_per_ip, true); + settings.set_bool(libtorrent::settings_pack::ignore_limits_on_local_network, true); + settings.set_int(libtorrent::settings_pack::connection_speed, 20); + settings.set_int(libtorrent::settings_pack::active_downloads, -1); + settings.set_int(libtorrent::settings_pack::active_seeds, -1); + settings.set_int(libtorrent::settings_pack::active_limit, 30); + settings.set_int(libtorrent::settings_pack::dht_announce_interval, 60); + _session->apply_settings(settings); + + _session->add_dht_router({ "router.utorrent.com", 6881 }); + _session->add_dht_router({ "dht.transmissionbt.com", 6881 }); + _session->add_dht_router({ "router.bittorrent.com", 6881 }); + _session->add_dht_router({ "router.bitcomet.com", 6881 }); + + libtorrent::error_code ec; + _session->listen_on(std::make_pair(20280, 20290), ec); + _session->start_upnp(); +} + + +int TorrentClient::addTorrent(std::string torrentFile, std::string destination) { + if (!_session) { + LERROR("Torrent session not initialized when adding torrent"); + return -1; + } + + libtorrent::error_code ec; + libtorrent::add_torrent_params p; + + p.save_path = destination; + p.ti = std::make_shared(torrentFile, ec, 0); + + _session->add_torrent(p, ec); + + std::vector handles = _session->get_torrents(); + libtorrent::torrent_status s = handles[0].status(); + + LINFO("Torrent: " << s.total_wanted_done << " out of " << s.total_wanted); +} + +void TorrentClient::removeTorrent(int id) { +} + + +} diff --git a/modules/sync/torrentclient.h b/modules/sync/torrentclient.h new file mode 100644 index 0000000000..aee9020baf --- /dev/null +++ b/modules/sync/torrentclient.h @@ -0,0 +1,55 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2017 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_MODULE_SYNC___TORRENTCLIENT___H__ +#define __OPENSPACE_MODULE_SYNC___TORRENTCLIENT___H__ + +#include +#include + +namespace libtorrent { + class session; +} + +namespace openspace { + +struct Torrent { + std::string _torrentFile; + std::string _destination; +}; + +class TorrentClient { +public: + TorrentClient(); + ~TorrentClient(); + void initialize(); + int addTorrent(std::string torrentFile, std::string destination); + void removeTorrent(int id); +private: + std::unique_ptr _session; +}; + +} // namespace openspace + +#endif // __OPENSPACE_MODULE_SYNC___TORRENTCLIENT___H__ diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index a751a36cbc..a94a9b3bb0 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -406,22 +406,8 @@ void OpenSpaceEngine::create(int argc, char** argv, sgctArguments.insert(sgctArguments.begin() + 2, absPath(sgctConfigurationPath)); // Set up asset loader - ResourceSynchronizationOptions syncOptions; - syncOptions.synchronizationRoot = absPath("${SYNC}"); - if (_engine->_configurationManager->hasKey( - ConfigurationManager::KeyHttpSynchronizationRepositories)) - { - ghoul::Dictionary dictionary = _engine->_configurationManager->value( - ConfigurationManager::KeyHttpSynchronizationRepositories - ); - for (std::string key : dictionary.keys()) { - syncOptions.httpSynchronizationRepositories.push_back( - dictionary.value(key) - ); - } - } _engine->_assetManager = std::make_unique( - std::make_unique(*OsEng.scriptEngine().luaState(), "${ASSETS}", syncOptions), + std::make_unique(*OsEng.scriptEngine().luaState(), "${ASSETS}"), std::make_unique(OsEng._resourceSynchronizer.get()) ); //_engine->_globalPropertyNamespace->addPropertySubOwner(_engine->_assetLoader->rootAsset()); diff --git a/src/scene/asset.cpp b/src/scene/asset.cpp index e53fdafe6c..43c28e702d 100644 --- a/src/scene/asset.cpp +++ b/src/scene/asset.cpp @@ -57,19 +57,6 @@ std::string Asset::resolveLocalResource(std::string resourceName) { resourceName; } -std::string Asset::syncDirectory() const { - std::string currentAssetDirectory = assetDirectory(); - std::string rootAssetDirectory = loader()->assetRootDirectory(); - std::string relativePath = FileSys.relativePath(currentAssetDirectory, - rootAssetDirectory); - - return loader()->syncRootDirectory() + - ghoul::filesystem::FileSystem::PathSeparator + - relativePath + - ghoul::filesystem::FileSystem::PathSeparator + - ghoul::filesystem::File(_assetPath).baseName(); -} - Asset::ReadyState Asset::readyState() const { return _readyState; } diff --git a/src/scene/assetloader.cpp b/src/scene/assetloader.cpp index da0e80a5d9..b5d9070ae9 100644 --- a/src/scene/assetloader.cpp +++ b/src/scene/assetloader.cpp @@ -71,13 +71,11 @@ namespace openspace { AssetLoader::AssetLoader( ghoul::lua::LuaState& luaState, - std::string assetRootDirectory, - ResourceSynchronizationOptions syncOptions + std::string assetRootDirectory ) : _luaState(&luaState) , _rootAsset(std::make_shared(this)) , _assetRootDirectory(assetRootDirectory) - , _synchronizationOptions(std::move(syncOptions)) { pushAsset(_rootAsset); @@ -226,10 +224,6 @@ std::shared_ptr AssetLoader::rootAsset() const { return _rootAsset; } -const std::string& AssetLoader::syncRootDirectory() { - return _synchronizationOptions.synchronizationRoot; -} - const std::string & AssetLoader::assetRootDirectory() { return _assetRootDirectory; @@ -304,7 +298,6 @@ int AssetLoader::syncedResourceLua(Asset* asset) { std::shared_ptr sync = ResourceSynchronization::createFromDictionary(d); - sync->setSynchronizationOptions(_synchronizationOptions); std::string absolutePath = sync->directory(); asset->addSynchronization(sync); diff --git a/src/util/resourcesynchronization.cpp b/src/util/resourcesynchronization.cpp index ab5aaba38f..1d2b8737c4 100644 --- a/src/util/resourcesynchronization.cpp +++ b/src/util/resourcesynchronization.cpp @@ -23,6 +23,9 @@ ****************************************************************************************/ #include +#include +#include +#include #include #include @@ -89,6 +92,7 @@ std::unique_ptr ResourceSynchronization::createFromDict return nullptr; } + const SyncModule* syncModule = OsEng.moduleEngine().module(); return result; } @@ -115,13 +119,6 @@ void ResourceSynchronization::updateProgress(float t) { _progress = std::min(1.0f, std::max(t, 0.0f)); } -void ResourceSynchronization::setSynchronizationOptions( - openspace::ResourceSynchronizationOptions opt) -{ - _synchronizationOptions = std::move(opt); -} - - // SynchronizationJob methods SynchronizationJob::SynchronizationJob(ResourceSynchronization* synchronization) {