registry.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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/log"
  10. "github.com/sagernet/sing-box/option"
  11. "github.com/sagernet/sing-box/protocol/block"
  12. "github.com/sagernet/sing-box/protocol/direct"
  13. "github.com/sagernet/sing-box/protocol/dns"
  14. "github.com/sagernet/sing-box/protocol/group"
  15. "github.com/sagernet/sing-box/protocol/http"
  16. "github.com/sagernet/sing-box/protocol/mixed"
  17. "github.com/sagernet/sing-box/protocol/naive"
  18. "github.com/sagernet/sing-box/protocol/redirect"
  19. "github.com/sagernet/sing-box/protocol/shadowsocks"
  20. "github.com/sagernet/sing-box/protocol/shadowtls"
  21. "github.com/sagernet/sing-box/protocol/socks"
  22. "github.com/sagernet/sing-box/protocol/ssh"
  23. "github.com/sagernet/sing-box/protocol/tor"
  24. "github.com/sagernet/sing-box/protocol/trojan"
  25. "github.com/sagernet/sing-box/protocol/tun"
  26. "github.com/sagernet/sing-box/protocol/vless"
  27. "github.com/sagernet/sing-box/protocol/vmess"
  28. E "github.com/sagernet/sing/common/exceptions"
  29. )
  30. func InboundRegistry() *inbound.Registry {
  31. registry := inbound.NewRegistry()
  32. tun.RegisterInbound(registry)
  33. redirect.RegisterRedirect(registry)
  34. redirect.RegisterTProxy(registry)
  35. direct.RegisterInbound(registry)
  36. socks.RegisterInbound(registry)
  37. http.RegisterInbound(registry)
  38. mixed.RegisterInbound(registry)
  39. shadowsocks.RegisterInbound(registry)
  40. vmess.RegisterInbound(registry)
  41. trojan.RegisterInbound(registry)
  42. naive.RegisterInbound(registry)
  43. shadowtls.RegisterInbound(registry)
  44. vless.RegisterInbound(registry)
  45. registerQUICInbounds(registry)
  46. registerStubForRemovedInbounds(registry)
  47. return registry
  48. }
  49. func OutboundRegistry() *outbound.Registry {
  50. registry := outbound.NewRegistry()
  51. direct.RegisterOutbound(registry)
  52. block.RegisterOutbound(registry)
  53. dns.RegisterOutbound(registry)
  54. group.RegisterSelector(registry)
  55. group.RegisterURLTest(registry)
  56. socks.RegisterOutbound(registry)
  57. http.RegisterOutbound(registry)
  58. shadowsocks.RegisterOutbound(registry)
  59. vmess.RegisterOutbound(registry)
  60. trojan.RegisterOutbound(registry)
  61. tor.RegisterOutbound(registry)
  62. ssh.RegisterOutbound(registry)
  63. shadowtls.RegisterOutbound(registry)
  64. vless.RegisterOutbound(registry)
  65. registerQUICOutbounds(registry)
  66. registerWireGuardOutbound(registry)
  67. registerStubForRemovedOutbounds(registry)
  68. return registry
  69. }
  70. func EndpointRegistry() *endpoint.Registry {
  71. registry := endpoint.NewRegistry()
  72. registerWireGuardEndpoint(registry)
  73. return registry
  74. }
  75. func registerStubForRemovedInbounds(registry *inbound.Registry) {
  76. 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) {
  77. return nil, E.New("ShadowsocksR is deprecated and removed in sing-box 1.6.0")
  78. })
  79. }
  80. func registerStubForRemovedOutbounds(registry *outbound.Registry) {
  81. 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) {
  82. return nil, E.New("ShadowsocksR is deprecated and removed in sing-box 1.6.0")
  83. })
  84. }