From ddf412139fd8c62facfb079d89406e7855fd93da Mon Sep 17 00:00:00 2001 From: database64128 Date: Sat, 21 Nov 2020 22:31:20 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=99=20Add=20type=20definitions=20for=20ss?= =?UTF-8?q?-rust=20and=20v2ray-core=20configs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Shadowsocks.Interop.csproj | 4 + Shadowsocks.Interop/SsRust/Config.cs | 113 +++++++++++++++++- Shadowsocks.Interop/V2Ray/ApiObject.cs | 37 ++++++ Shadowsocks.Interop/V2Ray/Config.cs | 48 ++++++-- Shadowsocks.Interop/V2Ray/Dns/ServerObject.cs | 39 ++++++ Shadowsocks.Interop/V2Ray/DnsObject.cs | 27 +++++ .../V2Ray/Inbound/AllocateObject.cs | 31 +++++ .../V2Ray/Inbound/SniffingObject.cs | 28 +++++ Shadowsocks.Interop/V2Ray/InboundObject.cs | 54 +++++++++ Shadowsocks.Interop/V2Ray/LogObject.cs | 31 +++++ .../V2Ray/Outbound/MuxObject.cs | 25 ++++ .../V2Ray/Outbound/ProxySettingsObject.cs | 16 +++ Shadowsocks.Interop/V2Ray/OutboundObject.cs | 86 +++++++++++++ .../V2Ray/Policy/LevelPolicyObject.cs | 24 ++++ .../V2Ray/Policy/SystemPolicyObject.cs | 18 +++ Shadowsocks.Interop/V2Ray/PolicyObject.cs | 26 ++++ .../V2Ray/Protocols/AccountObject.cs | 14 +++ .../Freedom/OutboundConfigurationObject.cs | 16 +++ .../Shadowsocks/InboundConfigurationObject.cs | 30 +++++ .../OutboundConfigurationObject.cs | 22 ++++ .../Protocols/Shadowsocks/ServerObject.cs | 43 +++++++ .../Socks/InboundConfigurationObject.cs | 27 +++++ .../Socks/OutboundConfigurationObject.cs | 23 ++++ .../V2Ray/Protocols/Socks/ServerObject.cs | 33 +++++ .../V2Ray/Protocols/Trojan/ClientObject.cs | 16 +++ .../V2Ray/Protocols/Trojan/FallbackObject.cs | 18 +++ .../Trojan/InboundConfigurationObject.cs | 16 +++ .../Trojan/OutboundConfigurationObject.cs | 22 ++++ .../V2Ray/Protocols/Trojan/ServerObject.cs | 29 +++++ .../V2Ray/Protocols/UserObject.cs | 7 ++ .../V2Ray/Protocols/VMess/DetourObject.cs | 12 ++ .../VMess/InboundConfigurationObject.cs | 18 +++ .../VMess/OutboundConfigurationObject.cs | 22 ++++ .../V2Ray/Protocols/VMess/ServerObject.cs | 28 +++++ .../V2Ray/Protocols/VMess/UserObject.cs | 26 ++++ .../V2Ray/Reverse/BridgeObject.cs | 22 ++++ .../V2Ray/Reverse/PortalObject.cs | 21 ++++ Shadowsocks.Interop/V2Ray/ReverseObject.cs | 17 +++ .../V2Ray/Routing/BalancerObject.cs | 24 ++++ .../V2Ray/Routing/RuleObject.cs | 40 +++++++ Shadowsocks.Interop/V2Ray/RoutingObject.cs | 32 +++++ Shadowsocks.Interop/V2Ray/StatsObject.cs | 6 + .../V2Ray/Transport/CertificateObject.cs | 22 ++++ .../V2Ray/Transport/DomainSocketObject.cs | 29 +++++ .../V2Ray/Transport/Header/HeaderObject.cs | 23 ++++ .../Header/Http/HttpRequestObject.cs | 47 ++++++++ .../Header/Http/HttpResponseObject.cs | 44 +++++++ .../Transport/Header/HttpHeaderObject.cs | 18 +++ .../V2Ray/Transport/HttpObject.cs | 16 +++ .../V2Ray/Transport/KcpObject.cs | 30 +++++ .../V2Ray/Transport/QuicObject.cs | 31 +++++ .../V2Ray/Transport/SockoptObject.cs | 16 +++ .../V2Ray/Transport/StreamSettingsObject.cs | 30 +++++ .../V2Ray/Transport/TcpObject.cs | 23 ++++ .../V2Ray/Transport/TlsObject.cs | 26 ++++ .../V2Ray/Transport/WebSocketObject.cs | 29 +++++ Shadowsocks.Interop/V2Ray/TransportObject.cs | 24 ++++ 57 files changed, 1586 insertions(+), 13 deletions(-) create mode 100644 Shadowsocks.Interop/V2Ray/ApiObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Dns/ServerObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/DnsObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Inbound/AllocateObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Inbound/SniffingObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/InboundObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/LogObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Outbound/MuxObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Outbound/ProxySettingsObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/OutboundObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Policy/LevelPolicyObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Policy/SystemPolicyObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/PolicyObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Protocols/AccountObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Protocols/Freedom/OutboundConfigurationObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Protocols/Shadowsocks/InboundConfigurationObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Protocols/Shadowsocks/OutboundConfigurationObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Protocols/Shadowsocks/ServerObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Protocols/Socks/InboundConfigurationObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Protocols/Socks/OutboundConfigurationObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Protocols/Socks/ServerObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Protocols/Trojan/ClientObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Protocols/Trojan/FallbackObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Protocols/Trojan/InboundConfigurationObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Protocols/Trojan/OutboundConfigurationObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Protocols/Trojan/ServerObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Protocols/UserObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Protocols/VMess/DetourObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Protocols/VMess/InboundConfigurationObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Protocols/VMess/OutboundConfigurationObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Protocols/VMess/ServerObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Protocols/VMess/UserObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Reverse/BridgeObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Reverse/PortalObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/ReverseObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Routing/BalancerObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Routing/RuleObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/RoutingObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/StatsObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Transport/CertificateObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Transport/DomainSocketObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Transport/Header/HeaderObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Transport/Header/Http/HttpRequestObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Transport/Header/Http/HttpResponseObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Transport/Header/HttpHeaderObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Transport/HttpObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Transport/KcpObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Transport/QuicObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Transport/SockoptObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Transport/StreamSettingsObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Transport/TcpObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Transport/TlsObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/Transport/WebSocketObject.cs create mode 100644 Shadowsocks.Interop/V2Ray/TransportObject.cs diff --git a/Shadowsocks.Interop/Shadowsocks.Interop.csproj b/Shadowsocks.Interop/Shadowsocks.Interop.csproj index 2991887b..2e8a8b98 100644 --- a/Shadowsocks.Interop/Shadowsocks.Interop.csproj +++ b/Shadowsocks.Interop/Shadowsocks.Interop.csproj @@ -5,4 +5,8 @@ enable + + + + diff --git a/Shadowsocks.Interop/SsRust/Config.cs b/Shadowsocks.Interop/SsRust/Config.cs index 1be66e0c..b29e854e 100644 --- a/Shadowsocks.Interop/SsRust/Config.cs +++ b/Shadowsocks.Interop/SsRust/Config.cs @@ -1,16 +1,117 @@ -using System; +using Shadowsocks.Models; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Text.Json.Serialization; namespace Shadowsocks.Interop.SsRust { - public class Config + public class Config : IGroup { + /// + public int Version { get; set; } + + /// + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + public List Servers { get; set; } + + /// + /// Gets or sets the listening address. + /// + public string LocalAddress { get; set; } + + /// + /// Gets or sets the listening port. + /// + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + public int LocalPort { get; set; } + + /// + /// Gets or sets the timeout for UDP associations in seconds. + /// Defaults to 300 seconds (5 minutes). + /// + public int UdpTimeout { get; set; } + + /// + /// Gets or sets the maximum number of UDP associations. + /// Defaults to 0 (unlimited). + /// + public int UdpMaxAssociations { get; set; } + + /// + /// Gets or sets the server manager address. + /// + public string ManagerAddress { get; set; } + + /// + /// Gets or sets the server manager port. + /// + public int ManagerPort { get; set; } + + /// + /// Gets or sets the DNS server used to resolve hostnames. + /// + public string Dns { get; set; } + + /// + /// Gets or sets the mode. + /// Defaults to tcp_only. + /// Can also be tcp_and_udp or udp_only. + /// + public string Mode { get; set; } + + /// + /// Gets or sets TCP_NODELAY. + /// Defaults to false. + /// + public bool NoDelay { get; set; } + + /// + /// Gets or sets the soft and hard limit of file descriptors. + /// + public int Nofile { get; set; } + + /// + /// Gets or sets whether IPv6 addresses take precedence over IPv4 addresses for resolved hostnames. + /// Defaults to false. + /// + public bool Ipv6First { get; set; } + public Config() { - + Version = 1; + Servers = new(); + LocalAddress = ""; + LocalPort = 1080; + UdpTimeout = 300; + UdpMaxAssociations = 0; + ManagerAddress = ""; + ManagerPort = 0; + Dns = ""; + Mode = "tcp_only"; + NoDelay = false; + Nofile = 0; + Ipv6First = false; } + + /// + /// Gets the default configuration for Linux. + /// + public static Config DefaultLinux => new() + { + LocalAddress = "::1", + Mode = "tcp_and_udp", + NoDelay = true, + Nofile = 32768, + Ipv6First = true, + }; + + /// + /// Gets the default configuration for Windows. + /// + public static Config DefaultWindows => new() + { + LocalAddress = "::1", + Mode = "tcp_and_udp", + Ipv6First = true, + }; } } diff --git a/Shadowsocks.Interop/V2Ray/ApiObject.cs b/Shadowsocks.Interop/V2Ray/ApiObject.cs new file mode 100644 index 00000000..5cb599e9 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/ApiObject.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; + +namespace Shadowsocks.Interop.V2Ray +{ + public class ApiObject + { + /// + /// Gets or sets the outbound tag for the API. + /// + public string Tag { get; set; } + + /// + /// Gets or sets the list of API services to enable. + /// + public List Services { get; set; } + + public ApiObject() + { + Tag = ""; + Services = new(); + } + + /// + /// Gets the default API object. + /// + public static ApiObject Default => new() + { + Tag = "api", + Services = new() + { + "HandlerService", + "LoggerService", + "StatsService", + }, + }; + } +} diff --git a/Shadowsocks.Interop/V2Ray/Config.cs b/Shadowsocks.Interop/V2Ray/Config.cs index 4ef63bfb..bc62cf65 100644 --- a/Shadowsocks.Interop/V2Ray/Config.cs +++ b/Shadowsocks.Interop/V2Ray/Config.cs @@ -1,16 +1,50 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Text.Json.Serialization; namespace Shadowsocks.Interop.V2Ray { public class Config { - public Config() + public LogObject Log { get; set; } + public ApiObject Api { get; set; } + public DnsObject Dns { get; set; } + public RoutingObject Routing { get; set; } + public PolicyObject Policy { get; set; } + public InboundObject Inbounds { get; set; } + public OutboundObject Outbounds { get; set; } + public TransportObject Transport { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + public StatsObject? Stats { get; set; } + public ReverseObject Reverse { get; set; } + + public Config(bool stats = true) { - + Log = new(); + Api = new(); + Dns = new(); + Routing = new(); + Policy = new(); + Inbounds = new(); + Outbounds = new(); + Transport = new(); + Stats = stats ? new() : null; + Reverse = new(); } + + /// + /// Gets the default configuration. + /// + public static Config Default => new() + { + Log = new(), + Api = ApiObject.Default, + Dns = new(), + Routing = new(), + Policy = PolicyObject.Default, + Inbounds = new(), + Outbounds = new(), + Transport = new(), + Stats = new(), + Reverse = new(), + }; } } diff --git a/Shadowsocks.Interop/V2Ray/Dns/ServerObject.cs b/Shadowsocks.Interop/V2Ray/Dns/ServerObject.cs new file mode 100644 index 00000000..c9a56681 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Dns/ServerObject.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; + +namespace Shadowsocks.Interop.V2Ray.Dns +{ + public class ServerObject + { + /// + /// Gets or sets the DNS server address. + /// Supports UDP and DoH. + /// + public string Address { get; set; } + + /// + /// Gets or sets the DNS server port. + /// Defaults to 53. + /// + public int Port { get; set; } + + /// + /// Gets or sets the list of domains + /// that prefers this DNS server. + /// + public List Domains { get; set; } + + /// + /// Gets or sets the ranges of IP addresses + /// this DNS server is expected to return. + /// + public List ExpectIPs { get; set; } + + public ServerObject() + { + Address = ""; + Port = 53; + Domains = new(); + ExpectIPs = new(); + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/DnsObject.cs b/Shadowsocks.Interop/V2Ray/DnsObject.cs new file mode 100644 index 00000000..42327eb7 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/DnsObject.cs @@ -0,0 +1,27 @@ +using Shadowsocks.Interop.V2Ray.Dns; +using System.Collections.Generic; + +namespace Shadowsocks.Interop.V2Ray +{ + public class DnsObject + { + /// + /// Gets or sets the dictionary storing hosts. + /// The key is the hostname. + /// The value can either be a hostname or an IP address. + /// + public Dictionary Hosts { get; set; } + + /// + /// Gets or sets the list of DNS servers. + /// A DNS server can either be a or a string. + /// + public List Servers { get; set; } + + public DnsObject() + { + Hosts = new(); + Servers = new(); + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Inbound/AllocateObject.cs b/Shadowsocks.Interop/V2Ray/Inbound/AllocateObject.cs new file mode 100644 index 00000000..855b5d05 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Inbound/AllocateObject.cs @@ -0,0 +1,31 @@ +namespace Shadowsocks.Interop.V2Ray.Inbound +{ + public class AllocateObject + { + /// + /// Gets or sets the port allocation strategy. + /// Defaults to "always". + /// Available values: "always" | "random" + /// + public string Strategy { get; set; } + + /// + /// Gets or sets the random port refreshing interval in minutes. + /// Defaults to 5 minutes. + /// + public int Refresh { get; set; } + + /// + /// Gets or sets the number of random ports. + /// Defaults to 3. + /// + public int Concurrency { get; set; } + + public AllocateObject() + { + Strategy = "always"; + Refresh = 5; + Concurrency = 3; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Inbound/SniffingObject.cs b/Shadowsocks.Interop/V2Ray/Inbound/SniffingObject.cs new file mode 100644 index 00000000..23c41336 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Inbound/SniffingObject.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; + +namespace Shadowsocks.Interop.V2Ray.Inbound +{ + public class SniffingObject + { + /// + /// Gets or sets whether to enable sniffing. + /// Defaults to true (enabled). + /// + public bool Enabled { get; set; } + + /// + /// Gets or sets the list of protocols that destination override is enabled. + /// + public List DestOverride { get; set; } + + public SniffingObject() + { + Enabled = true; + DestOverride = new() + { + "http", + "tls", + }; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/InboundObject.cs b/Shadowsocks.Interop/V2Ray/InboundObject.cs new file mode 100644 index 00000000..16a394b8 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/InboundObject.cs @@ -0,0 +1,54 @@ +using Shadowsocks.Interop.V2Ray.Inbound; +using Shadowsocks.Interop.V2Ray.Transport; + +namespace Shadowsocks.Interop.V2Ray +{ + public class InboundObject + { + public string Tag { get; set; } + public string Listen { get; set; } + public object Port { get; set; } + public string Protocol { get; set; } + public object? Settings { get; set; } + public StreamSettingsObject StreamSettings { get; set; } + public SniffingObject Sniffing { get; set; } + public AllocateObject Allocate { get; set; } + + public InboundObject() + { + Tag = ""; + Listen = "0.0.0.0"; + Port = ""; + Protocol = ""; + Settings = null; + StreamSettings = new(); + Sniffing = new(); + Allocate = new(); + } + + public static InboundObject DefaultLocalSocks => new() + { + Tag = "socks-in", + Listen = "127.0.0.1", + Port = 1080, + Protocol = "socks", + Settings = Protocols.Socks.InboundConfigurationObject.Default, + Sniffing = new() + { + Enabled = false, + }, + }; + + public static InboundObject DefaultLocalHttp => new() + { + Tag = "http-in", + Listen = "127.0.0.1", + Port = 8080, + Protocol = "http", + Sniffing = new() + { + Enabled = false, + }, + }; + } +} diff --git a/Shadowsocks.Interop/V2Ray/LogObject.cs b/Shadowsocks.Interop/V2Ray/LogObject.cs new file mode 100644 index 00000000..551d1606 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/LogObject.cs @@ -0,0 +1,31 @@ +namespace Shadowsocks.Interop.V2Ray +{ + public class LogObject + { + /// + /// Gets or sets the path to the access log file. + /// Defaults to empty, which prints to stdout. + /// + public string Access { get; set; } + + /// + /// Gets or sets the path to the error log file. + /// Defaults to empty, which prints to stdout. + /// + public string Error { get; set; } + + /// + /// Gets or sets the log level. + /// Defaults to warning. + /// Available values: "debug" | "info" | "warning" | "error" | "none" + /// + public string Loglevel { get; set; } + + public LogObject() + { + Access = ""; + Error = ""; + Loglevel = "warning"; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Outbound/MuxObject.cs b/Shadowsocks.Interop/V2Ray/Outbound/MuxObject.cs new file mode 100644 index 00000000..cb0fdbd0 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Outbound/MuxObject.cs @@ -0,0 +1,25 @@ +namespace Shadowsocks.Interop.V2Ray.Outbound +{ + public class MuxObject + { + /// + /// Gets or sets whether to enable mux. + /// Defaults to false (disabled). + /// + public bool Enabled { get; set; } + + /// + /// Gets or sets the concurrency for a single TCP connection when using mux. + /// Defaults to 8. + /// Range: [1, 1024]. + /// Set to -1 to disable the mux module. + /// + public int Concurrency { get; set; } + + public MuxObject() + { + Enabled = false; + Concurrency = 8; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Outbound/ProxySettingsObject.cs b/Shadowsocks.Interop/V2Ray/Outbound/ProxySettingsObject.cs new file mode 100644 index 00000000..6b476d93 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Outbound/ProxySettingsObject.cs @@ -0,0 +1,16 @@ +namespace Shadowsocks.Interop.V2Ray.Outbound +{ + public class ProxySettingsObject + { + /// + /// Gets or sets the tag of the outbound + /// used as the proxy. + /// + public string Tag { get; set; } + + public ProxySettingsObject() + { + Tag = ""; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/OutboundObject.cs b/Shadowsocks.Interop/V2Ray/OutboundObject.cs new file mode 100644 index 00000000..c94e3b96 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/OutboundObject.cs @@ -0,0 +1,86 @@ +using Shadowsocks.Interop.V2Ray.Outbound; +using Shadowsocks.Interop.V2Ray.Transport; +using Shadowsocks.Models; +using System.Net; + +namespace Shadowsocks.Interop.V2Ray +{ + public class OutboundObject + { + public string Tag { get; set; } + public string SendThrough { get; set; } + public string Protocol { get; set; } + public object? Settings { get; set; } + public StreamSettingsObject StreamSettings { get; set; } + public ProxySettingsObject ProxySettings { get; set; } + public MuxObject Mux { get; set; } + + public OutboundObject() + { + Tag = ""; + SendThrough = "0.0.0.0"; + Protocol = ""; + Settings = null; + StreamSettings = new(); + ProxySettings = new(); + Mux = new(); + } + + /// + /// Gets the for the SOCKS server. + /// + /// SOCKS server name. Used as outbound tag. + /// The SOCKS server. + /// + /// + /// + public static OutboundObject GetSocks(string name, DnsEndPoint socksEndPoint, string username = "", string password = "") => new() + { + Tag = name, + Protocol = "socks", + Settings = new Protocols.Socks.OutboundConfigurationObject(socksEndPoint, username, password), + }; + + /// + /// Gets the for the Shadowsocks server. + /// Plugins are not supported. Plugin information is silently discarded. + /// + /// + /// + public static OutboundObject GetShadowsocks(IServer server) => new() + { + Tag = server.Name, + Protocol = "shadowsocks", + Settings = new Protocols.Shadowsocks.OutboundConfigurationObject(), + }; + + /// + /// Gets the for the Trojan server. + /// + /// + /// + /// + /// + public static OutboundObject GetTrojan(string name, string address, int port, string password) => new() + { + Tag = name, + Protocol = "trojan", + Settings = new Protocols.Trojan.OutboundConfigurationObject(address, port, password), + }; + + /// + /// Gets the for the VMess server. + /// + /// + /// + /// + /// + /// + public static OutboundObject GetVMess(string name, string address, int port, string id) => new() + { + Tag = name, + Protocol = "vmess", + Settings = new Protocols.VMess.OutboundConfigurationObject(address, port, id), + }; + } +} diff --git a/Shadowsocks.Interop/V2Ray/Policy/LevelPolicyObject.cs b/Shadowsocks.Interop/V2Ray/Policy/LevelPolicyObject.cs new file mode 100644 index 00000000..6cd9f794 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Policy/LevelPolicyObject.cs @@ -0,0 +1,24 @@ +namespace Shadowsocks.Interop.V2Ray.Policy +{ + public class LevelPolicyObject + { + public int Handshake { get; set; } + public int ConnIdle { get; set; } + public int UplinkOnly { get; set; } + public int DownlinkOnly { get; set; } + public bool StatsUserUplink { get; set; } + public bool StatsUserDownlink { get; set; } + public int BufferSize { get; set; } + + public LevelPolicyObject() + { + Handshake = 4; + ConnIdle = 300; + UplinkOnly = 2; + DownlinkOnly = 5; + StatsUserUplink = false; + StatsUserDownlink = false; + BufferSize = 512; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Policy/SystemPolicyObject.cs b/Shadowsocks.Interop/V2Ray/Policy/SystemPolicyObject.cs new file mode 100644 index 00000000..93b1aec8 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Policy/SystemPolicyObject.cs @@ -0,0 +1,18 @@ +namespace Shadowsocks.Interop.V2Ray.Policy +{ + public class SystemPolicyObject + { + public bool StatsInboundUplink { get; set; } + public bool StatsInboundDownlink { get; set; } + public bool StatsOutboundUplink { get; set; } + public bool StatsOutboundDownlink { get; set; } + + public static SystemPolicyObject Default => new() + { + StatsInboundUplink = true, + StatsInboundDownlink = true, + StatsOutboundUplink = true, + StatsOutboundDownlink = true, + }; + } +} diff --git a/Shadowsocks.Interop/V2Ray/PolicyObject.cs b/Shadowsocks.Interop/V2Ray/PolicyObject.cs new file mode 100644 index 00000000..f4a4afe5 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/PolicyObject.cs @@ -0,0 +1,26 @@ +using Shadowsocks.Interop.V2Ray.Policy; +using System.Collections.Generic; + +namespace Shadowsocks.Interop.V2Ray +{ + public class PolicyObject + { + public Dictionary Levels { get; set; } + public SystemPolicyObject System { get; set; } + + public PolicyObject() + { + Levels = new(); + System = new(); + } + + /// + /// Gets the default policy object. + /// + public static PolicyObject Default => new() + { + Levels = new(), + System = SystemPolicyObject.Default, + }; + } +} diff --git a/Shadowsocks.Interop/V2Ray/Protocols/AccountObject.cs b/Shadowsocks.Interop/V2Ray/Protocols/AccountObject.cs new file mode 100644 index 00000000..9366ce49 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Protocols/AccountObject.cs @@ -0,0 +1,14 @@ +namespace Shadowsocks.Interop.V2Ray.Protocols +{ + public class AccountObject + { + public string User { get; set; } + public string Pass { get; set; } + + public AccountObject() + { + User = ""; + Pass = ""; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Protocols/Freedom/OutboundConfigurationObject.cs b/Shadowsocks.Interop/V2Ray/Protocols/Freedom/OutboundConfigurationObject.cs new file mode 100644 index 00000000..ae92c680 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Protocols/Freedom/OutboundConfigurationObject.cs @@ -0,0 +1,16 @@ +namespace Shadowsocks.Interop.V2Ray.Protocols.Freedom +{ + public class OutboundConfigurationObject + { + public string DomainStrategy { get; set; } + public string Redirect { get; set; } + public int UserLevel { get; set; } + + public OutboundConfigurationObject() + { + DomainStrategy = "AsIs"; + Redirect = ""; + UserLevel = 0; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Protocols/Shadowsocks/InboundConfigurationObject.cs b/Shadowsocks.Interop/V2Ray/Protocols/Shadowsocks/InboundConfigurationObject.cs new file mode 100644 index 00000000..5e988617 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Protocols/Shadowsocks/InboundConfigurationObject.cs @@ -0,0 +1,30 @@ +using System; +using System.Text.Json.Serialization; + +namespace Shadowsocks.Interop.V2Ray.Protocols.Shadowsocks +{ + public class InboundConfigurationObject + { + public string Email { get; set; } + + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + public string Method { get; set; } + + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + public string Password { get; set; } + + public int Level { get; set; } + + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + public string Network { get; set; } + + public InboundConfigurationObject() + { + Email = ""; + Method = "chacha20-ietf-poly1305"; + Password = new Guid().ToString(); + Level = 0; + Network = "tcp,udp"; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Protocols/Shadowsocks/OutboundConfigurationObject.cs b/Shadowsocks.Interop/V2Ray/Protocols/Shadowsocks/OutboundConfigurationObject.cs new file mode 100644 index 00000000..ebb54b7b --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Protocols/Shadowsocks/OutboundConfigurationObject.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; + +namespace Shadowsocks.Interop.V2Ray.Protocols.Shadowsocks +{ + public class OutboundConfigurationObject + { + public List Servers { get; set; } + + public OutboundConfigurationObject() + { + Servers = new(); + } + + public OutboundConfigurationObject(string address, int port, string method, string password) + { + Servers = new() + { + new(address, port, method, password), + }; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Protocols/Shadowsocks/ServerObject.cs b/Shadowsocks.Interop/V2Ray/Protocols/Shadowsocks/ServerObject.cs new file mode 100644 index 00000000..798d57a4 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Protocols/Shadowsocks/ServerObject.cs @@ -0,0 +1,43 @@ +using System.Text.Json.Serialization; + +namespace Shadowsocks.Interop.V2Ray.Protocols.Shadowsocks +{ + public class ServerObject + { + public string Email { get; set; } + + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + public string Address { get; set; } + + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + public int Port { get; set; } + + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + public string Method { get; set; } + + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + public string Password { get; set; } + + public int Level { get; set; } + + public ServerObject() + { + Email = ""; + Address = ""; + Port = 8388; + Method = "chacha20-ietf-poly1305"; + Password = ""; + Level = 0; + } + + public ServerObject(string address, int port, string method, string password) + { + Email = ""; + Address = address; + Port = port; + Method = method; + Password = password; + Level = 0; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Protocols/Socks/InboundConfigurationObject.cs b/Shadowsocks.Interop/V2Ray/Protocols/Socks/InboundConfigurationObject.cs new file mode 100644 index 00000000..06478b9e --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Protocols/Socks/InboundConfigurationObject.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; + +namespace Shadowsocks.Interop.V2Ray.Protocols.Socks +{ + public class InboundConfigurationObject + { + public string Auth { get; set; } + public List Accounts { get; set; } + public bool Udp { get; set; } + public string Ip { get; set; } + public int UserLevel { get; set; } + + public InboundConfigurationObject() + { + Auth = "noauth"; + Accounts = new(); + Udp = false; + Ip = "127.0.0.1"; + UserLevel = 0; + } + + public static InboundConfigurationObject Default => new() + { + Udp = true, + }; + } +} diff --git a/Shadowsocks.Interop/V2Ray/Protocols/Socks/OutboundConfigurationObject.cs b/Shadowsocks.Interop/V2Ray/Protocols/Socks/OutboundConfigurationObject.cs new file mode 100644 index 00000000..c66b9ec3 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Protocols/Socks/OutboundConfigurationObject.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; +using System.Net; + +namespace Shadowsocks.Interop.V2Ray.Protocols.Socks +{ + public class OutboundConfigurationObject + { + public List Servers { get; set; } + + public OutboundConfigurationObject() + { + Servers = new(); + } + + public OutboundConfigurationObject(DnsEndPoint socksEndPoint, string username = "", string password = "") + { + Servers = new() + { + new(socksEndPoint, username, password), + }; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Protocols/Socks/ServerObject.cs b/Shadowsocks.Interop/V2Ray/Protocols/Socks/ServerObject.cs new file mode 100644 index 00000000..ec1eea68 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Protocols/Socks/ServerObject.cs @@ -0,0 +1,33 @@ +using System.Collections.Generic; +using System.Net; + +namespace Shadowsocks.Interop.V2Ray.Protocols.Socks +{ + public class ServerObject + { + public string Address { get; set; } + public int Port { get; set; } + public List Users { get; set; } + + public ServerObject() + { + Address = ""; + Port = 0; + Users = new(); + } + + public ServerObject(DnsEndPoint socksEndPoint, string username = "", string password = "") + { + Address = socksEndPoint.Host; + Port = socksEndPoint.Port; + Users = new(); + var hasCredential = !string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password); + if (hasCredential) + Users.Add(new() + { + User = username, + Pass = password, + }); + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Protocols/Trojan/ClientObject.cs b/Shadowsocks.Interop/V2Ray/Protocols/Trojan/ClientObject.cs new file mode 100644 index 00000000..898edf54 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Protocols/Trojan/ClientObject.cs @@ -0,0 +1,16 @@ +namespace Shadowsocks.Interop.V2Ray.Protocols.Trojan +{ + public class ClientObject + { + public string Password { get; set; } + public string Email { get; set; } + public int Level { get; set; } + + public ClientObject() + { + Password = ""; + Email = ""; + Level = 0; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Protocols/Trojan/FallbackObject.cs b/Shadowsocks.Interop/V2Ray/Protocols/Trojan/FallbackObject.cs new file mode 100644 index 00000000..93fc0ced --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Protocols/Trojan/FallbackObject.cs @@ -0,0 +1,18 @@ +namespace Shadowsocks.Interop.V2Ray.Protocols.Trojan +{ + public class FallbackObject + { + public string Alpn { get; set; } + public string Path { get; set; } + public object Dest { get; set; } + public int Xver { get; set; } + + public FallbackObject() + { + Alpn = ""; + Path = ""; + Dest = 0; + Xver = 0; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Protocols/Trojan/InboundConfigurationObject.cs b/Shadowsocks.Interop/V2Ray/Protocols/Trojan/InboundConfigurationObject.cs new file mode 100644 index 00000000..761e329a --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Protocols/Trojan/InboundConfigurationObject.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; + +namespace Shadowsocks.Interop.V2Ray.Protocols.Trojan +{ + public class InboundConfigurationObject + { + public List Clients { get; set; } + public List Fallbacks { get; set; } + + public InboundConfigurationObject() + { + Clients = new(); + Fallbacks = new(); + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Protocols/Trojan/OutboundConfigurationObject.cs b/Shadowsocks.Interop/V2Ray/Protocols/Trojan/OutboundConfigurationObject.cs new file mode 100644 index 00000000..cfbeeedd --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Protocols/Trojan/OutboundConfigurationObject.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; + +namespace Shadowsocks.Interop.V2Ray.Protocols.Trojan +{ + public class OutboundConfigurationObject + { + public List Servers { get; set; } + + public OutboundConfigurationObject() + { + Servers = new(); + } + + public OutboundConfigurationObject(string address, int port, string password) + { + Servers = new() + { + new(address, port, password), + }; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Protocols/Trojan/ServerObject.cs b/Shadowsocks.Interop/V2Ray/Protocols/Trojan/ServerObject.cs new file mode 100644 index 00000000..ac75c56d --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Protocols/Trojan/ServerObject.cs @@ -0,0 +1,29 @@ +namespace Shadowsocks.Interop.V2Ray.Protocols.Trojan +{ + public class ServerObject + { + public string Address { get; set; } + public int Port { get; set; } + public string Password { get; set; } + public string Email { get; set; } + public int Level { get; set; } + + public ServerObject() + { + Address = ""; + Port = 0; + Password = ""; + Email = ""; + Level = 0; + } + + public ServerObject(string address, int port, string password) + { + Address = address; + Port = port; + Password = password; + Email = ""; + Level = 0; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Protocols/UserObject.cs b/Shadowsocks.Interop/V2Ray/Protocols/UserObject.cs new file mode 100644 index 00000000..881c1706 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Protocols/UserObject.cs @@ -0,0 +1,7 @@ +namespace Shadowsocks.Interop.V2Ray.Protocols +{ + public class UserObject : AccountObject + { + public int Level { get; set; } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Protocols/VMess/DetourObject.cs b/Shadowsocks.Interop/V2Ray/Protocols/VMess/DetourObject.cs new file mode 100644 index 00000000..775e8a62 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Protocols/VMess/DetourObject.cs @@ -0,0 +1,12 @@ +namespace Shadowsocks.Interop.V2Ray.Protocols.VMess +{ + public class DetourObject + { + public string To { get; set; } + + public DetourObject() + { + To = ""; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Protocols/VMess/InboundConfigurationObject.cs b/Shadowsocks.Interop/V2Ray/Protocols/VMess/InboundConfigurationObject.cs new file mode 100644 index 00000000..3b794d62 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Protocols/VMess/InboundConfigurationObject.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; + +namespace Shadowsocks.Interop.V2Ray.Protocols.VMess +{ + public class InboundConfigurationObject + { + public List Clients { get; set; } + public UserObject Default { get; set; } + public DetourObject Detour { get; set; } + + public InboundConfigurationObject() + { + Clients = new(); + Default = new(); + Detour = new(); + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Protocols/VMess/OutboundConfigurationObject.cs b/Shadowsocks.Interop/V2Ray/Protocols/VMess/OutboundConfigurationObject.cs new file mode 100644 index 00000000..78acc6c1 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Protocols/VMess/OutboundConfigurationObject.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; + +namespace Shadowsocks.Interop.V2Ray.Protocols.VMess +{ + public class OutboundConfigurationObject + { + public List Vnext { get; set; } + + public OutboundConfigurationObject() + { + Vnext = new(); + } + + public OutboundConfigurationObject(string address, int port, string id) + { + Vnext = new() + { + new(address, port, id), + }; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Protocols/VMess/ServerObject.cs b/Shadowsocks.Interop/V2Ray/Protocols/VMess/ServerObject.cs new file mode 100644 index 00000000..6ae48e4f --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Protocols/VMess/ServerObject.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; + +namespace Shadowsocks.Interop.V2Ray.Protocols.VMess +{ + public class ServerObject + { + public string Address { get; set; } + public int Port { get; set; } + public List Users { get; set; } + + public ServerObject() + { + Address = ""; + Port = 0; + Users = new(); + } + + public ServerObject(string address, int port, string id) + { + Address = address; + Port = port; + Users = new() + { + new(id), + }; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Protocols/VMess/UserObject.cs b/Shadowsocks.Interop/V2Ray/Protocols/VMess/UserObject.cs new file mode 100644 index 00000000..1e29e086 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Protocols/VMess/UserObject.cs @@ -0,0 +1,26 @@ +using System; + +namespace Shadowsocks.Interop.V2Ray.Protocols.VMess +{ + /// + /// The user object for VMess AEAD. + /// + public class UserObject + { + public string Id { get; set; } + public string Email { get; set; } + public int Level { get; set; } + + public UserObject(string id = "") + { + Id = id; + Email = ""; + Level = 0; + } + + public static UserObject Default => new() + { + Id = new Guid().ToString(), + }; + } +} diff --git a/Shadowsocks.Interop/V2Ray/Reverse/BridgeObject.cs b/Shadowsocks.Interop/V2Ray/Reverse/BridgeObject.cs new file mode 100644 index 00000000..f8a33bf6 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Reverse/BridgeObject.cs @@ -0,0 +1,22 @@ +namespace Shadowsocks.Interop.V2Ray.Reverse +{ + public class BridgeObject + { + /// + /// Gets or sets the inbound tag for the bridge. + /// + public string Tag { get; set; } + + /// + /// Gets or sets the domain name for the bridge. + /// Can be omitted. + /// + public string Domain { get; set; } + + public BridgeObject() + { + Tag = ""; + Domain = ""; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Reverse/PortalObject.cs b/Shadowsocks.Interop/V2Ray/Reverse/PortalObject.cs new file mode 100644 index 00000000..4d048434 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Reverse/PortalObject.cs @@ -0,0 +1,21 @@ +namespace Shadowsocks.Interop.V2Ray.Reverse +{ + public class PortalObject + { + /// + /// Gets or sets the outbound tag for the portal. + /// + public string Tag { get; set; } + + /// + /// Gets or sets the domain name for the portal. + /// + public string Domain { get; set; } + + public PortalObject() + { + Tag = ""; + Domain = ""; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/ReverseObject.cs b/Shadowsocks.Interop/V2Ray/ReverseObject.cs new file mode 100644 index 00000000..8da7465a --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/ReverseObject.cs @@ -0,0 +1,17 @@ +using Shadowsocks.Interop.V2Ray.Reverse; +using System.Collections.Generic; + +namespace Shadowsocks.Interop.V2Ray +{ + public class ReverseObject + { + public List Bridges { get; set; } + public List Portals { get; set; } + + public ReverseObject() + { + Bridges = new(); + Portals = new(); + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Routing/BalancerObject.cs b/Shadowsocks.Interop/V2Ray/Routing/BalancerObject.cs new file mode 100644 index 00000000..fff2283c --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Routing/BalancerObject.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; + +namespace Shadowsocks.Interop.V2Ray.Routing +{ + public class BalancerObject + { + /// + /// Gets or sets the outbound tag for the load balancer. + /// + public string Tag { get; set; } + + /// + /// Gets or sets a list of outbound tags + /// to include in the load balancer. + /// + public List Selector { get; set; } + + public BalancerObject() + { + Tag = ""; + Selector = new(); + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Routing/RuleObject.cs b/Shadowsocks.Interop/V2Ray/Routing/RuleObject.cs new file mode 100644 index 00000000..20a7d2ec --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Routing/RuleObject.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace Shadowsocks.Interop.V2Ray.Routing +{ + public class RuleObject + { + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + public string Type { get; set; } + public List Domain { get; set; } + public List Ip { get; set; } + public object Port { get; set; } + public object SourcePort { get; set; } + public string Network { get; set; } + public List Source { get; set; } + public List User { get; set; } + public List InboundTag { get; set; } + public List Protocol { get; set; } + public string Attrs { get; set; } + public string OutboundTag { get; set; } + public string BalancerTag { get; set; } + + public RuleObject() + { + Type = "field"; + Domain = new(); + Ip = new(); + Port = ""; + SourcePort = ""; + Network = ""; + Source = new(); + User = new(); + InboundTag = new(); + Protocol = new(); + Attrs = ""; + OutboundTag = ""; + BalancerTag = ""; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/RoutingObject.cs b/Shadowsocks.Interop/V2Ray/RoutingObject.cs new file mode 100644 index 00000000..d27bfb22 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/RoutingObject.cs @@ -0,0 +1,32 @@ +using Shadowsocks.Interop.V2Ray.Routing; +using System.Collections.Generic; + +namespace Shadowsocks.Interop.V2Ray +{ + public class RoutingObject + { + /// + /// Gets or sets the domain strategy used for routing. + /// Default value: AsIs. + /// Available values: "AsIs" | "IPIfNonMatch" | "IPOnDemand" + /// + public string DomainStrategy { get; set; } + + /// + /// Gets or sets the list of routing rules. + /// + public List Rules { get; set; } + + /// + /// Gets or sets the list of load balancers. + /// + public List Balancers { get; set; } + + public RoutingObject() + { + DomainStrategy = "AsIs"; + Rules = new(); + Balancers = new(); + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/StatsObject.cs b/Shadowsocks.Interop/V2Ray/StatsObject.cs new file mode 100644 index 00000000..4c4fda73 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/StatsObject.cs @@ -0,0 +1,6 @@ +namespace Shadowsocks.Interop.V2Ray +{ + public class StatsObject + { + } +} diff --git a/Shadowsocks.Interop/V2Ray/Transport/CertificateObject.cs b/Shadowsocks.Interop/V2Ray/Transport/CertificateObject.cs new file mode 100644 index 00000000..ae9ee8c3 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Transport/CertificateObject.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; + +namespace Shadowsocks.Interop.V2Ray.Transport +{ + public class CertificateObject + { + public string Usage { get; set; } + public string CertificateFile { get; set; } + public string KeyFile { get; set; } + public List Certificate { get; set; } + public List Key { get; set; } + + public CertificateObject() + { + Usage = "encipherment"; + CertificateFile = ""; + KeyFile = ""; + Certificate = new(); + Key = new(); + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Transport/DomainSocketObject.cs b/Shadowsocks.Interop/V2Ray/Transport/DomainSocketObject.cs new file mode 100644 index 00000000..44df04a1 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Transport/DomainSocketObject.cs @@ -0,0 +1,29 @@ +namespace Shadowsocks.Interop.V2Ray.Transport +{ + public class DomainSocketObject + { + /// + /// Gets or sets the path to the unix domain socket file. + /// + public string Path { get; set; } + + /// + /// Gets or sets whether the domain socket is abstract. + /// Defaults to false. + /// + public bool Abstract { get; set; } + + /// + /// Gets or sets whether padding is used. + /// Defaults to false. + /// + public bool Padding { get; set; } + + public DomainSocketObject() + { + Path = ""; + Abstract = false; + Padding = false; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Transport/Header/HeaderObject.cs b/Shadowsocks.Interop/V2Ray/Transport/Header/HeaderObject.cs new file mode 100644 index 00000000..a6d24ee9 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Transport/Header/HeaderObject.cs @@ -0,0 +1,23 @@ +namespace Shadowsocks.Interop.V2Ray.Transport.Header +{ + public class HeaderObject + { + /// + /// Gets or sets the header type. + /// Defaults to none. + /// Available values: + /// none + /// srtp + /// utp + /// wechat-video + /// dtls + /// wireguard + /// + public string Type { get; set; } + + public HeaderObject() + { + Type = "none"; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Transport/Header/Http/HttpRequestObject.cs b/Shadowsocks.Interop/V2Ray/Transport/Header/Http/HttpRequestObject.cs new file mode 100644 index 00000000..ec73ea54 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Transport/Header/Http/HttpRequestObject.cs @@ -0,0 +1,47 @@ +using System.Collections.Generic; + +namespace Shadowsocks.Interop.V2Ray.Transport.Header.Http +{ + public class HttpRequestObject + { + public string Version { get; set; } + public string Method { get; set; } + public List Path { get; set; } + public Dictionary> Headers { get; set; } + + public HttpRequestObject() + { + Version = "1.1"; + Method = "GET"; + Path = new() + { + "/", + }; + Headers = new() + { + ["Host"] = new() + { + "www.baidu.com", + "www.bing.com", + }, + ["User-Agent"] = new() + { + "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36", + "Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_2 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/53.0.2785.109 Mobile/14A456 Safari/601.1.46", + }, + ["Accept-Encoding"] = new() + { + "gzip, deflate", + }, + ["Connection"] = new() + { + "keep-alive", + }, + ["Pragma"] = new() + { + "no-cache", + }, + }; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Transport/Header/Http/HttpResponseObject.cs b/Shadowsocks.Interop/V2Ray/Transport/Header/Http/HttpResponseObject.cs new file mode 100644 index 00000000..1aa284c1 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Transport/Header/Http/HttpResponseObject.cs @@ -0,0 +1,44 @@ +using System.Collections.Generic; + +namespace Shadowsocks.Interop.V2Ray.Transport.Header.Http +{ + public class HttpResponseObject + { + public string Version { get; set; } + public string Status { get; set; } + public string Reason { get; set; } + public Dictionary> Headers { get; set; } + + public HttpResponseObject() + { + Version = "1.1"; + Status = "200"; + Reason = "OK"; + Headers = new() + { + ["Content-Type"] = new() + { + "application/octet-stream", + "video/mpeg", + }, + ["Transfer-Encoding"] = new() + { + "chunked", + }, + ["Connection"] = new() + { + "keep-alive", + }, + ["Pragma"] = new() + { + "no-cache", + }, + ["Cache-Control"] = new() + { + "private", + "no-cache", + }, + }; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Transport/Header/HttpHeaderObject.cs b/Shadowsocks.Interop/V2Ray/Transport/Header/HttpHeaderObject.cs new file mode 100644 index 00000000..1e387f87 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Transport/Header/HttpHeaderObject.cs @@ -0,0 +1,18 @@ +using Shadowsocks.Interop.V2Ray.Transport.Header.Http; + +namespace Shadowsocks.Interop.V2Ray.Transport.Header +{ + public class HttpHeaderObject : HeaderObject + { + public HttpRequestObject request { get; set; } + + public HttpResponseObject response { get; set; } + + public HttpHeaderObject() + { + Type = "http"; + request = new(); + response = new(); + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Transport/HttpObject.cs b/Shadowsocks.Interop/V2Ray/Transport/HttpObject.cs new file mode 100644 index 00000000..4fe5fc1a --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Transport/HttpObject.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; + +namespace Shadowsocks.Interop.V2Ray.Transport +{ + public class HttpObject + { + public List Host { get; set; } + public string Path { get; set; } + + public HttpObject() + { + Host = new(); + Path = "/"; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Transport/KcpObject.cs b/Shadowsocks.Interop/V2Ray/Transport/KcpObject.cs new file mode 100644 index 00000000..28784b96 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Transport/KcpObject.cs @@ -0,0 +1,30 @@ +using Shadowsocks.Interop.V2Ray.Transport.Header; + +namespace Shadowsocks.Interop.V2Ray.Transport +{ + public class KcpObject + { + public int Mtu { get; set; } + public int Tti { get; set; } + public int UplinkCapacity { get; set; } + public int DownlinkCapacity { get; set; } + public bool Congestion { get; set; } + public int ReadBufferSize { get; set; } + public int WriteBufferSize { get; set; } + public HeaderObject Header { get; set; } + public string Seed { get; set; } + + public KcpObject() + { + Mtu = 1350; + Tti = 50; + UplinkCapacity = 5; + DownlinkCapacity = 20; + Congestion = false; + ReadBufferSize = 2; + WriteBufferSize = 2; + Header = new(); + Seed = ""; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Transport/QuicObject.cs b/Shadowsocks.Interop/V2Ray/Transport/QuicObject.cs new file mode 100644 index 00000000..fea911eb --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Transport/QuicObject.cs @@ -0,0 +1,31 @@ +using Shadowsocks.Interop.V2Ray.Transport.Header; + +namespace Shadowsocks.Interop.V2Ray.Transport +{ + public class QuicObject + { + /// + /// Gets or sets the encryption method. + /// Defaults to "none" (no encryption). + /// Available values: "none" | "aes-128-gcm" | "chacha20-poly1305" + /// + public string Security { get; set; } + + /// + /// Gets or sets the encryption key. + /// + public string Key { get; set; } + + /// + /// Gets or sets the header options. + /// + public HeaderObject Header { get; set; } + + public QuicObject() + { + Security = "none"; + Key = ""; + Header = new(); + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Transport/SockoptObject.cs b/Shadowsocks.Interop/V2Ray/Transport/SockoptObject.cs new file mode 100644 index 00000000..dec18a3b --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Transport/SockoptObject.cs @@ -0,0 +1,16 @@ +namespace Shadowsocks.Interop.V2Ray.Transport +{ + public class SockoptObject + { + public int Mark { get; set; } + public bool TcpFastOpen { get; set; } + public string Tproxy { get; set; } + + public SockoptObject() + { + Mark = 0; + TcpFastOpen = false; + Tproxy = "off"; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Transport/StreamSettingsObject.cs b/Shadowsocks.Interop/V2Ray/Transport/StreamSettingsObject.cs new file mode 100644 index 00000000..2109ae7f --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Transport/StreamSettingsObject.cs @@ -0,0 +1,30 @@ +namespace Shadowsocks.Interop.V2Ray.Transport +{ + public class StreamSettingsObject : TransportObject + { + /// + /// Gets or sets the transport protocol type. + /// Defaults to "tcp". + /// Available values: "tcp" | "kcp" | "ws" | "http" | "domainsocket" | "quic" + /// + public string Network { get; set; } + + /// + /// Gets or sets the transport encryption type. + /// Defaults to "none" (no encryption). + /// Available values: "none" | "tls" + /// + public string Security { get; set; } + + public TlsObject TlsSettings { get; set; } + public SockoptObject Sockopt { get; set; } + + public StreamSettingsObject() + { + Network = "tcp"; + Security = "none"; + TlsSettings = new(); + Sockopt = new(); + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Transport/TcpObject.cs b/Shadowsocks.Interop/V2Ray/Transport/TcpObject.cs new file mode 100644 index 00000000..eada550a --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Transport/TcpObject.cs @@ -0,0 +1,23 @@ +using Shadowsocks.Interop.V2Ray.Transport.Header; + +namespace Shadowsocks.Interop.V2Ray.Transport +{ + public class TcpObject + { + /// + /// Gets or sets whether to use PROXY protocol. + /// + public bool AcceptProxyProtocol { get; set; } + + /// + /// Gets or sets the header options. + /// + public object Header { get; set; } + + public TcpObject() + { + AcceptProxyProtocol = false; + Header = new HeaderObject(); + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Transport/TlsObject.cs b/Shadowsocks.Interop/V2Ray/Transport/TlsObject.cs new file mode 100644 index 00000000..f1f60691 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Transport/TlsObject.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; + +namespace Shadowsocks.Interop.V2Ray.Transport +{ + public class TlsObject + { + public string ServerName { get; set; } + public bool AllowInsecure { get; set; } + public List Alpn { get; set; } + public List Certificates { get; set; } + public bool DisableSystemRoot { get; set; } + + public TlsObject() + { + ServerName = ""; + AllowInsecure = false; + Alpn = new() + { + "h2", + "http/1.1", + }; + Certificates = new(); + DisableSystemRoot = false; + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/Transport/WebSocketObject.cs b/Shadowsocks.Interop/V2Ray/Transport/WebSocketObject.cs new file mode 100644 index 00000000..ff3a303d --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/Transport/WebSocketObject.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; + +namespace Shadowsocks.Interop.V2Ray.Transport +{ + public class WebSocketObject + { + /// + /// Gets or sets whether to use PROXY protocol. + /// + public bool AcceptProxyProtocol { get; set; } + + /// + /// Gets or sets the HTTP query path. + /// + public string Path { get; set; } + + /// + /// Gets or sets HTTP header key-value pairs. + /// + public Dictionary Headers { get; set; } + + public WebSocketObject() + { + AcceptProxyProtocol = false; + Path = "/"; + Headers = new(); + } + } +} diff --git a/Shadowsocks.Interop/V2Ray/TransportObject.cs b/Shadowsocks.Interop/V2Ray/TransportObject.cs new file mode 100644 index 00000000..cf151fa6 --- /dev/null +++ b/Shadowsocks.Interop/V2Ray/TransportObject.cs @@ -0,0 +1,24 @@ +using Shadowsocks.Interop.V2Ray.Transport; + +namespace Shadowsocks.Interop.V2Ray +{ + public class TransportObject + { + public TcpObject TcpSettings { get; set; } + public KcpObject KcpSettings { get; set; } + public WebSocketObject WsSettings { get; set; } + public HttpObject HttpSettings { get; set; } + public QuicObject QuicSettings { get; set; } + public DomainSocketObject DsSettings { get; set; } + + public TransportObject() + { + TcpSettings = new(); + KcpSettings = new(); + WsSettings = new(); + HttpSettings = new(); + QuicSettings = new(); + DsSettings = new(); + } + } +}