registry.go 3.2 KB

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