From e3f6063d841933c3dcc6b16674613458a95c8c6f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 30 Apr 2026 23:45:02 -0500 Subject: fix up transfer --- src/slskd/Transfers/Types/Transfer.cs | 205 +++++++++++++++++++++++----------- 1 file changed, 139 insertions(+), 66 deletions(-) (limited to 'src') diff --git a/src/slskd/Transfers/Types/Transfer.cs b/src/slskd/Transfers/Types/Transfer.cs index 90fbe612..8d1afa25 100644 --- a/src/slskd/Transfers/Types/Transfer.cs +++ b/src/slskd/Transfers/Types/Transfer.cs @@ -31,71 +31,144 @@ // namespace slskd.Transfers; + +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Text.Json.Serialization; +using Soulseek; + +/// +/// A file Transfer between network peers. +/// +public class Transfer { - using System; - using System.ComponentModel.DataAnnotations; - using System.ComponentModel.DataAnnotations.Schema; - using System.Text.Json.Serialization; - using Soulseek; - - public class Transfer - { - public Guid? BatchId { get; init; } = null; - - [Key] - public Guid Id { get; init; } - public string Username { get; init; } - public TransferDirection Direction { get; init; } - - /// - /// Gets the remote filename. - /// - public string Filename { get; init; } - public long Size { get; set; } - public long StartOffset { get; init; } - - public TransferStates State { get; set; } = TransferStates.None; - - /// - /// Gets the string representation of the transfer . - /// - /// - /// This is a hack to get the string into the database. *DO NOT* use this property in code - /// and especially **DO NOT** set the value. The getter and setter can't be protected because - /// EF Core needs them to be public. - /// - public string StateDescription { get; set; } - public DateTime RequestedAt { get; set; } - public DateTime? EnqueuedAt { get; set; } - public DateTime? StartedAt { get; set; } - - /// - /// The time at which the transfer ended, or null if the transfer has not yet started or is in progress. - /// - /// - /// Guaranteed to be set for transfers in a terminal state. - /// - public DateTime? EndedAt { get; set; } - public long BytesTransferred { get; set; } - public double AverageSpeed { get; set; } - - public int? PlaceInQueue { get; set; } - public string Exception { get; set; } - - public int Attempts { get; set; } = 0; - - public DateTime? NextAttemptAt { get; set; } = null; - - [JsonIgnore] - public bool Removed { get; set; } - - [NotMapped] - public long BytesRemaining => Size - BytesTransferred; - [NotMapped] - public TimeSpan? ElapsedTime => StartedAt == null ? null : (EndedAt ?? DateTime.UtcNow) - StartedAt.Value; - [NotMapped] - public double PercentComplete => Size == 0 ? 0 : (BytesTransferred / (double)Size) * 100; - [NotMapped] - public TimeSpan? RemainingTime => AverageSpeed == 0 ? null : TimeSpan.FromSeconds(BytesRemaining / AverageSpeed); - } + /// + /// Gets the associated , if one was specified when the Transfer was created. + /// + public Guid? BatchId { get; init; } = null; + + /// + /// Gets the unique identifier for the Transfer. + /// + [Key] + public Guid Id { get; init; } + + /// + /// Gets the remote username associated with the Transfer. + /// + public string Username { get; init; } + + /// + /// Gets the Transfer direction (Upload, Download). + /// + public TransferDirection Direction { get; init; } + + /// + /// Gets the remote filename of the file. + /// + /// + /// Exactly as it appeared in the originating Search, Browse, or file directory contents response. + /// + public string Filename { get; init; } + + /// + /// Gets or sets the remote size of the file. + /// + public long Size { get; set; } + + /// + /// Gets or sets the state of the Transfer. + /// + public TransferStates State { get; set; } = TransferStates.None; + + /// + /// Gets or sets the string representation of the transfer . + /// + /// + /// This is a hack to get the string into the database. *DO NOT* use this property in code + /// and especially **DO NOT** set the value. The getter and setter can't be protected because + /// EF Core needs them to be public. + /// + public string StateDescription { get; set; } + + /// + /// Gets or sets the time at which the Transfer was requested from the remote peer. + /// + public DateTime RequestedAt { get; set; } + + /// + /// Gets or sets the time at which the Transfer was enqueued, or null if the Transfer has not yet been enqueued. + /// + /// + /// For downloads, this is the time at which the remote peer responded to our enqueue request. For uploads this + /// is the time at which the transfer was made available for scheduling by the upload queue, after we have + /// responded to the remote peer's request to enqueue. + /// + public DateTime? EnqueuedAt { get; set; } + + /// + /// Gets or sets the time at which the Transfer connection was established and data transfer began, or null if the + /// Transfer has not yet been started. + /// + public DateTime? StartedAt { get; set; } + + /// + /// Gets or sets the time at which the Transfer ended, or null if the Transfer has not yet started or is still in progress. + /// + /// + /// Guaranteed to be set for transfers in a terminal state. + /// + public DateTime? EndedAt { get; set; } + + /// + /// Gets or sets the number of bytes transferred. + /// + public long BytesTransferred { get; set; } + + /// + /// Gets or sets the average speed of the Transfer over the duration. + /// + public double AverageSpeed { get; set; } + + /// + /// Gets or sets the current place in line in the remote peer's queue, if place has been requested. + /// + /// + /// May be wildly innacurate to the point of uselessness. + /// + public int? PlaceInQueue { get; set; } + + /// + /// Gets or sets the associated Exception, if the Transfer did not end successfully, or null if it did. + /// + public string Exception { get; set; } + + /// + /// Gets or sets the number of attempts. Incremented each time the Transfer is retried. + /// + /// + /// Applicable to downloads only. + /// + public int Attempts { get; set; } = 0; + + /// + /// Gets or sets the time at which the next retry attempt will be made, if applicable. + /// + public DateTime? NextAttemptAt { get; set; } = null; + + /// + /// Gets or sets a value indicating whether the Transfer has been removed from the UI. + /// + [JsonIgnore] + public bool Removed { get; set; } + + [NotMapped] + public long BytesRemaining => Size - BytesTransferred; + [NotMapped] + public TimeSpan? ElapsedTime => StartedAt == null ? null : (EndedAt ?? DateTime.UtcNow) - StartedAt.Value; + [NotMapped] + public double PercentComplete => Size == 0 ? 0 : (BytesTransferred / (double)Size) * 100; + [NotMapped] + public TimeSpan? RemainingTime => AverageSpeed == 0 ? null : TimeSpan.FromSeconds(BytesRemaining / AverageSpeed); } \ No newline at end of file -- cgit v1.2.3