Add new top-level class: Agent → SystemQuery
depth++!
This commit is contained in:
parent
16f23e6b77
commit
1270a39808
2 changed files with 44 additions and 4 deletions
40
src/lib/SystemQuery.mjs
Normal file
40
src/lib/SystemQuery.mjs
Normal file
|
@ -0,0 +1,40 @@
|
|||
"use strict";
|
||||
|
||||
import sysinfo from 'systeminformation';
|
||||
|
||||
import Agent from './agent/Agent.mjs';
|
||||
|
||||
class SystemQuery {
|
||||
constructor(config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
async init() {
|
||||
///
|
||||
// 1: Create agent
|
||||
///
|
||||
this.agent = new Agent(this.config);
|
||||
await this.agent.init();
|
||||
|
||||
///
|
||||
// 2: Attach listeners
|
||||
///
|
||||
this.agent.on("message-query", this.handle_query.bind(this));
|
||||
this.agent.on("message-query-response", this.handle_query_response.bind(this));
|
||||
}
|
||||
|
||||
async handle_query(peer, msg) {
|
||||
|
||||
}
|
||||
async handle_query_response(peer, msg) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
SystemQuery.Create = async function(config) {
|
||||
let result = new SystemQuery(config);
|
||||
await result.init();
|
||||
return result;
|
||||
}
|
||||
|
||||
export default SystemQuery;
|
|
@ -8,7 +8,7 @@ import log from '../../lib/io/NamespacedLog.mjs'; const l = log("agent");
|
|||
import settings from '../../settings.mjs';
|
||||
import toml_settings_read from '../../lib/io/TomlSettings.mjs';
|
||||
|
||||
import Agent from '../../lib/agent/Agent.mjs';
|
||||
import SystemQuery from '../../lib/SystemQuery.mjs';
|
||||
|
||||
// HACK: Make sure __dirname is defined when using es6 modules. I forget where I found this - a PR with a source URL would be great :D
|
||||
const __dirname = import.meta.url.slice(7, import.meta.url.lastIndexOf("/"));
|
||||
|
@ -17,7 +17,7 @@ export default async function () {
|
|||
if(!fs.existsSync(settings.cli.config))
|
||||
throw new Error(`Error: The config file at '${settings.cli.config}' doesn't appear to exist, or we don't have permission to access it.`);
|
||||
|
||||
l.log(`
|
||||
console.error(`
|
||||
███████ ██ ██ ███████ ████████ ███████ ███ ███ ██████ ██ ██ ███████ ██████ ██ ██
|
||||
██ ██ ██ ██ ██ ██ ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||
███████ ████ ███████ ██ █████ ██ ████ ██ ██ ██ ██ ██ █████ ██████ ████
|
||||
|
@ -30,6 +30,6 @@ export default async function () {
|
|||
settings.cli.config
|
||||
);
|
||||
|
||||
let agent = new Agent(config);
|
||||
await agent.init();
|
||||
// Returns the systemquery instance, but we don't actually need it here
|
||||
await SystemQuery.Create(config);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue