aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-05-17 08:27:23 -0500
committerGitHub <noreply@github.com>2021-05-17 08:27:23 -0500
commit7b3bfb3ab5ee3f075fa63cef81e38c117f7f8ac8 (patch)
treed4d6dd89af90d005c4c9db4ee1232c2e5a969733 /src
parente22472791be56eb3b44d7af7064400aa5e6ef9fc (diff)
parent2ebcc6f312d337d1bb4412b41781a973fb253aed (diff)
downloadslskd-7b3bfb3ab5ee3f075fa63cef81e38c117f7f8ac8.tar.gz
Merge pull request #72 from slskd/proxy
Add SOCKS5 proxy support
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Common/Extensions.cs11
-rw-r--r--src/slskd/Options.cs50
-rw-r--r--src/slskd/Program.cs4
-rw-r--r--src/slskd/Properties/slskd.yml9
-rw-r--r--src/slskd/Service.cs23
5 files changed, 90 insertions, 7 deletions
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
@@ -44,6 +44,17 @@ namespace slskd
}
/// <summary>
+ /// 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.
+ /// </summary>
+ /// <param name="type">The type for which the colloquial name should be created.</param>
+ /// <returns>A "pretty" string representation of the provided Type.</returns>
+ public static string ToColloquialString(this Type type)
+ {
+ return !type.IsGenericType ? type.Name : type.Name.Split('`')[0] + "<" + string.Join(", ", type.GetGenericArguments().Select(a => a.ToColloquialString())) + ">";
+ }
+
+ /// <summary>
/// Returns the SHA1 hash of the given string.
/// </summary>
/// <param name="str">The string to hash.</param>
diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs
index 6074d650..efd689d5 100644
--- a/src/slskd/Options.cs
+++ b/src/slskd/Options.cs
@@ -265,6 +265,12 @@ namespace slskd
public BufferOptions Buffer { get; private set; } = new BufferOptions();
/// <summary>
+ /// Gets connection proxy options.
+ /// </summary>
+ [Validate]
+ public ProxyOptions Proxy { get; private set; } = new ProxyOptions();
+
+ /// <summary>
/// Connection buffer options.
/// </summary>
public class BufferOptions
@@ -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;
/// <summary>
/// Gets the connection inactivity timeout, in milliseconds.
@@ -311,6 +317,48 @@ namespace slskd
[Range(1000, int.MaxValue)]
public int Inactivity { get; private set; } = 15000;
}
+
+ /// <summary>
+ /// Connection proxy options.
+ /// </summary>
+ public class ProxyOptions
+ {
+ /// <summary>
+ /// Gets the proxy address.
+ /// </summary>
+ [Argument(default, "slsk-proxy-address")]
+ [EnvironmentVariable("SLSK_PROXY_ADDRESS")]
+ [Description("connection proxy address")]
+ [StringLength(255, MinimumLength = 1)]
+ public string Address { get; private set; }
+
+ /// <summary>
+ /// Gets the proxy port.
+ /// </summary>
+ [Argument(default, "slsk-proxy-port")]
+ [EnvironmentVariable("SLSK_PROXY_PORT")]
+ [Description("connection proxy port")]
+ [Range(1, 65535)]
+ public int? Port { get; private set; }
+
+ /// <summary>
+ /// Gets the proxy username, if applicable.
+ /// </summary>
+ [Argument(default, "slsk-proxy-username")]
+ [EnvironmentVariable("SLSK_PROXY_USERNAME")]
+ [Description("connection proxy username")]
+ [StringLength(255, MinimumLength = 1)]
+ public string Username { get; private set; }
+
+ /// <summary>
+ /// Gets the proxy password, if applicable.
+ /// </summary>
+ [Argument(default, "slsk-proxy-password")]
+ [EnvironmentVariable("SLSK_PROXY_PASSWORD")]
+ [Description("connection proxy password")]
+ [StringLength(255, MinimumLength = 1)]
+ public string Password { get; private set; }
+ }
}
/// <summary>
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)>();
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
diff --git a/src/slskd/Service.cs b/src/slskd/Service.cs
index 7f5c1901..8daab772 100644
--- a/src/slskd/Service.cs
+++ b/src/slskd/Service.cs
@@ -54,11 +54,23 @@ namespace slskd
RoomTracker = roomTracker;
SharedFileCache = sharedFileCache;
+ 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,
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 +84,7 @@ namespace slskd
serverConnectionOptions: connectionOptions,
peerConnectionOptions: connectionOptions,
transferConnectionOptions: connectionOptions,
+ distributedConnectionOptions: connectionOptions,
userInfoResponseResolver: UserInfoResponseResolver,
browseResponseResolver: BrowseResponseResolver,
directoryContentsResponseResolver: DirectoryContentsResponseResolver,
@@ -121,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");
@@ -395,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<byte>(),
uploadSlots: 1,
queueLength: 0,
hasFreeUploadSlot: false);