aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Application.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-03-15 07:36:22 -0500
committerGitHub <noreply@github.com>2022-03-15 07:36:22 -0500
commit0464030d853df284b97c8e12fd1338f9bf9649a3 (patch)
tree3967eb7d33f1a073effe98754e5f6c418522f9cd /src/slskd/Application.cs
parentf28d1171d11007bbb931425e246f6d232341163a (diff)
parent88850904cb1af6b92b7d9dad50c89fc1899d7d1a (diff)
downloadslskd-0464030d853df284b97c8e12fd1338f9bf9649a3.tar.gz
Merge pull request #386 from slskd/dnet-logs
Log distributed messages as debug, add distributed state
Diffstat (limited to 'src/slskd/Application.cs')
-rw-r--r--src/slskd/Application.cs34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs
index 618027bc..72478bde 100644
--- a/src/slskd/Application.cs
+++ b/src/slskd/Application.cs
@@ -136,6 +136,7 @@ namespace slskd
Client.Connected += Client_Connected;
Client.LoggedIn += Client_LoggedIn;
Client.StateChanged += Client_StateChanged;
+ Client.DistributedNetworkStateChanged += Client_DistributedNetworkStateChanged;
Client.DownloadDenied += (e, args) => Log.Information("Download of {Filename} from {Username} was denied: {Message}", args.Filename, args.Username, args.Message);
Client.DownloadFailed += (e, args) => Log.Information("Download of {Filename} from {Username} failed", args.Filename, args.Username);
}
@@ -366,13 +367,13 @@ namespace slskd
static LogEventLevel TranslateLogLevel(DiagnosticLevel diagnosticLevel) => diagnosticLevel switch
{
DiagnosticLevel.Debug => LogEventLevel.Debug,
- DiagnosticLevel.Info => LogEventLevel.Information,
+ DiagnosticLevel.Info => LogEventLevel.Debug,
DiagnosticLevel.Warning => LogEventLevel.Warning,
DiagnosticLevel.None => default,
_ => default,
};
- var logger = Loggers.GetOrAdd(sender.GetType().FullName, Log.ForContext("SourceContext", "Soulseek").ForContext("SoulseekContext", sender.GetType().FullName));
+ var logger = Loggers.GetOrAdd(sender.GetType().FullName, Log.ForContext("Context", "Soulseek").ForContext("SubContext", sender.GetType().FullName));
logger.Write(TranslateLogLevel(args.Level), "{@Message}", args.Message);
}
@@ -483,7 +484,34 @@ namespace slskd
private void Client_StateChanged(object sender, SoulseekClientStateChangedEventArgs e)
{
- State.SetValue(state => state with { Server = state.Server with { Address = Client.Address, IPEndPoint = Client.IPEndPoint, State = Client.State, Username = Client.Username } });
+ State.SetValue(state => state with
+ {
+ Server = state.Server with
+ {
+ Address = Client.Address,
+ IPEndPoint = Client.IPEndPoint,
+ State = Client.State,
+ Username = Client.Username,
+ },
+ });
+ }
+
+ private void Client_DistributedNetworkStateChanged(object sender, DistributedNetworkInfo e)
+ {
+ State.SetValue(state => state with
+ {
+ DistributedNetwork = new DistributedNetworkState()
+ {
+ BranchLevel = e.BranchLevel,
+ BranchRoot = e.BranchRoot,
+ CanAcceptChildren = e.CanAcceptChildren,
+ ChildLimit = e.ChildLimit,
+ Children = e.Children.Select(c => c.Username).ToList().AsReadOnly(),
+ HasParent = e.HasParent,
+ IsBranchRoot = e.IsBranchRoot,
+ Parent = e.Parent.Username,
+ },
+ });
}
private void Client_TransferProgressUpdated(object sender, TransferProgressUpdatedEventArgs args)