docs(fix): correct docs and example for pnet (#464)

* docs(fix): correct docs and example for pnet

* docs(fix): correct pnet docs
This commit is contained in:
Jacob Heun 2019-10-16 17:27:31 +02:00 committed by GitHub
parent 93a1e42ef3
commit 6a05f3e6e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 26 deletions

View File

@ -122,7 +122,7 @@ const MulticastDNS = require('libp2p-mdns')
const DHT = require('libp2p-kad-dht') const DHT = require('libp2p-kad-dht')
const GossipSub = require('libp2p-gossipsub') const GossipSub = require('libp2p-gossipsub')
const defaultsDeep = require('@nodeutils/defaults-deep') 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 DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
const DelegatedContentRouter = require('libp2p-delegated-content-routing') const DelegatedContentRouter = require('libp2p-delegated-content-routing')
@ -527,15 +527,15 @@ Libp2p provides support for connection protection, such as for private networks.
#### Protectors #### Protectors
Some available network 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 ## Development
**Clone and install dependencies:** **Clone and install dependencies:**
```sh ```sh
> git clone https://github.com/ipfs/js-ipfs.git > git clone https://github.com/libp2p/js-libp2p.git
> cd js-ipfs > cd js-libp2p
> npm install > npm install
``` ```

View File

@ -3,7 +3,7 @@
const IPFS = require('ipfs') const IPFS = require('ipfs')
const assert = require('assert').strict const assert = require('assert').strict
const writeKey = require('libp2p-pnet').generate const { generate: writeKey } = require('libp2p/src/pnet')
const path = require('path') const path = require('path')
const fs = require('fs') const fs = require('fs')
const privateLibp2pBundle = require('./libp2p-bundle') const privateLibp2pBundle = require('./libp2p-bundle')
@ -117,7 +117,7 @@ const connectAndTalk = async () => {
// Add some data to node 1 // Add some data to node 1
let addedCID let addedCID
try { try {
addedCID = await node1.files.add(dataToAdd) addedCID = await node1.add(dataToAdd)
} catch (err) { } catch (err) {
return doStop(err) return doStop(err)
} }
@ -126,7 +126,7 @@ const connectAndTalk = async () => {
// Retrieve the data from node 2 // Retrieve the data from node 2
let cattedData let cattedData
try { try {
cattedData = await node2.files.cat(addedCID[0].path) cattedData = await node2.cat(addedCID[0].path)
} catch (err) { } catch (err) {
return doStop(err) return doStop(err)
} }

View File

@ -5,7 +5,7 @@ const TCP = require('libp2p-tcp')
const MPLEX = require('libp2p-mplex') const MPLEX = require('libp2p-mplex')
const SECIO = require('libp2p-secio') const SECIO = require('libp2p-secio')
const fs = require('fs') const fs = require('fs')
const Protector = require('libp2p-pnet') const Protector = require('libp2p/src/pnet')
/** /**
* Options for the libp2p bundle * Options for the libp2p bundle

View File

@ -11,11 +11,10 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"ipfs": "~0.32.3", "ipfs": "^0.38.0",
"libp2p": "~0.23.1", "libp2p": "^0.26.2",
"libp2p-mplex": "~0.8.2", "libp2p-mplex": "^0.8.5",
"libp2p-pnet": "../../", "libp2p-secio": "^0.11.1",
"libp2p-secio": "~0.10.0", "libp2p-tcp": "^0.13.2"
"libp2p-tcp": "~0.13.0"
} }
} }

View File

@ -7,12 +7,15 @@ js-libp2p-pnet
## Table of Contents ## Table of Contents
- [Usage](#usage) - [js-libp2p-pnet](#js-libp2p-pnet)
- [Examples](#examples) - [Table of Contents](#table-of-contents)
- [Private Shared Keys (PSK)](#private-shared-keys) - [Usage](#usage)
- [PSK Generation](#psk-generation) - [Examples](#examples)
- [Contribute](#contribute) - [Private Shared Keys](#private-shared-keys)
- [License](#license) - [PSK Generation](#psk-generation)
- [From libp2p-pnet](#from-libp2p-pnet)
- [From a module using libp2p](#from-a-module-using-libp2p)
- [Programmatically](#programmatically)
## Usage ## Usage
@ -23,7 +26,7 @@ const privateConnection = protector.protect(myPublicConnection, (err) => { })
``` ```
### Examples ### Examples
[Private Networks with IPFS](./examples/pnet-ipfs) [Private Networks with IPFS](../../examples/pnet-ipfs)
### Private Shared Keys ### Private Shared Keys
@ -42,25 +45,25 @@ use one of the methods below to generate your key.
#### From libp2p-pnet #### 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 ```sh
node ./key-generator.js > swarm.key node ./src/pnet/key-generator.js > swarm.key
``` ```
#### From a module using libp2p #### 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. that project, assuming the node_modules are installed.
```sh ```sh
node -e "require('libp2p-pnet').generate(process.stdout)" > swarm.key node -e "require('libp2p/src/pnet').generate(process.stdout)" > swarm.key
``` ```
#### Programmatically #### Programmatically
```js ```js
const writeKey = require('libp2p-pnet').generate const writeKey = require('libp2p/src/pnet').generate
const swarmKey = Buffer.alloc(95) const swarmKey = Buffer.alloc(95)
writeKey(swarmKey) writeKey(swarmKey)
fs.writeFileSync('swarm.key', swarmKey) fs.writeFileSync('swarm.key', swarmKey)