From 6a05f3e6e7e76c453e8cac633b6b65348d745ff6 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Wed, 16 Oct 2019 17:27:31 +0200 Subject: [PATCH] docs(fix): correct docs and example for pnet (#464) * docs(fix): correct docs and example for pnet * docs(fix): correct pnet docs --- README.md | 8 ++++---- examples/pnet-ipfs/index.js | 6 +++--- examples/pnet-ipfs/libp2p-bundle.js | 2 +- examples/pnet-ipfs/package.json | 11 +++++------ src/pnet/README.md | 27 +++++++++++++++------------ 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 8ad40ebd..7a76104c 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ const MulticastDNS = require('libp2p-mdns') const DHT = require('libp2p-kad-dht') const GossipSub = require('libp2p-gossipsub') const defaultsDeep = require('@nodeutils/defaults-deep') -const Protector = require('libp2p-pnet') +const Protector = require('libp2p/src/pnet') const DelegatedPeerRouter = require('libp2p-delegated-peer-routing') const DelegatedContentRouter = require('libp2p-delegated-content-routing') @@ -527,15 +527,15 @@ Libp2p provides support for connection protection, such as for private networks. #### Protectors Some available network protectors: -* [libp2p-pnet](https://github.com/libp2p/js-libp2p-pnet) +* [libp2p-pnet](https://github.com/libp2p/js-libp2p/tree/master/src/pnet) ## Development **Clone and install dependencies:** ```sh -> git clone https://github.com/ipfs/js-ipfs.git -> cd js-ipfs +> git clone https://github.com/libp2p/js-libp2p.git +> cd js-libp2p > npm install ``` diff --git a/examples/pnet-ipfs/index.js b/examples/pnet-ipfs/index.js index c0d95728..1df94171 100644 --- a/examples/pnet-ipfs/index.js +++ b/examples/pnet-ipfs/index.js @@ -3,7 +3,7 @@ const IPFS = require('ipfs') const assert = require('assert').strict -const writeKey = require('libp2p-pnet').generate +const { generate: writeKey } = require('libp2p/src/pnet') const path = require('path') const fs = require('fs') const privateLibp2pBundle = require('./libp2p-bundle') @@ -117,7 +117,7 @@ const connectAndTalk = async () => { // Add some data to node 1 let addedCID try { - addedCID = await node1.files.add(dataToAdd) + addedCID = await node1.add(dataToAdd) } catch (err) { return doStop(err) } @@ -126,7 +126,7 @@ const connectAndTalk = async () => { // Retrieve the data from node 2 let cattedData try { - cattedData = await node2.files.cat(addedCID[0].path) + cattedData = await node2.cat(addedCID[0].path) } catch (err) { return doStop(err) } diff --git a/examples/pnet-ipfs/libp2p-bundle.js b/examples/pnet-ipfs/libp2p-bundle.js index b7c700a5..ff4fd37e 100644 --- a/examples/pnet-ipfs/libp2p-bundle.js +++ b/examples/pnet-ipfs/libp2p-bundle.js @@ -5,7 +5,7 @@ const TCP = require('libp2p-tcp') const MPLEX = require('libp2p-mplex') const SECIO = require('libp2p-secio') const fs = require('fs') -const Protector = require('libp2p-pnet') +const Protector = require('libp2p/src/pnet') /** * Options for the libp2p bundle diff --git a/examples/pnet-ipfs/package.json b/examples/pnet-ipfs/package.json index f4b05a5d..649e2711 100644 --- a/examples/pnet-ipfs/package.json +++ b/examples/pnet-ipfs/package.json @@ -11,11 +11,10 @@ "author": "", "license": "ISC", "dependencies": { - "ipfs": "~0.32.3", - "libp2p": "~0.23.1", - "libp2p-mplex": "~0.8.2", - "libp2p-pnet": "../../", - "libp2p-secio": "~0.10.0", - "libp2p-tcp": "~0.13.0" + "ipfs": "^0.38.0", + "libp2p": "^0.26.2", + "libp2p-mplex": "^0.8.5", + "libp2p-secio": "^0.11.1", + "libp2p-tcp": "^0.13.2" } } diff --git a/src/pnet/README.md b/src/pnet/README.md index 180df12a..97d5c0b5 100644 --- a/src/pnet/README.md +++ b/src/pnet/README.md @@ -7,12 +7,15 @@ js-libp2p-pnet ## Table of Contents -- [Usage](#usage) - - [Examples](#examples) - - [Private Shared Keys (PSK)](#private-shared-keys) - - [PSK Generation](#psk-generation) -- [Contribute](#contribute) -- [License](#license) +- [js-libp2p-pnet](#js-libp2p-pnet) + - [Table of Contents](#table-of-contents) + - [Usage](#usage) + - [Examples](#examples) + - [Private Shared Keys](#private-shared-keys) + - [PSK Generation](#psk-generation) + - [From libp2p-pnet](#from-libp2p-pnet) + - [From a module using libp2p](#from-a-module-using-libp2p) + - [Programmatically](#programmatically) ## Usage @@ -23,7 +26,7 @@ const privateConnection = protector.protect(myPublicConnection, (err) => { }) ``` ### Examples -[Private Networks with IPFS](./examples/pnet-ipfs) +[Private Networks with IPFS](../../examples/pnet-ipfs) ### Private Shared Keys @@ -42,25 +45,25 @@ use one of the methods below to generate your key. #### From libp2p-pnet -If you have libp2p-pnet locally, you can run the following from the projects root. +If you have libp2p locally, you can run the following from the projects root. ```sh -node ./key-generator.js > swarm.key +node ./src/pnet/key-generator.js > swarm.key ``` #### From a module using libp2p -If you have a module locally that depends on libp2p-pnet, you can run the following from +If you have a module locally that depends on libp2p, you can run the following from that project, assuming the node_modules are installed. ```sh -node -e "require('libp2p-pnet').generate(process.stdout)" > swarm.key +node -e "require('libp2p/src/pnet').generate(process.stdout)" > swarm.key ``` #### Programmatically ```js -const writeKey = require('libp2p-pnet').generate +const writeKey = require('libp2p/src/pnet').generate const swarmKey = Buffer.alloc(95) writeKey(swarmKey) fs.writeFileSync('swarm.key', swarmKey)