优化endpoint
This commit is contained in:
parent
653e808ee1
commit
f21297fa3a
@ -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());
|
||||
}
|
||||
|
||||
|
||||
@ -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<AppNode, AppEdge>();
|
||||
|
||||
const handleSave = (): void => {
|
||||
onUpdate({persistentKeepalive : keepalive});
|
||||
onUpdate({persistentKeepalive : keepalive, endPint: endpoint});
|
||||
onClose();
|
||||
};
|
||||
|
||||
@ -56,7 +58,20 @@ export default function NodeEditor({
|
||||
}
|
||||
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 className="editor-actions">
|
||||
<button className="btn-save" onClick={handleSave}>保存</button>
|
||||
|
||||
@ -30,6 +30,7 @@ export type EdgeData = {
|
||||
|
||||
export type EdgeDataUpdate = {
|
||||
persistentKeepalive?: number;
|
||||
endPint?: string;
|
||||
}
|
||||
|
||||
type GetEdges = () => AppEdge[];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user