mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-26 15:31:34 +00:00
chore: address review
This commit is contained in:
committed by
Vasco Santos
parent
0bf0b7cf89
commit
5c72424e57
@ -242,7 +242,7 @@ class AutoRelay {
|
||||
try {
|
||||
const cid = await namespaceToCid(RELAY_RENDEZVOUS_NS)
|
||||
for await (const provider of this._libp2p.contentRouting.findProviders(cid)) {
|
||||
if (!provider || !provider.id || !provider.multiaddrs || !provider.multiaddrs.length) {
|
||||
if (!provider || !provider.multiaddrs.length) {
|
||||
continue
|
||||
}
|
||||
const peerId = provider.id
|
||||
|
@ -3,10 +3,10 @@
|
||||
const minute = 60 * 1000
|
||||
|
||||
module.exports = {
|
||||
ADVERTISE_BOOT_DELAY: 15 * minute,
|
||||
ADVERTISE_TTL: 30 * minute,
|
||||
CIRCUIT_PROTO_CODE: 290,
|
||||
HOP_METADATA_KEY: 'hop_relay',
|
||||
HOP_METADATA_VALUE: 'true',
|
||||
RELAY_RENDEZVOUS_NS: '/libp2p/relay'
|
||||
ADVERTISE_BOOT_DELAY: 15 * minute, // Delay before HOP relay service is advertised on the network
|
||||
ADVERTISE_TTL: 30 * minute, // Delay Between HOP relay service advertisements on the network
|
||||
CIRCUIT_PROTO_CODE: 290, // Multicodec code
|
||||
HOP_METADATA_KEY: 'hop_relay', // PeerStore metadaBook key for HOP relay service
|
||||
HOP_METADATA_VALUE: 'true', // PeerStore metadaBook value for HOP relay service
|
||||
RELAY_RENDEZVOUS_NS: '/libp2p/relay' // Relay HOP relay service namespace for discovery
|
||||
}
|
||||
|
@ -20,8 +20,16 @@ class Relay {
|
||||
* @param {Libp2p} libp2p
|
||||
*/
|
||||
constructor (libp2p) {
|
||||
this._options = libp2p._config.relay
|
||||
this._libp2p = libp2p
|
||||
this._options = {
|
||||
advertise: {
|
||||
bootDelay: ADVERTISE_BOOT_DELAY,
|
||||
enabled: true,
|
||||
ttl: ADVERTISE_TTL,
|
||||
...libp2p._config.relay.advertise
|
||||
},
|
||||
...libp2p._config.relay
|
||||
}
|
||||
|
||||
// Create autoRelay if enabled
|
||||
this._autoRelay = this._options.autoRelay.enabled && new AutoRelay({ libp2p, ...this._options.autoRelay })
|
||||
@ -35,10 +43,10 @@ class Relay {
|
||||
// Advertise service if HOP enabled
|
||||
const canHop = this._options.hop.enabled
|
||||
|
||||
if (canHop) {
|
||||
if (canHop && this._options.advertise.enabled) {
|
||||
this._timeout = setTimeout(() => {
|
||||
this._advertiseService()
|
||||
}, this._options.advertise.bootDelay || ADVERTISE_BOOT_DELAY)
|
||||
}, this._options.advertise.bootDelay)
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,12 +72,16 @@ class Relay {
|
||||
} else {
|
||||
log.error(err)
|
||||
}
|
||||
// Stop the advertise
|
||||
this.stop()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Restart timeout
|
||||
this._timeout = setTimeout(() => {
|
||||
this._advertiseService()
|
||||
}, this._options.advertise.ttl || ADVERTISE_TTL)
|
||||
}, this._options.advertise.ttl)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,7 @@ const DefaultConfig = {
|
||||
enabled: true,
|
||||
advertise: {
|
||||
bootDelay: RelayConstants.ADVERTISE_BOOT_DELAY,
|
||||
enabled: true,
|
||||
ttl: RelayConstants.ADVERTISE_TTL
|
||||
},
|
||||
hop: {
|
||||
|
Reference in New Issue
Block a user