Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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
```

Expand Down
6 changes: 3 additions & 3 deletions examples/pnet-ipfs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/pnet-ipfs/libp2p-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions examples/pnet-ipfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
27 changes: 15 additions & 12 deletions src/pnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

Expand All @@ -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)
Expand Down