mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-07 00:03:07 +00:00
Clean up imports
This commit is contained in:
parent
ff9bfa7f0a
commit
ff8e96b60c
@ -4,7 +4,7 @@ import util from 'util';
|
|||||||
import Waku from '../lib/waku';
|
import Waku from '../lib/waku';
|
||||||
import { WakuMessage } from '../lib/waku_message';
|
import { WakuMessage } from '../lib/waku_message';
|
||||||
import { RelayDefaultTopic } from '../lib/waku_relay';
|
import { RelayDefaultTopic } from '../lib/waku_relay';
|
||||||
import { delay } from '../test_utils/delay';
|
import { delay } from '../test_utils/';
|
||||||
|
|
||||||
import { ChatMessage } from './chat_message';
|
import { ChatMessage } from './chat_message';
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
|
|
||||||
import { NOISE_KEY_1 } from '../test_utils/constants';
|
import { makeLogFileName, NimWaku, NOISE_KEY_1 } from '../test_utils/';
|
||||||
import { makeLogFileName } from '../test_utils/log_file';
|
|
||||||
import { NimWaku } from '../test_utils/nim_waku';
|
|
||||||
|
|
||||||
import Waku from './waku';
|
import Waku from './waku';
|
||||||
import { RelayCodec } from './waku_relay';
|
import { RelayCodec } from './waku_relay';
|
||||||
|
|||||||
@ -12,14 +12,7 @@ import PeerId from 'peer-id';
|
|||||||
|
|
||||||
import { WakuMessage } from '../waku_message';
|
import { WakuMessage } from '../waku_message';
|
||||||
|
|
||||||
import {
|
import * as constants from './constants';
|
||||||
RelayCodec,
|
|
||||||
RelayDefaultTopic,
|
|
||||||
RelayGossipFactor,
|
|
||||||
RelayMaxIHaveLength,
|
|
||||||
RelayPruneBackoff,
|
|
||||||
RelayPrunePeers,
|
|
||||||
} from './constants';
|
|
||||||
import { getRelayPeers } from './get_relay_peers';
|
import { getRelayPeers } from './get_relay_peers';
|
||||||
import { RelayHeartbeat } from './relay_heartbeat';
|
import { RelayHeartbeat } from './relay_heartbeat';
|
||||||
|
|
||||||
@ -43,7 +36,7 @@ export class WakuRelayPubsub extends Gossipsub {
|
|||||||
|
|
||||||
this.heartbeat = new RelayHeartbeat(this);
|
this.heartbeat = new RelayHeartbeat(this);
|
||||||
|
|
||||||
const multicodecs = [RelayCodec];
|
const multicodecs = [constants.RelayCodec];
|
||||||
|
|
||||||
// This is the downside of using `libp2p-gossipsub` instead of
|
// This is the downside of using `libp2p-gossipsub` instead of
|
||||||
// implementing WakuRelay from scratch.
|
// implementing WakuRelay from scratch.
|
||||||
@ -193,7 +186,7 @@ export class WakuRelayPubsub extends Gossipsub {
|
|||||||
shuffle(messageIDs);
|
shuffle(messageIDs);
|
||||||
|
|
||||||
// if we are emitting more than GossipsubMaxIHaveLength ids, truncate the list
|
// if we are emitting more than GossipsubMaxIHaveLength ids, truncate the list
|
||||||
if (messageIDs.length > RelayMaxIHaveLength) {
|
if (messageIDs.length > constants.RelayMaxIHaveLength) {
|
||||||
// we do the truncation (with shuffling) per peer below
|
// we do the truncation (with shuffling) per peer below
|
||||||
this.log(
|
this.log(
|
||||||
'too many messages for gossip; will truncate IHAVE list (%d messages)',
|
'too many messages for gossip; will truncate IHAVE list (%d messages)',
|
||||||
@ -219,7 +212,7 @@ export class WakuRelayPubsub extends Gossipsub {
|
|||||||
if (
|
if (
|
||||||
!exclude.has(id) &&
|
!exclude.has(id) &&
|
||||||
!this.direct.has(id) &&
|
!this.direct.has(id) &&
|
||||||
peerStreams.protocol == RelayCodec &&
|
peerStreams.protocol == constants.RelayCodec &&
|
||||||
this.score.score(id) >= this._options.scoreThresholds.gossipThreshold
|
this.score.score(id) >= this._options.scoreThresholds.gossipThreshold
|
||||||
) {
|
) {
|
||||||
peersToGossip.push(id);
|
peersToGossip.push(id);
|
||||||
@ -227,7 +220,7 @@ export class WakuRelayPubsub extends Gossipsub {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let target = this._options.Dlazy;
|
let target = this._options.Dlazy;
|
||||||
const factor = RelayGossipFactor * peersToGossip.length;
|
const factor = constants.RelayGossipFactor * peersToGossip.length;
|
||||||
if (factor > target) {
|
if (factor > target) {
|
||||||
target = factor;
|
target = factor;
|
||||||
}
|
}
|
||||||
@ -239,13 +232,13 @@ export class WakuRelayPubsub extends Gossipsub {
|
|||||||
// Emit the IHAVE gossip to the selected peers up to the target
|
// Emit the IHAVE gossip to the selected peers up to the target
|
||||||
peersToGossip.slice(0, target).forEach((id) => {
|
peersToGossip.slice(0, target).forEach((id) => {
|
||||||
let peerMessageIDs = messageIDs;
|
let peerMessageIDs = messageIDs;
|
||||||
if (messageIDs.length > RelayMaxIHaveLength) {
|
if (messageIDs.length > constants.RelayMaxIHaveLength) {
|
||||||
// shuffle and slice message IDs per peer so that we emit a different set for each peer
|
// shuffle and slice message IDs per peer so that we emit a different set for each peer
|
||||||
// we have enough redundancy in the system that this will significantly increase the message
|
// we have enough redundancy in the system that this will significantly increase the message
|
||||||
// coverage when we do truncate
|
// coverage when we do truncate
|
||||||
peerMessageIDs = shuffle(peerMessageIDs.slice()).slice(
|
peerMessageIDs = shuffle(peerMessageIDs.slice()).slice(
|
||||||
0,
|
0,
|
||||||
RelayMaxIHaveLength
|
constants.RelayMaxIHaveLength
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
this._pushGossip(id, {
|
this._pushGossip(id, {
|
||||||
@ -265,14 +258,14 @@ export class WakuRelayPubsub extends Gossipsub {
|
|||||||
_makePrune(id: string, topic: string, doPX: boolean): ControlPrune {
|
_makePrune(id: string, topic: string, doPX: boolean): ControlPrune {
|
||||||
// backoff is measured in seconds
|
// backoff is measured in seconds
|
||||||
// RelayPruneBackoff is measured in milliseconds
|
// RelayPruneBackoff is measured in milliseconds
|
||||||
const backoff = RelayPruneBackoff / 1000;
|
const backoff = constants.RelayPruneBackoff / 1000;
|
||||||
const px: PeerInfo[] = [];
|
const px: PeerInfo[] = [];
|
||||||
if (doPX) {
|
if (doPX) {
|
||||||
// select peers for Peer eXchange
|
// select peers for Peer eXchange
|
||||||
const peers = getRelayPeers(
|
const peers = getRelayPeers(
|
||||||
this,
|
this,
|
||||||
topic,
|
topic,
|
||||||
RelayPrunePeers,
|
constants.RelayPrunePeers,
|
||||||
(xid: string): boolean => {
|
(xid: string): boolean => {
|
||||||
return xid !== id && this.score.score(xid) >= 0;
|
return xid !== id && this.score.score(xid) >= 0;
|
||||||
}
|
}
|
||||||
@ -305,11 +298,11 @@ export class WakuRelay {
|
|||||||
|
|
||||||
// At this stage we are always using the same topic so we do not pass it as a parameter
|
// At this stage we are always using the same topic so we do not pass it as a parameter
|
||||||
async subscribe() {
|
async subscribe() {
|
||||||
await this.pubsub.subscribe(RelayDefaultTopic);
|
await this.pubsub.subscribe(constants.RelayDefaultTopic);
|
||||||
}
|
}
|
||||||
|
|
||||||
async publish(message: WakuMessage) {
|
async publish(message: WakuMessage) {
|
||||||
const msg = message.toBinary();
|
const msg = message.toBinary();
|
||||||
await this.pubsub.publish(RelayDefaultTopic, msg);
|
await this.pubsub.publish(constants.RelayDefaultTopic, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
5
src/test_utils/index.ts
Normal file
5
src/test_utils/index.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export * from './async_fs';
|
||||||
|
export * from './constants';
|
||||||
|
export * from './delay';
|
||||||
|
export * from './log_file';
|
||||||
|
export * from './nim_waku';
|
||||||
Loading…
x
Reference in New Issue
Block a user