Another day, another set of bugs

This commit is contained in:
Starbeamrainbowlabs 2022-01-09 00:57:06 +00:00
parent c5e2d31c47
commit 306180d9d8
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
6 changed files with 103 additions and 133 deletions

206
package-lock.json generated
View file

@ -12,8 +12,8 @@
"@ltd/j-toml": "^1.24.0",
"applause-cli": "^1.7.0",
"jpake": "^1.0.1",
"log": "^6.2.0",
"log-node": "^8.0.1",
"log": "^6.3.1",
"log-node": "^8.0.3",
"nexline": "^1.2.2",
"p-queue": "^7.1.0",
"p-retry": "^5.0.0",
@ -37,11 +37,11 @@
"integrity": "sha512-xoDlM2S4ortawSWORYqsdU+2rxdh4LRW9ytc3zmT37RIKQh6IHyKwwtKhKis9ah8ol07DCkZxPt8BBvPjC6v4g=="
},
"node_modules/ansi-regex": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=",
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"engines": {
"node": ">=0.10.0"
"node": ">=8"
}
},
"node_modules/applause-cli": {
@ -50,40 +50,32 @@
"integrity": "sha512-zO/nBR9x37Iqlm3R2Glo0NyDIevwbDPrISprK61Z/M01Xvm5dFkL2FZAONxxHctT9QoF71fiY22sFRuq8Sqxug=="
},
"node_modules/cli-color": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/cli-color/-/cli-color-2.0.0.tgz",
"integrity": "sha512-a0VZ8LeraW0jTuCkuAGMNufareGHhyZU9z8OGsW0gXd1hZGi1SRuNRXdbGkraBBKnhyUhyebFWnRbp+dIn0f0A==",
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/cli-color/-/cli-color-2.0.1.tgz",
"integrity": "sha512-eBbxZF6fqPUNnf7CLAFOersUnyYzv83tHFLSlts+OAHsNendaqv2tHCq+/MO+b3Y+9JeoUlIvobyxG/Z8GNeOg==",
"dependencies": {
"ansi-regex": "^2.1.1",
"d": "^1.0.1",
"es5-ext": "^0.10.51",
"es5-ext": "^0.10.53",
"es6-iterator": "^2.0.3",
"memoizee": "^0.4.14",
"memoizee": "^0.4.15",
"timers-ext": "^0.1.7"
},
"engines": {
"node": ">=0.10"
}
},
"node_modules/cli-sprintf-format": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/cli-sprintf-format/-/cli-sprintf-format-1.1.0.tgz",
"integrity": "sha512-t3LcCdPvrypZovStadWdRS4a186gsq9aoHJYTIer55VY20YdVjGVHDV4uPWcWCXTw1tPjfwlRGE7zKMWJ663Sw==",
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/cli-sprintf-format/-/cli-sprintf-format-1.1.1.tgz",
"integrity": "sha512-BbEjY9BEdA6wagVwTqPvmAwGB24U93rQPBFZUT8lNCDxXzre5LFHQUTJc70czjgUomVg8u8R5kW8oY9DYRFNeg==",
"dependencies": {
"cli-color": "^1.3",
"es5-ext": "^0.10.46",
"sprintf-kit": "2",
"supports-color": "^5.5"
}
},
"node_modules/cli-sprintf-format/node_modules/cli-color": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/cli-color/-/cli-color-1.4.0.tgz",
"integrity": "sha512-xu6RvQqqrWEo6MPR1eixqGPywhYBHRs653F9jfXB2Hx4jdM/3WxiNE1vppRmxtMIfl16SFYTpYlrnqH/HsK/2w==",
"dependencies": {
"ansi-regex": "^2.1.1",
"d": "1",
"es5-ext": "^0.10.46",
"es6-iterator": "^2.0.3",
"memoizee": "^0.4.14",
"timers-ext": "^0.1.5"
"cli-color": "^2.0.1",
"es5-ext": "^0.10.53",
"sprintf-kit": "^2.0.1",
"supports-color": "^6.1.0"
},
"engines": {
"node": ">=6.0"
}
},
"node_modules/cli-sprintf-format/node_modules/has-flag": {
@ -95,14 +87,14 @@
}
},
"node_modules/cli-sprintf-format/node_modules/supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.1.0.tgz",
"integrity": "sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==",
"dependencies": {
"has-flag": "^3.0.0"
},
"engines": {
"node": ">=4"
"node": ">=6"
}
},
"node_modules/crypto-js": {
@ -213,25 +205,6 @@
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.8.tgz",
"integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg=="
},
"node_modules/has-ansi": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-4.0.1.tgz",
"integrity": "sha512-Qr4RtTm30xvEdqUXbSBVWDu+PrTokJOwe/FU+VdfJPk+MXAPoeOzKpRyrDTnZIJwAkQ4oBLTU53nu0HrkF/Z2A==",
"dependencies": {
"ansi-regex": "^4.1.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/has-ansi/node_modules/ansi-regex": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz",
"integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==",
"engines": {
"node": ">=6"
}
},
"node_modules/has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
@ -275,28 +248,29 @@
}
},
"node_modules/log": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/log/-/log-6.2.0.tgz",
"integrity": "sha512-W1sDY5FqR6wlpygW8ZFSxCfBhKx/RzCHK5S+Br8zA14bAnwSgCm5hToIWzi0Yhy6x9Ppw7pyIV06r8F5cSRHUw==",
"version": "6.3.1",
"resolved": "https://registry.npmjs.org/log/-/log-6.3.1.tgz",
"integrity": "sha512-McG47rJEWOkXTDioZzQNydAVvZNeEkSyLJ1VWkFwfW+o1knW+QSi8D1KjPn/TnctV+q99lkvJNe1f0E1IjfY2A==",
"dependencies": {
"d": "^1.0.1",
"duration": "^0.2.2",
"es5-ext": "^0.10.53",
"event-emitter": "^0.3.5",
"sprintf-kit": "^2.0.1",
"type": "^2.5.0"
"type": "^2.5.0",
"uni-global": "^1.0.0"
}
},
"node_modules/log-node": {
"version": "8.0.1",
"resolved": "https://registry.npmjs.org/log-node/-/log-node-8.0.1.tgz",
"integrity": "sha512-w6ii8zZo+O4Os9EBB0+ruaeVU6CysNgYj/cUDOtobBxnNPRHynjMjzyqjEuNKGT/AD89sZzGh0pS3/0ZPRR1iQ==",
"version": "8.0.3",
"resolved": "https://registry.npmjs.org/log-node/-/log-node-8.0.3.tgz",
"integrity": "sha512-1UBwzgYiCIDFs8A0rM2QdBFo8Wd8UQ0HrSTu/MNI+/2zN3NoHRj2fhplurAyuxTYUXu3Oohugq1jAn5s05u1MQ==",
"dependencies": {
"cli-color": "^2.0.0",
"cli-sprintf-format": "^1.1.0",
"ansi-regex": "^5.0.1",
"cli-color": "^2.0.1",
"cli-sprintf-format": "^1.1.1",
"d": "^1.0.1",
"es5-ext": "^0.10.53",
"has-ansi": "^4.0.1",
"sprintf-kit": "^2.0.1",
"supports-color": "^8.1.1",
"type": "^2.5.0"
@ -477,6 +451,14 @@
"resolved": "https://registry.npmjs.org/type/-/type-2.5.0.tgz",
"integrity": "sha512-180WMDQaIMm3+7hGXWf12GtdniDEy7nYcyFMKJn/eZz/6tSLXrUN9V0wKSbMjej0I1WHWbpREDEKHtqPQa9NNw=="
},
"node_modules/uni-global": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/uni-global/-/uni-global-1.0.0.tgz",
"integrity": "sha512-WWM3HP+siTxzIWPNUg7hZ4XO8clKi6NoCAJJWnuRL+BAqyFXF8gC03WNyTefGoUXYc47uYgXxpKLIEvo65PEHw==",
"dependencies": {
"type": "^2.5.0"
}
},
"node_modules/universalify": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
@ -503,9 +485,9 @@
"integrity": "sha512-xoDlM2S4ortawSWORYqsdU+2rxdh4LRW9ytc3zmT37RIKQh6IHyKwwtKhKis9ah8ol07DCkZxPt8BBvPjC6v4g=="
},
"ansi-regex": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8="
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ=="
},
"applause-cli": {
"version": "1.7.0",
@ -513,51 +495,37 @@
"integrity": "sha512-zO/nBR9x37Iqlm3R2Glo0NyDIevwbDPrISprK61Z/M01Xvm5dFkL2FZAONxxHctT9QoF71fiY22sFRuq8Sqxug=="
},
"cli-color": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/cli-color/-/cli-color-2.0.0.tgz",
"integrity": "sha512-a0VZ8LeraW0jTuCkuAGMNufareGHhyZU9z8OGsW0gXd1hZGi1SRuNRXdbGkraBBKnhyUhyebFWnRbp+dIn0f0A==",
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/cli-color/-/cli-color-2.0.1.tgz",
"integrity": "sha512-eBbxZF6fqPUNnf7CLAFOersUnyYzv83tHFLSlts+OAHsNendaqv2tHCq+/MO+b3Y+9JeoUlIvobyxG/Z8GNeOg==",
"requires": {
"ansi-regex": "^2.1.1",
"d": "^1.0.1",
"es5-ext": "^0.10.51",
"es5-ext": "^0.10.53",
"es6-iterator": "^2.0.3",
"memoizee": "^0.4.14",
"memoizee": "^0.4.15",
"timers-ext": "^0.1.7"
}
},
"cli-sprintf-format": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/cli-sprintf-format/-/cli-sprintf-format-1.1.0.tgz",
"integrity": "sha512-t3LcCdPvrypZovStadWdRS4a186gsq9aoHJYTIer55VY20YdVjGVHDV4uPWcWCXTw1tPjfwlRGE7zKMWJ663Sw==",
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/cli-sprintf-format/-/cli-sprintf-format-1.1.1.tgz",
"integrity": "sha512-BbEjY9BEdA6wagVwTqPvmAwGB24U93rQPBFZUT8lNCDxXzre5LFHQUTJc70czjgUomVg8u8R5kW8oY9DYRFNeg==",
"requires": {
"cli-color": "^1.3",
"es5-ext": "^0.10.46",
"sprintf-kit": "2",
"supports-color": "^5.5"
"cli-color": "^2.0.1",
"es5-ext": "^0.10.53",
"sprintf-kit": "^2.0.1",
"supports-color": "^6.1.0"
},
"dependencies": {
"cli-color": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/cli-color/-/cli-color-1.4.0.tgz",
"integrity": "sha512-xu6RvQqqrWEo6MPR1eixqGPywhYBHRs653F9jfXB2Hx4jdM/3WxiNE1vppRmxtMIfl16SFYTpYlrnqH/HsK/2w==",
"requires": {
"ansi-regex": "^2.1.1",
"d": "1",
"es5-ext": "^0.10.46",
"es6-iterator": "^2.0.3",
"memoizee": "^0.4.14",
"timers-ext": "^0.1.5"
}
},
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
},
"supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.1.0.tgz",
"integrity": "sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==",
"requires": {
"has-flag": "^3.0.0"
}
@ -671,21 +639,6 @@
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.8.tgz",
"integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg=="
},
"has-ansi": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-4.0.1.tgz",
"integrity": "sha512-Qr4RtTm30xvEdqUXbSBVWDu+PrTokJOwe/FU+VdfJPk+MXAPoeOzKpRyrDTnZIJwAkQ4oBLTU53nu0HrkF/Z2A==",
"requires": {
"ansi-regex": "^4.1.0"
},
"dependencies": {
"ansi-regex": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz",
"integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg=="
}
}
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
@ -723,28 +676,29 @@
}
},
"log": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/log/-/log-6.2.0.tgz",
"integrity": "sha512-W1sDY5FqR6wlpygW8ZFSxCfBhKx/RzCHK5S+Br8zA14bAnwSgCm5hToIWzi0Yhy6x9Ppw7pyIV06r8F5cSRHUw==",
"version": "6.3.1",
"resolved": "https://registry.npmjs.org/log/-/log-6.3.1.tgz",
"integrity": "sha512-McG47rJEWOkXTDioZzQNydAVvZNeEkSyLJ1VWkFwfW+o1knW+QSi8D1KjPn/TnctV+q99lkvJNe1f0E1IjfY2A==",
"requires": {
"d": "^1.0.1",
"duration": "^0.2.2",
"es5-ext": "^0.10.53",
"event-emitter": "^0.3.5",
"sprintf-kit": "^2.0.1",
"type": "^2.5.0"
"type": "^2.5.0",
"uni-global": "^1.0.0"
}
},
"log-node": {
"version": "8.0.1",
"resolved": "https://registry.npmjs.org/log-node/-/log-node-8.0.1.tgz",
"integrity": "sha512-w6ii8zZo+O4Os9EBB0+ruaeVU6CysNgYj/cUDOtobBxnNPRHynjMjzyqjEuNKGT/AD89sZzGh0pS3/0ZPRR1iQ==",
"version": "8.0.3",
"resolved": "https://registry.npmjs.org/log-node/-/log-node-8.0.3.tgz",
"integrity": "sha512-1UBwzgYiCIDFs8A0rM2QdBFo8Wd8UQ0HrSTu/MNI+/2zN3NoHRj2fhplurAyuxTYUXu3Oohugq1jAn5s05u1MQ==",
"requires": {
"cli-color": "^2.0.0",
"cli-sprintf-format": "^1.1.0",
"ansi-regex": "^5.0.1",
"cli-color": "^2.0.1",
"cli-sprintf-format": "^1.1.1",
"d": "^1.0.1",
"es5-ext": "^0.10.53",
"has-ansi": "^4.0.1",
"sprintf-kit": "^2.0.1",
"supports-color": "^8.1.1",
"type": "^2.5.0"
@ -872,6 +826,14 @@
"resolved": "https://registry.npmjs.org/type/-/type-2.5.0.tgz",
"integrity": "sha512-180WMDQaIMm3+7hGXWf12GtdniDEy7nYcyFMKJn/eZz/6tSLXrUN9V0wKSbMjej0I1WHWbpREDEKHtqPQa9NNw=="
},
"uni-global": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/uni-global/-/uni-global-1.0.0.tgz",
"integrity": "sha512-WWM3HP+siTxzIWPNUg7hZ4XO8clKi6NoCAJJWnuRL+BAqyFXF8gC03WNyTefGoUXYc47uYgXxpKLIEvo65PEHw==",
"requires": {
"type": "^2.5.0"
}
},
"universalify": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",

View file

@ -20,8 +20,8 @@
"@ltd/j-toml": "^1.24.0",
"applause-cli": "^1.7.0",
"jpake": "^1.0.1",
"log": "^6.2.0",
"log-node": "^8.0.1",
"log": "^6.3.1",
"log-node": "^8.0.3",
"nexline": "^1.2.2",
"p-queue": "^7.1.0",
"p-retry": "^5.0.0",

View file

@ -35,7 +35,7 @@ class Agent {
async init() {
/** Our peer id - calculated automatically from the system's uuid */
this.peer_id = await hostuuid();
this.peer_id = await hostuuid(this.config.net.port);
this.peer_name = os.hostname();
this.server = new PeerServer(

View file

@ -40,9 +40,8 @@ class Peer extends EventEmitter {
*/
this.known_peers = [];
// TODO: Log when disconnected too
this.once("connect", () => {
l.log(`${this.connection.address}:${this.connection.port} connected`);
l.notice(`${this.connection.address}:${this.connection.port} connected`);
});
}
@ -82,7 +81,9 @@ class Peer extends EventEmitter {
__handle_hello(msg) {
this.id = msg.id;
this.known_peers = msg.peers;
if(msg.id === this.server.our_id) {
if(this.id === this.server.our_id) {
l.warn(`Our id (${this.server.our_id}) is equal to that of the remote (${this.id}), killing connection`);
return false;
}
return true;

View file

@ -176,12 +176,18 @@ class PeerServer extends EventEmitter {
* @return {Promise<Peer|null>} A Promise that resolves to the resulting Peer connection, or null if the connection wasn't attemped.
*/
async __add_peer(address, port) {
l.notice(`Attempting to connect to ${address}:${port}`);
// If we're already connected, don't bother reconnecting again
if(this.peers().some(el => el.address === address && el.port === port))
if(this.peers().some(el => el.address === address && el.port === port)) {
l.notice(`A connection is already open to ${address}:${port}, skipping`);
return;
}
// If we are attempting to connect to ourselves, then don't bother
if(address == this.host && port == this.port)
if(address == this.host && port == this.port) {
l.notice(`${address}:${port} is actually us, skipping`);
return;
}
const peer_string = `peer:${address}:${port}`;
this.connecting_peers.push(peer_string);

View file

@ -6,12 +6,13 @@ import hash from '../crypto/hash.mjs';
/**
* Returns what (should) be a reproducible UUID for each host that it runs on.
* @return {string}
* @param {number} port The port number the agent will listen on. Optional - useful to disambiguating multiple agents running on the same machine for development purposes.
* @return {string}
*/
export default async function() {
export default async function(port) {
let serial = (await systeminfo.system()).serial;
let uuid = await systeminfo.uuid();
return hash("sha256", "base64",
`${serial}@${uuid.os}@${uuid.hardware}@${uuid.macs.join("#")}`
`${port}@${serial}@${uuid.os}@${uuid.hardware}@${uuid.macs.join("#")}`
).replace(/[+/=]/g, "");
}