From fe35c3cea07710b8e4082a9a4861f13103da2320 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Tue, 10 Dec 2019 19:40:39 +0100 Subject: [PATCH 1/7] refactor: examples-delegated-routing --- examples/delegated-routing/README.md | 6 +- examples/delegated-routing/package.json | 25 ++++----- examples/delegated-routing/src/App.js | 56 ++++++++----------- ...bp2p-bundle.js => libp2p-configuration.js} | 13 ++--- 4 files changed, 44 insertions(+), 56 deletions(-) rename examples/delegated-routing/src/{libp2p-bundle.js => libp2p-configuration.js} (83%) diff --git a/examples/delegated-routing/README.md b/examples/delegated-routing/README.md index e72e512e86..c9b7cfdd02 100644 --- a/examples/delegated-routing/README.md +++ b/examples/delegated-routing/README.md @@ -10,7 +10,7 @@ especially useful when your libp2p node will have limited resources, making runn also highly useful if your node is generating content, but can't reliably be on the network. You can use delegate nodes to provide content on your behalf. -The starting [Libp2p Bundle](./src/libp2p-bundle.js) in this example starts by disabling the DHT and adding the Delegated Peer and Content Routers. +The starting [Libp2p Configuration](./src/libp2p-configuration.js) in this example starts by disabling the DHT and adding the Delegated Peer and Content Routers. Once you've completed the example, you should try enabled the DHT and see what kind of results you get! You can also enable the various Peer Discovery modules and see the impact it has on your Peer count. @@ -23,7 +23,9 @@ various Peer Discovery modules and see the impact it has on your Peer count. 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` 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. -5. In `./src/libp2p-bundle.js` check if the host and port of your node are correct, according to the previous step. If they are different, replace them. + - 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"` +5. In `./src/libp2p-configuration.js` check if the host and port of your node are correct, according to the previous step. If they are different, replace them. 6. In `./src/App.js` replace `BootstrapNode` with your nodes Websocket address from step 4. 7. Start this example: diff --git a/examples/delegated-routing/package.json b/examples/delegated-routing/package.json index 164e0d3c54..a2193c1743 100644 --- a/examples/delegated-routing/package.json +++ b/examples/delegated-routing/package.json @@ -3,19 +3,18 @@ "version": "0.1.0", "private": true, "dependencies": { - "ipfs": "~0.34.4", - "libp2p": "github:libp2p/js-libp2p#master", - "libp2p-delegated-content-routing": "~0.2.2", - "libp2p-delegated-peer-routing": "~0.2.2", - "libp2p-kad-dht": "~0.14.12", - "libp2p-mplex": "~0.8.5", - "libp2p-secio": "~0.11.1", - "libp2p-webrtc-star": "~0.15.8", - "libp2p-websocket-star": "~0.10.2", - "libp2p-websockets": "~0.12.2", - "react": "^16.8.6", - "react-dom": "^16.8.6", - "react-scripts": "2.1.8" + "ipfs": "~0.40.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" }, "scripts": { "start": "react-scripts start" diff --git a/examples/delegated-routing/src/App.js b/examples/delegated-routing/src/App.js index ce6af6777f..365d808f7d 100644 --- a/examples/delegated-routing/src/App.js +++ b/examples/delegated-routing/src/App.js @@ -3,12 +3,11 @@ import React from 'react' import Ipfs from 'ipfs' -import libp2pBundle from './libp2p-bundle' -const Component = React.Component +import libp2pConfig from './libp2p-configuration' -const BootstrapNode = '/ip4/127.0.0.1/tcp/8081/ws/p2p/QmdoG8DpzYUZMVP5dGmgmigZwR1RE8Cf6SxMPg1SBXJAQ8' +const BootstrapNode = '/ip4/127.0.0.1/tcp/4004/ws/ipfs/QmPHafDaco9vynQ93MHv5cRSW6UCECycCGdTRafL8X5WEj' -class App extends Component { +class App extends React.Component { constructor (props) { super(props) this.state = { @@ -38,34 +37,30 @@ class App extends Component { }) } - handleHashSubmit (event) { + async handleHashSubmit (event) { event.preventDefault() this.setState({ isLoading: this.state.isLoading + 1 }) - this.ipfs.cat(this.state.hash, (err, data) => { - if (err) console.log('Error', err) + const data = await this.ipfs.cat(this.state.hash) - this.setState({ - response: data.toString(), - isLoading: this.state.isLoading - 1 - }) + this.setState({ + response: data.toString(), + isLoading: this.state.isLoading - 1 }) } - handlePeerSubmit (event) { + async handlePeerSubmit (event) { event.preventDefault() this.setState({ isLoading: this.state.isLoading + 1 }) - this.ipfs.dht.findpeer(this.state.peer, (err, results) => { - if (err) console.log('Error', err) + const results = await this.ipfs.dht.findpeer(this.state.peer) - this.setState({ - response: JSON.stringify(results, null, 2), - isLoading: this.state.isLoading - 1 - }) + this.setState({ + response: JSON.stringify(results, null, 2), + isLoading: this.state.isLoading - 1 }) } @@ -90,25 +85,22 @@ class App extends Component { preload: { enabled: false }, - libp2p: libp2pBundle + libp2p: libp2pConfig }) - this.ipfs.on('ready', () => { + + this.ipfs.on('ready', async () => { if (this.peerInterval) { clearInterval(this.peerInterval) } - this.ipfs.swarm.connect(BootstrapNode, (err) => { - if (err) { - console.log('Error connecting to the node', err) - } - console.log('Connected!') - }) - - this.peerInterval = setInterval(() => { - this.ipfs.swarm.peers((err, peers) => { - if (err) console.log(err) - if (peers) this.setState({peers: peers.length}) - }) + + 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) }) } diff --git a/examples/delegated-routing/src/libp2p-bundle.js b/examples/delegated-routing/src/libp2p-configuration.js similarity index 83% rename from examples/delegated-routing/src/libp2p-bundle.js rename to examples/delegated-routing/src/libp2p-configuration.js index 48fb090699..c5f7698447 100644 --- a/examples/delegated-routing/src/libp2p-bundle.js +++ b/examples/delegated-routing/src/libp2p-configuration.js @@ -3,7 +3,6 @@ const Libp2p = require('libp2p') const Websockets = require('libp2p-websockets') -const WebSocketStar = require('libp2p-websocket-star') const WebRTCStar = require('libp2p-webrtc-star') const MPLEX = require('libp2p-mplex') const SECIO = require('libp2p-secio') @@ -11,18 +10,16 @@ const KadDHT = require('libp2p-kad-dht') const DelegatedPeerRouter = require('libp2p-delegated-peer-routing') const DelegatedContentRouter = require('libp2p-delegated-content-routing') -export default function Libp2pBundle ({peerInfo, peerBook}) { +export default function Libp2pConfiguration ({peerInfo}) { const wrtcstar = new WebRTCStar({id: peerInfo.id}) - const wsstar = new WebSocketStar({id: peerInfo.id}) const delegatedApiOptions = { - host: '0.0.0.0', + host: '127.0.0.1', protocol: 'http', - port: '8080' + port: '5001' } return new Libp2p({ peerInfo, - peerBook, // Lets limit the connection managers peers and have it check peer health less frequently connectionManager: { maxPeers: 10, @@ -36,12 +33,10 @@ export default function Libp2pBundle ({peerInfo, peerBook}) { new DelegatedPeerRouter(delegatedApiOptions) ], peerDiscovery: [ - wrtcstar.discovery, - wsstar.discovery + wrtcstar.discovery ], transport: [ wrtcstar, - wsstar, Websockets ], streamMuxer: [ From fb75728682f4b57e4446af46ad4391728b981357 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Tue, 7 Jul 2020 18:56:37 +0200 Subject: [PATCH 2/7] 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 0000000000..4a6b212591 --- /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 c9b7cfdd02..8111e1e9af 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 a2193c1743..e4b5350816 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 365d808f7d..4009598706 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 c5f7698447..08dc2041cd 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: [ From 44ce1a2a3a2178465cf7213625261cc196b8e550 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Tue, 7 Jul 2020 19:17:42 +0200 Subject: [PATCH 3/7] fix: use new apis --- examples/delegated-routing/README.md | 2 +- examples/delegated-routing/package.json | 1 + examples/delegated-routing/src/App.js | 11 ++++++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/delegated-routing/README.md b/examples/delegated-routing/README.md index 8111e1e9af..362d055601 100644 --- a/examples/delegated-routing/README.md +++ b/examples/delegated-routing/README.md @@ -36,7 +36,7 @@ This should open your browser to http://localhost:3000. If it does not, go ahead ### Finding Content via the Delegate 1. Add a file to your IPFS node. From this example root you can do `ipfs add ./README.md` to add the example readme. -2. Copy the hash from line 5, it will look something like *Qmf33vz4HJFkqgH7XPP1uA6atYKTX1BWQEQthzpKcAdeyZ*. +2. Copy the hash from line 5, it will look something like *QmV8QZ1m4fi57fbmaYDAkaTSTjHZVLUJmsqvaP6EcUyUNb*. 3. In the browser, paste the hash into the *Hash* field and hit `Find`. The readme contents should display. This will do a few things: diff --git a/examples/delegated-routing/package.json b/examples/delegated-routing/package.json index e4b5350816..377e5a59cf 100644 --- a/examples/delegated-routing/package.json +++ b/examples/delegated-routing/package.json @@ -12,6 +12,7 @@ "libp2p-secio": "~0.12.5", "libp2p-webrtc-star": "~0.18.6", "libp2p-websockets": "~0.13.6", + "peer-id": "^0.13.13", "react": "^16.8.6", "react-dom": "^16.8.6", "react-scripts": "^3.2.0" diff --git a/examples/delegated-routing/src/App.js b/examples/delegated-routing/src/App.js index 4009598706..c19c7630d3 100644 --- a/examples/delegated-routing/src/App.js +++ b/examples/delegated-routing/src/App.js @@ -4,6 +4,7 @@ import React from 'react' import Ipfs from 'ipfs' import libp2pConfig from './libp2p-configuration' +import PeerId from 'peer-id' const BootstrapNode = '/ip4/127.0.0.1/tcp/4010/ws/p2p/QmZrsjJ7v9QoJNjDJmjsQ8947wiK3UnaPPLQvrTSRDAZ2d' @@ -43,10 +44,13 @@ class App extends React.Component { isLoading: this.state.isLoading + 1 }) - const data = await this.ipfs.cat(this.state.hash) + const chunks = [] + for await (const chunk of this.ipfs.cat(this.state.hash)) { + chunks.push(chunk) + } this.setState({ - response: data.toString(), + response: Buffer.concat(chunks).toString(), isLoading: this.state.isLoading - 1 }) } @@ -56,7 +60,8 @@ class App extends React.Component { isLoading: this.state.isLoading + 1 }) - const results = await this.ipfs.dht.findpeer(this.state.peer) + const peerId = PeerId.createFromB58String(this.state.peer) + const results = await this.ipfs.libp2p.peerRouting.findPeer(peerId) this.setState({ response: JSON.stringify(results, null, 2), From 71eda21feb2d5caf61bd78cc96902f1ba9bf6018 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Tue, 7 Jul 2020 19:55:24 +0200 Subject: [PATCH 4/7] chore: rephrase react-scripts .env need --- examples/delegated-routing/.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/delegated-routing/.env b/examples/delegated-routing/.env index 4a6b212591..5ee1b5956f 100644 --- a/examples/delegated-routing/.env +++ b/examples/delegated-routing/.env @@ -1,3 +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. +# a conflicting version of webpack in the node_modules dir for js-libp2p (aegir). SKIP_PREFLIGHT_CHECK=true \ No newline at end of file From 92b5b783f954c82e7820db50da302a4d31686862 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 8 Jul 2020 14:06:35 +0200 Subject: [PATCH 5/7] chore: use public delegated routing --- examples/delegated-routing/README.md | 28 ++++++++----------- examples/delegated-routing/src/App.js | 2 +- .../src/libp2p-configuration.js | 6 ++-- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/examples/delegated-routing/README.md b/examples/delegated-routing/README.md index 362d055601..208c35977b 100644 --- a/examples/delegated-routing/README.md +++ b/examples/delegated-routing/README.md @@ -1,29 +1,21 @@ # 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 -on the DHT implementation. This example takes that a step further and introduces delegated routing. Delegated routing is -especially useful when your libp2p node will have limited resources, making running a DHT impractical. It's -also highly useful if your node is generating content, but can't reliably be on the network. You can use delegate nodes -to provide content on your behalf. +This example shows how to use delegated peer and content routing. The [Peer and Content Routing Example](../peer-and-content-routing) focuses on the DHT implementation. This example takes that a step further and introduces delegated routing. Delegated routing is especially useful when your libp2p node will have limited resources, making running a DHT impractical. It's also highly useful if your node is generating content, but can't reliably be on the network. You can use delegate nodes to provide content on your behalf. The starting [Libp2p Configuration](./src/libp2p-configuration.js) in this example starts by disabling the DHT and adding the Delegated Peer and Content Routers. -Once you've completed the example, you should try enabled the DHT and see what kind of results you get! You can also enable the -various Peer Discovery modules and see the impact it has on your Peer count. +Once you've completed the example, you should try enabled the DHT and see what kind of results you get! You can also enable the various Peer Discovery modules and see the impact it has on your Peer count. -## Prerequisite -**NOTE**: This example is currently dependent on a clone of the [delegated routing support branch of go-ipfs](https://github.com/ipfs/go-ipfs/pull/4595). +This example uses a publicly known delegated routing node. This aims to ease experimentation, but you should not rely on this in production. ## Running this example 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/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. +3. 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"` -5. In `./src/libp2p-configuration.js` check if the host and port of your node are correct, according to the previous step. If they are different, replace them. -6. In `./src/App.js` replace `BootstrapNode` with your nodes Websocket address from step 4. -7. Start this example: +4. In `./src/App.js` replace `BootstrapNode` with your nodes Websocket address from the step above. +5. Start this example: ```sh npm install @@ -32,7 +24,7 @@ npm start This should open your browser to http://localhost:3000. If it does not, go ahead and do that now. -8. Your browser should show you connected to at least 1 peer. +6. Your browser should show you connected to at least 1 peer. ### Finding Content via the Delegate 1. Add a file to your IPFS node. From this example root you can do `ipfs add ./README.md` to add the example readme. @@ -46,6 +38,10 @@ This will do a few things: ### Finding Peers via the Delegate 1. Get a list of your delegate nodes peer by querying the IPFS daemon: `ipfs swarm peers` -2. Copy one of the CIDs from the list of peer addresses, this will be the last portion of the address and will look something like `QmdoG8DpzYUZMVP5dGmgmigZwR1RE8Cf6SxMPg1SBXJAQ8`. +2. Copy one of the CIDs from the list of peer addresses, this will be the last portion of the address and will look something like `QmSb5LGwyVTCSgi5etuBnKhkEgH68cDxfwp3rtc94Fegv4`. 3. In your browser, paste the CID into the *Peer* field and hit `Find`. 4. You should see information about the peer including its addresses. + +## Going to production? + +TODO diff --git a/examples/delegated-routing/src/App.js b/examples/delegated-routing/src/App.js index c19c7630d3..7530d009fa 100644 --- a/examples/delegated-routing/src/App.js +++ b/examples/delegated-routing/src/App.js @@ -16,7 +16,7 @@ class App extends React.Component { // This hash is the IPFS readme hash: 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB', // This peer is one of the Bootstrap nodes for IPFS - peer: 'QmV6kA2fB8kTr6jc3pL5zbNsjKbmPUHAPKKHRBYe1kDEyc', + peer: 'QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z', isLoading: 0 } this.peerInterval = null diff --git a/examples/delegated-routing/src/libp2p-configuration.js b/examples/delegated-routing/src/libp2p-configuration.js index 08dc2041cd..0c09ac0980 100644 --- a/examples/delegated-routing/src/libp2p-configuration.js +++ b/examples/delegated-routing/src/libp2p-configuration.js @@ -12,9 +12,9 @@ const DelegatedContentRouter = require('libp2p-delegated-content-routing') export default function Libp2pConfiguration ({peerId}) { const delegatedApiOptions = { - host: '127.0.0.1', - protocol: 'http', - port: '5001' + protocol: 'https', + port: 443, + host: 'node0.delegate.ipfs.io' } return new Libp2p({ From 900f8ae52443c3693425c4da34d4dce2adda353b Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Fri, 24 Jul 2020 15:02:04 +0200 Subject: [PATCH 6/7] docs: production guide --- doc/production/CIRCUIT_RELAY.md | 0 doc/production/DELEGATE_NODES.md | 83 ++++++++++++++++++++++++++++++++ doc/production/README.md | 40 +++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 doc/production/CIRCUIT_RELAY.md create mode 100644 doc/production/DELEGATE_NODES.md create mode 100644 doc/production/README.md diff --git a/doc/production/CIRCUIT_RELAY.md b/doc/production/CIRCUIT_RELAY.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/doc/production/DELEGATE_NODES.md b/doc/production/DELEGATE_NODES.md new file mode 100644 index 0000000000..21195d8015 --- /dev/null +++ b/doc/production/DELEGATE_NODES.md @@ -0,0 +1,83 @@ +# Delegate Nodes with IPFS + +This document aims to guide the setup of a delegate node in the IPFS/libp2p network. It is recommended that you look into the [Delegated Routing with Libp2p and IPFS](../examples/deledated-routing) example first. This example describes how to use the public delegate nodes available for demos and experiments. + +## Table of Contents + +* [Delegate Nodes with IPFS](#delegate-nodes-with-ipfs) + * [Setup a local go-ipfs node as a Delegate Node for the example](#setup-a-local-go-ipfs-node-as-a-delegate-node-for-the-example) + * [Setup a remote go-ipfs node as a Delegate Node for the example](#setup-a-remote-go-ipfs-node-as-a-delegate-node-for-the-example) + * [Setup a remote go-ipfs node as a Delegate Node for js-ipfs](#setup-a-remote-go-ipfs-node-as-a-delegate-node-for-js-ipfs) + +## Setup a local go-ipfs node as a Delegate Node for the example + +The simplest first step before going into production is to setup a delegate node locally and try it out in the [Delegated Routing with Libp2p and IPFS](../examples/deledated-routing) example. + +Taking into account the browser policies regarding CORS, proper HTTP headers must be configured in `go-ipfs`. + +1. Install `go-ipfs` locally, if you don't have it already. Check the [Install Guidelines](https://github.com/ipfs/go-ipfs/#install). +2. Configure HTTP headers for access control + +```sh +ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]' +ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["GET", "POST"]' +``` + +Bear in mind that this allows access to any origin. You might want to control the allowed origins. + +3. Start your `go-ipfs` daemon. + +```sh +ipfs daemon +``` + +The daemon will output a line about its API address, like `API server listening on /ip4/127.0.0.1/tcp/5001` + +4. Modify the example `libp2p-configuration` to use the local `go-ipfs` node API + +```js +const delegatedApiOptions = { + protocol: 'http', + port: 5001, + host: '127.0.0.1' +} +``` + +5. Start the example and retry its flows. You should have your browser node leveraging the delegate `go-ipfs` node for `content-routing` and `peer-routing`. + +## Setup a remote go-ipfs node as a Delegate Node for the example + +1. Install `go-ipfs`. Check the [Install Guidelines](https://github.com/ipfs/go-ipfs/#install). +2. Configure HTTP headers for access control + +```sh +ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]' +ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["GET", "POST"]' +``` + +Bear in mind that this allows access to any origin. You might want to control the allowed origins. + +3. Start your `go-ipfs` daemon. + +4. Expose the API to the outside world. You should setup an SSL certificate with nginx and proxy to the API. You can use a service that already offers an SSL certificate with the server and configure nginx, or you can create valid certificates with for example [Letsencrypt](https://certbot.eff.org/lets-encrypt/osx-nginx). Letsencrypt won’t give you a cert for an IP address (yet) so you need to connect via SSL to a domain name. + +5. Modify the example `libp2p-configuration` to use the remote `go-ipfs` node host name. + +6. Start the example and retry its flows. + +## Setup a remote go-ipfs node as a Delegate Node for js-ipfs + +You should follow all the steps mentioned for the setup of a remote go-ipfs for the libp2p example, except for the integration with the example. + +5. You should add your delegate multiaddr to the `js-ipfs` config file as follows: + +```js +Addresses: { + Delegates: [ + '/dns4/node0.mydelegatenode.io/tcp/443/https', + '/dns4/node1.mydelegatenode.io/tcp/443/https', + '/dns4/node2.mydelegatenode.io/tcp/443/https', + '/dns4/node3.mydelegatenode.io/tcp/443/https' + ] +}, +``` diff --git a/doc/production/README.md b/doc/production/README.md new file mode 100644 index 0000000000..27564c6b05 --- /dev/null +++ b/doc/production/README.md @@ -0,0 +1,40 @@ +# Production + +`js-libp2p` can be used in multiple environments, as well as for a wide range of use cases. Different environments and different use cases mean different configurations and challenges in the network. + +Libp2p nodes in the network can vary from nodes behind an application, to infrastructure nodes that enable the network to operate and to be efficient. In this context, the Libp2p project provides public infrastructure to boost the network, enable nodes connectivity and improve constrained nodes performance. This public infrastructure should be leveraged for learning the concepts and experimenting. When an application on top of libp2p aims to move into production, its own infrastructure should be setup as the public nodes will be intensively used by others and its availability is not guaranteed. + +This guide aims to guide you from using the public infrastructure into setting up your own. + +## Table of Contents + +* [Production](#production) + * [Bootstrap nodes](#bootstrap-nodes) + * [Star servers](#star-servers) + * [Delegate nodes](#delegate-nodes) + * [Circuit Relay](#circuit-relay) + * [Rendezvous Server nodes](#rendezvous-server-nodes) + +## Bootstrap nodes + +TODO: Problem that solve... + +## Star servers + +TODO: Problem that solve... + +## Delegate nodes + +Libp2p nodes in a browser environment, in constrained devices, as well as in other scenarios, will not be an efficient node in the libp2p DHT overlay, as a consequence of their known limitations regarding connectivity and performance. + +Aiming to support these type of nodes to find other peers and content in the network, delegate nodes can be setup. With a set of well known libp2p delegate nodes, nodes with limitations in the network can leverage them to perform peer and content routing calls. + +You can read on how to setup your own set of delegated nodes in [DELEGATE_NODES.md](./DELEGATE_NODES.md). + +## Circuit Relay + +TODO: Problem that solve... + +## Rendezvous Server nodes + +TODO: Problem that solve... From 7435ebd06afe1e6261b961fe495458043151746a Mon Sep 17 00:00:00 2001 From: Jose Aguinaga Date: Fri, 31 Jul 2020 10:03:24 +0200 Subject: [PATCH 7/7] chore: Add extra init instructions for ipfs start (#722) --- doc/production/DELEGATE_NODES.md | 7 +++++++ examples/delegated-routing/README.md | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/production/DELEGATE_NODES.md b/doc/production/DELEGATE_NODES.md index 21195d8015..ea2b2629e9 100644 --- a/doc/production/DELEGATE_NODES.md +++ b/doc/production/DELEGATE_NODES.md @@ -65,6 +65,13 @@ Bear in mind that this allows access to any origin. You might want to control th 6. Start the example and retry its flows. +
+Troubleshooting + +

Error: no IPFS repo found in $INSTALLATION_PATH/ipfs/common

+Bear in mind that in some distributions you might need to run ipfs init before starting the go-ipfs daemon. If you are running the go-ipfs node in a server you might prefer using the server profile and running ipfs init --profile server instead. For more detailed instructions, please refer to the canonical documentation for initializing the repository +
+ ## Setup a remote go-ipfs node as a Delegate Node for js-ipfs You should follow all the steps mentioned for the setup of a remote go-ipfs for the libp2p example, except for the integration with the example. diff --git a/examples/delegated-routing/README.md b/examples/delegated-routing/README.md index 208c35977b..0388939a54 100644 --- a/examples/delegated-routing/README.md +++ b/examples/delegated-routing/README.md @@ -13,7 +13,7 @@ This example uses a publicly known delegated routing node. This aims to ease exp 2. Run the IPFS daemon: `ipfs daemon` 3. 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"` + - Add to Swarm Addresses something like: `"/ip4/127.0.0.1/tcp/4001/ws"`. Make sure to restart your IPFS node afterwards to ensure the new settings had been applied. 4. In `./src/App.js` replace `BootstrapNode` with your nodes Websocket address from the step above. 5. Start this example: