From ff2f8131a48324efb50bea168274c868a3af4745 Mon Sep 17 00:00:00 2001 From: Ryan Kistner Date: Sun, 16 Mar 2014 01:01:35 -0600 Subject: [PATCH] Added support for CDN content servers --- DepotDownloader/ContentDownloader.cs | 19 ++++++++++++++---- DepotDownloader/Steam3Session.cs | 30 ++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index 36d0d2fd..8af0938f 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -29,15 +29,17 @@ namespace DepotDownloader private sealed class DepotDownloadInfo { public uint id { get; private set; } + public uint appId { get; private set; } public string installDir { get; private set; } public string contentName { get; private set; } public ulong manifestId { get; private set; } public byte[] depotKey; - public DepotDownloadInfo(uint depotid, ulong manifestId, string installDir, string contentName) + public DepotDownloadInfo(uint depotid, uint appId, ulong manifestId, string installDir, string contentName) { this.id = depotid; + this.appId = appId; this.manifestId = manifestId; this.installDir = installDir; this.contentName = contentName; @@ -429,7 +431,7 @@ namespace DepotDownloader byte[] depotKey = steam3.DepotKeys[depotId]; - var info = new DepotDownloadInfo( depotId, manifestID, installDir, contentName ); + var info = new DepotDownloadInfo( depotId, appId, manifestID, installDir, contentName ); info.depotKey = depotKey; return info; } @@ -458,6 +460,16 @@ namespace DepotDownloader { CDNClient c; + if (s.Type == "CDN") + { + // serialize access to steam3 if we are called from AsParallel code + lock (steam3) + { + steam3.RequestCDNAuthToken(depot.appId, s.Host); + s.CDNAuthToken = steam3.CDNAuthTokens[Tuple.Create(depot.appId, s.Host)].Token; + } + } + if ( tries == 0 ) { c = initialClient; @@ -475,9 +487,8 @@ namespace DepotDownloader catch { Console.WriteLine( "\nFailed to connect to content server {0}. Remaining content servers for depot: {1}.", s, Config.MaxServers - tries - 1 ); + tries++; } - - tries++; } if ( cdnClients.Count == 0 ) diff --git a/DepotDownloader/Steam3Session.cs b/DepotDownloader/Steam3Session.cs index 8af2bbc6..b40559db 100644 --- a/DepotDownloader/Steam3Session.cs +++ b/DepotDownloader/Steam3Session.cs @@ -32,6 +32,7 @@ namespace DepotDownloader public Dictionary AppTickets { get; private set; } public Dictionary AppTokens { get; private set; } public Dictionary DepotKeys { get; private set; } + public Dictionary, SteamApps.CDNAuthTokenCallback> CDNAuthTokens { get; private set; } public Dictionary AppInfo { get; private set; } public Dictionary PackageInfo { get; private set; } @@ -67,6 +68,7 @@ namespace DepotDownloader this.AppTickets = new Dictionary(); this.AppTokens = new Dictionary(); this.DepotKeys = new Dictionary(); + this.CDNAuthTokens = new Dictionary, SteamApps.CDNAuthTokenCallback>(); this.AppInfo = new Dictionary(); this.PackageInfo = new Dictionary(); @@ -279,6 +281,34 @@ namespace DepotDownloader } } + public void RequestCDNAuthToken(uint appid, string host) + { + if (CDNAuthTokens.ContainsKey(Tuple.Create(appid, host)) || bAborted) + return; + + Action cbMethod = (cdnAuth, jobId) => + { + Console.WriteLine("Got CDN auth token for {0} result: {1}", host, cdnAuth.Result); + + if (cdnAuth.Result != EResult.OK) + { + Abort(); + return; + } + + CDNAuthTokens[Tuple.Create(appid, host)] = cdnAuth; + }; + + using (var cdnAuthCallback = new JobCallback(cbMethod, callbacks, steamApps.GetCDNAuthToken(appid, host))) + { + do + { + WaitForCallbacks(); + } + while (!cdnAuthCallback.Completed && !bAborted); + } + } + void Connect() { bAborted = false;