1
0

registry.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. package include
  2. import (
  3. "context"
  4. "github.com/sagernet/sing-box"
  5. "github.com/sagernet/sing-box/adapter"
  6. "github.com/sagernet/sing-box/adapter/certificate"
  7. "github.com/sagernet/sing-box/adapter/endpoint"
  8. "github.com/sagernet/sing-box/adapter/inbound"
  9. "github.com/sagernet/sing-box/adapter/outbound"
  10. "github.com/sagernet/sing-box/adapter/service"
  11. C "github.com/sagernet/sing-box/constant"
  12. "github.com/sagernet/sing-box/dns"
  13. "github.com/sagernet/sing-box/dns/transport"
  14. "github.com/sagernet/sing-box/dns/transport/fakeip"
  15. "github.com/sagernet/sing-box/dns/transport/hosts"
  16. "github.com/sagernet/sing-box/dns/transport/local"
  17. "github.com/sagernet/sing-box/log"
  18. "github.com/sagernet/sing-box/option"
  19. "github.com/sagernet/sing-box/protocol/anytls"
  20. "github.com/sagernet/sing-box/protocol/block"
  21. "github.com/sagernet/sing-box/protocol/direct"
  22. "github.com/sagernet/sing-box/protocol/group"
  23. "github.com/sagernet/sing-box/protocol/http"
  24. "github.com/sagernet/sing-box/protocol/mixed"
  25. "github.com/sagernet/sing-box/protocol/naive"
  26. "github.com/sagernet/sing-box/protocol/redirect"
  27. "github.com/sagernet/sing-box/protocol/shadowsocks"
  28. "github.com/sagernet/sing-box/protocol/shadowtls"
  29. "github.com/sagernet/sing-box/protocol/socks"
  30. "github.com/sagernet/sing-box/protocol/ssh"
  31. "github.com/sagernet/sing-box/protocol/tor"
  32. "github.com/sagernet/sing-box/protocol/trojan"
  33. "github.com/sagernet/sing-box/protocol/tun"
  34. "github.com/sagernet/sing-box/protocol/vless"
  35. "github.com/sagernet/sing-box/protocol/vmess"
  36. originca "github.com/sagernet/sing-box/service/origin_ca"
  37. "github.com/sagernet/sing-box/service/resolved"
  38. "github.com/sagernet/sing-box/service/ssmapi"
  39. E "github.com/sagernet/sing/common/exceptions"
  40. )
  41. func Context(ctx context.Context) context.Context {
  42. return box.Context(ctx, InboundRegistry(), OutboundRegistry(), EndpointRegistry(), DNSTransportRegistry(), ServiceRegistry(), CertificateProviderRegistry())
  43. }
  44. func InboundRegistry() *inbound.Registry {
  45. registry := inbound.NewRegistry()
  46. tun.RegisterInbound(registry)
  47. redirect.RegisterRedirect(registry)
  48. redirect.RegisterTProxy(registry)
  49. direct.RegisterInbound(registry)
  50. socks.RegisterInbound(registry)
  51. http.RegisterInbound(registry)
  52. mixed.RegisterInbound(registry)
  53. shadowsocks.RegisterInbound(registry)
  54. vmess.RegisterInbound(registry)
  55. trojan.RegisterInbound(registry)
  56. naive.RegisterInbound(registry)
  57. shadowtls.RegisterInbound(registry)
  58. vless.RegisterInbound(registry)
  59. anytls.RegisterInbound(registry)
  60. registerQUICInbounds(registry)
  61. registerStubForRemovedInbounds(registry)
  62. return registry
  63. }
  64. func OutboundRegistry() *outbound.Registry {
  65. registry := outbound.NewRegistry()
  66. direct.RegisterOutbound(registry)
  67. block.RegisterOutbound(registry)
  68. group.RegisterSelector(registry)
  69. group.RegisterURLTest(registry)
  70. socks.RegisterOutbound(registry)
  71. http.RegisterOutbound(registry)
  72. shadowsocks.RegisterOutbound(registry)
  73. vmess.RegisterOutbound(registry)
  74. trojan.RegisterOutbound(registry)
  75. registerNaiveOutbound(registry)
  76. tor.RegisterOutbound(registry)
  77. ssh.RegisterOutbound(registry)
  78. shadowtls.RegisterOutbound(registry)
  79. vless.RegisterOutbound(registry)
  80. anytls.RegisterOutbound(registry)
  81. registerQUICOutbounds(registry)
  82. registerStubForRemovedOutbounds(registry)
  83. return registry
  84. }
  85. func EndpointRegistry() *endpoint.Registry {
  86. registry := endpoint.NewRegistry()
  87. registerWireGuardEndpoint(registry)
  88. registerTailscaleEndpoint(registry)
  89. return registry
  90. }
  91. func DNSTransportRegistry() *dns.TransportRegistry {
  92. registry := dns.NewTransportRegistry()
  93. transport.RegisterTCP(registry)
  94. transport.RegisterUDP(registry)
  95. transport.RegisterTLS(registry)
  96. transport.RegisterHTTPS(registry)
  97. hosts.RegisterTransport(registry)
  98. local.RegisterTransport(registry)
  99. fakeip.RegisterTransport(registry)
  100. resolved.RegisterTransport(registry)
  101. registerQUICTransports(registry)
  102. registerDHCPTransport(registry)
  103. registerTailscaleTransport(registry)
  104. return registry
  105. }
  106. func ServiceRegistry() *service.Registry {
  107. registry := service.NewRegistry()
  108. resolved.RegisterService(registry)
  109. ssmapi.RegisterService(registry)
  110. registerDERPService(registry)
  111. registerCCMService(registry)
  112. registerOCMService(registry)
  113. registerOOMKillerService(registry)
  114. return registry
  115. }
  116. func CertificateProviderRegistry() *certificate.Registry {
  117. registry := certificate.NewRegistry()
  118. registerACMECertificateProvider(registry)
  119. registerTailscaleCertificateProvider(registry)
  120. originca.RegisterCertificateProvider(registry)
  121. return registry
  122. }
  123. func registerStubForRemovedInbounds(registry *inbound.Registry) {
  124. 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) {
  125. return nil, E.New("ShadowsocksR is deprecated and removed in sing-box 1.6.0")
  126. })
  127. }
  128. func registerStubForRemovedOutbounds(registry *outbound.Registry) {
  129. 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) {
  130. return nil, E.New("ShadowsocksR is deprecated and removed in sing-box 1.6.0")
  131. })
  132. 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) {
  133. 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")
  134. })
  135. }