| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- import { z } from 'zod';
- export const SockoptDomainStrategySchema = z.enum([
- 'AsIs',
- 'UseIP',
- 'UseIPv6v4',
- 'UseIPv6',
- 'UseIPv4v6',
- 'UseIPv4',
- 'ForceIP',
- 'ForceIPv6v4',
- 'ForceIPv6',
- 'ForceIPv4v6',
- 'ForceIPv4',
- ]);
- export type SockoptDomainStrategy = z.infer<typeof SockoptDomainStrategySchema>;
- export const TcpCongestionSchema = z.enum(['bbr', 'cubic', 'reno']);
- export type TcpCongestion = z.infer<typeof TcpCongestionSchema>;
- export const TproxyModeSchema = z.enum(['off', 'redirect', 'tproxy']);
- export type TproxyMode = z.infer<typeof TproxyModeSchema>;
- export const AddressPortStrategySchema = z.enum([
- 'none',
- 'SrvPortOnly',
- 'SrvAddressOnly',
- 'SrvPortAndAddress',
- 'TxtPortOnly',
- 'TxtAddressOnly',
- 'TxtPortAndAddress',
- ]);
- export type AddressPortStrategy = z.infer<typeof AddressPortStrategySchema>;
- export const HappyEyeballsSchema = z.object({
- tryDelayMs: z.number().int().min(0).default(250),
- prioritizeIPv6: z.boolean().default(false),
- interleave: z.number().int().min(1).default(1),
- maxConcurrentTry: z.number().int().min(0).default(4),
- });
- export type HappyEyeballs = z.infer<typeof HappyEyeballsSchema>;
- export const CustomSockoptSchema = z.object({
- system: z.enum(['linux', 'windows', 'darwin']).optional(),
- type: z.enum(['int', 'str']),
- level: z.string().default('6'),
- opt: z.string(),
- value: z.union([z.string(), z.number()]),
- });
- export type CustomSockopt = z.infer<typeof CustomSockoptSchema>;
- export const SockoptStreamSettingsSchema = z.object({
- acceptProxyProtocol: z.boolean().default(false),
- tcpFastOpen: z.union([z.boolean(), z.number().int()]).default(false),
- mark: z.number().int().default(0),
- tproxy: TproxyModeSchema.default('off'),
- tcpMptcp: z.boolean().default(false),
- penetrate: z.boolean().default(false),
- domainStrategy: SockoptDomainStrategySchema.default('AsIs'),
- // 0 = omit on the wire; xray-core skips sockopt fields <= 0 and uses OS defaults.
- // Non-zero defaults here previously came from the xray docs *example* (clamp 600,
- // maxSeg 1440, userTimeout 10000) and were written into every config when the
- // panel sockopt switch was enabled, throttling long-haul links.
- tcpMaxSeg: z.number().int().min(0).default(0),
- dialerProxy: z.string().default(''),
- tcpKeepAliveInterval: z.number().int().min(0).default(0),
- tcpKeepAliveIdle: z.number().int().min(0).default(0),
- tcpUserTimeout: z.number().int().min(0).default(0),
- tcpcongestion: TcpCongestionSchema.default('bbr'),
- V6Only: z.boolean().default(false),
- tcpWindowClamp: z.number().int().min(0).default(0),
- interface: z.string().default(''),
- trustedXForwardedFor: z.array(z.string()).default([]),
- addressPortStrategy: AddressPortStrategySchema.default('none'),
- happyEyeballs: HappyEyeballsSchema.optional(),
- customSockopt: z.array(CustomSockoptSchema).default([]),
- });
- export type SockoptStreamSettings = z.infer<typeof SockoptStreamSettingsSchema>;
|