From 1eaf7619a73738c4c9c09d5a2e4c105e65aa7974 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Tue, 7 Jul 2020 18:56:37 +0200 Subject: [PATCH] chore: update deps --- examples/delegated-routing/.env | 3 +++ examples/delegated-routing/README.md | 6 +---- examples/delegated-routing/package.json | 22 ++++++++-------- examples/delegated-routing/src/App.js | 25 +++++++------------ .../src/libp2p-configuration.js | 12 +++------ 5 files changed, 28 insertions(+), 40 deletions(-) create mode 100644 examples/delegated-routing/.env diff --git a/examples/delegated-routing/.env b/examples/delegated-routing/.env new file mode 100644 index 00000000..4a6b2125 --- /dev/null +++ b/examples/delegated-routing/.env @@ -0,0 +1,3 @@ +# required because react-scripts scans *up* the tree from this project and finds +# a conflicting version of eslint in the node_modules dir for js-ipfs. +SKIP_PREFLIGHT_CHECK=true \ No newline at end of file diff --git a/examples/delegated-routing/README.md b/examples/delegated-routing/README.md index c9b7cfdd..8111e1e9 100644 --- a/examples/delegated-routing/README.md +++ b/examples/delegated-routing/README.md @@ -1,7 +1,3 @@ -❗❗Outdated: This example is still not refactored with the `0.27.*` release. -WIP on [libp2p/js-libp2p#507](https://github.com/libp2p/js-libp2p/pull/507) -====== - # Delegated Routing with Libp2p and IPFS This example shows how to use delegated peer and content routing. The [Peer and Content Routing Example](../peer-and-content-routing) focuses @@ -21,7 +17,7 @@ various Peer Discovery modules and see the impact it has on your Peer count. 1. Install IPFS locally if you dont already have it. [Install Guide](https://docs.ipfs.io/introduction/install/) 2. Run the IPFS daemon: `ipfs daemon` -3. The daemon will output a line about its API address, like `API server listening on /ip4/127.0.0.1/tcp/8080` +3. The daemon will output a line about its API address, like `API server listening on /ip4/127.0.0.1/tcp/5001` 4. In another window output the addresses of the node: `ipfs id`. Make note of the websocket address, it will contain `/ws/` in the address. - If there is no websocket address, you will need to add it in the ipfs config file (`~/.ipfs/config`) - Add to Swarm Addresses something like: `"/ip4/127.0.0.1/tcp/4010/ws"` diff --git a/examples/delegated-routing/package.json b/examples/delegated-routing/package.json index a2193c17..e4b53508 100644 --- a/examples/delegated-routing/package.json +++ b/examples/delegated-routing/package.json @@ -3,18 +3,18 @@ "version": "0.1.0", "private": true, "dependencies": { - "ipfs": "~0.40.0", + "ipfs": "~0.47.0", "libp2p": "../..", - "libp2p-delegated-content-routing": "~0.4.1", - "libp2p-delegated-peer-routing": "~0.4.0", - "libp2p-kad-dht": "~0.18.2", - "libp2p-mplex": "~0.9.3", - "libp2p-secio": "~0.12.1", - "libp2p-webrtc-star": "~0.17.0", - "libp2p-websockets": "~0.13.1", - "react": "^16.12.0", - "react-dom": "^16.12.0", - "react-scripts": "3.3.0" + "libp2p-delegated-content-routing": "~0.5.0", + "libp2p-delegated-peer-routing": "~0.5.0", + "libp2p-kad-dht": "~0.19.7", + "libp2p-mplex": "~0.9.5", + "libp2p-secio": "~0.12.5", + "libp2p-webrtc-star": "~0.18.6", + "libp2p-websockets": "~0.13.6", + "react": "^16.8.6", + "react-dom": "^16.8.6", + "react-scripts": "^3.2.0" }, "scripts": { "start": "react-scripts start" diff --git a/examples/delegated-routing/src/App.js b/examples/delegated-routing/src/App.js index 365d808f..40095987 100644 --- a/examples/delegated-routing/src/App.js +++ b/examples/delegated-routing/src/App.js @@ -5,7 +5,7 @@ import React from 'react' import Ipfs from 'ipfs' import libp2pConfig from './libp2p-configuration' -const BootstrapNode = '/ip4/127.0.0.1/tcp/4004/ws/ipfs/QmPHafDaco9vynQ93MHv5cRSW6UCECycCGdTRafL8X5WEj' +const BootstrapNode = '/ip4/127.0.0.1/tcp/4010/ws/p2p/QmZrsjJ7v9QoJNjDJmjsQ8947wiK3UnaPPLQvrTSRDAZ2d' class App extends React.Component { constructor (props) { @@ -64,8 +64,8 @@ class App extends React.Component { }) } - componentDidMount () { - window.ipfs = this.ipfs = new Ipfs({ + async componentDidMount () { + window.ipfs = this.ipfs = await Ipfs.create({ config: { Addresses: { Swarm: [] @@ -88,21 +88,14 @@ class App extends React.Component { libp2p: libp2pConfig }) - this.ipfs.on('ready', async () => { - if (this.peerInterval) { - clearInterval(this.peerInterval) - } + await this.ipfs.swarm.connect(BootstrapNode) + console.log('Connected!') + this.peerInterval = setInterval(async () => { + const peers = await this.ipfs.swarm.peers() - await this.ipfs.swarm.connect(BootstrapNode) - console.log('Connected!') - - this.peerInterval = setInterval(async () => { - const peers = await this.ipfs.swarm.peers() - - if (peers) this.setState({peers: peers.length}) - }, 2500) - }) + if (peers) this.setState({ peers: peers.length }) + }, 2500) } render () { diff --git a/examples/delegated-routing/src/libp2p-configuration.js b/examples/delegated-routing/src/libp2p-configuration.js index c5f76984..08dc2041 100644 --- a/examples/delegated-routing/src/libp2p-configuration.js +++ b/examples/delegated-routing/src/libp2p-configuration.js @@ -10,8 +10,7 @@ const KadDHT = require('libp2p-kad-dht') const DelegatedPeerRouter = require('libp2p-delegated-peer-routing') const DelegatedContentRouter = require('libp2p-delegated-content-routing') -export default function Libp2pConfiguration ({peerInfo}) { - const wrtcstar = new WebRTCStar({id: peerInfo.id}) +export default function Libp2pConfiguration ({peerId}) { const delegatedApiOptions = { host: '127.0.0.1', protocol: 'http', @@ -19,7 +18,7 @@ export default function Libp2pConfiguration ({peerInfo}) { } return new Libp2p({ - peerInfo, + peerId, // Lets limit the connection managers peers and have it check peer health less frequently connectionManager: { maxPeers: 10, @@ -27,16 +26,13 @@ export default function Libp2pConfiguration ({peerInfo}) { }, modules: { contentRouting: [ - new DelegatedContentRouter(peerInfo.id, delegatedApiOptions) + new DelegatedContentRouter(peerId, delegatedApiOptions) ], peerRouting: [ new DelegatedPeerRouter(delegatedApiOptions) ], - peerDiscovery: [ - wrtcstar.discovery - ], transport: [ - wrtcstar, + WebRTCStar, Websockets ], streamMuxer: [