mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-18 12:11:35 +00:00
Randomize nostr relay connection
This commit is contained in:
parent
b8ba5e98f2
commit
9bcf4c1c85
@ -10,7 +10,9 @@ interface RoboPoolEvents {
|
|||||||
class RoboPool {
|
class RoboPool {
|
||||||
constructor(settings: Settings, origin: string) {
|
constructor(settings: Settings, origin: string) {
|
||||||
this.network = settings.network ?? 'mainnet';
|
this.network = settings.network ?? 'mainnet';
|
||||||
this.relays = Object.values(defaultFederation)
|
|
||||||
|
this.relays = [];
|
||||||
|
const federationRelays = Object.values(defaultFederation)
|
||||||
.map((coord) => {
|
.map((coord) => {
|
||||||
const url: string = coord[this.network][settings.selfhostedClient ? 'onion' : origin];
|
const url: string = coord[this.network][settings.selfhostedClient ? 'onion' : origin];
|
||||||
|
|
||||||
@ -19,6 +21,19 @@ class RoboPool {
|
|||||||
return `ws://${url.replace(/^https?:\/\//, '')}/nostr`;
|
return `ws://${url.replace(/^https?:\/\//, '')}/nostr`;
|
||||||
})
|
})
|
||||||
.filter((item) => item !== undefined);
|
.filter((item) => item !== undefined);
|
||||||
|
if (settings.host) {
|
||||||
|
const hostNostr = `ws://${settings.host.replace(/^https?:\/\//, '')}/nostr`;
|
||||||
|
if (federationRelays.includes(hostNostr)) {
|
||||||
|
this.relays.push(hostNostr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (this.relays.length < 3) {
|
||||||
|
const randomRelay =
|
||||||
|
federationRelays[Math.floor(Math.random() * Object.keys(federationRelays).length)];
|
||||||
|
if (!this.relays.includes(randomRelay)) {
|
||||||
|
this.relays.push(randomRelay);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public relays: string[];
|
public relays: string[];
|
||||||
|
Loading…
Reference in New Issue
Block a user