1
0

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/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/block"
  17. "github.com/sagernet/sing-box/protocol/direct"
  18. protocolDNS "github.com/sagernet/sing-box/protocol/dns"
  19. "github.com/sagernet/sing-box/protocol/group"
  20. "github.com/sagernet/sing-box/protocol/http"
  21. "github.com/sagernet/sing-box/protocol/mixed"
  22. "github.com/sagernet/sing-box/protocol/naive"
  23. "github.com/sagernet/sing-box/protocol/redirect"
  24. "github.com/sagernet/sing-box/protocol/shadowsocks"
  25. "github.com/sagernet/sing-box/protocol/shadowtls"
  26. "github.com/sagernet/sing-box/protocol/socks"
  27. "github.com/sagernet/sing-box/protocol/ssh"
  28. "github.com/sagernet/sing-box/protocol/tor"
  29. "github.com/sagernet/sing-box/protocol/trojan"
  30. "github.com/sagernet/sing-box/protocol/tun"
  31. "github.com/sagernet/sing-box/protocol/vless"
  32. "github.com/sagernet/sing-box/protocol/vmess"
  33. E "github.com/sagernet/sing/common/exceptions"
  34. )
  35. func InboundRegistry() *inbound.Registry {
  36. registry := inbound.NewRegistry()
  37. tun.RegisterInbound(registry)
  38. redirect.RegisterRedirect(registry)
  39. redirect.RegisterTProxy(registry)
  40. direct.RegisterInbound(registry)
  41. socks.RegisterInbound(registry)
  42. http.RegisterInbound(registry)
  43. mixed.RegisterInbound(registry)
  44. shadowsocks.RegisterInbound(registry)
  45. vmess.RegisterInbound(registry)
  46. trojan.RegisterInbound(registry)
  47. naive.RegisterInbound(registry)
  48. shadowtls.RegisterInbound(registry)
  49. vless.RegisterInbound(registry)
  50. registerQUICInbounds(registry)
  51. registerStubForRemovedInbounds(registry)
  52. return registry
  53. }
  54. func OutboundRegistry() *outbound.Registry {
  55. registry := outbound.NewRegistry()
  56. direct.RegisterOutbound(registry)
  57. block.RegisterOutbound(registry)
  58. protocolDNS.RegisterOutbound(registry)
  59. group.RegisterSelector(registry)
  60. group.RegisterURLTest(registry)
  61. socks.RegisterOutbound(registry)
  62. http.RegisterOutbound(registry)
  63. shadowsocks.RegisterOutbound(registry)
  64. vmess.RegisterOutbound(registry)
  65. trojan.RegisterOutbound(registry)
  66. tor.RegisterOutbound(registry)
  67. ssh.RegisterOutbound(registry)
  68. shadowtls.RegisterOutbound(registry)
  69. vless.RegisterOutbound(registry)
  70. registerQUICOutbounds(registry)
  71. registerWireGuardOutbound(registry)
  72. registerStubForRemovedOutbounds(registry)
  73. return registry
  74. }
  75. func EndpointRegistry() *endpoint.Registry {
  76. registry := endpoint.NewRegistry()
  77. registerWireGuardEndpoint(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. hosts.RegisterTransport(registry)
  88. local.RegisterTransport(registry)
  89. fakeip.RegisterTransport(registry)
  90. registerQUICTransports(registry)
  91. registerDHCPTransport(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. }