예제 #1
0
        public void RequestCDNAuthToken(uint appid, uint depotid, string host, string cdnKey)
        {
            if (CDNAuthTokens.ContainsKey(cdnKey) || bAborted)
            {
                return;
            }

            if (!CDNAuthTokens.TryAdd(cdnKey, new TaskCompletionSource <SteamApps.CDNAuthTokenCallback>()))
            {
                return;
            }

            bool completed   = false;
            var  timeoutDate = DateTime.Now.AddSeconds(10);
            Action <SteamApps.CDNAuthTokenCallback> cbMethod = (cdnAuth) =>
            {
                completed = true;
                Log.Info("Got CDN auth token for {0} result: {1} (expires {2})", host, cdnAuth.Result, cdnAuth.Expiration);

                if (cdnAuth.Result != EResult.OK)
                {
                    Abort();
                    return;
                }

                CDNAuthTokens[cdnKey].TrySetResult(cdnAuth);
            };

            WaitUntilCallback(() =>
            {
                callbacks.Subscribe(steamApps.GetCDNAuthToken(appid, depotid, host), cbMethod);
            }, () => { return(completed || DateTime.Now >= timeoutDate); });
        }
예제 #2
0
        public void RequestCDNAuthToken(uint depotid, string host)
        {
            if (CDNAuthTokens.ContainsKey(Tuple.Create(depotid, host)) || bAborted)
            {
                return;
            }

            bool completed = false;
            Action <SteamApps.CDNAuthTokenCallback> cbMethod = (cdnAuth) =>
            {
                completed = true;
                Console.WriteLine("Got CDN auth token for {0} result: {1}", host, cdnAuth.Result);

                if (cdnAuth.Result != EResult.OK)
                {
                    Abort();
                    return;
                }

                CDNAuthTokens[Tuple.Create(depotid, host)] = cdnAuth;
            };

            WaitUntilCallback(() =>
            {
                callbacks.Subscribe(steamApps.GetCDNAuthToken(depotid, host), cbMethod);
            }, () => { return(completed); });
        }
예제 #3
0
        public void RequestCDNAuthToken(uint appid, uint depotid, string host)
        {
            host = ResolveCDNTopLevelHost(host);
            var cdnKey = string.Format("{0:D}:{1}", depotid, host);

            if (CDNAuthTokens.ContainsKey(cdnKey) || bAborted)
            {
                return;
            }

            bool completed = false;
            Action <SteamApps.CDNAuthTokenCallback> cbMethod = (cdnAuth) =>
            {
                completed = true;
                Console.WriteLine("Got CDN auth token for {0} result: {1} (expires {2})", host, cdnAuth.Result, cdnAuth.Expiration);

                if (cdnAuth.Result != EResult.OK)
                {
                    Abort();
                    return;
                }

                CDNAuthTokens.TryAdd(cdnKey, cdnAuth);
            };

            WaitUntilCallback(() =>
            {
                callbacks.Subscribe(steamApps.GetCDNAuthToken(appid, depotid, host), cbMethod);
            }, () => { return(completed); });
        }
예제 #4
0
        public Task <bool> RequestCDNAuthToken(uint appid, uint depotid, string host)
        {
            var tsc = new TaskCompletionSource <bool>();

            host = ResolveCDNTopLevelHost(host);
            var cdnKey = string.Format("{0:D}:{1}", depotid, host);

            if (CDNAuthTokens.ContainsKey(cdnKey) || bAborted)
            {
                tsc.SetResult(true);
                return(tsc.Task);
            }
            else
            {
                IDisposable subscription = null;
                Action <SteamApps.CDNAuthTokenCallback> cbMethod = (cdnAuth) =>
                {
                    subscription.Dispose();
                    DebugLog.WriteLine("Steam3Session", "Got CDN auth token for " + host + " result: " + cdnAuth.Result + " (expires " + cdnAuth.Expiration + ")");

                    if (cdnAuth.Result != EResult.OK)
                    {
                        Abort();
                        return;
                    }

                    CDNAuthTokens.TryAdd(cdnKey, cdnAuth);

                    tsc.SetResult(true);
                };

                subscription = callbacks.Subscribe(steamApps.GetCDNAuthToken(appid, depotid, host), cbMethod);
                return(tsc.Task);
            }
        }
예제 #5
0
        private async Task <LocalConfig.CDNAuthToken> GetCDNAuthToken(SteamApps instance, uint appID, uint depotID)
        {
            if (LocalConfig.CDNAuthTokens.ContainsKey(depotID))
            {
                var token = LocalConfig.CDNAuthTokens[depotID];

                if (DateTime.Now < token.Expiration)
                {
                    return(token);
                }

#if DEBUG
                Log.WriteDebug("Depot Downloader", "Token for depot {0} expired, will request a new one", depotID);
            }
            else
            {
                Log.WriteDebug("Depot Downloader", "Requesting a new token for depot {0}", depotID);
#endif
            }

            var newToken = new LocalConfig.CDNAuthToken
            {
                Server = GetContentServer()
            };

            var task = instance.GetCDNAuthToken(appID, depotID, newToken.Server);
            task.Timeout = TimeSpan.FromMinutes(15);

            SteamApps.CDNAuthTokenCallback tokenCallback;

            try
            {
                tokenCallback = await task;
            }
            catch (TaskCanceledException)
            {
                Log.WriteError("Depot Processor", "CDN auth token timed out for {0}", depotID);

                return(null);
            }

#if DEBUG
            Log.WriteDebug("Depot Downloader", "Token for depot {0} result: {1}", depotID, tokenCallback.Result);
#endif

            if (tokenCallback.Result != EResult.OK)
            {
                return(null);
            }

            newToken.Token      = tokenCallback.Token;
            newToken.Expiration = tokenCallback.Expiration.Subtract(TimeSpan.FromMinutes(1));

            LocalConfig.CDNAuthTokens[depotID] = newToken;

            SaveLocalConfig = true;

            return(newToken);
        }
예제 #6
0
        public async Task <string> RequestCDNAuthToken(uint appId, uint depotId, string host)
        {
            var dKey = depotId + "-" + appId + "-" + host;

            if (!CDNAuthKeys.ContainsKey(dKey))
            {
                CDNAuthKeys[dKey] = (await Apps.GetCDNAuthToken(appId, depotId, host)).Token;
            }

            return(CDNAuthKeys[dKey]);
        }
예제 #7
0
        public Task <SteamApps.CDNAuthTokenCallback> RequestCDNAuthToken(uint appId, uint depotId, string host, string cdnKey, bool allowCached = true)
        {
            if (allowCached && cachedCdnAuthTokens.TryGetValue(cdnKey, out var runningTask))
            {
                return(runningTask);
            }

            return(cachedCdnAuthTokens[cdnKey] = Task.Run(async() =>
            {
                var cdnTokenCallback = await steamApps.GetCDNAuthToken(appId, depotId, host);
                return cdnTokenCallback;
            }));
        }
예제 #8
0
        private async Task <CDNAuthTokenCallback> RequestCDNAuthToken(uint appId, uint depotId, string host)
        {
            host = ResolveCDNTopLevelHost(host);
            var cdnKey = $"{depotId:D}:{host}";

            if (_cdnAuthTokens.TryGetValue(cdnKey, out CDNAuthTokenCallback callback) && callback != null)
            {
                return(callback);
            }

            callback = await _apps.GetCDNAuthToken(appId, depotId, host);

            _cdnAuthTokens[cdnKey] = callback ?? throw new Exception("Failed to get CDN token");
            return(callback);
        }