xtcp模式下打洞失败回退 stcp

This commit is contained in:
刘嘉伟 2024-11-08 16:10:54 +08:00
parent dba788a1dd
commit e7f4572768
3 changed files with 111 additions and 5 deletions

View File

@ -36,7 +36,8 @@ const getFrpcVersionWorkerPath = (
const isRangePort = (m: Proxy) => {
return (
(m.type === "tcp" || m.type === "udp") &&
(String(m.localPort).indexOf("-") !== -1 || String(m.localPort).indexOf(",") !== -1)
(String(m.localPort).indexOf("-") !== -1 ||
String(m.localPort).indexOf(",") !== -1)
);
};
@ -54,7 +55,11 @@ ${
? `{{- range $_, $v := parseNumberRangePair "${m.localPort}" "${m.remotePort}" }}`
: ""
}
[[${(m.type === "stcp" || m.type === "xtcp") && m.stcpModel === "visitors" ? "visitors" : "proxies"}]]
[[${
(m.type === "stcp" || m.type === "xtcp") && m.stcpModel === "visitors"
? "visitors"
: "proxies"
}]]
${rangePort ? "" : `name = "${m.name}"\n`}
type = "${m.type}"
`;
@ -100,6 +105,12 @@ serverName = "${m.serverName}"
bindAddr = "${m.bindAddr}"
bindPort = ${m.bindPort}
`;
if (m.fallbackTo) {
toml += `
fallbackTo = "${m.fallbackTo}"
fallbackTimeoutMs = ${m.fallbackTimeoutMs || 500}
`;
}
} else if (m.stcpModel === "visited") {
// 被访问者
toml += `
@ -249,6 +260,12 @@ server_name = "${m.serverName}"
bind_addr = "${m.bindAddr}"
bind_port = ${m.bindPort}
`;
if (m.fallbackTo) {
ini += `
fallback_to = ${m.fallbackTo}
fallback_timeout_ms = ${m.fallbackTimeoutMs || 500}
`;
}
} else if (m.stcpModel === "visited") {
// 被访问者
ini += `

View File

@ -61,7 +61,9 @@ const defaultForm = ref<Proxy>({
subdomain: "",
basicAuth: false,
httpUser: "",
httpPassword: ""
httpPassword: "",
fallbackTo: "",
fallbackTimeoutMs: 500
});
/**
@ -391,6 +393,9 @@ const handleOpenInsert = () => {
const handleOpenUpdate = (proxy: Proxy) => {
editForm.value = clone(proxy);
if (!editForm.value.fallbackTimeoutMs) {
editForm.value.fallbackTimeoutMs = defaultForm.value.fallbackTimeoutMs;
}
edit.value = {
title: "修改代理",
visible: true
@ -537,7 +542,8 @@ const handleRandomProxyName = () => {
const randomIndex = Math.floor(Math.random() * characters.length);
result += characters[randomIndex];
}
editForm.value.name = `df_${editForm.value.type}_${result}`.toLocaleLowerCase();
editForm.value.name =
`df_${editForm.value.type}_${result}`.toLocaleLowerCase();
};
onMounted(() => {
@ -1065,7 +1071,7 @@ onUnmounted(() => {
</el-col>
</template>
<template v-if="isStcpVisitors">
<el-col :span="12">
<el-col :span="24">
<el-form-item label="被访问者代理名称:" prop="serverName">
<el-input
type="text"
@ -1152,12 +1158,93 @@ onUnmounted(() => {
</div>
</template>
<el-input-number
class="w-full"
:min="-1"
:step="1"
controls-position="right"
v-model="editForm.bindPort"
placeholder="8080"
/>
</el-form-item>
</el-col>
</template>
<template v-if="isXtcp && isStcpVisitors">
<el-col :span="12">
<el-form-item label="回退stcp代理名称" prop="fallbackTo">
<template #label>
<div class="inline-block">
<div class="flex items-center">
<div class="mr-1">
<el-popover placement="top" trigger="hover" width="300">
<template #default>
对应参数<span class="font-black text-[#5A3DAA]"
>fallbackTo</span
>
<br />
xtcp 打洞失败会回退到使用 stcp-visitor 建立连接
</template>
<template #reference>
<IconifyIconOffline
class="text-base"
color="#5A3DAA"
icon="info"
/>
</template>
</el-popover>
</div>
回退stcp代理名称
</div>
</div>
</template>
<el-input
type="text"
v-model="editForm.fallbackTo"
placeholder="回退stcp代理名称"
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="回退超时毫秒" prop="fallbackTimeoutMs">
<template #label>
<div class="inline-block">
<div class="flex items-center">
<div class="mr-1">
<el-popover placement="top" trigger="hover" width="300">
<template #default>
对应参数<span class="font-black text-[#5A3DAA]"
>fallbackTimeoutMs</span
>
<br />
xtcp 打洞时间超过该时间会回退到使用 stcp-visitor
建立连接 单位<span
class="font-black text-[#5A3DAA]"
>毫秒</span
>
</template>
<template #reference>
<IconifyIconOffline
class="text-base"
color="#5A3DAA"
icon="info"
/>
</template>
</el-popover>
</div>
回退超时毫秒
</div>
</div>
</template>
<el-input-number
class="w-full"
:min="0"
:step="1"
controls-position="right"
v-model="editForm.fallbackTimeoutMs"
placeholder="回退超时毫秒"
/>
</el-form-item>
</el-col>
</template>
<el-col :span="24">
<el-form-item>
<div class="w-full flex justify-end">

2
types/global.d.ts vendored
View File

@ -31,6 +31,8 @@ declare global {
basicAuth: boolean;
httpUser: string;
httpPassword: string;
fallbackTo: string;
fallbackTimeoutMs: number;
};
/**