From bfdb23b935fb2bb72e72a17a2f25a806cdff9e52 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sat, 8 Jan 2022 21:55:18 +0000 Subject: [PATCH] fix moar bugz --- src/lib/agent/Agent.mjs | 12 +++++------- src/lib/io/hostuuid.mjs | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 src/lib/io/hostuuid.mjs diff --git a/src/lib/agent/Agent.mjs b/src/lib/agent/Agent.mjs index 89914e6..1c2c161 100644 --- a/src/lib/agent/Agent.mjs +++ b/src/lib/agent/Agent.mjs @@ -4,13 +4,12 @@ import fs from 'fs'; import os from 'os'; import log from 'log'; const l = log.get("agent"); -import systeminfo from 'systeminformation'; import settings from '../../settings.mjs'; import PeerServer from './PeerServer.mjs'; -import hash from '../crypto/hash.mjs'; import parse_peer_name from '../parse/peer_name.mjs'; +import hostuuid from '../io/hostuuid.mjs'; class Agent { constructor(config) { @@ -35,8 +34,7 @@ class Agent { async init() { /** Our peer id - calculated automatically from the system's uuid */ - this.peer_id = hash("sha256", "base64", await systeminfo.system().serial) - .replace(/[+/=]/g, ""); + this.peer_id = await hostuuid(); this.peer_name = os.hostname(); this.server = new PeerServer( @@ -45,17 +43,17 @@ class Agent { ); this.server.retries = this.config.net.peer_retries; - l.log(`Starting peer listener....`); + l.notice(`Starting peer listener....`); await this.server.listen( this.config.net.port, this.config.net.bind_address ); - l.log(`Listening on ${this.config.net.bind_address}:${this.config.net.port}`); + l.notice(`Listening on ${this.config.net.bind_address}:${this.config.net.port}`); await this.server.add_peers(...this.config.peers.map( peer => parse_peer_name(peer) )); - l.log(`Added ${this.config.peers.length} initial peers`); + l.notice(`Added ${this.config.peers.length} initial peers`); if(this.config.peers.length < 1) l.warn(`No initial peers were specified! It's recommended that you specify at least 1 on every host.`); } diff --git a/src/lib/io/hostuuid.mjs b/src/lib/io/hostuuid.mjs new file mode 100644 index 0000000..04f1b94 --- /dev/null +++ b/src/lib/io/hostuuid.mjs @@ -0,0 +1,17 @@ +"use strict"; + +import systeminfo from 'systeminformation'; + +import hash from '../crypto/hash.mjs'; + +/** + * Returns what (should) be a reproducible UUID for each host that it runs on. + * @return {string} + */ +export default async function() { + let serial = (await systeminfo.system()).serial; + let uuid = await systeminfo.uuid(); + return hash("sha256", "base64", + `${serial}@${uuid.os}@${uuid.hardware}@${uuid.macs.join("#")}` + ).replace(/[+/=]/g, ""); +}