Fall back to normal relay connections if multiplexer fails to connect

This commit is contained in:
Jonathan Staab 2023-03-29 11:13:15 -05:00
parent 3ba160c123
commit 681d36d443
3 changed files with 24 additions and 13 deletions

14
package-lock.json generated
View File

@ -23,7 +23,7 @@
"lru-cache": "^7.18.3",
"nostr-tools": "^1.7.4",
"npm-run-all": "^4.1.5",
"paravel": "^0.1.10",
"paravel": "^0.1.11",
"qr-scanner": "^1.4.2",
"qrcode": "^1.5.1",
"ramda": "^0.28.0",
@ -6183,9 +6183,9 @@
"integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
},
"node_modules/paravel": {
"version": "0.1.10",
"resolved": "https://registry.npmjs.org/paravel/-/paravel-0.1.10.tgz",
"integrity": "sha512-Q07fbV0oYzv+1stBVk5GsSkPIWZzt9268x6txIGsq3jygwssO2zf0NAD81Ul4P2e6PwdVi4PkfFOUuO7ei+QNw==",
"version": "0.1.11",
"resolved": "https://registry.npmjs.org/paravel/-/paravel-0.1.11.tgz",
"integrity": "sha512-PCnI0/7vGfrGnYmN4DAZk4bJQlfjAxCe0HNSd+UoGD+/qIvlhbH6XoKhG2wJ8x8FMdNIF97MM66aq/LYVuJoZQ==",
"dependencies": {
"husky": "^8.0.3",
"isomorphic-ws": "^5.0.0",
@ -13021,9 +13021,9 @@
"integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
},
"paravel": {
"version": "0.1.10",
"resolved": "https://registry.npmjs.org/paravel/-/paravel-0.1.10.tgz",
"integrity": "sha512-Q07fbV0oYzv+1stBVk5GsSkPIWZzt9268x6txIGsq3jygwssO2zf0NAD81Ul4P2e6PwdVi4PkfFOUuO7ei+QNw==",
"version": "0.1.11",
"resolved": "https://registry.npmjs.org/paravel/-/paravel-0.1.11.tgz",
"integrity": "sha512-PCnI0/7vGfrGnYmN4DAZk4bJQlfjAxCe0HNSd+UoGD+/qIvlhbH6XoKhG2wJ8x8FMdNIF97MM66aq/LYVuJoZQ==",
"requires": {
"husky": "^8.0.3",
"isomorphic-ws": "^5.0.0",

View File

@ -46,7 +46,7 @@
"lru-cache": "^7.18.3",
"nostr-tools": "^1.7.4",
"npm-run-all": "^4.1.5",
"paravel": "^0.1.10",
"paravel": "^0.1.11",
"qr-scanner": "^1.4.2",
"qrcode": "^1.5.1",
"ramda": "^0.28.0",

View File

@ -159,11 +159,22 @@ function getExecutor(urls) {
urls = forceUrls
}
const executor = new Executor(
Config.multiplextrUrl
? new Plex(urls, pool.get(Config.multiplextrUrl))
: new Relays(urls.map(url => pool.get(url)))
)
let target
// Try to use our multiplexer, but if it fails to connect fall back to relays
if (Config.multiplextrUrl) {
const socket = pool.get(Config.multiplextrUrl)
if (!socket.error) {
target = new Plex(urls, pool.get(Config.multiplextrUrl))
}
}
if (!target) {
target = new Relays(urls.map(url => pool.get(url)))
}
const executor = new Executor(target)
executor.handleAuth({
onAuth(url, challenge) {