From 984247a4964a299bf83af78bfd509ffa4e7557be Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 15 May 2021 14:57:30 -0500 Subject: add proxy to example yml --- src/slskd/Properties/slskd.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/slskd/Properties/slskd.yml b/src/slskd/Properties/slskd.yml index c049aa7a..ccfe60f9 100644 --- a/src/slskd/Properties/slskd.yml +++ b/src/slskd/Properties/slskd.yml @@ -39,8 +39,13 @@ # child_limit: 25 # connection: # timeout: -# connect: 5000 +# connect: 10000 # inactivity: 15000 # buffer: # read: 16384 -# write: 16384 \ No newline at end of file +# write: 16384 +# proxy: +# address: ~ +# port: ~ +# username: ~ +# password: ~ \ No newline at end of file -- cgit v1.2.3 From fa21ad5fc45c4453a80b33059c2aadaaabeaea74 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 15 May 2021 14:57:47 -0500 Subject: add proxy options --- src/slskd/Options.cs | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index 6074d650..59cc8a11 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -264,6 +264,12 @@ namespace slskd [Validate] public BufferOptions Buffer { get; private set; } = new BufferOptions(); + /// + /// Gets connection proxy options. + /// + [Validate] + public ProxyOptions Proxy { get; private set; } = new ProxyOptions(); + /// /// Connection buffer options. /// @@ -300,7 +306,7 @@ namespace slskd [EnvironmentVariable("SLSK_CONNECTION_TIMEOUT")] [Description("connection timeout, in milliseconds")] [Range(1000, int.MaxValue)] - public int Connect { get; private set; } = 5000; + public int Connect { get; private set; } = 10000; /// /// Gets the connection inactivity timeout, in milliseconds. @@ -311,6 +317,48 @@ namespace slskd [Range(1000, int.MaxValue)] public int Inactivity { get; private set; } = 15000; } + + /// + /// Connection proxy options. + /// + public class ProxyOptions + { + /// + /// Gets the proxy address. + /// + [Argument(default, "slsk-proxy-address")] + [EnvironmentVariable("SLSK_PROXY_ADDRESS")] + [Description("connection proxy address")] + [StringLength(255, MinimumLength = 1)] + public string Address { get; private set; } + + /// + /// Gets the proxy port. + /// + [Argument(default, "slsk-proxy-port")] + [EnvironmentVariable("SLSK_PROXY_PORT")] + [Description("connection proxy port")] + [Range(1, 65535)] + public int Port { get; private set; } + + /// + /// Gets the proxy username, if applicable. + /// + [Argument(default, "slsk-proxy-username")] + [EnvironmentVariable("SLSK_PROXY_USERNAME")] + [Description("connection proxy username")] + [StringLength(255, MinimumLength = 1)] + public string Username { get; private set; } + + /// + /// Gets the proxy password, if applicable. + /// + [Argument(default, "slsk-proxy-password")] + [EnvironmentVariable("SLSK_PROXY_PASSWORD")] + [Description("connection proxy password")] + [StringLength(255, MinimumLength = 1)] + public string Password { get; private set; } + } } /// -- cgit v1.2.3 From 0e75d9e7fdc2f35c0862994cb298f1560281cec0 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 15 May 2021 14:57:58 -0500 Subject: use proxy options when instantiating SoulseekClient --- src/slskd/Service.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Service.cs b/src/slskd/Service.cs index 7f5c1901..d7ea664e 100644 --- a/src/slskd/Service.cs +++ b/src/slskd/Service.cs @@ -54,11 +54,18 @@ namespace slskd RoomTracker = roomTracker; SharedFileCache = sharedFileCache; + var proxyOptions = new ProxyOptions( + address: Options.Soulseek.Connection.Proxy.Address, + port: Options.Soulseek.Connection.Proxy.Port, + username: Options.Soulseek.Connection.Proxy.Username, + password: Options.Soulseek.Connection.Proxy.Password); + var connectionOptions = new ConnectionOptions( readBufferSize: Options.Soulseek.Connection.Buffer.Read, writeBufferSize: Options.Soulseek.Connection.Buffer.Write, connectTimeout: Options.Soulseek.Connection.Timeout.Connect, - inactivityTimeout: Options.Soulseek.Connection.Timeout.Inactivity); + inactivityTimeout: Options.Soulseek.Connection.Timeout.Inactivity, + proxyOptions: proxyOptions); var clientOptions = new SoulseekClientOptions( listenPort: Options.Soulseek.ListenPort, @@ -72,6 +79,7 @@ namespace slskd serverConnectionOptions: connectionOptions, peerConnectionOptions: connectionOptions, transferConnectionOptions: connectionOptions, + distributedConnectionOptions: connectionOptions, userInfoResponseResolver: UserInfoResponseResolver, browseResponseResolver: BrowseResponseResolver, directoryContentsResponseResolver: DirectoryContentsResponseResolver, -- cgit v1.2.3 From fe6cb87f7a24cd09149c1bf5a90954c52dace426 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 16 May 2021 23:25:13 -0500 Subject: make proxy port nullable --- src/slskd/Options.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index 59cc8a11..efd689d5 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -339,7 +339,7 @@ namespace slskd [EnvironmentVariable("SLSK_PROXY_PORT")] [Description("connection proxy port")] [Range(1, 65535)] - public int Port { get; private set; } + public int? Port { get; private set; } /// /// Gets the proxy username, if applicable. -- cgit v1.2.3 From 00cd66c8e74488244220f1c5e6cbb59253c022b1 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 16 May 2021 23:28:11 -0500 Subject: don't set proxy options if none are supplied. log info when using proxy --- src/slskd/Service.cs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/slskd/Service.cs b/src/slskd/Service.cs index d7ea664e..8daab772 100644 --- a/src/slskd/Service.cs +++ b/src/slskd/Service.cs @@ -54,11 +54,16 @@ namespace slskd RoomTracker = roomTracker; SharedFileCache = sharedFileCache; - var proxyOptions = new ProxyOptions( - address: Options.Soulseek.Connection.Proxy.Address, - port: Options.Soulseek.Connection.Proxy.Port, - username: Options.Soulseek.Connection.Proxy.Username, - password: Options.Soulseek.Connection.Proxy.Password); + ProxyOptions proxyOptions = default; + + if (UsingProxy) + { + proxyOptions = new ProxyOptions( + address: Options.Soulseek.Connection.Proxy.Address, + port: Options.Soulseek.Connection.Proxy.Port.Value, + username: Options.Soulseek.Connection.Proxy.Username, + password: Options.Soulseek.Connection.Proxy.Password); + } var connectionOptions = new ConnectionOptions( readBufferSize: Options.Soulseek.Connection.Buffer.Read, @@ -129,11 +134,17 @@ namespace slskd private IRoomTracker RoomTracker { get; set; } private ISharedFileCache SharedFileCache { get; set; } private ITransferTracker TransferTracker { get; set; } + private bool UsingProxy => !string.IsNullOrWhiteSpace(Options.Soulseek.Connection.Proxy.Address) && Options.Soulseek.Connection.Proxy.Port.HasValue; public async Task StartAsync(CancellationToken cancellationToken) { await Client.ConnectAsync(Options.Soulseek.Username, Options.Soulseek.Password).ConfigureAwait(false); + if (UsingProxy) + { + Logger.Information($"Using Proxy {Options.Soulseek.Connection.Proxy.Address}:{Options.Soulseek.Connection.Proxy.Port}"); + } + Logger.Information("Connected and logged in as {Username}", Options.Soulseek.Username); Logger.Information("Listening on port {Port}", Options.Soulseek.ListenPort); Logger.Information("Client started"); @@ -403,7 +414,7 @@ namespace slskd { var info = new UserInfo( description: $"Soulseek.NET Web Example! also, your username is {username}, and IP endpoint is {endpoint}", - picture: System.IO.File.ReadAllBytes(@"slsk_bird.jpg"), + picture: Array.Empty(), uploadSlots: 1, queueLength: 0, hasFreeUploadSlot: false); -- cgit v1.2.3 From d6434c02da80e499a357954f685ffedef49b4d66 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 16 May 2021 23:36:33 -0500 Subject: add ToColloquialString() --- src/slskd/Common/Extensions.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/slskd/Common/Extensions.cs b/src/slskd/Common/Extensions.cs index 4e08ed02..4bf9f919 100644 --- a/src/slskd/Common/Extensions.cs +++ b/src/slskd/Common/Extensions.cs @@ -43,6 +43,17 @@ namespace slskd return string.Join(separator, parts.Take(parts.Length - 1)); } + /// + /// Returns a "pretty" string representation of the provided Type; specifically, corrects the naming of generic Types + /// and appends the type parameters for the type to the name as it appears in the code editor. + /// + /// The type for which the colloquial name should be created. + /// A "pretty" string representation of the provided Type. + public static string ToColloquialString(this Type type) + { + return !type.IsGenericType ? type.Name : type.Name.Split('`')[0] + "<" + string.Join(", ", type.GetGenericArguments().Select(a => a.ToColloquialString())) + ">"; + } + /// /// Returns the SHA1 hash of the given string. /// -- cgit v1.2.3 From 2ebcc6f312d337d1bb4412b41781a973fb253aed Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 16 May 2021 23:36:50 -0500 Subject: show friendly name of option types --- src/slskd/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index d70b50c1..f7d3fd66 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -408,7 +408,7 @@ namespace slskd private static void PrintCommandLineArguments(Type targetType) { static string GetLongName(string longName, Type type) - => type == typeof(bool) ? longName : $"{longName} <{type.Name.ToLowerInvariant()}>"; + => type == typeof(bool) ? longName : $"{longName} <{type.ToColloquialString().ToLowerInvariant()}>"; var lines = new List<(string Item, string Description)>(); @@ -456,7 +456,7 @@ namespace slskd private static void PrintEnvironmentVariables(Type targetType, string prefix) { - static string GetName(string name, Type type) => $"{name} <{type.Name.ToLowerInvariant()}>"; + static string GetName(string name, Type type) => $"{name} <{type.ToColloquialString().ToLowerInvariant()}>"; var lines = new List<(string Item, string Description)>(); -- cgit v1.2.3