Hack in support for multiple servers and retry logic with concurrent downloading.

pull/8/head
Nicholas Hastings 12 years ago
parent 5bbb826a3f
commit bb1724746b

@ -443,38 +443,49 @@ namespace DepotDownloader
Console.WriteLine("Downloading depot {0} - {1}", depot.id, depot.contentName); Console.WriteLine("Downloading depot {0} - {1}", depot.id, depot.contentName);
Console.Write("Finding content servers..."); Console.Write("Finding content servers...");
CDNClient client = new CDNClient(steam3.steamClient, depot.id, steam3.AppTickets[depot.id], depot.depotKey); var cdnClients = new List<CDNClient>();
var cdnServers = client.FetchServerList(cellId: (uint)Config.CellID); CDNClient initialClient = new CDNClient(steam3.steamClient, depot.id, steam3.AppTickets[depot.id], depot.depotKey);
var cdnServers = initialClient.FetchServerList(cellId: (uint)Config.CellID);
if (cdnServers.Count == 0) if (cdnServers.Count == 0)
{ {
Console.WriteLine("\nUnable to find any content servers for depot {0} - {1}", depot.id, depot.contentName); Console.WriteLine("\nUnable to find any content servers for depot {0} - {1}", depot.id, depot.contentName);
return; continue;
} }
Console.WriteLine(" Done!"); // Grab the six best servers
Console.Write("Downloading depot manifest..."); Enumerable.Range(0, Math.Min(cdnServers.Count, 6)).ToList().ForEach(s =>
for (int i = 0; i < cdnServers.Count; ++i)
{ {
var server = cdnServers[i]; CDNClient c;
if( s == 0 )
{
c = initialClient;
}
else
{
c = new CDNClient(steam3.steamClient, depot.id, steam3.AppTickets[depot.id], depot.depotKey);
}
try try
{ {
client.Connect(server); c.Connect(cdnServers[s]);
break; cdnClients.Add(c);
} }
catch catch
{ {
Console.WriteLine("\nFailed to connect to content server {0}. Remaining content servers for depot: {1}.", server, cdnServers.Count - i - 1); Console.WriteLine("\nFailed to connect to content server {0}. Remaining content servers for depot: {1}.", cdnServers[s], cdnServers.Count - s - 1);
} }
} });
Console.WriteLine(" Done!");
Console.Write("Downloading depot manifest...");
DepotManifest depotManifest = null; DepotManifest depotManifest = null;
foreach (var server in cdnServers) foreach (var c in cdnClients)
{ {
try try
{ {
depotManifest = client.DownloadManifest(depot.manifestId); depotManifest = c.DownloadManifest(depot.manifestId);
break; break;
} }
catch (WebException) { } catch (WebException) { }
@ -537,8 +548,12 @@ namespace DepotDownloader
complete_download_size += file.TotalSize; complete_download_size += file.TotalSize;
} }
var rand = new Random();
depotManifest.Files.AsParallel().WithDegreeOfParallelism(4).ForAll(file => depotManifest.Files.AsParallel().WithDegreeOfParallelism(4).ForAll(file =>
{ {
var clientIndex = rand.Next(0, cdnClients.Count);
string download_path = Path.Combine(depot.installDir, file.FileName); string download_path = Path.Combine(depot.installDir, file.FileName);
string fileStagingPath = Path.Combine(stagingDir, file.FileName); string fileStagingPath = Path.Combine(stagingDir, file.FileName);
@ -663,7 +678,31 @@ namespace DepotDownloader
{ {
string chunkID = Util.EncodeHexString(chunk.ChunkID); string chunkID = Util.EncodeHexString(chunk.ChunkID);
var chunkData = client.DownloadDepotChunk(chunk); CDNClient.DepotChunk chunkData = null;
int idx = clientIndex;
while (true)
{
try
{
chunkData = cdnClients[idx].DownloadDepotChunk(chunk);
break;
}
catch
{
if (++idx >= cdnClients.Count)
idx = 0;
if (idx == clientIndex)
break;
}
}
if (chunkData == null)
{
Console.WriteLine("Failed to find any server with chunk {0} for depot {1}. Aborting.", chunkID, depot);
return;
}
TotalBytesCompressed += chunk.CompressedLength; TotalBytesCompressed += chunk.CompressedLength;
DepotBytesCompressed += chunk.CompressedLength; DepotBytesCompressed += chunk.CompressedLength;
TotalBytesUncompressed += chunk.UncompressedLength; TotalBytesUncompressed += chunk.UncompressedLength;

Loading…
Cancel
Save