From f21297fa3a15716d6f845f3ee3ebfdd4a852ead1 Mon Sep 17 00:00:00 2001 From: limil Date: Wed, 18 Feb 2026 12:17:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TODO.md | 2 +- src/components/CustomNode.tsx | 30 ++++++++++++++++++------------ src/components/EdgeEditor.tsx | 17 ++++++++++++++++- src/types/graph.ts | 1 + 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/TODO.md b/TODO.md index b7fa55d..daa79fe 100644 --- a/TODO.md +++ b/TODO.md @@ -8,7 +8,7 @@ --- -- [ ] 实现子网路由功能 +- [x] 实现子网路由功能 - [ ] 实现配置保存和加载功能(支持加密私钥) --- diff --git a/src/components/CustomNode.tsx b/src/components/CustomNode.tsx index 5fca8c6..ff741bf 100644 --- a/src/components/CustomNode.tsx +++ b/src/components/CustomNode.tsx @@ -134,23 +134,28 @@ function generateConfig(settings: Settings, data: NodeData, graph: AppGraph, sub config.appendLine(`# ${nextData.label}`); config.appendLine(`PublicKey = ${ publicKey}`); - if(edge.data?.isTwoWayEdge || edge.source === data.id) { - if(edge.data?.persistentKeepalive) { - config.appendLine(`PersistentKeepalive = ${edge.data.persistentKeepalive}`); + const edgeData = edge.data; + if(edgeData && (edgeData.isTwoWayEdge || edge.source === data.id)) { + if(edgeData.persistentKeepalive) { + config.appendLine(`PersistentKeepalive = ${edgeData.persistentKeepalive}`); } - if(!nextData.listenAddress) { + let listenAddress = nextData.listenAddress; + if(listenAddress) { + if(listenAddress.includes(":")) listenAddress = `[${listenAddress}]`; + const listenPort = nextData.listenPort || settings.listenPort; + listenAddress = `${listenAddress}:${listenPort}` + } + + if(!edgeData.isTwoWayEdge && edge.source === data.id && edgeData.endPint) { + listenAddress = edgeData.endPint; + } + + if(!listenAddress) { return new ConfigResult(false, undefined, `节点 ${nextData.label} 未设置监听地址,无法生成配置`); } - const parse = IPUtils.parse(`${nextData.listenAddress}/0`); - if(!parse.cidr) { - return new ConfigResult(false, undefined, `节点 ${nextData.label} 的监听地址无效`); - } - - const listenAddress = parse.cidr.version === 'IPv4' ? nextData.listenAddress : `[${nextData.listenAddress}]`; - const listenPort = nextData.listenPort || settings.listenPort; - config.appendLine(`EndPoint = ${listenAddress}:${listenPort}`); + config.appendLine(`EndPoint = ${listenAddress}`); } const allowIPs = allowIPsConfig.get(next); @@ -159,6 +164,7 @@ function generateConfig(settings: Settings, data: NodeData, graph: AppGraph, sub } } + console.log(config.toString()) return new ConfigResult(true, config.toString()); } diff --git a/src/components/EdgeEditor.tsx b/src/components/EdgeEditor.tsx index 319c48d..5dddc17 100644 --- a/src/components/EdgeEditor.tsx +++ b/src/components/EdgeEditor.tsx @@ -16,10 +16,12 @@ export default function NodeEditor({ }: EdgeEditorProps): ReactNode { const [keepalive, setKeepalive] = useState(edge.persistentKeepalive); + const [endpoint, setEndPoint] = useState(edge.endPint); + const { getNode, getEdge } = useReactFlow(); const handleSave = (): void => { - onUpdate({persistentKeepalive : keepalive}); + onUpdate({persistentKeepalive : keepalive, endPint: endpoint}); onClose(); }; @@ -56,7 +58,20 @@ export default function NodeEditor({ } placeholder={`留空或0代表不保活`} /> + + + {!edge.isTwoWayEdge && ( +
+ + setEndPoint(e.target.value)} + placeholder={`留空使用节点上配置的监听地址`} + />
+ )} +
diff --git a/src/types/graph.ts b/src/types/graph.ts index d1483b3..b7a6cd5 100644 --- a/src/types/graph.ts +++ b/src/types/graph.ts @@ -30,6 +30,7 @@ export type EdgeData = { export type EdgeDataUpdate = { persistentKeepalive?: number; + endPint?: string; } type GetEdges = () => AppEdge[];