registry.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. E "github.com/sagernet/sing/common/exceptions"
  37. )
  38. func InboundRegistry() *inbound.Registry {
  39. registry := inbound.NewRegistry()
  40. tun.RegisterInbound(registry)
  41. redirect.RegisterRedirect(registry)
  42. redirect.RegisterTProxy(registry)
  43. direct.RegisterInbound(registry)
  44. socks.RegisterInbound(registry)
  45. http.RegisterInbound(registry)
  46. mixed.RegisterInbound(registry)
  47. shadowsocks.RegisterInbound(registry)
  48. vmess.RegisterInbound(registry)
  49. trojan.RegisterInbound(registry)
  50. naive.RegisterInbound(registry)
  51. shadowtls.RegisterInbound(registry)
  52. vless.RegisterInbound(registry)
  53. anytls.RegisterInbound(registry)
  54. registerQUICInbounds(registry)
  55. registerStubForRemovedInbounds(registry)
  56. return registry
  57. }
  58. func OutboundRegistry() *outbound.Registry {
  59. registry := outbound.NewRegistry()
  60. direct.RegisterOutbound(registry)
  61. block.RegisterOutbound(registry)
  62. protocolDNS.RegisterOutbound(registry)
  63. group.RegisterSelector(registry)
  64. group.RegisterURLTest(registry)
  65. socks.RegisterOutbound(registry)
  66. http.RegisterOutbound(registry)
  67. shadowsocks.RegisterOutbound(registry)
  68. vmess.RegisterOutbound(registry)
  69. trojan.RegisterOutbound(registry)
  70. tor.RegisterOutbound(registry)
  71. ssh.RegisterOutbound(registry)
  72. shadowtls.RegisterOutbound(registry)
  73. vless.RegisterOutbound(registry)
  74. anytls.RegisterOutbound(registry)
  75. registerQUICOutbounds(registry)
  76. registerWireGuardOutbound(registry)
  77. registerStubForRemovedOutbounds(registry)
  78. return registry
  79. }
  80. func EndpointRegistry() *endpoint.Registry {
  81. registry := endpoint.NewRegistry()
  82. registerWireGuardEndpoint(registry)
  83. registerTailscaleEndpoint(registry)
  84. return registry
  85. }
  86. func DNSTransportRegistry() *dns.TransportRegistry {
  87. registry := dns.NewTransportRegistry()
  88. transport.RegisterTCP(registry)
  89. transport.RegisterUDP(registry)
  90. transport.RegisterTLS(registry)
  91. transport.RegisterHTTPS(registry)
  92. hosts.RegisterTransport(registry)
  93. local.RegisterTransport(registry)
  94. fakeip.RegisterTransport(registry)
  95. resolved.RegisterTransport(registry)
  96. registerQUICTransports(registry)
  97. registerDHCPTransport(registry)
  98. registerTailscaleTransport(registry)
  99. return registry
  100. }
  101. func ServiceRegistry() *service.Registry {
  102. registry := service.NewRegistry()
  103. resolved.RegisterService(registry)
  104. registerDERPService(registry)
  105. return registry
  106. }
  107. func registerStubForRemovedInbounds(registry *inbound.Registry) {
  108. 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) {
  109. return nil, E.New("ShadowsocksR is deprecated and removed in sing-box 1.6.0")
  110. })
  111. }
  112. func registerStubForRemovedOutbounds(registry *outbound.Registry) {
  113. 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) {
  114. return nil, E.New("ShadowsocksR is deprecated and removed in sing-box 1.6.0")
  115. })
  116. }