Skip to content

Commit

Permalink
feat(config): add form field
Browse files Browse the repository at this point in the history
- pprof_port: 0
- enable_local_tcp_fast_redirect: false
- mptcp: false
- bandwidth_max_tx: 26214400
- bandwidth_max_rx: 131072000

Signed-off-by: wano <[email protected]>
  • Loading branch information
wanlce committed Oct 16, 2024
1 parent 0b0a0f5 commit 027bd55
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 51 deletions.
5 changes: 5 additions & 0 deletions src/apis/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ export const useConfigsQuery = () => {
utlsImitate
tproxyPortProtect
soMarkFromDae
pprofPort
enableLocalTcpFastRedirect
mptcp
bandwidthMaxTx
bandwidthMaxRx
}
}
}
Expand Down
50 changes: 50 additions & 0 deletions src/components/ConfigFormModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand All @@ -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 = <T extends z.infer<typeof schema>>({
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -296,6 +311,15 @@ export const ConfigFormDrawer = forwardRef(({ opened, onClose }: { opened: boole
})}
/>

<NumberInput
label={t('pprofPort')}
description={t('descriptions.config.pprofPort')}
withAsterisk
min={0}
max={65535}
{...form.getInputProps('pprofPort')}
/>

<NumberInput
label={t('soMarkFromDae')}
description={t('descriptions.config.soMarkFromDae')}
Expand Down Expand Up @@ -327,6 +351,20 @@ export const ConfigFormDrawer = forwardRef(({ opened, onClose }: { opened: boole
type: 'checkbox',
})}
/>

<Checkbox
label={t('enableLocalTcpFastRedirect')}
{...form.getInputProps('enableLocalTcpFastRedirect', {
type: 'checkbox',
})}
/>

<Checkbox
label={t('mptcp')}
{...form.getInputProps('mptcp', {
type: 'checkbox',
})}
/>
</Stack>
</Accordion.Panel>
</Accordion.Item>
Expand Down Expand Up @@ -483,6 +521,18 @@ export const ConfigFormDrawer = forwardRef(({ opened, onClose }: { opened: boole
{...form.getInputProps('utlsImitate')}
/>
)}

<NumberInput
label={`${t('bandwidthMaxTx')}`}
description={t('descriptions.config.bandwidthMaxTx')}
{...form.getInputProps('bandwidthMaxTx')}
/>

<NumberInput
label={`${t('bandwidthMaxRx')}`}
description={t('descriptions.config.bandwidthMaxRx')}
{...form.getInputProps('bandwidthMaxRx')}
/>
</Stack>
</Accordion.Panel>
</Accordion.Item>
Expand Down
10 changes: 10 additions & 0 deletions src/constants/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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`,
Expand All @@ -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
Expand Down
11 changes: 10 additions & 1 deletion src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 10 additions & 1 deletion src/i18n/locales/zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "从组中为每个连接选择最后延迟最小的节点",
Expand Down Expand Up @@ -174,6 +178,11 @@
"tlsImplementation": "TLS 实现",
"tproxyPort": "透明代理端口",
"tproxyPortProtect": "透明代理端口保护",
"pprofPort": "pprof 端口",
"enableLocalTcpFastRedirect": "启用本地 TCP 快速重定向",
"mptcp": "MPTCP",
"bandwidthMaxTx": "最大发送带宽",
"bandwidthMaxRx": "最大接收带宽",
"trace": "跟踪",
"udpCheckDns": "UDP 检测 DNS",
"updatedAt": "更新时间",
Expand Down
6 changes: 3 additions & 3 deletions src/schemas/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const documents = {
types.NodesDocument,
'\n query Subscriptions {\n subscriptions {\n id\n tag\n status\n link\n info\n updatedAt\n nodes {\n edges {\n id\n name\n protocol\n link\n }\n }\n }\n }\n ':
types.SubscriptionsDocument,
'\n query Configs {\n configs {\n id\n name\n selected\n global {\n logLevel\n tproxyPort\n allowInsecure\n checkInterval\n checkTolerance\n lanInterface\n wanInterface\n udpCheckDns\n tcpCheckUrl\n dialMode\n tcpCheckHttpMethod\n disableWaitingNetwork\n autoConfigKernelParameter\n sniffingTimeout\n tlsImplementation\n utlsImitate\n tproxyPortProtect\n soMarkFromDae\n }\n }\n }\n ':
'\n query Configs {\n configs {\n id\n name\n selected\n global {\n logLevel\n tproxyPort\n allowInsecure\n checkInterval\n checkTolerance\n lanInterface\n wanInterface\n udpCheckDns\n tcpCheckUrl\n dialMode\n tcpCheckHttpMethod\n disableWaitingNetwork\n autoConfigKernelParameter\n sniffingTimeout\n tlsImplementation\n utlsImitate\n tproxyPortProtect\n soMarkFromDae\n pprofPort\n enableLocalTcpFastRedirect\n mptcp\n bandwidthMaxTx\n bandwidthMaxRx\n }\n }\n }\n ':
types.ConfigsDocument,
'\n query Groups {\n groups {\n id\n name\n nodes {\n id\n link\n name\n address\n protocol\n tag\n subscriptionID\n }\n subscriptions {\n id\n updatedAt\n tag\n link\n status\n info\n\n nodes {\n edges {\n id\n link\n name\n address\n protocol\n tag\n subscriptionID\n }\n }\n }\n policy\n policyParams {\n key\n val\n }\n }\n }\n ':
types.GroupsDocument,
Expand Down Expand Up @@ -367,8 +367,8 @@ export function graphql(
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(
source: '\n query Configs {\n configs {\n id\n name\n selected\n global {\n logLevel\n tproxyPort\n allowInsecure\n checkInterval\n checkTolerance\n lanInterface\n wanInterface\n udpCheckDns\n tcpCheckUrl\n dialMode\n tcpCheckHttpMethod\n disableWaitingNetwork\n autoConfigKernelParameter\n sniffingTimeout\n tlsImplementation\n utlsImitate\n tproxyPortProtect\n soMarkFromDae\n }\n }\n }\n ',
): (typeof documents)['\n query Configs {\n configs {\n id\n name\n selected\n global {\n logLevel\n tproxyPort\n allowInsecure\n checkInterval\n checkTolerance\n lanInterface\n wanInterface\n udpCheckDns\n tcpCheckUrl\n dialMode\n tcpCheckHttpMethod\n disableWaitingNetwork\n autoConfigKernelParameter\n sniffingTimeout\n tlsImplementation\n utlsImitate\n tproxyPortProtect\n soMarkFromDae\n }\n }\n }\n ']
source: '\n query Configs {\n configs {\n id\n name\n selected\n global {\n logLevel\n tproxyPort\n allowInsecure\n checkInterval\n checkTolerance\n lanInterface\n wanInterface\n udpCheckDns\n tcpCheckUrl\n dialMode\n tcpCheckHttpMethod\n disableWaitingNetwork\n autoConfigKernelParameter\n sniffingTimeout\n tlsImplementation\n utlsImitate\n tproxyPortProtect\n soMarkFromDae\n pprofPort\n enableLocalTcpFastRedirect\n mptcp\n bandwidthMaxTx\n bandwidthMaxRx\n }\n }\n }\n ',
): (typeof documents)['\n query Configs {\n configs {\n id\n name\n selected\n global {\n logLevel\n tproxyPort\n allowInsecure\n checkInterval\n checkTolerance\n lanInterface\n wanInterface\n udpCheckDns\n tcpCheckUrl\n dialMode\n tcpCheckHttpMethod\n disableWaitingNetwork\n autoConfigKernelParameter\n sniffingTimeout\n tlsImplementation\n utlsImitate\n tproxyPortProtect\n soMarkFromDae\n pprofPort\n enableLocalTcpFastRedirect\n mptcp\n bandwidthMaxTx\n bandwidthMaxRx\n }\n }\n }\n ']
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
Loading

0 comments on commit 027bd55

Please sign in to comment.