Add new top-level class: Agent → SystemQuery

depth++!
This commit is contained in:
Starbeamrainbowlabs 2022-01-23 19:51:23 +00:00
parent 16f23e6b77
commit 1270a39808
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 44 additions and 4 deletions

40
src/lib/SystemQuery.mjs Normal file
View 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;

View file

@ -8,7 +8,7 @@ import log from '../../lib/io/NamespacedLog.mjs'; const l = log("agent");
import settings from '../../settings.mjs'; import settings from '../../settings.mjs';
import toml_settings_read from '../../lib/io/TomlSettings.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 // 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("/")); 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)) 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.`); 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 settings.cli.config
); );
let agent = new Agent(config); // Returns the systemquery instance, but we don't actually need it here
await agent.init(); await SystemQuery.Create(config);
} }