优化endpoint

This commit is contained in:
limil 2026-02-18 12:17:13 +08:00
parent 653e808ee1
commit f21297fa3a
4 changed files with 36 additions and 14 deletions

View File

@ -8,7 +8,7 @@
--- ---
- [ ] 实现子网路由功能 - [x] 实现子网路由功能
- [ ] 实现配置保存和加载功能(支持加密私钥) - [ ] 实现配置保存和加载功能(支持加密私钥)
--- ---

View File

@ -134,23 +134,28 @@ function generateConfig(settings: Settings, data: NodeData, graph: AppGraph, sub
config.appendLine(`# ${nextData.label}`); config.appendLine(`# ${nextData.label}`);
config.appendLine(`PublicKey = ${ publicKey}`); config.appendLine(`PublicKey = ${ publicKey}`);
if(edge.data?.isTwoWayEdge || edge.source === data.id) { const edgeData = edge.data;
if(edge.data?.persistentKeepalive) { if(edgeData && (edgeData.isTwoWayEdge || edge.source === data.id)) {
config.appendLine(`PersistentKeepalive = ${edge.data.persistentKeepalive}`); 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} 未设置监听地址,无法生成配置`); return new ConfigResult(false, undefined, `节点 ${nextData.label} 未设置监听地址,无法生成配置`);
} }
const parse = IPUtils.parse(`${nextData.listenAddress}/0`); config.appendLine(`EndPoint = ${listenAddress}`);
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}`);
} }
const allowIPs = allowIPsConfig.get(next); 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()); return new ConfigResult(true, config.toString());
} }

View File

@ -16,10 +16,12 @@ export default function NodeEditor({
}: EdgeEditorProps): ReactNode { }: EdgeEditorProps): ReactNode {
const [keepalive, setKeepalive] = useState(edge.persistentKeepalive); const [keepalive, setKeepalive] = useState(edge.persistentKeepalive);
const [endpoint, setEndPoint] = useState(edge.endPint);
const { getNode, getEdge } = useReactFlow<AppNode, AppEdge>(); const { getNode, getEdge } = useReactFlow<AppNode, AppEdge>();
const handleSave = (): void => { const handleSave = (): void => {
onUpdate({persistentKeepalive : keepalive}); onUpdate({persistentKeepalive : keepalive, endPint: endpoint});
onClose(); onClose();
}; };
@ -56,7 +58,20 @@ export default function NodeEditor({
} }
placeholder={`留空或0代表不保活`} placeholder={`留空或0代表不保活`}
/> />
</div>
{!edge.isTwoWayEdge && (
<div className="form-group">
<label>EndPoint</label>
<input
type="text"
value={endpoint || ''}
onChange={e => setEndPoint(e.target.value)}
placeholder={`留空使用节点上配置的监听地址`}
/>
</div> </div>
)}
<div className="editor-actions"> <div className="editor-actions">
<button className="btn-save" onClick={handleSave}></button> <button className="btn-save" onClick={handleSave}></button>

View File

@ -30,6 +30,7 @@ export type EdgeData = {
export type EdgeDataUpdate = { export type EdgeDataUpdate = {
persistentKeepalive?: number; persistentKeepalive?: number;
endPint?: string;
} }
type GetEdges = () => AppEdge[]; type GetEdges = () => AppEdge[];