diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-04-30 23:45:02 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-04-30 23:45:02 -0500 |
| commit | e3f6063d841933c3dcc6b16674613458a95c8c6f (patch) | |
| tree | f229a9fb42e9316876fd881a117ed8d2077da20e /src | |
| parent | eba232fe9de343359b96ca4686c5414912d4b276 (diff) | |
| download | slskd-e3f6063d841933c3dcc6b16674613458a95c8c6f.tar.gz | |
fix up transfer
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Transfers/Types/Transfer.cs | 205 |
1 files changed, 139 insertions, 66 deletions
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 @@ // </copyright> namespace slskd.Transfers; + +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Text.Json.Serialization; +using Soulseek; + +/// <summary> +/// A file Transfer between network peers. +/// </summary> +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; } - - /// <summary> - /// Gets the remote filename. - /// </summary> - public string Filename { get; init; } - public long Size { get; set; } - public long StartOffset { get; init; } - - public TransferStates State { get; set; } = TransferStates.None; - - /// <summary> - /// Gets the string representation of the transfer <see cref="State"/>. - /// </summary> - /// <remarks> - /// 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. - /// </remarks> - public string StateDescription { get; set; } - public DateTime RequestedAt { get; set; } - public DateTime? EnqueuedAt { get; set; } - public DateTime? StartedAt { get; set; } - - /// <summary> - /// The time at which the transfer ended, or null if the transfer has not yet started or is in progress. - /// </summary> - /// <remarks> - /// Guaranteed to be set for transfers in a terminal state. - /// </remarks> - 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); - } + /// <summary> + /// Gets the associated <see cref="Batch.Id"/>, if one was specified when the Transfer was created. + /// </summary> + public Guid? BatchId { get; init; } = null; + + /// <summary> + /// Gets the unique identifier for the Transfer. + /// </summary> + [Key] + public Guid Id { get; init; } + + /// <summary> + /// Gets the remote username associated with the Transfer. + /// </summary> + public string Username { get; init; } + + /// <summary> + /// Gets the Transfer direction (Upload, Download). + /// </summary> + public TransferDirection Direction { get; init; } + + /// <summary> + /// Gets the remote filename of the file. + /// </summary> + /// <remarks> + /// Exactly as it appeared in the originating Search, Browse, or file directory contents response. + /// </remarks> + public string Filename { get; init; } + + /// <summary> + /// Gets or sets the remote size of the file. + /// </summary> + public long Size { get; set; } + + /// <summary> + /// Gets or sets the state of the Transfer. + /// </summary> + public TransferStates State { get; set; } = TransferStates.None; + + /// <summary> + /// Gets or sets the string representation of the transfer <see cref="State"/>. + /// </summary> + /// <remarks> + /// 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. + /// </remarks> + public string StateDescription { get; set; } + + /// <summary> + /// Gets or sets the time at which the Transfer was requested from the remote peer. + /// </summary> + public DateTime RequestedAt { get; set; } + + /// <summary> + /// Gets or sets the time at which the Transfer was enqueued, or null if the Transfer has not yet been enqueued. + /// </summary> + /// <remarks> + /// 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. + /// </remarks> + public DateTime? EnqueuedAt { get; set; } + + /// <summary> + /// 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. + /// </summary> + public DateTime? StartedAt { get; set; } + + /// <summary> + /// Gets or sets the time at which the Transfer ended, or null if the Transfer has not yet started or is still in progress. + /// </summary> + /// <remarks> + /// Guaranteed to be set for transfers in a terminal state. + /// </remarks> + public DateTime? EndedAt { get; set; } + + /// <summary> + /// Gets or sets the number of bytes transferred. + /// </summary> + public long BytesTransferred { get; set; } + + /// <summary> + /// Gets or sets the average speed of the Transfer over the duration. + /// </summary> + public double AverageSpeed { get; set; } + + /// <summary> + /// Gets or sets the current place in line in the remote peer's queue, if place has been requested. + /// </summary> + /// <remarks> + /// May be wildly innacurate to the point of uselessness. + /// </remarks> + public int? PlaceInQueue { get; set; } + + /// <summary> + /// Gets or sets the associated Exception, if the Transfer did not end successfully, or null if it did. + /// </summary> + public string Exception { get; set; } + + /// <summary> + /// Gets or sets the number of attempts. Incremented each time the Transfer is retried. + /// </summary> + /// <remarks> + /// Applicable to downloads only. + /// </remarks> + public int Attempts { get; set; } = 0; + + /// <summary> + /// Gets or sets the time at which the next retry attempt will be made, if applicable. + /// </summary> + public DateTime? NextAttemptAt { get; set; } = null; + + /// <summary> + /// Gets or sets a value indicating whether the Transfer has been removed from the UI. + /// </summary> + [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 |
