Returns waku relay peers, not all waku peers across the various protocols

This commit is contained in:
Franck Royer 2021-04-01 16:44:28 +11:00
parent 433a490dec
commit b487e7803b
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
3 changed files with 10 additions and 10 deletions

View File

@ -13,7 +13,7 @@ import { RelayCodec, WakuRelayPubsub } from './index';
* @returns {Set<string>} * @returns {Set<string>}
* *
*/ */
export function getWakuPeers( export function getRelayPeers(
router: WakuRelayPubsub, router: WakuRelayPubsub,
topic: string, topic: string,
count: number, count: number,

View File

@ -7,7 +7,7 @@ import { SignaturePolicy } from 'libp2p-interfaces/src/pubsub/signature-policy';
import { WakuMessage } from '../waku_message'; import { WakuMessage } from '../waku_message';
import { RelayCodec, RelayDefaultTopic } from './constants'; import { RelayCodec, RelayDefaultTopic } from './constants';
import { getWakuPeers } from './get_waku_peers'; import { getRelayPeers } from './get_relay_peers';
import { RelayHeartbeat } from './relay_heartbeat'; import { RelayHeartbeat } from './relay_heartbeat';
export * from './constants'; export * from './constants';
@ -59,7 +59,7 @@ export class WakuRelayPubsub extends Gossipsub {
}); });
if (fanoutPeers.size < this._options.D) { if (fanoutPeers.size < this._options.D) {
// we need more peers; eager, as this would get fixed in the next heartbeat // we need more peers; eager, as this would get fixed in the next heartbeat
getWakuPeers( getRelayPeers(
this, this,
topic, topic,
this._options.D - fanoutPeers.size, this._options.D - fanoutPeers.size,
@ -77,7 +77,7 @@ export class WakuRelayPubsub extends Gossipsub {
this.fanout.delete(topic); this.fanout.delete(topic);
this.lastpub.delete(topic); this.lastpub.delete(topic);
} else { } else {
const peers = getWakuPeers( const peers = getRelayPeers(
this, this,
topic, topic,
this._options.D, this._options.D,
@ -132,7 +132,7 @@ export class WakuRelayPubsub extends Gossipsub {
meshPeers = this.fanout.get(topic); meshPeers = this.fanout.get(topic);
if (!meshPeers) { if (!meshPeers) {
// If we are not in the fanout, then pick peers in topic above the publishThreshold // If we are not in the fanout, then pick peers in topic above the publishThreshold
const peers = getWakuPeers(this, topic, this._options.D, (id) => { const peers = getRelayPeers(this, topic, this._options.D, (id) => {
return ( return (
this.score.score(id) >= this.score.score(id) >=
this._options.scoreThresholds.publishThreshold this._options.scoreThresholds.publishThreshold

View File

@ -3,7 +3,7 @@ import { Heartbeat } from 'libp2p-gossipsub/src/heartbeat';
import { shuffle } from 'libp2p-gossipsub/src/utils'; import { shuffle } from 'libp2p-gossipsub/src/utils';
import * as constants from './constants'; import * as constants from './constants';
import { getWakuPeers } from './get_waku_peers'; import { getRelayPeers } from './get_relay_peers';
export class RelayHeartbeat extends Heartbeat { export class RelayHeartbeat extends Heartbeat {
/** /**
@ -152,7 +152,7 @@ export class RelayHeartbeat extends Heartbeat {
if (peers.size < Dlo) { if (peers.size < Dlo) {
const backoff = this.gossipsub.backoff.get(topic); const backoff = this.gossipsub.backoff.get(topic);
const ineed = D - peers.size; const ineed = D - peers.size;
const peersSet = getWakuPeers( const peersSet = getRelayPeers(
this.gossipsub, this.gossipsub,
topic, topic,
ineed, ineed,
@ -239,7 +239,7 @@ export class RelayHeartbeat extends Heartbeat {
if (outbound < Dout) { if (outbound < Dout) {
const ineed = Dout - outbound; const ineed = Dout - outbound;
const backoff = this.gossipsub.backoff.get(topic); const backoff = this.gossipsub.backoff.get(topic);
getWakuPeers(this.gossipsub, topic, ineed, (id: string): boolean => { getRelayPeers(this.gossipsub, topic, ineed, (id: string): boolean => {
// filter our current mesh peers, direct peers, peers we are backing off, peers with negative score // filter our current mesh peers, direct peers, peers we are backing off, peers with negative score
return ( return (
!peers.has(id) && !peers.has(id) &&
@ -278,7 +278,7 @@ export class RelayHeartbeat extends Heartbeat {
this.gossipsub._options.scoreThresholds.opportunisticGraftThreshold this.gossipsub._options.scoreThresholds.opportunisticGraftThreshold
) { ) {
const backoff = this.gossipsub.backoff.get(topic); const backoff = this.gossipsub.backoff.get(topic);
const peersToGraft = getWakuPeers( const peersToGraft = getRelayPeers(
this.gossipsub, this.gossipsub,
topic, topic,
constants.RelayOpportunisticGraftPeers, constants.RelayOpportunisticGraftPeers,
@ -334,7 +334,7 @@ export class RelayHeartbeat extends Heartbeat {
// do we need more peers? // do we need more peers?
if (fanoutPeers.size < D) { if (fanoutPeers.size < D) {
const ineed = D - fanoutPeers.size; const ineed = D - fanoutPeers.size;
const peersSet = getWakuPeers( const peersSet = getRelayPeers(
this.gossipsub, this.gossipsub,
topic, topic,
ineed, ineed,