fix: use placeholder dht/pubsub (#1193)

Instead of making the `.dht` and `.pubsub` properties optional, use dummy implementations that throw exceptions if they are not configured.

This way we don't have to null guard everywhere they are accessed.
This commit is contained in:
Alex Potsides
2022-04-21 15:46:06 +01:00
committed by GitHub
parent 147304449e
commit 5397137c65
14 changed files with 186 additions and 78 deletions

View File

@@ -4,7 +4,7 @@ import { createLibp2p } from 'libp2p'
import { TCP } from '@libp2p/tcp'
import { Mplex } from '@libp2p/mplex'
import { Noise } from '@chainsafe/libp2p-noise'
import { Gossipsub } from '@achingbrain/libp2p-gossipsub'
import { FloodSub } from '@libp2p/floodsub'
import { Bootstrap } from '@libp2p/bootstrap'
import { PubSubPeerDiscovery } from '@libp2p/pubsub-peer-discovery'
@@ -16,7 +16,7 @@ const createNode = async (bootstrappers) => {
transports: [new TCP()],
streamMuxers: [new Mplex()],
connectionEncryption: [new Noise()],
pubsub: new Gossipsub(),
pubsub: new FloodSub(),
peerDiscovery: [
new Bootstrap({
list: bootstrappers
@@ -40,7 +40,7 @@ const createNode = async (bootstrappers) => {
transports: [new TCP()],
streamMuxers: [new Mplex()],
connectionEncryption: [new Noise()],
pubsub: new Gossipsub(),
pubsub: new FloodSub(),
peerDiscovery: [
new PubSubPeerDiscovery({
interval: 1000