Skip to content
122 changes: 97 additions & 25 deletions constant/proxy.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,57 @@
package constant

const (
TypeTun = "tun"
TypeRedirect = "redirect"
TypeTProxy = "tproxy"
TypeDirect = "direct"
TypeBlock = "block"
TypeDNS = "dns"
TypeSOCKS = "socks"
TypeHTTP = "http"
TypeMixed = "mixed"
TypeShadowsocks = "shadowsocks"
TypeVMess = "vmess"
TypeTrojan = "trojan"
TypeNaive = "naive"
TypeWireGuard = "wireguard"
TypeHysteria = "hysteria"
TypeTor = "tor"
TypeSSH = "ssh"
TypeShadowTLS = "shadowtls"
TypeShadowsocksR = "shadowsocksr"
TypeVLESS = "vless"
TypeTUIC = "tuic"
TypeHysteria2 = "hysteria2"
TypeCustom = "custom"
TypeXray = "xray"
TypeInvalidConfig = "invalid"
TypeTun = "tun"
TypeRedirect = "redirect"
TypeTProxy = "tproxy"
TypeDirect = "direct"
TypeBlock = "block"
TypeDNS = "dns"
TypeSOCKS = "socks"
TypeHTTP = "http"
TypeMixed = "mixed"
TypeShadowsocks = "shadowsocks"
TypeVMess = "vmess"
TypeTrojan = "trojan"
TypeNaive = "naive"
TypeWireGuard = "wireguard"
TypeWARP = "warp"
TypeHysteria = "hysteria"
TypeTor = "tor"
TypeSSH = "ssh"
TypeShadowTLS = "shadowtls"
TypeMieru = "mieru"
TypeAnyTLS = "anytls"
TypeSnell = "snell"
TypeMASQUE = "masque"
TypeShadowsocksR = "shadowsocksr"
TypeVLESS = "vless"
TypeTUIC = "tuic"
TypeHysteria2 = "hysteria2"
TypeHysteriaRealm = "hysteria-realm"
TypePsiphon = "psiphon"
TypeTunnelClient = "tunnel_client"
TypeTunnelServer = "tunnel_server"
TypeTailscale = "tailscale"
TypeCloudflared = "cloudflared"
TypeDERP = "derp"
TypeResolved = "resolved"
TypeSSMAPI = "ssm-api"
TypeCCM = "ccm"
TypeOCM = "ocm"
TypeOOMKiller = "oom-killer"
TypeACME = "acme"
TypeCloudflareOriginCA = "cloudflare-origin-ca"

TypeHInvalidConfig = "hinvalid" //H
TypeXray = "xray" //H
TypeCustom = "custom" //H
TypeAwg = "awg" //H
TypeBalancer = "balancer" //H
TypeDNSTT = "dnstt" //H
TypeGooseRelay = "gooserelay" //H
TypeFirebaseTunnel = "firebasetunnel" //H
TypeSmartDNSPool = "smart_dns_pool" //H — local recursive-resolver pool with AIMD throttling + recovery probing (github.com/hiddify/hmrd_multi_resolver_dns)
)

const (
Expand All @@ -35,6 +61,12 @@ const (

func ProxyDisplayName(proxyType string) string {
switch proxyType {
case TypeTun:
return "TUN"
case TypeRedirect:
return "Redirect"
case TypeTProxy:
return "TProxy"
case TypeDirect:
return "Direct"
case TypeBlock:
Expand All @@ -45,6 +77,8 @@ func ProxyDisplayName(proxyType string) string {
return "SOCKS"
case TypeHTTP:
return "HTTP"
case TypeMixed:
return "Mixed"
case TypeShadowsocks:
return "Shadowsocks"
case TypeVMess:
Expand All @@ -55,6 +89,8 @@ func ProxyDisplayName(proxyType string) string {
return "Naive"
case TypeWireGuard:
return "WireGuard"
case TypeWARP:
return "WARP"
case TypeHysteria:
return "Hysteria"
case TypeTor:
Expand All @@ -71,11 +107,47 @@ func ProxyDisplayName(proxyType string) string {
return "TUIC"
case TypeHysteria2:
return "Hysteria2"
case TypeMieru:
return "Mieru"
case TypeAnyTLS:
return "AnyTLS"
case TypeSnell:
return "Snell"
case TypeMASQUE:
return "MASQUE"
case TypePsiphon:
return "Psiphon"
case TypeTailscale:
return "Tailscale"
case TypeCloudflared:
return "Cloudflared"
case TypeSelector:
return "Selector"
case TypeURLTest:
return "URLTest"
case TypeHInvalidConfig:
return "Invalid"
case TypeXray:
return "xray"
case TypeCustom:
return "custom"
case TypeTunnelClient:
return "Tunnel Client"
case TypeTunnelServer:
return "Tunnel Server"
case TypeAwg:
return "Awg"
case TypeBalancer:
return "Balancer"
case TypeDNSTT:
return "DNSTT"
case TypeGooseRelay:
return "GooseRelay"
case TypeFirebaseTunnel:
return "Firebase Tunnel"
default:
return "Unknown"
}
}

const DefaultBrowserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36"
203 changes: 203 additions & 0 deletions include/registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
package include

import (
"context"

box "github.com/sagernet/sing-box"
"github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing-box/adapter/certificate"
"github.com/sagernet/sing-box/adapter/endpoint"
"github.com/sagernet/sing-box/adapter/inbound"
"github.com/sagernet/sing-box/adapter/outbound"
"github.com/sagernet/sing-box/adapter/service"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/dns"
"github.com/sagernet/sing-box/dns/transport"
"github.com/sagernet/sing-box/dns/transport/fakeip"
"github.com/sagernet/sing-box/dns/transport/hosts"
"github.com/sagernet/sing-box/dns/transport/local"
"github.com/sagernet/sing-box/dns/transport/multi"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing-box/protocol/anytls"
"github.com/sagernet/sing-box/protocol/block"
"github.com/sagernet/sing-box/protocol/direct"
"github.com/sagernet/sing-box/protocol/group"
"github.com/sagernet/sing-box/protocol/group/balancer"
"github.com/sagernet/sing-box/protocol/hiddify/dnstt"
"github.com/sagernet/sing-box/protocol/hiddify/gooserelay"
"github.com/sagernet/sing-box/protocol/hiddify/hinvalid"

"github.com/sagernet/sing-box/protocol/hiddify/xray"
"github.com/sagernet/sing-box/protocol/http"
"github.com/sagernet/sing-box/protocol/mieru"
"github.com/sagernet/sing-box/protocol/mixed"
"github.com/sagernet/sing-box/protocol/naive"
"github.com/sagernet/sing-box/protocol/psiphon"
"github.com/sagernet/sing-box/protocol/redirect"
"github.com/sagernet/sing-box/protocol/shadowsocks"
"github.com/sagernet/sing-box/protocol/shadowtls"
snellprotocol "github.com/sagernet/sing-box/protocol/snell"
"github.com/sagernet/sing-box/protocol/socks"
"github.com/sagernet/sing-box/protocol/ssh"
"github.com/sagernet/sing-box/protocol/tor"
"github.com/sagernet/sing-box/protocol/trojan"
"github.com/sagernet/sing-box/protocol/tun"
"github.com/sagernet/sing-box/protocol/firebasetunnel"
"github.com/sagernet/sing-box/protocol/tunnel"
"github.com/sagernet/sing-box/protocol/vless"
"github.com/sagernet/sing-box/protocol/vmess"
originca "github.com/sagernet/sing-box/service/origin_ca"
"github.com/sagernet/sing-box/service/resolved"
smartdnspool "github.com/sagernet/sing-box/service/smart_dns_pool"
"github.com/sagernet/sing-box/service/ssmapi"
E "github.com/sagernet/sing/common/exceptions"
)

func Context(ctx context.Context) context.Context {
return box.Context(ctx, InboundRegistry(), OutboundRegistry(), EndpointRegistry(), DNSTransportRegistry(), ServiceRegistry(), CertificateProviderRegistry())
}

func InboundRegistry() *inbound.Registry {
registry := inbound.NewRegistry()

tun.RegisterInbound(registry)
redirect.RegisterRedirect(registry)
redirect.RegisterTProxy(registry)
direct.RegisterInbound(registry)

socks.RegisterInbound(registry)
http.RegisterInbound(registry)
mixed.RegisterInbound(registry)

shadowsocks.RegisterInbound(registry)
vmess.RegisterInbound(registry)
trojan.RegisterInbound(registry)
naive.RegisterInbound(registry)
shadowtls.RegisterInbound(registry)
vless.RegisterInbound(registry)
anytls.RegisterInbound(registry)
mieru.RegisterInbound(registry)
ssh.RegisterInbound(registry)
snellprotocol.RegisterInbound(registry)

registerQUICInbounds(registry)
registerCloudflaredInbound(registry)
registerStubForRemovedInbounds(registry)

return registry
}

func OutboundRegistry() *outbound.Registry {
registry := outbound.NewRegistry()

direct.RegisterOutbound(registry)

block.RegisterOutbound(registry)

group.RegisterSelector(registry)
group.RegisterURLTest(registry)

socks.RegisterOutbound(registry)
http.RegisterOutbound(registry)
shadowsocks.RegisterOutbound(registry)
vmess.RegisterOutbound(registry)
trojan.RegisterOutbound(registry)
registerNaiveOutbound(registry)
tor.RegisterOutbound(registry)
ssh.RegisterOutbound(registry)
shadowtls.RegisterOutbound(registry)
vless.RegisterOutbound(registry)
psiphon.RegisterOutbound(registry)
mieru.RegisterOutbound(registry)
anytls.RegisterOutbound(registry)
hinvalid.RegisterOutbound(registry)
xray.RegisterOutbound(registry)
dnstt.RegisterOutbound(registry)
gooserelay.RegisterOutbound(registry)
balancer.RegisterLoadBalance(registry)
snellprotocol.RegisterOutbound(registry)

registerMASQUEOutbound(registry)
registerQUICOutbounds(registry)
registerStubForRemovedOutbounds(registry)

return registry
}

func EndpointRegistry() *endpoint.Registry {
registry := endpoint.NewRegistry()

tunnel.RegisterServerEndpoint(registry)
tunnel.RegisterClientEndpoint(registry)
firebasetunnel.RegisterEndpoint(registry)

registerWireGuardEndpoint(registry)
registerWarpEndpoint(registry)
registerTailscaleEndpoint(registry)
registerAwgEndpoint(registry)

return registry
}

func DNSTransportRegistry() *dns.TransportRegistry {
registry := dns.NewTransportRegistry()

transport.RegisterTCP(registry)
transport.RegisterUDP(registry)
transport.RegisterTLS(registry)
transport.RegisterHTTPS(registry)
transport.RegisterSDNS(registry)

multi.RegisterTransport(registry) //H
hosts.RegisterTransport(registry)
local.RegisterTransport(registry)
fakeip.RegisterTransport(registry)
resolved.RegisterTransport(registry)

registerQUICTransports(registry)
registerDHCPTransport(registry)
registerTailscaleTransport(registry)

return registry
}

func ServiceRegistry() *service.Registry {
registry := service.NewRegistry()

resolved.RegisterService(registry)
ssmapi.RegisterService(registry)
smartdnspool.RegisterService(registry) //H

registerDERPService(registry)
registerCCMService(registry)
registerOCMService(registry)
registerOOMKillerService(registry)

return registry
}

func CertificateProviderRegistry() *certificate.Registry {
registry := certificate.NewRegistry()

registerACMECertificateProvider(registry)
registerTailscaleCertificateProvider(registry)
originca.RegisterCertificateProvider(registry)

return registry
}

func registerStubForRemovedInbounds(registry *inbound.Registry) {
inbound.Register[option.ShadowsocksInboundOptions](registry, C.TypeShadowsocksR, func(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.ShadowsocksInboundOptions) (adapter.Inbound, error) {
return nil, E.New("ShadowsocksR is deprecated and removed in sing-box 1.6.0")
})
}

func registerStubForRemovedOutbounds(registry *outbound.Registry) {
outbound.Register[option.ShadowsocksROutboundOptions](registry, C.TypeShadowsocksR, func(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.ShadowsocksROutboundOptions) (adapter.Outbound, error) {
return nil, E.New("ShadowsocksR is deprecated and removed in sing-box 1.6.0")
})
outbound.Register[option.StubOptions](registry, C.TypeWireGuard, func(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.StubOptions) (adapter.Outbound, error) {
return nil, E.New("WireGuard outbound is deprecated in sing-box 1.11.0 and removed in sing-box 1.13.0, use WireGuard endpoint instead")
})
}
Loading