fix moar bugz

This commit is contained in:
Starbeamrainbowlabs 2022-01-08 21:55:18 +00:00
parent 19f2003fbf
commit bfdb23b935
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 22 additions and 7 deletions

View file

@ -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.`);
}

17
src/lib/io/hostuuid.mjs Normal file
View file

@ -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, "");
}