protocols.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Pure decision logic for the protocol wizard. No React/DOM.
  2. export type UseCase = 'censorship' | 'general' | 'speed';
  3. export type CensorshipLevel = 'high' | 'medium' | 'low';
  4. export type ClientSupport = 'modern' | 'broad';
  5. export interface WizardAnswers {
  6. useCase: UseCase;
  7. censorship: CensorshipLevel;
  8. clientSupport: ClientSupport;
  9. }
  10. export interface Recommendation {
  11. protocol: string;
  12. transport: string;
  13. security: string;
  14. rationale: string;
  15. links: { title: string; href: string }[];
  16. }
  17. const REALITY_LINK = { title: 'REALITY setup', href: '/docs/config/reality' };
  18. const TRANSPORTS_LINK = { title: 'Transports', href: '/docs/config/transports' };
  19. const INBOUNDS_LINK = { title: 'Inbounds', href: '/docs/config/inbounds' };
  20. export function recommend(a: WizardAnswers): Recommendation {
  21. const heavyCensorship = a.useCase === 'censorship' || a.censorship === 'high';
  22. if (heavyCensorship) {
  23. if (a.clientSupport === 'modern') {
  24. return {
  25. protocol: 'VLESS',
  26. transport: 'TCP',
  27. security: 'REALITY + XTLS-Vision',
  28. rationale:
  29. 'REALITY disguises traffic as a real TLS site without a certificate, and XTLS-Vision keeps it fast. The best stealth option for heavy censorship — needs a modern client.',
  30. links: [REALITY_LINK, INBOUNDS_LINK],
  31. };
  32. }
  33. return {
  34. protocol: 'VMess',
  35. transport: 'WebSocket',
  36. security: 'TLS',
  37. rationale:
  38. 'WebSocket + TLS works through CDNs and is supported by almost every client, making it a resilient fallback when broad client support matters more than peak stealth.',
  39. links: [TRANSPORTS_LINK, INBOUNDS_LINK],
  40. };
  41. }
  42. if (a.useCase === 'speed') {
  43. if (a.clientSupport === 'modern') {
  44. return {
  45. protocol: 'VLESS',
  46. transport: 'TCP',
  47. security: 'REALITY + XTLS-Vision',
  48. rationale:
  49. 'XTLS-Vision over raw TCP has the lowest overhead, so it is the fastest option for modern clients.',
  50. links: [REALITY_LINK, TRANSPORTS_LINK],
  51. };
  52. }
  53. return {
  54. protocol: 'Trojan',
  55. transport: 'TCP',
  56. security: 'TLS',
  57. rationale: 'Trojan over TCP + TLS is simple and fast, and is widely supported by clients.',
  58. links: [INBOUNDS_LINK, TRANSPORTS_LINK],
  59. };
  60. }
  61. // general use
  62. if (a.clientSupport === 'modern') {
  63. return {
  64. protocol: 'VLESS',
  65. transport: 'WebSocket',
  66. security: 'TLS',
  67. rationale:
  68. 'VLESS + WebSocket + TLS is a flexible, CDN-friendly default for everyday use with modern clients.',
  69. links: [TRANSPORTS_LINK, INBOUNDS_LINK],
  70. };
  71. }
  72. return {
  73. protocol: 'VMess',
  74. transport: 'WebSocket',
  75. security: 'TLS',
  76. rationale: 'VMess + WebSocket + TLS is the most broadly compatible everyday setup.',
  77. links: [TRANSPORTS_LINK, INBOUNDS_LINK],
  78. };
  79. }