fix moar bugz
This commit is contained in:
parent
19f2003fbf
commit
bfdb23b935
2 changed files with 22 additions and 7 deletions
|
@ -4,13 +4,12 @@ import fs from 'fs';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
|
|
||||||
import log from 'log'; const l = log.get("agent");
|
import log from 'log'; const l = log.get("agent");
|
||||||
import systeminfo from 'systeminformation';
|
|
||||||
|
|
||||||
import settings from '../../settings.mjs';
|
import settings from '../../settings.mjs';
|
||||||
|
|
||||||
import PeerServer from './PeerServer.mjs';
|
import PeerServer from './PeerServer.mjs';
|
||||||
import hash from '../crypto/hash.mjs';
|
|
||||||
import parse_peer_name from '../parse/peer_name.mjs';
|
import parse_peer_name from '../parse/peer_name.mjs';
|
||||||
|
import hostuuid from '../io/hostuuid.mjs';
|
||||||
|
|
||||||
class Agent {
|
class Agent {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
|
@ -35,8 +34,7 @@ class Agent {
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
/** Our peer id - calculated automatically from the system's uuid */
|
/** Our peer id - calculated automatically from the system's uuid */
|
||||||
this.peer_id = hash("sha256", "base64", await systeminfo.system().serial)
|
this.peer_id = await hostuuid();
|
||||||
.replace(/[+/=]/g, "");
|
|
||||||
this.peer_name = os.hostname();
|
this.peer_name = os.hostname();
|
||||||
|
|
||||||
this.server = new PeerServer(
|
this.server = new PeerServer(
|
||||||
|
@ -45,17 +43,17 @@ class Agent {
|
||||||
);
|
);
|
||||||
this.server.retries = this.config.net.peer_retries;
|
this.server.retries = this.config.net.peer_retries;
|
||||||
|
|
||||||
l.log(`Starting peer listener....`);
|
l.notice(`Starting peer listener....`);
|
||||||
await this.server.listen(
|
await this.server.listen(
|
||||||
this.config.net.port,
|
this.config.net.port,
|
||||||
this.config.net.bind_address
|
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(
|
await this.server.add_peers(...this.config.peers.map(
|
||||||
peer => parse_peer_name(peer)
|
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)
|
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.`);
|
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
17
src/lib/io/hostuuid.mjs
Normal 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, "");
|
||||||
|
}
|
Loading…
Reference in a new issue