mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-10-07 22:57:07 +00:00
feat: Default Libp2p config for node.js and browser peers.
This commit is contained in:
@@ -1,48 +1,13 @@
|
||||
import { createHelia } from 'helia'
|
||||
import { createLibp2p } from 'libp2p'
|
||||
import { identifyService } from 'libp2p/identify'
|
||||
import { webSockets } from '@libp2p/websockets'
|
||||
import { webRTC } from '@libp2p/webrtc'
|
||||
import { all } from '@libp2p/websockets/filters'
|
||||
import { noise } from '@chainsafe/libp2p-noise'
|
||||
import { yamux } from '@chainsafe/libp2p-yamux'
|
||||
import { gossipsub } from '@chainsafe/libp2p-gossipsub'
|
||||
import { circuitRelayTransport } from 'libp2p/circuit-relay'
|
||||
import { DefaultLibp2pOptions, DefaultLibp2pBrowserOptions } from '../../src/index.js'
|
||||
|
||||
const isBrowser = () => typeof window !== 'undefined'
|
||||
|
||||
export default async () => {
|
||||
const options = {
|
||||
addresses: {
|
||||
listen: [
|
||||
isBrowser() ? '/webrtc' : '/ip4/0.0.0.0/tcp/0/ws'
|
||||
]
|
||||
},
|
||||
transports: [
|
||||
webSockets({
|
||||
filter: all
|
||||
}),
|
||||
webRTC(),
|
||||
circuitRelayTransport({
|
||||
discoverRelays: 1
|
||||
})
|
||||
],
|
||||
connectionEncryption: [noise()],
|
||||
streamMuxers: [
|
||||
yamux()
|
||||
],
|
||||
connectionGater: {
|
||||
denyDialMultiaddr: () => {
|
||||
return false
|
||||
}
|
||||
},
|
||||
services: {
|
||||
identify: identifyService(),
|
||||
pubsub: gossipsub({ allowPublishToZeroPeers: true })
|
||||
}
|
||||
}
|
||||
const options = isBrowser() ? DefaultLibp2pBrowserOptions : DefaultLibp2pOptions
|
||||
|
||||
const libp2p = await createLibp2p(options)
|
||||
const libp2p = await createLibp2p({ ...options })
|
||||
|
||||
return createHelia({ libp2p })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user