registry.go 4.2 KB

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