diff options
| author | Stefan Boberg <[email protected]> | 2021-05-18 22:49:45 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-05-18 22:50:15 +0200 |
| commit | d38a000ffd19d404d9f93a0f56a6c8be04ef258d (patch) | |
| tree | c5ced3ce194cbb1c888ce5b142b3e3cc2ca9df24 | |
| parent | Merge branch 'main' of https://github.com/EpicGames/zen into main (diff) | |
| download | zen-d38a000ffd19d404d9f93a0f56a6c8be04ef258d.tar.xz zen-d38a000ffd19d404d9f93a0f56a6c8be04ef258d.zip | |
Partial implementation of Jupiter chunk filtering, pending more information about response format
Also implemented compact binary PUT
| -rw-r--r-- | zenserver/upstream/jupiter.cpp | 40 | ||||
| -rw-r--r-- | zenserver/upstream/jupiter.h | 8 |
2 files changed, 46 insertions, 2 deletions
diff --git a/zenserver/upstream/jupiter.cpp b/zenserver/upstream/jupiter.cpp index 6b54f3d01..523ee61f4 100644 --- a/zenserver/upstream/jupiter.cpp +++ b/zenserver/upstream/jupiter.cpp @@ -3,6 +3,7 @@ #include "jupiter.h" #include <fmt/format.h> +#include <zencore/compactbinary.h> #include <zencore/iobuffer.h> #include <zencore/iohash.h> #include <zencore/string.h> @@ -108,6 +109,45 @@ CloudCacheSession::Put(std::string_view BucketId, std::string_view Key, IoBuffer } } +void +CloudCacheSession::Put(std::string_view BucketId, std::string_view Key, CbObjectView Data) +{ + ExtendableStringBuilder<256> Uri; + Uri << m_CacheClient->ServiceUrl(); + Uri << "/api/v1/c/ddc/" << m_CacheClient->Namespace() << "/" << BucketId << "/" TESTING_PREFIX << Key; + + auto& Session = m_SessionState->Session; + + IoHash Hash = Data.GetHash(); + MemoryView DataView = Data.GetView(); + + std::string Auth; + m_CacheClient->AcquireAccessToken(Auth); + Session.SetOption(cpr::Url{Uri.c_str()}); + Session.SetOption( + cpr::Header{{"Authorization", Auth}, {"X-Jupiter-IoHash", Hash.ToHexString()}, {"Content-Type", "application/x-ue-cb"}}); + Session.SetOption(cpr::Body{(const char*)DataView.GetData(), DataView.GetSize()}); + + cpr::Response Response = Session.Put(); + + if (Response.error) + { + spdlog::warn("PUT failed: '{}'", Response.error.message); + } +} + +std::vector<IoHash> +CloudCacheSession::Filter(std::string_view BucketId, const std::vector<IoHash>& ChunkHashes) +{ + ExtendableStringBuilder<256> Uri; + Uri << m_CacheClient->ServiceUrl(); + Uri << "/api/v1/s/" << m_CacheClient->Namespace(); + + ZEN_UNUSED(BucketId, ChunkHashes); + + return {}; +} + ////////////////////////////////////////////////////////////////////////// std::string diff --git a/zenserver/upstream/jupiter.h b/zenserver/upstream/jupiter.h index dd01cfb86..5bcec2904 100644 --- a/zenserver/upstream/jupiter.h +++ b/zenserver/upstream/jupiter.h @@ -8,6 +8,7 @@ #include <atomic> #include <list> #include <memory> +#include <vector> namespace zen { namespace detail { @@ -17,6 +18,7 @@ namespace detail { class IoBuffer; class CloudCacheClient; struct IoHash; +class CbObjectView; /** * Cached access token, for use with `Authorization:` header @@ -47,8 +49,10 @@ public: CloudCacheSession(CloudCacheClient* OuterClient); ~CloudCacheSession(); - IoBuffer Get(std::string_view BucketId, std::string_view Key); - void Put(std::string_view BucketId, std::string_view Key, IoBuffer Data); + IoBuffer Get(std::string_view BucketId, std::string_view Key); + void Put(std::string_view BucketId, std::string_view Key, IoBuffer Data); + void Put(std::string_view BucketId, std::string_view Key, CbObjectView Data); + std::vector<IoHash> Filter(std::string_view BucketId, const std::vector<IoHash>& ChunkHashes); private: RefPtr<CloudCacheClient> m_CacheClient; |