diff --git a/src/logic/meson.build b/src/logic/meson.build index 5fa06cc..0fffdbf 100644 --- a/src/logic/meson.build +++ b/src/logic/meson.build @@ -1,7 +1,4 @@ utils_sources = 'logic/utils.vala' -singularity_sources += [ - utils_sources, -] singularity_deps += [ dependency('json-glib-1.0'), @@ -9,3 +6,9 @@ singularity_deps += [ ] subdir('transports') +subdir('outbounds') +singularity_sources += [ + utils_sources, + outbounds_sources, + transports_sources, +] diff --git a/src/logic/outbounds/dial.vala b/src/logic/outbounds/dial.vala new file mode 100644 index 0000000..fa8fe7a --- /dev/null +++ b/src/logic/outbounds/dial.vala @@ -0,0 +1,43 @@ +/* dial.vala + * + * Copyright 2025 Vasiliy Doylov (NekoCWD) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +/* + * Base for outbound with Dial fields. + * DASH and TYPE FIX REQUIRED + */ +class Singularity.Outbound.Dial : Outbound { + public string detour { get; set; default = null; } + public string bind_interface { get; set; default = null; } + public string inet4_bind_address { get; set; default = null; } + public string inet6_bind_address { get; set; default = null; } + public int64 routing_mark { get; set; default = 0; } + public bool reuse_addr { get; set; default = false; } + public string netns { get; set; default = null; } + public string connect_timeout { get; set; default = null; } + public bool tcp_fast_open { get; set; default = false; } + public bool tcp_multi_path { get; set; default = false; } + public bool udp_fragment { get; set; default = false; } + + public string[] domain_resolver { get; set; default = new string[0]; } + public string network_strategy { get; set; default = null; } + public string[] network_type { get; set; default = new string[0]; } + public string[] fallback_network_type { get; set; default = new string[0]; } + public string fallback_delay { get; set; default = null; } +} diff --git a/src/logic/outbounds/meson.build b/src/logic/outbounds/meson.build new file mode 100644 index 0000000..63e42ad --- /dev/null +++ b/src/logic/outbounds/meson.build @@ -0,0 +1,5 @@ +outbounds_sources = [ + 'logic/outbounds/outbound.vala', + 'logic/outbounds/dial.vala', + 'logic/outbounds/trojan.vala', +] diff --git a/src/logic/outbounds/outbound.vala b/src/logic/outbounds/outbound.vala new file mode 100644 index 0000000..6d29c89 --- /dev/null +++ b/src/logic/outbounds/outbound.vala @@ -0,0 +1,5 @@ +class Singularity.Outbound.Outbound : Object, Json.Serializable { + // We can't use name `type` in vala + public string type_name { get; construct set; default = ""; } + public string tag { get; set; default = ""; } +} diff --git a/src/logic/outbounds/trojan.vala b/src/logic/outbounds/trojan.vala new file mode 100644 index 0000000..41f072a --- /dev/null +++ b/src/logic/outbounds/trojan.vala @@ -0,0 +1,53 @@ +/* trojan.vala + * + * Copyright 2025 Vasiliy Doylov (NekoCWD) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +/* + * Trojan outbound. + * DASH and TYPE FIX REQUIRED + */ +class Singularity.Outbound.Trojan : Dial, Json.Serializable { + public string server { get; set; default = null; } + public int64 server_port { get; set; default = 1080; } + public string password { get; set; default = null; } + public string network { get; set; default = null; } + public Transport.Transport transport { get; set; default = null; } + + /* + * public TLS tls { get; set; default = null; } + * TODO: Implement TLS + */ + /* + * public Multiplex multiplex { get; set; default = null; } + * TODO: Implement Multiplex + */ + + construct { + type_name = "trojan"; + } + + public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) { + var node = default_serialize_property (property_name, value, pspec); + if (property_name == "transport") { + Utils.fix_type (ref node); + Utils.fix_dash (ref node); + } + return node; + } +}