Skip to content

Commit

Permalink
Merge pull request #2 from Nuclearistt/cdnclient-rework
Browse files Browse the repository at this point in the history
CDN Client rework
  • Loading branch information
Nuclearistt authored Feb 2, 2024
2 parents bed4106 + f3fc741 commit c4e7e1f
Show file tree
Hide file tree
Showing 7 changed files with 566 additions and 544 deletions.
2 changes: 1 addition & 1 deletion TEKSteamClient.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<BaseVersion>1.2.0</BaseVersion>
<BaseVersion>1.3.0</BaseVersion>
<Version>$(BaseVersion)</Version>
<Version Condition="'$(GITHUB_RUN_NUMBER)' != ''">$(BaseVersion)-alpha.$(GITHUB_RUN_NUMBER)</Version>
<Authors>Nuclearist</Authors>
Expand Down
181 changes: 97 additions & 84 deletions src/AppManager.cs

Large diffs are not rendered by default.

888 changes: 446 additions & 442 deletions src/CDNClient.cs

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/CM/WebSocketConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ public void Connect()
_socket.Dispose();
continue;
}
_thread = new Thread(ConnectionLoop);
_thread = new Thread(ConnectionLoop)
{
Name = "CM WebSocket Connection Thread"
};
_thread.Start();
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Manifest/DepotDelta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void countAcq(in DirectoryEntry dir, DirectoryEntry.AcquisitionStaging acquisiti
foreach (var acquisitionFile in acquisitionDir.Files)
{
numChunks += acquisitionFile.Chunks.Count;
var file = dir.Files[acquisitionFile.Index];
var file = manifest.FileBuffer[acquisitionFile.Index];
if (acquisitionFile.Chunks.Count is 0)
{
numDownloadFiles++;
Expand All @@ -40,14 +40,14 @@ void countAcq(in DirectoryEntry dir, DirectoryEntry.AcquisitionStaging acquisiti
for (int i = 0; i < acquisitionFile.Chunks.Count; i++)
{
int index = acquisitionFile.Chunks[i].Index;
var chunk = file.Chunks[index];
var chunk = manifest.ChunkBuffer[index];
downloadSize += chunk.CompressedSize;
acquisitionFile.Chunks[i] = new(index) { Offset = chunkBufferFileSize };
chunkBufferFileSize += chunk.UncompressedSize;
}
}
foreach (var subdir in acquisitionDir.Subdirectories)
countAcq(dir.Subdirectories[subdir.Index], subdir);
countAcq(in manifest.DirectoryBuffer[subdir.Index], subdir);
}
countAcq(in manifest.Root, acquisitionTree);
ChunkBufferFileSize = chunkBufferFileSize;
Expand Down
10 changes: 5 additions & 5 deletions src/Manifest/DirectoryEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal readonly struct AcquisitionEntry
{
/// <summary>Indicates whether directory has been added or modifed.</summary>
public required bool IsNew { get; init; }
/// <summary>Index of the directory entry in its parent directory.</summary>
/// <summary>Index of the directory entry in <see cref="DepotManifest.DirectoryBuffer"/>.</summary>
public required int Index { get; init; }
/// <summary>Directory's file entries.</summary>
public required ArraySegment<FileEntry.AcquisitionEntry> Files { get; init; }
Expand All @@ -24,7 +24,7 @@ internal readonly struct AcquisitionEntry
/// <summary>Structure used in <see cref="DepotDelta"/> to store auxiliary data like patched chunks and relocations for files or removed items.</summary>
internal readonly struct AuxiliaryEntry
{
/// <summary>Index of the directory entry in its parent directory, or in source manifest directory buffer if <see cref="FilesToRemove"/> is empty.</summary>
/// <summary>Index of the directory entry in <see cref="DepotManifest.DirectoryBuffer"/>. If <see cref="FilesToRemove"/> is empty, the index is for source manifest.</summary>
public required int Index { get; init; }
/// <summary>Indexes of the files that must be removed. If empty, the directory with all its contents is removed instead.</summary>
public ArraySegment<int>? FilesToRemove { get; init; }
Expand All @@ -37,7 +37,7 @@ internal readonly struct AuxiliaryEntry
internal class AcquisitionStaging
{
/// <summary>Creates an empty staging directory entry with specified index.</summary>
/// <param name="index">Index of the directory entry in its parent directory.</param>
/// <param name="index">Index of the directory entry in <see cref="DepotManifest.DirectoryBuffer"/>.</param>
/// <param name="isNew">Value indicating whether directory has been added or modifed.</param>
public AcquisitionStaging(int index, bool isNew)
{
Expand All @@ -64,7 +64,7 @@ public AcquisitionStaging(ReadOnlySpan<int> buffer, ref int offset)
}
/// <summary>Indicates whether directory has been added or modifed.</summary>
public bool IsNew { get; internal set; }
/// <summary>Index of the directory entry in its parent directory.</summary>
/// <summary>Index of the directory entry in <see cref="DepotManifest.DirectoryBuffer"/>.</summary>
public int Index { get; }
/// <summary>Directory's file entries.</summary>
public List<FileEntry.AcquisitionStaging> Files { get; }
Expand All @@ -90,7 +90,7 @@ public void WriteToBuffer(Span<int> buffer, ref int offset)
/// <param name="index">Index of the directory entry in its parent directory.</param>
internal class AuxiliaryStaging(int index)
{
/// <summary>Index of the directory entry in its parent directory, or in source manifest directory buffer if <see cref="FilesToRemove"/> is empty.</summary>
/// <summary>Index of the directory entry in <see cref="DepotManifest.DirectoryBuffer"/>. If <see cref="FilesToRemove"/> is empty, the index is for source manifest.</summary>
public int Index { get; } = index;
/// <summary>Indexes of the files that must be removed. If empty, the directory with all its contents is removed instead.</summary>
public List<int>? FilesToRemove { get; set; }
Expand Down
18 changes: 10 additions & 8 deletions src/Manifest/FileEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public enum Flag
/// <summary>Structure used in <see cref="DepotDelta"/> to store indexes of files and chunks that must be acquired.</summary>
internal readonly struct AcquisitionEntry
{
/// <summary>Index of the file entry in its parent directory.</summary>
/// <summary>Index of the file entry in <see cref="DepotManifest.FileBuffer"/>.</summary>
public required int Index { get; init; }
/// <summary>File's chunks that must be acquired. If empty, the whole file is acquired.</summary>
public required ArraySegment<ChunkEntry> Chunks { get; init; }
/// <summary>Structure storing chunk's index along with its optional offset in chunk buffer file.</summary>
/// <param name="index">Index of the chunk in its file.</param>
public readonly struct ChunkEntry(int index)
{
/// <summary>Index of the chunk entry in its file.</summary>
/// <summary>Index of the chunk entry in <see cref="DepotManifest.ChunkBuffer"/>.</summary>
public int Index { get; } = index;
/// <summary>Offset of the chunk data from the beginning of chunk buffer file.</summary>
public long Offset { get; init; }
Expand All @@ -46,7 +46,7 @@ public readonly struct ChunkEntry(int index)
/// <summary>Structure used in <see cref="DepotDelta"/> to store auxiliary data like patched chunks and relocations.</summary>
internal readonly struct AuxiliaryEntry
{
/// <summary>Index of the file entry in its parent directory.</summary>
/// <summary>Index of the file entry in <see cref="DepotManifest.FileBuffer"/>.</summary>
public required int Index { get; init; }
/// <summary>File's chunk patch and relocation entries.</summary>
public ArraySegment<ITransferOperation> TransferOperations { get; init; }
Expand All @@ -55,7 +55,7 @@ public interface ITransferOperation { }
/// <summary>Contains data that is needed to patch a chunk.</summary>
public class ChunkPatchEntry : ITransferOperation
{
/// <summary>Index of the target chunk in the file.</summary>
/// <summary>Index of target chunk entry in <see cref="DepotManifest.ChunkBuffer"/>.</summary>
public required int ChunkIndex { get; init; }
/// <summary>Index of the corresponding patch chunk.</summary>
public required int PatchChunkIndex { get; init; }
Expand Down Expand Up @@ -96,7 +96,7 @@ public AcquisitionStaging(ReadOnlySpan<int> buffer, ref int offset)
for (int i = 0; i < numChunks; i++)
Chunks.Add(new(buffer[offset++]));
}
/// <summary>Index of the file entry in its parent directory.</summary>
/// <summary>Index of the file entry in <see cref="DepotManifest.FileBuffer"/>.</summary>
public int Index { get; }
/// <summary>File's chunks that must be acquired. If empty, the whole file is acquired.</summary>
public List<AcquisitionEntry.ChunkEntry> Chunks { get; }
Expand All @@ -115,7 +115,7 @@ public void WriteToBuffer(Span<int> buffer, ref int offset)
/// <param name="index">Index of the file entry in its parent directory.</param>
internal class AuxiliaryStaging(int index)
{
/// <summary>Index of the file entry in its parent directory.</summary>
/// <summary>Index of the file entry in <see cref="DepotManifest.FileBuffer"/>.</summary>
public int Index { get; } = index;
/// <summary>File's chunk patch entries.</summary>
public List<ChunkPatchEntry> ChunkPatches { get; } = [];
Expand All @@ -130,15 +130,15 @@ public class ChunkPatchEntry : ITransferOperation
{
/// <summary>Indicates whether intermediate file needs to be used as a buffer to avoid overlapping further chunks.</summary>
public bool UseIntermediateFile { get; set; }
/// <summary>Index of the target chunk in the file.</summary>
/// <summary>Index of target chunk entry in <see cref="DepotManifest.ChunkBuffer"/>.</summary>
public required int ChunkIndex { get; init; }
/// <summary>Index of the corresponding patch chunk.</summary>
public required int PatchChunkIndex { get; init; }
/// <summary>Size of either source chunk or patched chunk data, whichever is smaller.</summary>
public required long Size { get; init; }
}
/// <summary>Describes data that needs to be moved within the file.</summary>
public class RelocationEntry : ITransferOperation
public class RelocationEntry : ITransferOperation, IComparable<RelocationEntry>
{
/// <summary>Indicates whether intermediate file needs to be used as a buffer to avoid overlapping further relocations and chunk patches.</summary>
public bool UseIntermediateFile { get; set; }
Expand All @@ -148,6 +148,8 @@ public class RelocationEntry : ITransferOperation
public required long TargetOffset { get; init; }
/// <summary>Size of data bulk.</summary>
public required long Size { get; set; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(RelocationEntry? other) => other is null ? 1 : SourceOffset.CompareTo(other.SourceOffset);
}
/// <summary>Represents an operation that takes data from certain region of a file and writes data to another region of a file.</summary>
public class TransferOperation : IComparable<TransferOperation>
Expand Down

0 comments on commit c4e7e1f

Please sign in to comment.