From 2fc60552c8e543c55a550f12d1a6cb0e9f36ce29 Mon Sep 17 00:00:00 2001 From: wano <55907021+wanlce@users.noreply.github.com> Date: Tue, 15 Oct 2024 23:28:12 +0800 Subject: [PATCH] feat(config): add form field - pprof_port - enable_local_tcp_fast_redirect - mptcp: false - bandwidth_max_tx - bandwidth_max_rx Signed-off-by: wano <55907021+wanlce@users.noreply.github.com> --- src/components/ConfigFormModal.tsx | 50 ++++++++++++++++++++++++++ src/constants/default.ts | 10 ++++++ src/i18n/locales/en.json | 11 +++++- src/i18n/locales/zh-Hans.json | 11 +++++- src/schemas/gql/graphql.ts | 58 +++++++----------------------- 5 files changed, 92 insertions(+), 48 deletions(-) diff --git a/src/components/ConfigFormModal.tsx b/src/components/ConfigFormModal.tsx index 72357ce6..ceb5199d 100644 --- a/src/components/ConfigFormModal.tsx +++ b/src/components/ConfigFormModal.tsx @@ -27,10 +27,15 @@ import { useCreateConfigMutation, useGeneralQuery, useUpdateConfigMutation } fro import { DEFAULT_ALLOW_INSECURE, DEFAULT_AUTO_CONFIG_KERNEL_PARAMETER, + DEFAULT_BANDWIDTH_MAX_RX, + DEFAULT_BANDWIDTH_MAX_TX, DEFAULT_CHECK_INTERVAL_SECONDS, DEFAULT_CHECK_TOLERANCE_MS, DEFAULT_DIAL_MODE, DEFAULT_DISABLE_WAITING_NETWORK, + DEFAULT_ENABLE_LOCAL_TCP_FAST_REDIRECT, + DEFAULT_MPTCP, + DEFAULT_PPROF_PORT, DEFAULT_SNIFFING_TIMEOUT_MS, DEFAULT_SO_MARK_FROM_DAE, DEFAULT_TCP_CHECK_HTTP_METHOD, @@ -55,6 +60,7 @@ const schema = z.object({ name: z.string().nonempty(), logLevelNumber: z.number().min(0).max(4), tproxyPort: z.number(), + pprofPort: z.number(), allowInsecure: z.boolean(), checkIntervalSeconds: z.number(), checkToleranceMS: z.number(), @@ -71,6 +77,10 @@ const schema = z.object({ utlsImitate: z.string(), tproxyPortProtect: z.boolean(), soMarkFromDae: z.number(), + mptcp: z.boolean(), + enableLocalTcpFastRedirect: z.boolean(), + bandwidthMaxTx: z.number(), + bandwidthMaxRx: z.number(), }) const InputList = >({ @@ -140,6 +150,11 @@ export const ConfigFormDrawer = forwardRef(({ opened, onClose }: { opened: boole validate: zodResolver(schema), initialValues: { name: '', + pprofPort: DEFAULT_PPROF_PORT, + mptcp: DEFAULT_MPTCP, + enableLocalTcpFastRedirect: DEFAULT_ENABLE_LOCAL_TCP_FAST_REDIRECT, + bandwidthMaxTx: DEFAULT_BANDWIDTH_MAX_TX, + bandwidthMaxRx: DEFAULT_BANDWIDTH_MAX_RX, soMarkFromDae: DEFAULT_SO_MARK_FROM_DAE, logLevelNumber: 2, tproxyPort: DEFAULT_TPROXY_PORT, @@ -296,6 +311,15 @@ export const ConfigFormDrawer = forwardRef(({ opened, onClose }: { opened: boole })} /> + + + + + + @@ -483,6 +521,18 @@ export const ConfigFormDrawer = forwardRef(({ opened, onClose }: { opened: boole {...form.getInputProps('utlsImitate')} /> )} + + + + diff --git a/src/constants/default.ts b/src/constants/default.ts index dc751f66..8f3650b8 100644 --- a/src/constants/default.ts +++ b/src/constants/default.ts @@ -33,6 +33,11 @@ export const DEFAULT_DISABLE_WAITING_NETWORK = false export const DEFAULT_AUTO_CONFIG_KERNEL_PARAMETER = true export const DEFAULT_TLS_IMPLEMENTATION = TLSImplementation.tls export const DEFAULT_UTLS_IMITATE = UTLSImitate.chrome_auto +export const DEFAULT_MPTCP = false +export const DEFAULT_ENABLE_LOCAL_TCP_FAST_REDIRECT = false +export const DEFAULT_PPROF_PORT = 0 +export const DEFAULT_BANDWIDTH_MAX_TX = 26214400 +export const DEFAULT_BANDWIDTH_MAX_RX = 131072000 export const DEFAULT_CONFIG_NAME = 'global' export const DEFAULT_DNS_NAME = 'default' @@ -43,6 +48,7 @@ export const DEFAULT_CONFIG_WITH_LAN_INTERFACEs = (interfaces: string[] = []): G logLevel: DEFAULT_LOG_LEVEL, tproxyPort: DEFAULT_TPROXY_PORT, tproxyPortProtect: DEFAULT_TPROXY_PORT_PROTECT, + pprofPort: DEFAULT_PPROF_PORT, soMarkFromDae: DEFAULT_SO_MARK_FROM_DAE, allowInsecure: DEFAULT_ALLOW_INSECURE, checkInterval: `${DEFAULT_CHECK_INTERVAL_SECONDS}s`, @@ -58,6 +64,10 @@ export const DEFAULT_CONFIG_WITH_LAN_INTERFACEs = (interfaces: string[] = []): G tlsImplementation: DEFAULT_TLS_IMPLEMENTATION, utlsImitate: DEFAULT_UTLS_IMITATE, disableWaitingNetwork: DEFAULT_DISABLE_WAITING_NETWORK, + enableLocalTcpFastRedirect: DEFAULT_ENABLE_LOCAL_TCP_FAST_REDIRECT, + mptcp: DEFAULT_MPTCP, + bandwidthMaxTx: DEFAULT_BANDWIDTH_MAX_TX, + bandwidthMaxRx: DEFAULT_BANDWIDTH_MAX_RX, }) export const DEFAULT_GROUP_POLICY = Policy.MinMovingAvg diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 29a9aedd..332af2de 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -108,7 +108,11 @@ "tproxyPortProtect": "Set it true to protect tproxy port from unsolicited traffic. Set it false to allow users to use self-managed iptables tproxy rules.", "udpCheckDns": "This DNS will be used to check UDP connectivity of nodes. And if dns_upstream below contains tcp, it also be used to check TCP DNS connectivity of nodes. First is URL, others are IP addresses if given. This DNS should have both IPv4 and IPv6 if you have double stack in local.", "utlsImitate": "The Client Hello ID for uTLS to imitate. This takes effect only if tls_implementation is utls.", - "wanInterface": "The WAN interface to bind. Use it if you want to proxy localhost." + "wanInterface": "The WAN interface to bind. Use it if you want to proxy localhost.", + "PprofPort": "Pprof Port", + "mptcp": "Enable MPTCP", + "bandwidthMaxRx": "Max Receive Bandwidth. '200 mbps' # uplink, or '200 m' or '200 mb' or '200 mbps' or 25000000 (which is 200/8*1000*1000)", + "bandwidthMaxTx": "Max Transmit Bandwidth. '200 mbps' # uplink, or '200 m' or '200 mb' or '200 mbps' or 25000000 (which is 200/8*1000*1000)" }, "group": { "Min": "Select the node with min last latency from the group for every connection", @@ -174,6 +178,11 @@ "tlsImplementation": "TLS Implementation", "tproxyPort": "Transparent Proxy Port", "tproxyPortProtect": "Tproxy Port Protect", + "PprofPort": "pprof Port", + "EnableLocalTcpFastRedirect": "Enable Local TCP Fast Redirect", + "Mptcp": "MPTCP", + "BandwidthMaxTx": "Max Transmit Bandwidth", + "BandwidthMaxRx": "Max Receive Bandwidth", "trace": "trace", "udpCheckDns": "UDP Check DNS", "updatedAt": "updatedAt", diff --git a/src/i18n/locales/zh-Hans.json b/src/i18n/locales/zh-Hans.json index 66edd331..6af2f1ad 100644 --- a/src/i18n/locales/zh-Hans.json +++ b/src/i18n/locales/zh-Hans.json @@ -108,7 +108,11 @@ "tproxyPortProtect": "将其设置为 true 可保护透明代理端口免受未经请求的流量的影响。将其设置为 false 以允许用户使用自我管理的 iptables 透明代理规则。", "udpCheckDns": "此 DNS 将用于检查节点的 UDP 连接。如果下面的 DNS 上游包含 TCP,它也可以用于检查节点的 TCP DNS 连接。第一个是 URL,其他是 IP地址(如果给定的话)。如果您在本地有 dual stack(双协议栈),则此 DNS 应该同时具有 IPv4 和 IPv6。", "utlsImitate": "要模仿的 uTLS 的客户端 Hello ID。只有当 TLS 实现 为 utls 时,此操作才会生效。", - "wanInterface": "要绑定的 WAN 接口。如果您想代理本机,请使用它。" + "wanInterface": "要绑定的 WAN 接口。如果您想代理本机,请使用它。", + "pprofPort": "pprof 端口", + "mptcp": "启用 MPTCP。", + "bandwidthMaxRx": "最大接收带宽。'200 mbps' # uplink, or '200 m' or '200 mb' or '200 mbps' or 25000000 (which is 200/8*1000*1000)", + "bandwidthMaxTx": "最大发送带宽。'1 gbps' # downlink, or '1 g' or '1 gb' or '1 gbps' or 125000000 (which is 1000/8*1000*1000)" }, "group": { "Min": "从组中为每个连接选择最后延迟最小的节点", @@ -174,6 +178,11 @@ "tlsImplementation": "TLS 实现", "tproxyPort": "透明代理端口", "tproxyPortProtect": "透明代理端口保护", + "pprofPort": "pprof 端口", + "enableLocalTcpFastRedirect": "启用本地 TCP 快速重定向", + "mptcp": "MPTCP", + "bandwidthMaxTx": "最大发送带宽", + "bandwidthMaxRx": "最大接收带宽", "trace": "跟踪", "udpCheckDns": "UDP 检测 DNS", "updatedAt": "更新时间", diff --git a/src/schemas/gql/graphql.ts b/src/schemas/gql/graphql.ts index c4bc9789..f0618563 100644 --- a/src/schemas/gql/graphql.ts +++ b/src/schemas/gql/graphql.ts @@ -46,7 +46,6 @@ export type ConfigFlatDesc = { export type Dae = { __typename?: 'Dae' - /** modified indicates whether the running config has been modified. */ modified: Scalars['Boolean']['output'] running: Scalars['Boolean']['output'] version: Scalars['String']['output'] @@ -110,13 +109,19 @@ export type GeneralInterfacesArgs = { export type Global = { __typename?: 'Global' allowInsecure: Scalars['Boolean']['output'] + autoConfigFirewallRule: Scalars['Boolean']['output'] autoConfigKernelParameter: Scalars['Boolean']['output'] + bandwidthMaxRx: Scalars['Int']['output'] + bandwidthMaxTx: Scalars['Int']['output'] checkInterval: Scalars['Duration']['output'] checkTolerance: Scalars['Duration']['output'] dialMode: Scalars['String']['output'] disableWaitingNetwork: Scalars['Boolean']['output'] + enableLocalTcpFastRedirect: Scalars['Boolean']['output'] lanInterface: Array logLevel: Scalars['String']['output'] + mptcp: Scalars['Boolean']['output'] + pprofPort: Scalars['Int']['output'] sniffingTimeout: Scalars['Duration']['output'] soMarkFromDae: Scalars['Int']['output'] tcpCheckHttpMethod: Scalars['String']['output'] @@ -164,83 +169,44 @@ export type InterfaceFlag = { export type Mutation = { __typename?: 'Mutation' - /** createConfig creates a global config. Null arguments will be converted to default value. */ createConfig: Config - /** createConfig creates a dns config. Null arguments will be converted to default value. */ createDns: Dns - /** createGroup is to create a group. */ createGroup: Group - /** createConfig creates a routing config. Null arguments will be converted to default value. */ createRouting: Routing - /** createUser creates a user if there is no user. */ createUser: Scalars['String']['output'] - /** groupAddNodes is to add nodes to the group. Nodes will not be removed from its subscription when subscription update. */ groupAddNodes: Scalars['Int']['output'] - /** groupAddSubscriptions is to add subscriptions to the group. */ groupAddSubscriptions: Scalars['Int']['output'] - /** groupDelNodes is to remove nodes from the group. */ groupDelNodes: Scalars['Int']['output'] - /** groupDelSubscriptions is to remove subscriptions from the group. */ groupDelSubscriptions: Scalars['Int']['output'] - /** groupSetPolicy is to set the group a new policy. */ groupSetPolicy: Scalars['Int']['output'] - /** importNodes is to import nodes with no subscription ID. rollbackError means abort the import on error. */ importNodes: Array - /** importSubscription is to fetch and resolve the subscription into nodes. */ importSubscription: SubscriptionImportResult - /** removeConfig is to remove a config with given config ID. */ removeConfig: Scalars['Int']['output'] - /** removeDns is to remove a dns config with given dns ID. */ removeDns: Scalars['Int']['output'] - /** removeGroup is to remove a group. */ removeGroup: Scalars['Int']['output'] - /** removeJsonStorage remove given paths from user related json storage. Empty paths is to clear json storage. Refer to https://github.com/tidwall/sjson */ removeJsonStorage: Scalars['Int']['output'] - /** removeNodes is to remove nodes that have no subscription ID. */ removeNodes: Scalars['Int']['output'] - /** removeRouting is to remove a routing config with given routing ID. */ removeRouting: Scalars['Int']['output'] - /** removeSubscriptions is to remove subscriptions with given ID list. */ removeSubscriptions: Scalars['Int']['output'] - /** renameConfig is to give the config a new name. */ renameConfig: Scalars['Int']['output'] - /** renameDns is to give the dns config a new name. */ renameDns: Scalars['Int']['output'] - /** renameGroup is to rename a group. */ renameGroup: Scalars['Int']['output'] - /** renameRouting is to give the routing config a new name. */ renameRouting: Scalars['Int']['output'] - /** run proxy with selected config+dns+routing. Dry-run can be used to stop the proxy. */ run: Scalars['Int']['output'] - /** selectConfig is to select a config as the current config. */ selectConfig: Scalars['Int']['output'] - /** selectConfig is to select a dns config as the current dns. */ selectDns: Scalars['Int']['output'] - /** selectConfig is to select a routing config as the current routing. */ selectRouting: Scalars['Int']['output'] - /** setJsonStorage set given paths to values in user related json storage. Refer to https://github.com/tidwall/sjson */ setJsonStorage: Scalars['Int']['output'] - /** tagNode is to give the node a new tag. */ tagNode: Scalars['Int']['output'] - /** tagSubscription is to give the subscription a new tag. */ tagSubscription: Scalars['Int']['output'] - /** updateAvatar update avatar for current user. Remove avatar if avatar is null. Blob base64 encoded image is recommended. */ updateAvatar: Scalars['Int']['output'] - /** updateConfig allows to partially update global config with given id. */ updateConfig: Config - /** updateDns is to update dns config with given id. */ updateDns: Dns - /** updateName update name for current user. Remove name if name is null. */ updateName: Scalars['Int']['output'] - /** updateNode is to update a node with no subscription ID. */ updateNode: Node - /** updatePassword update password for current user. currentPassword is needed to authenticate. Return new token. */ updatePassword: Scalars['String']['output'] - /** updateRouting is to update routing config with given id. */ updateRouting: Routing - /** updateSubscription is to re-fetch subscription and resolve subscription into nodes. Old nodes that independently belong to any groups will not be removed. */ updateSubscription: Subscription - /** updateUsername update username for current user. */ updateUsername: Scalars['Int']['output'] } @@ -491,7 +457,6 @@ export type Query = { group: Group groups: Array healthCheck: Scalars['Int']['output'] - /** jsonStorage get given paths from user related json storage. Empty paths is to get all. Refer to https://github.com/tidwall/gjson */ jsonStorage: Array nodes: NodesConnection numberUsers: Scalars['Int']['output'] @@ -603,20 +568,21 @@ export type User = { username: Scalars['String']['output'] } -export type _Service = { - __typename?: '_Service' - sdl: Scalars['String']['output'] -} - export type GlobalInput = { allowInsecure?: InputMaybe + autoConfigFirewallRule?: InputMaybe autoConfigKernelParameter?: InputMaybe + bandwidthMaxRx?: InputMaybe + bandwidthMaxTx?: InputMaybe checkInterval?: InputMaybe checkTolerance?: InputMaybe dialMode?: InputMaybe disableWaitingNetwork?: InputMaybe + enableLocalTcpFastRedirect?: InputMaybe lanInterface?: InputMaybe> logLevel?: InputMaybe + mptcp?: InputMaybe + pprofPort?: InputMaybe sniffingTimeout?: InputMaybe soMarkFromDae?: InputMaybe tcpCheckHttpMethod?: InputMaybe