Skip to content

Commit

Permalink
fix: update Helia usage and fix tests (#63)
Browse files Browse the repository at this point in the history
Helia 1.1.x comes with a libp2p instance so remove custom libp2p
creation.  The 101 example still has it so there's still a reference
to link people to.
  • Loading branch information
achingbrain authored May 22, 2023
1 parent 90384cc commit 8042513
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 53 deletions.
7 changes: 0 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,8 @@
"test": "npm run build && test-browser-example test"
},
"dependencies": {
"@chainsafe/libp2p-noise": "^12.0.0",
"@chainsafe/libp2p-yamux": "^4.0.1",
"@helia/unixfs": "^1.2.1",
"@libp2p/bootstrap": "^8.0.0",
"@libp2p/websockets": "^6.0.1",
"blockstore-core": "^4.1.0",
"datastore-core": "^9.1.1",
"helia": "^1.0.0",
"libp2p": "^0.45.0",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
47 changes: 1 addition & 46 deletions src/provider/HeliaProvider.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
/* eslint-disable no-console */

import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { unixfs } from '@helia/unixfs'
import { bootstrap } from '@libp2p/bootstrap'
import { webSockets } from '@libp2p/websockets'
import { MemoryBlockstore } from 'blockstore-core'
import { MemoryDatastore } from 'datastore-core'
import { createHelia } from 'helia'
import { createLibp2p } from 'libp2p'
import { identifyService } from 'libp2p/identify'
import PropTypes from 'prop-types'
import {
React,
Expand Down Expand Up @@ -42,45 +34,8 @@ export const HeliaProvider = ({ children }) => {
setStarting(false)
} else {
try {
// the blockstore is where we store the blocks that make up files
const blockstore = new MemoryBlockstore()

// application-specific data lives in the datastore
const datastore = new MemoryDatastore()

// libp2p is the networking layer that underpins Helia
// Make sure to stick libp2p here when running react in strict mode
const libp2p = await createLibp2p({
datastore,
transports: [
webSockets()
],
connectionEncryption: [
noise()
],
streamMuxers: [
yamux()
],
peerDiscovery: [
bootstrap({
list: [
'/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN',
'/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa',
'/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb',
'/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt'
]
})
],
services: {
identify: identifyService()
}
})
console.info('Starting Helia')
const helia = await createHelia({
datastore,
blockstore,
libp2p
})
const helia = await createHelia()
setHelia(helia)
setFs(unixfs(helia))
setStarting(false)
Expand Down

0 comments on commit 8042513

Please sign in to comment.