mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-05-14 00:51:12 +03:00
Add MTProxy, MASQUE, VPN, Link parser. Update AmneziaWG. Remove Tunneling
This commit is contained in:
9
option/cloudflare.go
Normal file
9
option/cloudflare.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package option
|
||||
|
||||
type CloudflareProfile struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
AuthToken string `json:"auth_token,omitempty"`
|
||||
PrivateKey string `json:"private_key,omitempty"`
|
||||
Recreate bool `json:"recreate,omitempty"`
|
||||
Detour string `json:"detour,omitempty"`
|
||||
}
|
||||
@@ -11,13 +11,14 @@ type ExperimentalOptions struct {
|
||||
}
|
||||
|
||||
type CacheFileOptions struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
CacheID string `json:"cache_id,omitempty"`
|
||||
StoreFakeIP bool `json:"store_fakeip,omitempty"`
|
||||
StoreRDRC bool `json:"store_rdrc,omitempty"`
|
||||
StoreWARPConfig bool `json:"store_warp_config,omitempty"`
|
||||
RDRCTimeout badoption.Duration `json:"rdrc_timeout,omitempty"`
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
CacheID string `json:"cache_id,omitempty"`
|
||||
StoreFakeIP bool `json:"store_fakeip,omitempty"`
|
||||
StoreRDRC bool `json:"store_rdrc,omitempty"`
|
||||
StoreWARPConfig bool `json:"store_warp_config,omitempty"`
|
||||
StoreMASQUEConfig bool `json:"store_masque_config,omitempty"`
|
||||
RDRCTimeout badoption.Duration `json:"rdrc_timeout,omitempty"`
|
||||
}
|
||||
|
||||
type ClashAPIOptions struct {
|
||||
|
||||
9
option/failover.go
Normal file
9
option/failover.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package option
|
||||
|
||||
type FailoverInboundOptions struct {
|
||||
Inbounds []Inbound `json:"inbounds"`
|
||||
}
|
||||
|
||||
type FailoverOutboundOptions struct {
|
||||
Outbounds []Outbound `json:"outbounds"`
|
||||
}
|
||||
@@ -3,13 +3,13 @@ package option
|
||||
import "github.com/sagernet/sing/common/json/badoption"
|
||||
|
||||
type SelectorOutboundOptions struct {
|
||||
Outbounds []string `json:"outbounds"`
|
||||
Default string `json:"default,omitempty"`
|
||||
InterruptExistConnections bool `json:"interrupt_exist_connections,omitempty"`
|
||||
GroupCommonOption
|
||||
Default string `json:"default,omitempty"`
|
||||
InterruptExistConnections bool `json:"interrupt_exist_connections,omitempty"`
|
||||
}
|
||||
|
||||
type URLTestOutboundOptions struct {
|
||||
Outbounds []string `json:"outbounds"`
|
||||
GroupCommonOption
|
||||
URL string `json:"url,omitempty"`
|
||||
Interval badoption.Duration `json:"interval,omitempty"`
|
||||
Tolerance uint16 `json:"tolerance,omitempty"`
|
||||
@@ -17,6 +17,14 @@ type URLTestOutboundOptions struct {
|
||||
InterruptExistConnections bool `json:"interrupt_exist_connections,omitempty"`
|
||||
}
|
||||
|
||||
type FailoverOutboundOptions struct {
|
||||
type FallbackOutboundOptions struct {
|
||||
Outbounds []string `json:"outbounds"`
|
||||
}
|
||||
|
||||
type GroupCommonOption struct {
|
||||
Outbounds []string `json:"outbounds"`
|
||||
Providers []string `json:"providers"`
|
||||
Exclude *badoption.Regexp `json:"exclude,omitempty"`
|
||||
Include *badoption.Regexp `json:"include,omitempty"`
|
||||
UseAllProviders bool `json:"use_all_providers,omitempty"`
|
||||
}
|
||||
|
||||
32
option/masque.go
Normal file
32
option/masque.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package option
|
||||
|
||||
import (
|
||||
"github.com/sagernet/sing/common/json/badoption"
|
||||
)
|
||||
|
||||
type MASQUEOutboundOptions struct {
|
||||
UseHTTP2 bool `json:"use_http2,omitempty"`
|
||||
UseIPv6 bool `json:"use_ipv6,omitempty"`
|
||||
Profile CloudflareProfile `json:"profile,omitempty"`
|
||||
UDPTimeout badoption.Duration `json:"udp_timeout,omitempty"`
|
||||
UDPKeepalivePeriod badoption.Duration `json:"udp_keepalive_period,omitempty"`
|
||||
UDPInitialPacketSize uint16 `json:"udp_initial_packet_size,omitempty"`
|
||||
ReconnectDelay badoption.Duration `json:"reconnect_delay,omitempty"`
|
||||
MASQUEOutboundTLSOptions
|
||||
DialerOptions
|
||||
}
|
||||
|
||||
type MASQUEOutboundTLSOptions struct {
|
||||
Insecure bool `json:"insecure,omitempty"`
|
||||
CipherSuites badoption.Listable[string] `json:"cipher_suites,omitempty"`
|
||||
CurvePreferences badoption.Listable[CurvePreference] `json:"curve_preferences,omitempty"`
|
||||
Fragment bool `json:"fragment,omitempty"`
|
||||
FragmentFallbackDelay badoption.Duration `json:"fragment_fallback_delay,omitempty"`
|
||||
RecordFragment bool `json:"record_fragment,omitempty"`
|
||||
KernelTx bool `json:"kernel_tx,omitempty"`
|
||||
KernelRx bool `json:"kernel_rx,omitempty"`
|
||||
}
|
||||
|
||||
type MASQUEOutboundTLSOptionsContainer struct {
|
||||
TLS *OutboundTLSOptions `json:"tls,omitempty"`
|
||||
}
|
||||
89
option/mtproxy.go
Normal file
89
option/mtproxy.go
Normal file
@@ -0,0 +1,89 @@
|
||||
package option
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/sagernet/sing/common/json/badoption"
|
||||
)
|
||||
|
||||
type MTProxyInboundOptions struct {
|
||||
ListenOptions
|
||||
Users []MTProxyUser `json:"users,omitempty"`
|
||||
Concurrency uint `json:"concurrency,omitempty"`
|
||||
DomainFrontingPort uint `json:"domain_fronting_port,omitempty"`
|
||||
DomainFrontingIP string `json:"domain_fronting_ip,omitempty"`
|
||||
DomainFrontingProxyProtocol bool `json:"domain_fronting_proxy_protocol,omitempty"`
|
||||
PreferIP string `json:"prefer_ip,omitempty"`
|
||||
AutoUpdate bool `json:"auto_update,omitempty"`
|
||||
AllowFallbackOnUnknownDC bool `json:"allow_fallback_on_unknown_dc,omitempty"`
|
||||
TolerateTimeSkewness badoption.Duration `json:"tolerate_time_skewness,omitempty"`
|
||||
IdleTimeout badoption.Duration `json:"idle_timeout,omitempty"`
|
||||
HandshakeTimeout badoption.Duration `json:"handshake_timeout,omitempty"`
|
||||
DoppelGangerURLs []string `json:"doppelganger_urls,omitempty"`
|
||||
DoppelGangerPerRaid uint `json:"doppelganger_per_raid,omitempty"`
|
||||
DoppelGangerEach badoption.Duration `json:"doppelganger_each,omitempty"`
|
||||
DoppelGangerDRS bool `json:"doppelganger_drs,omitempty"`
|
||||
ThrottleMaxConnections uint `json:"throttle_max_connections,omitempty"`
|
||||
ThrottleCheckInterval badoption.Duration `json:"throttle_check_interval,omitempty"`
|
||||
}
|
||||
|
||||
func (o *MTProxyInboundOptions) GetConcurrency() uint {
|
||||
if o.Concurrency == 0 {
|
||||
return 8192
|
||||
}
|
||||
return o.Concurrency
|
||||
}
|
||||
|
||||
func (o *MTProxyInboundOptions) GetDomainFrontingPort() uint {
|
||||
if o.DomainFrontingPort == 0 {
|
||||
return 443
|
||||
}
|
||||
return o.DomainFrontingPort
|
||||
}
|
||||
|
||||
func (o *MTProxyInboundOptions) GetPreferIP() string {
|
||||
if o.PreferIP == "" {
|
||||
return "prefer-ipv4"
|
||||
}
|
||||
return o.PreferIP
|
||||
}
|
||||
|
||||
func (o *MTProxyInboundOptions) GetIdleTimeout() time.Duration {
|
||||
if o.IdleTimeout == 0 {
|
||||
return 5 * time.Minute
|
||||
}
|
||||
return o.IdleTimeout.Build()
|
||||
}
|
||||
|
||||
func (o *MTProxyInboundOptions) GetHandshakeTimeout() time.Duration {
|
||||
if o.HandshakeTimeout == 0 {
|
||||
return 10 * time.Second
|
||||
}
|
||||
return o.HandshakeTimeout.Build()
|
||||
}
|
||||
|
||||
func (o *MTProxyInboundOptions) GetDoppelGangerPerRaid() uint {
|
||||
if o.DoppelGangerPerRaid == 0 {
|
||||
return 10
|
||||
}
|
||||
return o.DoppelGangerPerRaid
|
||||
}
|
||||
|
||||
func (o *MTProxyInboundOptions) GetDoppelGangerEach() time.Duration {
|
||||
if o.HandshakeTimeout == 0 {
|
||||
return 6 * time.Hour
|
||||
}
|
||||
return o.DoppelGangerEach.Build()
|
||||
}
|
||||
|
||||
func (o *MTProxyInboundOptions) GetThrottleCheckInterval() time.Duration {
|
||||
if o.ThrottleCheckInterval == 0 {
|
||||
return 5 * time.Second
|
||||
}
|
||||
return o.ThrottleCheckInterval.Build()
|
||||
}
|
||||
|
||||
type MTProxyUser struct {
|
||||
Name string `json:"name"`
|
||||
Secret string `json:"secret"`
|
||||
}
|
||||
@@ -19,6 +19,7 @@ type _Options struct {
|
||||
Endpoints []Endpoint `json:"endpoints,omitempty"`
|
||||
Inbounds []Inbound `json:"inbounds,omitempty"`
|
||||
Outbounds []Outbound `json:"outbounds,omitempty"`
|
||||
Providers []Provider `json:"providers,omitempty"`
|
||||
Route *RouteOptions `json:"route,omitempty"`
|
||||
Services []Service `json:"services,omitempty"`
|
||||
Experimental *ExperimentalOptions `json:"experimental,omitempty"`
|
||||
|
||||
6
option/parser.go
Normal file
6
option/parser.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package option
|
||||
|
||||
type ParserOutboundOptions struct {
|
||||
DialerOptions
|
||||
Link string `json:"link"`
|
||||
}
|
||||
75
option/provider.go
Normal file
75
option/provider.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package option
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
"github.com/sagernet/sing/common/json"
|
||||
"github.com/sagernet/sing/common/json/badjson"
|
||||
"github.com/sagernet/sing/common/json/badoption"
|
||||
"github.com/sagernet/sing/service"
|
||||
)
|
||||
|
||||
type ProviderOptionsRegistry interface {
|
||||
CreateOptions(providerType string) (any, bool)
|
||||
}
|
||||
type _Provider struct {
|
||||
Type string `json:"type"`
|
||||
Tag string `json:"tag,omitempty"`
|
||||
Options any `json:"-"`
|
||||
}
|
||||
|
||||
type Provider _Provider
|
||||
|
||||
func (h *Provider) MarshalJSONContext(ctx context.Context) ([]byte, error) {
|
||||
return badjson.MarshallObjectsContext(ctx, (*_Provider)(h), h.Options)
|
||||
}
|
||||
|
||||
func (h *Provider) UnmarshalJSONContext(ctx context.Context, content []byte) error {
|
||||
err := json.UnmarshalContext(ctx, content, (*_Provider)(h))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
registry := service.FromContext[ProviderOptionsRegistry](ctx)
|
||||
if registry == nil {
|
||||
return E.New("missing provider options registry in context")
|
||||
}
|
||||
options, loaded := registry.CreateOptions(h.Type)
|
||||
if !loaded {
|
||||
return E.New("unknown provider type: ", h.Type)
|
||||
}
|
||||
err = badjson.UnmarshallExcludedContext(ctx, content, (*_Provider)(h), options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h.Options = options
|
||||
return nil
|
||||
}
|
||||
|
||||
type ProviderLocalOptions struct {
|
||||
Path string `json:"path"`
|
||||
HealthCheck ProviderHealthCheckOptions `json:"health_check,omitempty"`
|
||||
}
|
||||
|
||||
type ProviderRemoteOptions struct {
|
||||
URL string `json:"url"`
|
||||
UserAgent string `json:"user_agent,omitempty"`
|
||||
DownloadDetour string `json:"download_detour,omitempty"`
|
||||
UpdateInterval badoption.Duration `json:"update_interval,omitempty"`
|
||||
|
||||
Exclude *badoption.Regexp `json:"exclude,omitempty"`
|
||||
Include *badoption.Regexp `json:"include,omitempty"`
|
||||
HealthCheck ProviderHealthCheckOptions `json:"health_check,omitempty"`
|
||||
}
|
||||
|
||||
type ProviderInlineOptions struct {
|
||||
Outbounds []Outbound `json:"outbounds,omitempty"`
|
||||
HealthCheck ProviderHealthCheckOptions `json:"health_check,omitempty"`
|
||||
}
|
||||
|
||||
type ProviderHealthCheckOptions struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
URL string `json:"url,omitempty"`
|
||||
Interval badoption.Duration `json:"interval,omitempty"`
|
||||
Timeout badoption.Duration `json:"timeout,omitempty"`
|
||||
}
|
||||
@@ -88,8 +88,6 @@ type RawDefaultRule struct {
|
||||
SourcePortRange badoption.Listable[string] `json:"source_port_range,omitempty"`
|
||||
Port badoption.Listable[uint16] `json:"port,omitempty"`
|
||||
PortRange badoption.Listable[string] `json:"port_range,omitempty"`
|
||||
TunnelSource badoption.Listable[string] `json:"tunnel_source,omitempty"`
|
||||
TunnelDestination badoption.Listable[string] `json:"tunnel_destination,omitempty"`
|
||||
ProcessName badoption.Listable[string] `json:"process_name,omitempty"`
|
||||
ProcessPath badoption.Listable[string] `json:"process_path,omitempty"`
|
||||
ProcessPathRegex badoption.Listable[string] `json:"process_path_regex,omitempty"`
|
||||
|
||||
@@ -155,9 +155,10 @@ type RouteActionOptions struct {
|
||||
}
|
||||
|
||||
type RawRouteOptionsActionOptions struct {
|
||||
OverrideAddress string `json:"override_address,omitempty"`
|
||||
OverridePort uint16 `json:"override_port,omitempty"`
|
||||
OverrideTunnelDestination string `json:"override_tunnel_destination,omitempty"`
|
||||
OverrideAddress string `json:"override_address,omitempty"`
|
||||
OverridePort uint16 `json:"override_port,omitempty"`
|
||||
|
||||
OverrideGateway string `json:"override_gateway,omitempty"`
|
||||
|
||||
NetworkStrategy *NetworkStrategy `json:"network_strategy,omitempty"`
|
||||
FallbackDelay uint32 `json:"fallback_delay,omitempty"`
|
||||
|
||||
@@ -90,8 +90,6 @@ type RawDefaultDNSRule struct {
|
||||
SourcePortRange badoption.Listable[string] `json:"source_port_range,omitempty"`
|
||||
Port badoption.Listable[uint16] `json:"port,omitempty"`
|
||||
PortRange badoption.Listable[string] `json:"port_range,omitempty"`
|
||||
TunnelSource badoption.Listable[string] `json:"tunnel_source,omitempty"`
|
||||
TunnelDestination badoption.Listable[string] `json:"tunnel_destination,omitempty"`
|
||||
ProcessName badoption.Listable[string] `json:"process_name,omitempty"`
|
||||
ProcessPath badoption.Listable[string] `json:"process_path,omitempty"`
|
||||
ProcessPathRegex badoption.Listable[string] `json:"process_path_regex,omitempty"`
|
||||
|
||||
@@ -194,8 +194,6 @@ type DefaultHeadlessRule struct {
|
||||
SourcePortRange badoption.Listable[string] `json:"source_port_range,omitempty"`
|
||||
Port badoption.Listable[uint16] `json:"port,omitempty"`
|
||||
PortRange badoption.Listable[string] `json:"port_range,omitempty"`
|
||||
TunnelSource badoption.Listable[string] `json:"tunnel_source,omitempty"`
|
||||
TunnelDestination badoption.Listable[string] `json:"tunnel_destination,omitempty"`
|
||||
ProcessName badoption.Listable[string] `json:"process_name,omitempty"`
|
||||
ProcessPath badoption.Listable[string] `json:"process_path,omitempty"`
|
||||
ProcessPathRegex badoption.Listable[string] `json:"process_path_regex,omitempty"`
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package option
|
||||
|
||||
import "github.com/sagernet/sing/common/json/badoption"
|
||||
|
||||
type TunnelClientEndpointOptions struct {
|
||||
UUID string `json:"uuid"`
|
||||
Key string `json:"key"`
|
||||
Outbound Outbound `json:"outbound"`
|
||||
}
|
||||
|
||||
type TunnelServerEndpointOptions struct {
|
||||
UUID string `json:"uuid"`
|
||||
Users []TunnelUser `json:"users"`
|
||||
Inbound Inbound `json:"inbound"`
|
||||
ConnectTimeout badoption.Duration `json:"connect_timeout,omitempty"`
|
||||
}
|
||||
|
||||
type TunnelUser struct {
|
||||
UUID string `json:"uuid"`
|
||||
Key string `json:"key"`
|
||||
}
|
||||
25
option/vpn.go
Normal file
25
option/vpn.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package option
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
|
||||
"github.com/sagernet/sing/common/json/badoption"
|
||||
)
|
||||
|
||||
type VPNClientEndpointOptions struct {
|
||||
Address netip.Addr `json:"address"`
|
||||
Key string `json:"key"`
|
||||
Outbound Outbound `json:"outbound"`
|
||||
}
|
||||
|
||||
type VPNServerEndpointOptions struct {
|
||||
Address netip.Addr `json:"address"`
|
||||
Users []VPNUser `json:"users"`
|
||||
Inbounds []Inbound `json:"inbounds"`
|
||||
ConnectTimeout badoption.Duration `json:"connect_timeout,omitempty"`
|
||||
}
|
||||
|
||||
type VPNUser struct {
|
||||
Address netip.Addr `json:"address"`
|
||||
Key string `json:"key"`
|
||||
}
|
||||
18
option/warp.go
Normal file
18
option/warp.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package option
|
||||
|
||||
import "github.com/sagernet/sing/common/json/badoption"
|
||||
|
||||
type WARPEndpointOptions struct {
|
||||
System bool `json:"system,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
ListenPort uint16 `json:"listen_port,omitempty"`
|
||||
UDPTimeout badoption.Duration `json:"udp_timeout,omitempty"`
|
||||
PersistentKeepaliveInterval uint16 `json:"persistent_keepalive_interval,omitempty"`
|
||||
Reserved []uint8 `json:"reserved,omitempty"`
|
||||
Workers int `json:"workers,omitempty"`
|
||||
PreallocatedBuffersPerPool uint32 `json:"preallocated_buffers_per_pool,omitempty"`
|
||||
DisablePauses bool `json:"disable_pauses,omitempty"`
|
||||
Amnezia *WireGuardAmnezia `json:"amnezia,omitempty"`
|
||||
Profile CloudflareProfile `json:"profile,omitempty"`
|
||||
DialerOptions
|
||||
}
|
||||
@@ -33,29 +33,6 @@ type WireGuardPeer struct {
|
||||
Reserved []uint8 `json:"reserved,omitempty"`
|
||||
}
|
||||
|
||||
type WireGuardWARPEndpointOptions struct {
|
||||
System bool `json:"system,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
ListenPort uint16 `json:"listen_port,omitempty"`
|
||||
UDPTimeout badoption.Duration `json:"udp_timeout,omitempty"`
|
||||
PersistentKeepaliveInterval uint16 `json:"persistent_keepalive_interval,omitempty"`
|
||||
Reserved []uint8 `json:"reserved,omitempty"`
|
||||
Workers int `json:"workers,omitempty"`
|
||||
PreallocatedBuffersPerPool uint32 `json:"preallocated_buffers_per_pool,omitempty"`
|
||||
DisablePauses bool `json:"disable_pauses,omitempty"`
|
||||
Amnezia *WireGuardAmnezia `json:"amnezia,omitempty"`
|
||||
Profile WARPProfile `json:"profile,omitempty"`
|
||||
DialerOptions
|
||||
}
|
||||
|
||||
type WARPProfile struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
PrivateKey string `json:"private_key,omitempty"`
|
||||
AuthToken string `json:"auth_token,omitempty"`
|
||||
Recreate bool `json:"recreate,omitempty"`
|
||||
Detour string `json:"detour,omitempty"`
|
||||
}
|
||||
|
||||
type WireGuardAmnezia struct {
|
||||
JC int `json:"jc,omitempty"`
|
||||
JMin int `json:"jmin,omitempty"`
|
||||
|
||||
Reference in New Issue
Block a user