Skip to content

Commit 5742ee7

Browse files
committed
DepotDownloader: Retry different CDN servers when we encounter an error
--HG-- extra : rebase_source : 35a93f8bdd98c03f8cd99423e6c4f95ed713d0d2
1 parent a897a73 commit 5742ee7

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

Projects/DepotDownloader/DepotDownloader/ContentDownloader.cs

+36-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ static class ContentDownloader
1616
const string DEFAULT_DIR = "depots";
1717
const int MAX_STORAGE_RETRIES = 500;
1818
const int MAX_CONNECT_RETRIES = 10;
19+
const int NUM_STEAM3_CONNECTIONS = 4;
1920

2021
public static DownloadConfig Config = new DownloadConfig();
2122

@@ -522,31 +523,43 @@ private static void DownloadSteam3( int depotId, ulong depot_manifest, byte[] de
522523

523524
List<CDNClient.ClientEndPoint> cdnEndpoints = cdnServers.Where((ep) => { return ep.Type == "CDN"; }).ToList();
524525
List<CDNClient.ClientEndPoint> csEndpoints = cdnServers.Where((ep) => { return ep.Type == "CS"; }).ToList();
525-
CDNClient cdnClient = null;
526+
527+
List<CDNClient> cdnClients = new List<CDNClient>();
526528

527529
foreach (var server in csEndpoints)
528530
{
529531
CDNClient client = new CDNClient(server, steam3.AppTickets[(uint)depotId]);
530532

531533
if (client.Connect())
532534
{
533-
cdnClient = client;
534-
break;
535+
cdnClients.Add(client);
536+
537+
if (cdnClients.Count >= NUM_STEAM3_CONNECTIONS)
538+
break;
535539
}
536540
}
537541

538-
if (cdnClient == null)
542+
if (cdnClients.Count == 0)
539543
{
540544
Console.WriteLine("\nCould not initialize connection with CDN.");
541545
return;
542546
}
543547

544-
DepotManifest depotManifest = cdnClient.DownloadDepotManifest( depotId, depot_manifest );
548+
DepotManifest depotManifest = cdnClients[0].DownloadDepotManifest( depotId, depot_manifest );
545549

546550
if ( depotManifest == null )
547551
{
548-
Console.WriteLine( "\nUnable to download manifest {0} for depot {1}", depot_manifest, depotId );
549-
return;
552+
// TODO: check for 401s
553+
for (int i = 1; i < cdnClients.Count && depotManifest == null; i++)
554+
{
555+
depotManifest = cdnClients[i].DownloadDepotManifest( depotId, depot_manifest );
556+
}
557+
558+
if (depotManifest == null)
559+
{
560+
Console.WriteLine("\nUnable to download manifest {0} for depot {1}", depot_manifest, depotId);
561+
return;
562+
}
550563
}
551564

552565
if (!depotManifest.DecryptFilenames(depotKey))
@@ -602,7 +615,22 @@ private static void DownloadSteam3( int depotId, ulong depot_manifest, byte[] de
602615
{
603616
string chunkID = EncodeHexString(chunk.ChunkID);
604617

605-
byte[] encrypted_chunk = cdnClient.DownloadDepotChunk(depotId, chunkID);
618+
byte[] encrypted_chunk = cdnClients[0].DownloadDepotChunk(depotId, chunkID);
619+
620+
if (encrypted_chunk == null)
621+
{
622+
for (int i = 1; i < cdnClients.Count && encrypted_chunk == null; i++)
623+
{
624+
encrypted_chunk = cdnClients[i].DownloadDepotChunk(depotId, chunkID);
625+
}
626+
627+
if (encrypted_chunk == null)
628+
{
629+
Console.WriteLine("Unable to download chunk id {0} for depot {1}", chunkID, depotId);
630+
return;
631+
}
632+
}
633+
606634
byte[] chunk_data = CDNClient.ProcessChunk(encrypted_chunk, depotKey);
607635

608636
fs.Seek((long)chunk.Offset, SeekOrigin.Begin);

0 commit comments

Comments
 (0)