-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from prateekreddy/js-libp2p-v0.27.4
WIP Update Libp2p to v0.27.6
- Loading branch information
Showing
41 changed files
with
2,256 additions
and
1,361 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
'use strict' | ||
|
||
const util = require('util'); | ||
const { createLibp2p } = require('libp2p') | ||
const Libp2p = require('libp2p') | ||
const TCP = require('libp2p-tcp') | ||
|
||
let options = {} | ||
// NOTE: Transport and id are mandatory parameters to create a libp2p instance. Id if not specified will be generated automatically | ||
let options = { | ||
modules: { | ||
transport: [ TCP ] | ||
} | ||
} | ||
|
||
async function main() { | ||
// Create a libp2p instance | ||
let libp2p = await util.promisify(createLibp2p)(options) | ||
let libp2p = await Libp2p.create(options) | ||
console.log(libp2p.peerInfo.id.toJSON()) | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
'use-strict' | ||
|
||
// Include `util` from the standard lib | ||
// Include `createLibp2p` from the libp2p | ||
// Require `libp2p` module | ||
// Require `libp2p-tcp` module | ||
|
||
|
||
// Create an empty map options | ||
// Add mandatory transport options needed to create libp2p instance | ||
let options = { | ||
modules: { | ||
transport: [ /* TODO: add `libp2p-tcp` instance */ ] | ||
} | ||
} | ||
|
||
// Declare async main | ||
// Inside main declare libp2p node using promisified createLibp2p and pass options | ||
// Inside main declare libp2p node using `create` method of Libp2p module and pass options | ||
// See for youself the id of the libp2p node we have created by using libp2p node's peerInfo.id.toJSON() | ||
|
||
// Call main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,30 @@ | ||
'use strict' | ||
|
||
const util = require('util'); | ||
const { createLibp2p } = require('libp2p') | ||
const Libp2p = require('libp2p') | ||
|
||
const TCP = require('libp2p-tcp') | ||
const WS = require('libp2p-websockets') | ||
const WStar = require('libp2p-webrtc-star') | ||
const Wrtc = require('wrtc') | ||
|
||
const WebrtcStar = new WStar({ wrtc: Wrtc }) | ||
const transportKey = WStar.prototype[Symbol.toStringTag] | ||
|
||
let options = { | ||
modules: { | ||
transport: [ TCP, WS, WebrtcStar ] | ||
transport: [ TCP, WS, WStar ] | ||
}, | ||
config: { | ||
transport: { | ||
[transportKey]: { | ||
Wrtc | ||
} | ||
} | ||
} | ||
} | ||
|
||
async function main() { | ||
// Create a libp2p instance | ||
let libp2p = await util.promisify(createLibp2p)(options) | ||
let libp2p = await Libp2p.create(options) | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
'use strict' | ||
|
||
const util = require('util'); | ||
const { createLibp2p } = require('libp2p') | ||
// TODO: require `libp2p-tcp`, `libp2p-websockets`, and `libp2p-webrtc-star` | ||
const Libp2p = require('libp2p') | ||
|
||
const TCP = require('libp2p-tcp') | ||
// TODO: require `libp2p-websockets` and `libp2p-webrtc-star` | ||
// TODO: require `wrtc` | ||
|
||
// TODO: Create a new instance of `libp2p-webrtc-star`, and pass it { wrtc } | ||
// TODO: Get the toString tag for `libp2p-webrtc-star` class using `.prototype[Symbol.toStringTag]` method | ||
|
||
let options = { | ||
modules: { | ||
transport: [/* TODO: add `libp2p-tcp`, `libp2p-websockets`, and your `libp2p-webrtc-star` instance */] | ||
} | ||
transport: [ TCP, /* TODO: add `libp2p-websockets`, and `libp2p-webrtc-star` instance */ ], | ||
}, | ||
config: { | ||
transport: { | ||
// TODO: add map with key as key for `libp2p-webrtc-star` and value as the arguments to be sent to the module while initializing | ||
// NOTE: The elements specified here are passed as arguments for the modules specified. As here we are using wrtc implementation for webRTC | ||
} | ||
} | ||
} | ||
|
||
async function main() { | ||
// Create a libp2p instance | ||
let libp2p = await util.promisify(createLibp2p)(options) | ||
let libp2p = await Libp2p.create(options) | ||
console.log(libp2p.peerInfo.id.toJSON()) | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,33 @@ | ||
'use strict' | ||
|
||
const util = require('util'); | ||
const { createLibp2p } = require('libp2p') | ||
const Libp2p = require('libp2p') | ||
|
||
const TCP = require('libp2p-tcp') | ||
const WS = require('libp2p-websockets') | ||
const WStar = require('libp2p-webrtc-star') | ||
const Wrtc = require('wrtc') | ||
|
||
const WebrtcStar = new WStar({ wrtc: Wrtc }) | ||
const transportKey = WStar.prototype[Symbol.toStringTag] | ||
|
||
let options = { | ||
modules: { | ||
transport: [ TCP, WS, WebrtcStar ] | ||
transport: [ TCP, WS, WStar ] | ||
}, | ||
config: { | ||
transport: { | ||
[transportKey]: { | ||
Wrtc | ||
} | ||
} | ||
} | ||
} | ||
|
||
async function main() { | ||
// Create a libp2p instance | ||
let libp2p = await util.promisify(createLibp2p)(options) | ||
|
||
libp2p.on('start', () => { | ||
console.info(`Libp2p Started`) | ||
}) | ||
let libp2p = await Libp2p.create(options) | ||
|
||
await libp2p.start(); | ||
console.info(`Libp2p Started`) | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,36 @@ | ||
'use strict' | ||
|
||
const util = require('util'); | ||
const { createLibp2p } = require('libp2p') | ||
const Libp2p = require('libp2p') | ||
|
||
const TCP = require('libp2p-tcp') | ||
const WS = require('libp2p-websockets') | ||
const WStar = require('libp2p-webrtc-star') | ||
const Wrtc = require('wrtc') | ||
|
||
const multiaddr = require('multiaddr') | ||
|
||
const WebrtcStar = new WStar({ wrtc: Wrtc }) | ||
const transportKey = WStar.prototype[Symbol.toStringTag] | ||
|
||
let options = { | ||
modules: { | ||
transport: [ TCP, WS, WebrtcStar ] | ||
transport: [ TCP, WS, WStar ] | ||
}, | ||
config: { | ||
transport: { | ||
[transportKey]: { | ||
Wrtc | ||
} | ||
} | ||
} | ||
} | ||
|
||
async function main() { | ||
// Create a libp2p instance | ||
let libp2p = await util.promisify(createLibp2p)(options) | ||
|
||
libp2p.on('start', () => { | ||
console.info(`Libp2p Started`) | ||
}) | ||
let libp2p = await Libp2p.create(options) | ||
|
||
libp2p.peerInfo.multiaddrs.add('/ip4/0.0.0.0/tcp/0') | ||
libp2p.peerInfo.multiaddrs.add('/ip4/0.0.0.0/tcp/0/ws') | ||
|
||
await libp2p.start(); | ||
console.info(`Libp2p Started`) | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,36 @@ | ||
'use strict' | ||
|
||
const util = require('util'); | ||
const { createLibp2p } = require('libp2p') | ||
const Libp2p = require('libp2p') | ||
|
||
const TCP = require('libp2p-tcp') | ||
const WS = require('libp2p-websockets') | ||
const WStar = require('libp2p-webrtc-star') | ||
const Wrtc = require('wrtc') | ||
|
||
// Include multiaddr | ||
|
||
const WebrtcStar = new WStar({ wrtc: Wrtc }) | ||
const transportKey = WStar.prototype[Symbol.toStringTag] | ||
|
||
let options = { | ||
modules: { | ||
transport: [ TCP, WS, WebrtcStar ] | ||
transport: [ TCP, WS, WStar ] | ||
}, | ||
config: { | ||
transport: { | ||
[transportKey]: { | ||
Wrtc | ||
} | ||
} | ||
} | ||
} | ||
|
||
async function main() { | ||
// Create a libp2p instance | ||
let libp2p = await util.promisify(createLibp2p)(options) | ||
|
||
libp2p.on('start', () => { | ||
console.info(`Libp2p Started`) | ||
}) | ||
let libp2p = await Libp2p.create(options) | ||
|
||
// Add multiaddr for TCP | ||
// Add multiaddr for ws | ||
|
||
await libp2p.start(); | ||
console.info(`Libp2p Started`) | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,43 @@ | ||
'use strict' | ||
|
||
const util = require('util') | ||
const { createLibp2p } = require('libp2p') | ||
const Libp2p = require('libp2p') | ||
|
||
const TCP = require('libp2p-tcp') | ||
const WS = require('libp2p-websockets') | ||
const WStar = require('libp2p-webrtc-star') | ||
const Wrtc = require('wrtc') | ||
const Plaintext = require('libp2p/src/insecure/plaintext') | ||
|
||
const multiaddr = require('multiaddr') | ||
|
||
const WebrtcStar = new WStar({ wrtc: Wrtc }) | ||
const transportKey = WStar.prototype[Symbol.toStringTag] | ||
|
||
let options = { | ||
modules: { | ||
transport: [ TCP, WS, WebrtcStar ] | ||
transport: [ TCP, WS, WStar ], | ||
connEncryption: [ Plaintext ] | ||
}, | ||
config: { | ||
transport: { | ||
[transportKey]: { | ||
Wrtc | ||
} | ||
} | ||
} | ||
} | ||
|
||
async function main() { | ||
// Create a libp2p instance | ||
let libp2p = await util.promisify(createLibp2p)(options) | ||
|
||
libp2p.on('start', () => { | ||
console.info(`Libp2p Started`) | ||
libp2p.peerInfo.multiaddrs.forEach(ma => console.log(ma.toString())) | ||
}); | ||
let libp2p = await Libp2p.create(options) | ||
|
||
libp2p.on('connection:start', (peerInfo) => { | ||
libp2p.on('peer:connect', (peerInfo) => { | ||
console.info(`Connected to ${peerInfo.id.toB58String()}!`) | ||
}) | ||
|
||
libp2p.peerInfo.multiaddrs.add('/ip4/0.0.0.0/tcp/0') | ||
libp2p.peerInfo.multiaddrs.add('/ip4/0.0.0.0/tcp/0/ws') | ||
|
||
await libp2p.start() | ||
await libp2p.start(); | ||
console.info(`Libp2p Started`) | ||
libp2p.peerInfo.multiaddrs.forEach(ma => console.log(ma.toString())) | ||
} | ||
|
||
main() |
Oops, something went wrong.
36cfda2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: