diff --git a/src/lib/SystemQuery.mjs b/src/lib/SystemQuery.mjs new file mode 100644 index 0000000..8409940 --- /dev/null +++ b/src/lib/SystemQuery.mjs @@ -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; diff --git a/src/subcommands/agent/agent.mjs b/src/subcommands/agent/agent.mjs index c65e209..3bbf3ea 100644 --- a/src/subcommands/agent/agent.mjs +++ b/src/subcommands/agent/agent.mjs @@ -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); }