registry.go 4.1 KB

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