-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel_bridge.js
More file actions
62 lines (54 loc) · 1.93 KB
/
kernel_bridge.js
File metadata and controls
62 lines (54 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const { MptcpKernel } = require('../meshadmin-pathways/packages/mptcp-kernel/src/index.js');
class PythonBridge {
constructor() {
this.kernel = new MptcpKernel({
endpoint: 'localhost',
port: 9090,
secure: false
});
}
async execute(command, args = []) {
try {
await this.kernel.connect();
let result;
switch (command) {
case 'healthCheck':
result = await this.kernel.healthCheck();
break;
case 'getSystemOverview':
const overview = await this.kernel.getStats();
const connections = await this.kernel.listConnections();
result = { overview, connections };
break;
case 'listConnections':
result = await this.kernel.listConnections();
break;
case 'getPathStatistics':
result = await this.kernel.getTopology();
break;
case 'getPerformanceMetrics':
result = await this.kernel.getStats();
break;
default:
throw new Error(`Unknown command: ${command}`);
}
return { success: true, data: result };
} catch (error) {
return { success: false, error: error.message };
}
}
}
// Command line interface
if (require.main === module) {
const bridge = new PythonBridge();
const command = process.argv[2];
const args = process.argv.slice(3);
bridge.execute(command, args).then(result => {
console.log(JSON.stringify(result));
process.exit(0);
}).catch(error => {
console.log(JSON.stringify({ success: false, error: error.message }));
process.exit(1);
});
}
module.exports = PythonBridge;