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 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
```

View File

@ -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)
}

View File

@ -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

View File

@ -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"
}
}

View File

@ -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)