Skip to content

Commit

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

Signed-off-by: wano <[email protected]>
  • Loading branch information
wanlce committed Oct 15, 2024
1 parent 0b0a0f5 commit 2fc6055
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 48 deletions.
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
58 changes: 12 additions & 46 deletions src/schemas/gql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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<Scalars['String']['output']>
logLevel: Scalars['String']['output']
mptcp: Scalars['Boolean']['output']
pprofPort: Scalars['Int']['output']
sniffingTimeout: Scalars['Duration']['output']
soMarkFromDae: Scalars['Int']['output']
tcpCheckHttpMethod: Scalars['String']['output']
Expand Down Expand Up @@ -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<NodeImportResult>
/** 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']
}

Expand Down Expand Up @@ -491,7 +457,6 @@ export type Query = {
group: Group
groups: Array<Group>
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<Scalars['String']['output']>
nodes: NodesConnection
numberUsers: Scalars['Int']['output']
Expand Down Expand Up @@ -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<Scalars['Boolean']['input']>
autoConfigFirewallRule?: InputMaybe<Scalars['Boolean']['input']>
autoConfigKernelParameter?: InputMaybe<Scalars['Boolean']['input']>
bandwidthMaxRx?: InputMaybe<Scalars['Int']['input']>
bandwidthMaxTx?: InputMaybe<Scalars['Int']['input']>
checkInterval?: InputMaybe<Scalars['Duration']['input']>
checkTolerance?: InputMaybe<Scalars['Duration']['input']>
dialMode?: InputMaybe<Scalars['String']['input']>
disableWaitingNetwork?: InputMaybe<Scalars['Boolean']['input']>
enableLocalTcpFastRedirect?: InputMaybe<Scalars['Boolean']['input']>
lanInterface?: InputMaybe<Array<Scalars['String']['input']>>
logLevel?: InputMaybe<Scalars['String']['input']>
mptcp?: InputMaybe<Scalars['Boolean']['input']>
pprofPort?: InputMaybe<Scalars['Int']['input']>
sniffingTimeout?: InputMaybe<Scalars['Duration']['input']>
soMarkFromDae?: InputMaybe<Scalars['Int']['input']>
tcpCheckHttpMethod?: InputMaybe<Scalars['String']['input']>
Expand Down

0 comments on commit 2fc6055

Please sign in to comment.