diff --git a/Shadowsocks.WPF/Models/Server.cs b/Shadowsocks.WPF/Models/Server.cs
index 9e5c6107..477bb7ff 100644
--- a/Shadowsocks.WPF/Models/Server.cs
+++ b/Shadowsocks.WPF/Models/Server.cs
@@ -3,28 +3,19 @@ namespace Shadowsocks.WPF.Models
public class Server : Shadowsocks.Models.Server
{
///
- /// Gets or sets the arguments passed to the plugin process.
+ /// Gets or sets the amount of data ingress in bytes.
///
- public string PluginArgs { get; set; }
+ public ulong BytesIngress { get; set; }
- public Server()
- {
- PluginArgs = "";
- }
+ ///
+ /// Gets or sets the amount of data egress in bytes.
+ ///
+ public ulong BytesEgress { get; set; }
- public Server(
- string name,
- string uuid,
- string host,
- int port,
- string password,
- string method,
- string plugin = "",
- string pluginOpts = "",
- string pluginArgs = "")
- : base(name, uuid, host, port, password, method, plugin, pluginOpts)
+ public Server()
{
- PluginArgs = pluginArgs;
+ BytesIngress = 0UL;
+ BytesEgress = 0UL;
}
}
}
diff --git a/Shadowsocks.WPF/Services/Sip003Plugin.cs b/Shadowsocks.WPF/Services/Sip003Plugin.cs
index 2da18b72..2f136958 100644
--- a/Shadowsocks.WPF/Services/Sip003Plugin.cs
+++ b/Shadowsocks.WPF/Services/Sip003Plugin.cs
@@ -1,5 +1,6 @@
using Shadowsocks.WPF.Models;
using System;
+using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
@@ -40,7 +41,7 @@ namespace Shadowsocks.WPF.Services
showPluginOutput);
}
- private Sip003Plugin(string plugin, string pluginOpts, string pluginArgs, string serverAddress, int serverPort, bool showPluginOutput)
+ private Sip003Plugin(string plugin, string pluginOpts, List pluginArgs, string serverAddress, int serverPort, bool showPluginOutput)
{
if (plugin == null) throw new ArgumentNullException(nameof(plugin));
if (string.IsNullOrWhiteSpace(serverAddress))
@@ -52,24 +53,27 @@ namespace Shadowsocks.WPF.Services
throw new ArgumentOutOfRangeException("serverPort");
}
- _pluginProcess = new Process
+ var pluginProcessStartInfo = new ProcessStartInfo
{
- StartInfo = new ProcessStartInfo
- {
- FileName = plugin,
- Arguments = pluginArgs,
- UseShellExecute = false,
- CreateNoWindow = !showPluginOutput,
- ErrorDialog = false,
- WindowStyle = ProcessWindowStyle.Hidden,
- WorkingDirectory = Utils.Utilities.WorkingDirectory ?? Environment.CurrentDirectory,
- Environment =
+ FileName = plugin,
+ UseShellExecute = false,
+ CreateNoWindow = !showPluginOutput,
+ ErrorDialog = false,
+ WindowStyle = ProcessWindowStyle.Hidden,
+ WorkingDirectory = Utils.Utilities.WorkingDirectory ?? Environment.CurrentDirectory,
+ Environment =
{
["SS_REMOTE_HOST"] = serverAddress,
["SS_REMOTE_PORT"] = serverPort.ToString(),
["SS_PLUGIN_OPTIONS"] = pluginOpts
}
- }
+ };
+ foreach (var arg in pluginArgs)
+ pluginProcessStartInfo.ArgumentList.Add(arg);
+
+ _pluginProcess = new Process()
+ {
+ StartInfo = pluginProcessStartInfo,
};
}
diff --git a/Shadowsocks/Models/IServer.cs b/Shadowsocks/Models/IServer.cs
index e4f65798..82cdcf9f 100644
--- a/Shadowsocks/Models/IServer.cs
+++ b/Shadowsocks/Models/IServer.cs
@@ -5,14 +5,43 @@ namespace Shadowsocks.Models
{
public interface IServer : IEquatable
{
+ ///
+ /// Gets or sets the server address.
+ ///
[JsonPropertyName("server")]
public string Host { get; set; }
+
+ ///
+ /// Gets or sets the server port.
+ ///
[JsonPropertyName("server_port")]
public int Port { get; set; }
+
+ ///
+ /// Gets or sets the password for the server.
+ ///
public string Password { get; set; }
+
+ ///
+ /// Gets or sets the method used for the server.
+ ///
public string Method { get; set; }
+
+ ///
+ /// Gets or sets the plugin executable filename.
+ ///
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public string Plugin { get; set; }
+
+ ///
+ /// Gets or sets the plugin options passed as environment variables.
+ ///
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public string PluginOpts { get; set; }
+
+ ///
+ /// Gets or sets the server name.
+ ///
[JsonPropertyName("remarks")]
public string Name { get; set; }
}
diff --git a/Shadowsocks/Models/Server.cs b/Shadowsocks/Models/Server.cs
index cc1212d5..6f9c276c 100644
--- a/Shadowsocks/Models/Server.cs
+++ b/Shadowsocks/Models/Server.cs
@@ -7,16 +7,39 @@ namespace Shadowsocks.Models
{
public class Server : IServer
{
+ ///
[JsonPropertyName("server")]
public string Host { get; set; }
+
+ ///
[JsonPropertyName("server_port")]
public int Port { get; set; }
+
+ ///
public string Password { get; set; }
+
+ ///
public string Method { get; set; }
+
+ ///
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public string Plugin { get; set; }
+
+ ///
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public string PluginOpts { get; set; }
+
+ ///
+ /// Gets or sets the arguments passed to the plugin process.
+ ///
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
+ public List PluginArgs { get; set; }
+
+ ///
[JsonPropertyName("remarks")]
public string Name { get; set; }
+
+ ///
[JsonPropertyName("id")]
public string Uuid { get; set; }
@@ -28,30 +51,11 @@ namespace Shadowsocks.Models
Method = "chacha20-ietf-poly1305";
Plugin = "";
PluginOpts = "";
+ PluginArgs = new();
Name = "";
Uuid = "";
}
- public Server(
- string name,
- string uuid,
- string host,
- int port,
- string password,
- string method,
- string plugin = "",
- string pluginOpts = "")
- {
- Host = host;
- Port = port;
- Password = password;
- Method = method;
- Plugin = plugin;
- PluginOpts = pluginOpts;
- Name = name;
- Uuid = uuid;
- }
-
public bool Equals(IServer? other) => other is Server anotherServer && Uuid == anotherServer.Uuid;
public override int GetHashCode() => Uuid.GetHashCode();
public override string ToString() => Name;
@@ -95,7 +99,15 @@ namespace Shadowsocks.Models
var userinfoSplitArray = userinfo.Split(':', 2);
var method = userinfoSplitArray[0];
var password = userinfoSplitArray[1];
- server = new Server(uri.Fragment, new Guid().ToString(), uri.Host, uri.Port, password, method);
+ server = new Server()
+ {
+ Name = uri.Fragment,
+ Uuid = new Guid().ToString(),
+ Host = uri.Host,
+ Port = uri.Port,
+ Password = password,
+ Method = method,
+ };
// find the plugin query
var parsedQueriesArray = uri.Query.Split("?&");
var pluginQueryContent = "";