diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2022-01-31 22:51:45 -0600 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2022-01-31 22:51:45 -0600 |
| commit | 4d2ae22106b88d80873b80abea58f9c3b9c3530f (patch) | |
| tree | 84ee091bbb9f8b39a052167419cd58106f9679b0 /src/slskd/Application.cs | |
| parent | 6f2fae7c40c53021f6326e4a4ea3ab705a0360b1 (diff) | |
| download | slskd-4d2ae22106b88d80873b80abea58f9c3b9c3530f.tar.gz | |
rough in UploadQueue
Diffstat (limited to 'src/slskd/Application.cs')
| -rw-r--r-- | src/slskd/Application.cs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index d1257b21..3e91e99e 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -69,6 +69,7 @@ namespace slskd ISharedFileCache sharedFileCache, IPushbulletService pushbulletService, IGovernor governor, + IUploadQueue uploadQueue, IHubContext<ApplicationHub> applicationHub, IHubContext<LogsHub> logHub) { @@ -91,6 +92,7 @@ namespace slskd Pushbullet = pushbulletService; Governor = governor; + UploadQueue = uploadQueue; RoomService = roomService; ApplicationHub = applicationHub; @@ -129,6 +131,7 @@ namespace slskd private IBrowseTracker BrowseTracker { get; set; } private IConversationTracker ConversationTracker { get; set; } private IGovernor Governor { get; set; } + private IUploadQueue UploadQueue { get; set; } private ILogger Log { get; set; } = Serilog.Log.ForContext<Application>(); private ConcurrentDictionary<string, ILogger> Loggers { get; } = new ConcurrentDictionary<string, ILogger>(); private Options Options => OptionsMonitor.CurrentValue; @@ -552,10 +555,20 @@ namespace slskd // create a new cancellation token source so that we can cancel the upload from the UI. var cts = new CancellationTokenSource(); var topts = new TransferOptions( - stateChanged: (e) => tracker.AddOrUpdate(e, cts), + stateChanged: (e) => + { + tracker.AddOrUpdate(e, cts); + + if (e.Transfer.State.HasFlag(TransferStates.Queued)) + { + UploadQueue.Enqueue(e.Transfer); + } + }, progressUpdated: (e) => tracker.AddOrUpdate(e, cts), governor: (tx, req, ct) => Governor.GetBytesAsync(tx, req, ct), - reporter: (tx, att, grant, act) => Governor.ReturnBytes(tx, att, grant, act)); + reporter: (tx, att, grant, act) => Governor.ReturnBytes(tx, att, grant, act), + slotAwaiter: (tx, ct) => UploadQueue.StartAsync(tx), + slotReleased: (tx) => UploadQueue.Complete(tx)); // accept all download requests, and begin the upload immediately. normally there would be an internal queue, and // uploads would be handled separately. @@ -563,6 +576,7 @@ namespace slskd { using var stream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read); await Client.UploadAsync(username, filename, fileInfo.FullName, options: topts, cancellationToken: cts.Token); + }).ContinueWith(t => { Console.WriteLine($"[UPLOAD FAILED] {t.Exception}"); |
