From cda5eb5137f9fcad1ca07a06cec352923b100f7c Mon Sep 17 00:00:00 2001 From: Ryan Kistner Date: Thu, 5 Nov 2020 23:38:25 -0700 Subject: [PATCH] Proxy logic brought into SteamKit --- DepotDownloader/CDNClientPool.cs | 29 +++------------------------- DepotDownloader/ContentDownloader.cs | 10 ++++++++++ 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/DepotDownloader/CDNClientPool.cs b/DepotDownloader/CDNClientPool.cs index 1a35533c..8147563d 100644 --- a/DepotDownloader/CDNClientPool.cs +++ b/DepotDownloader/CDNClientPool.cs @@ -18,12 +18,11 @@ namespace DepotDownloader private readonly Steam3Session steamSession; private readonly uint appId; + public CDNClient CDNClient { get; } #if STEAMKIT_UNRELEASED - private CDNClient.Server proxyServer; + public CDNClient.Server ProxyServer { get; private set; } #endif - public CDNClient CDNClient { get; } - private readonly ConcurrentStack activeConnectionPool; private readonly BlockingCollection availableServerEndpoints; @@ -32,33 +31,11 @@ namespace DepotDownloader private readonly CancellationTokenSource shutdownToken; public CancellationTokenSource ExhaustedToken { get; set; } -#if STEAMKIT_UNRELEASED - private UriBuilder TransformCdnClientRequest(UriBuilder uriBuilder) - { - if (proxyServer != null) - { - var pathTemplate = proxyServer.ProxyRequestPathTemplate; - pathTemplate = pathTemplate.Replace("%host%", uriBuilder.Host); - pathTemplate = pathTemplate.Replace("%path%", $"/{uriBuilder.Path}"); - uriBuilder.Scheme = proxyServer.Protocol == CDNClient.Server.ConnectionProtocol.HTTP ? "http" : "https"; - uriBuilder.Host = proxyServer.VHost; - uriBuilder.Port = proxyServer.Port; - uriBuilder.Path = pathTemplate; - } - - return uriBuilder; - } -#endif - public CDNClientPool(Steam3Session steamSession, uint appId) { this.steamSession = steamSession; this.appId = appId; -#if STEAMKIT_UNRELEASED - CDNClient = new CDNClient(steamSession.steamClient, TransformCdnClientRequest); -#else CDNClient = new CDNClient(steamSession.steamClient); -#endif activeConnectionPool = new ConcurrentStack(); availableServerEndpoints = new BlockingCollection(); @@ -125,7 +102,7 @@ namespace DepotDownloader } #if STEAMKIT_UNRELEASED - proxyServer = servers.Where(x => x.UseAsProxy).FirstOrDefault(); + ProxyServer = servers.Where(x => x.UseAsProxy).FirstOrDefault(); #endif var weightedCdnServers = servers diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index bf5d7107..c7093dc5 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -760,8 +760,13 @@ namespace DepotDownloader connection = cdnPool.GetConnection(cts.Token); var cdnToken = await cdnPool.AuthenticateConnection(appId, depot.id, connection); +#if STEAMKIT_UNRELEASED + depotManifest = await cdnPool.CDNClient.DownloadManifestAsync(depot.id, depot.manifestId, + connection, cdnToken, depot.depotKey, proxyServer: cdnPool.ProxyServer).ConfigureAwait(false); +#else depotManifest = await cdnPool.CDNClient.DownloadManifestAsync(depot.id, depot.manifestId, connection, cdnToken, depot.depotKey).ConfigureAwait(false); +#endif cdnPool.ReturnConnection(connection); } @@ -1123,8 +1128,13 @@ namespace DepotDownloader connection = cdnPool.GetConnection(cts.Token); var cdnToken = await cdnPool.AuthenticateConnection(appId, depot.id, connection); +#if STEAMKIT_UNRELEASED + chunkData = await cdnPool.CDNClient.DownloadDepotChunkAsync(depot.id, data, + connection, cdnToken, depot.depotKey, proxyServer: cdnPool.ProxyServer).ConfigureAwait(false); +#else chunkData = await cdnPool.CDNClient.DownloadDepotChunkAsync(depot.id, data, connection, cdnToken, depot.depotKey).ConfigureAwait(false); +#endif cdnPool.ReturnConnection(connection); }