registry.go 4.6 KB

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