registry.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. registerCloudflaredInbound(registry)
  62. registerStubForRemovedInbounds(registry)
  63. return registry
  64. }
  65. func OutboundRegistry() *outbound.Registry {
  66. registry := outbound.NewRegistry()
  67. direct.RegisterOutbound(registry)
  68. block.RegisterOutbound(registry)
  69. group.RegisterSelector(registry)
  70. group.RegisterURLTest(registry)
  71. socks.RegisterOutbound(registry)
  72. http.RegisterOutbound(registry)
  73. shadowsocks.RegisterOutbound(registry)
  74. vmess.RegisterOutbound(registry)
  75. trojan.RegisterOutbound(registry)
  76. registerNaiveOutbound(registry)
  77. tor.RegisterOutbound(registry)
  78. ssh.RegisterOutbound(registry)
  79. shadowtls.RegisterOutbound(registry)
  80. vless.RegisterOutbound(registry)
  81. anytls.RegisterOutbound(registry)
  82. registerQUICOutbounds(registry)
  83. registerStubForRemovedOutbounds(registry)
  84. return registry
  85. }
  86. func EndpointRegistry() *endpoint.Registry {
  87. registry := endpoint.NewRegistry()
  88. registerWireGuardEndpoint(registry)
  89. registerTailscaleEndpoint(registry)
  90. return registry
  91. }
  92. func DNSTransportRegistry() *dns.TransportRegistry {
  93. registry := dns.NewTransportRegistry()
  94. transport.RegisterTCP(registry)
  95. transport.RegisterUDP(registry)
  96. transport.RegisterTLS(registry)
  97. transport.RegisterHTTPS(registry)
  98. hosts.RegisterTransport(registry)
  99. local.RegisterTransport(registry)
  100. fakeip.RegisterTransport(registry)
  101. resolved.RegisterTransport(registry)
  102. registerQUICTransports(registry)
  103. registerDHCPTransport(registry)
  104. registerTailscaleTransport(registry)
  105. return registry
  106. }
  107. func ServiceRegistry() *service.Registry {
  108. registry := service.NewRegistry()
  109. resolved.RegisterService(registry)
  110. ssmapi.RegisterService(registry)
  111. registerDERPService(registry)
  112. registerCCMService(registry)
  113. registerOCMService(registry)
  114. registerOOMKillerService(registry)
  115. return registry
  116. }
  117. func CertificateProviderRegistry() *certificate.Registry {
  118. registry := certificate.NewRegistry()
  119. registerACMECertificateProvider(registry)
  120. registerTailscaleCertificateProvider(registry)
  121. originca.RegisterCertificateProvider(registry)
  122. return registry
  123. }
  124. func registerStubForRemovedInbounds(registry *inbound.Registry) {
  125. 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) {
  126. return nil, E.New("ShadowsocksR is deprecated and removed in sing-box 1.6.0")
  127. })
  128. }
  129. func registerStubForRemovedOutbounds(registry *outbound.Registry) {
  130. 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) {
  131. return nil, E.New("ShadowsocksR is deprecated and removed in sing-box 1.6.0")
  132. })
  133. 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) {
  134. 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")
  135. })
  136. }