From 9c8626f6a961851deff42d1bba7738dbbc06df75 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 7 Mar 2022 08:24:43 -0600 Subject: add SubContext --- src/slskd/Common/Logging/LogRecord.cs | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/slskd/Common/Logging/LogRecord.cs b/src/slskd/Common/Logging/LogRecord.cs index 49e00276..0ca3534c 100644 --- a/src/slskd/Common/Logging/LogRecord.cs +++ b/src/slskd/Common/Logging/LogRecord.cs @@ -23,6 +23,7 @@ namespace slskd { public DateTime Timestamp { get; init; } public string Context { get; init; } + public string SubContext { get; init; } public string Level { get; init; } public string Message { get; init; } } -- cgit v1.2.3 From cc79e2c9fd3ceeee81c34e44d697e59e8f1fb6a1 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 7 Mar 2022 08:32:14 -0600 Subject: log info diagnostics as debug --- src/slskd/Application.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 618027bc..6d874f97 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -366,13 +366,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); } -- cgit v1.2.3 From c634773eeb520c9b7a997d68651fafd4e93f64be Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 7 Mar 2022 08:32:29 -0600 Subject: tweak context/subcontext --- src/slskd/Program.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 6a399a02..0857ef4d 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -277,11 +277,11 @@ namespace slskd .Enrich.WithProperty("ProcessId", ProcessId) .Enrich.FromLogContext() .WriteTo.Console( - outputTemplate: (OptionsAtStartup.Debug ? "[{SourceContext}] [{SoulseekContext}] " : string.Empty) + "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}") + outputTemplate: (OptionsAtStartup.Debug ? "[{SubContext}] " : string.Empty) + "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}") .WriteTo.Async(config => config.File( Path.Combine(AppDirectory, "logs", $"{AppName}-.log"), - outputTemplate: (OptionsAtStartup.Debug ? "[{SourceContext}] " : string.Empty) + "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}", + outputTemplate: (OptionsAtStartup.Debug ? "[{SubContext}] " : string.Empty) + "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}", rollingInterval: RollingInterval.Day)) .WriteTo.Conditional( e => !string.IsNullOrEmpty(OptionsAtStartup.Logger.Loki), @@ -293,7 +293,8 @@ namespace slskd var record = new LogRecord() { Timestamp = logEvent.Timestamp.LocalDateTime, - Context = logEvent.Properties["SourceContext"].ToString().TrimStart('"').TrimEnd('"'), + Context = logEvent.Properties["Context"].ToString().TrimStart('"').TrimEnd('"'), + SubContext = logEvent.Properties["SubContext"].ToString().TrimStart('"').TrimEnd('"'), Level = logEvent.Level.ToString(), Message = logEvent.RenderMessage().TrimStart('"').TrimEnd('"'), }; -- cgit v1.2.3 From ed55302b09e51f48fc1064d5d8e5c2178b388954 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 14 Mar 2022 07:27:09 -0500 Subject: bump Soulseek.NET to 4.5.0 --- src/slskd/slskd.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/slskd.csproj b/src/slskd/slskd.csproj index 4b7ebe1d..70c689b8 100644 --- a/src/slskd/slskd.csproj +++ b/src/slskd/slskd.csproj @@ -69,7 +69,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive -- cgit v1.2.3 From 5d802f45166fea9f4986d46428ec21bf27474721 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 14 Mar 2022 08:02:30 -0500 Subject: add DistributedNetworkState --- src/slskd/State.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src') diff --git a/src/slskd/State.cs b/src/slskd/State.cs index bd82f8d7..71807728 100644 --- a/src/slskd/State.cs +++ b/src/slskd/State.cs @@ -18,6 +18,7 @@ namespace slskd { using System; + using System.Collections.Generic; using System.Net; using System.Text.Json.Serialization; using slskd.Users; @@ -33,6 +34,7 @@ namespace slskd public bool PendingRestart { get; init; } public bool PendingShareRescan { get; init; } public ServerState Server { get; init; } = new ServerState(); + public DistributedNetworkState DistributedNetwork { get; init; } = new DistributedNetworkState(); public SharedFileCacheState SharedFileCache { get; init; } = new SharedFileCacheState(); public string[] Rooms { get; init; } = Array.Empty(); public User[] Users { get; init; } = Array.Empty(); @@ -61,6 +63,18 @@ namespace slskd public bool IsTransitioning => State.HasFlag(SoulseekClientStates.Connecting) || State.HasFlag(SoulseekClientStates.Disconnecting) || State.HasFlag(SoulseekClientStates.LoggingIn); } + public record DistributedNetworkState + { + public int BranchLevel { get; init; } + public string BranchRoot { get; init; } + public bool CanAcceptChildren { get; init; } + public int ChildLimit { get; init; } + public IReadOnlyCollection<(string Username, IPEndPoint IPEndPoint)> Children { get; init; } + public bool HasParent { get; init; } + public bool IsBranchRoot { get; init; } + public (string Username, IPEndPoint IPEndPoint) Parent { get; init; } + } + /// /// Share cache state. /// -- cgit v1.2.3 From e76c22000ae02e01cefd21d17e06817c1eeb78a4 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 14 Mar 2022 08:02:40 -0500 Subject: handle DistributedNetworkStateChanged --- src/slskd/Application.cs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 6d874f97..4ae5ea6d 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); } @@ -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, + HasParent = e.HasParent, + IsBranchRoot = e.IsBranchRoot, + Parent = e.Parent, + }, + }); } private void Client_TransferProgressUpdated(object sender, TransferProgressUpdatedEventArgs args) -- cgit v1.2.3 From ba76c59f806a45f77c6179dfc4166d7a75bd843b Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 14 Mar 2022 08:17:41 -0500 Subject: only include usernames for distributed parent and children --- src/slskd/Application.cs | 4 ++-- src/slskd/State.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 4ae5ea6d..72478bde 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -506,10 +506,10 @@ namespace slskd BranchRoot = e.BranchRoot, CanAcceptChildren = e.CanAcceptChildren, ChildLimit = e.ChildLimit, - Children = e.Children, + Children = e.Children.Select(c => c.Username).ToList().AsReadOnly(), HasParent = e.HasParent, IsBranchRoot = e.IsBranchRoot, - Parent = e.Parent, + Parent = e.Parent.Username, }, }); } diff --git a/src/slskd/State.cs b/src/slskd/State.cs index 71807728..0daa5d76 100644 --- a/src/slskd/State.cs +++ b/src/slskd/State.cs @@ -69,10 +69,10 @@ namespace slskd public string BranchRoot { get; init; } public bool CanAcceptChildren { get; init; } public int ChildLimit { get; init; } - public IReadOnlyCollection<(string Username, IPEndPoint IPEndPoint)> Children { get; init; } + public IReadOnlyCollection Children { get; init; } public bool HasParent { get; init; } public bool IsBranchRoot { get; init; } - public (string Username, IPEndPoint IPEndPoint) Parent { get; init; } + public string Parent { get; init; } } /// -- cgit v1.2.3