Skip to content

Commit 2e7f49e

Browse files
committed
chore: merge 0.30
2 parents cba25c8 + a279926 commit 2e7f49e

File tree

10 files changed

+45
-35
lines changed

10 files changed

+45
-35
lines changed

Diff for: doc/CONFIGURATION.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,13 @@ const node = await Libp2p.create({
445445
const Libp2p = require('libp2p')
446446
const TCP = require('libp2p-tcp')
447447
const MPLEX = require('libp2p-mplex')
448-
const SECIO = require('libp2p-secio')
448+
const { NOISE } = require('libp2p-noise')
449449

450450
const node = await Libp2p.create({
451451
modules: {
452452
transport: [TCP],
453453
streamMuxer: [MPLEX],
454-
connEncryption: [SECIO]
454+
connEncryption: [NOISE]
455455
},
456456
config: {
457457
relay: { // Circuit Relay options (this config is part of libp2p core configurations)

Diff for: examples/pubsub/1.js

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const createNode = async () => {
4343
})
4444
await node1.pubsub.subscribe(topic)
4545

46+
// Will not receive own published messages by default
4647
node2.pubsub.on(topic, (msg) => {
4748
console.log(`node2 received: ${uint8ArrayToString(msg.data)}`)
4849
})

Diff for: examples/pubsub/README.md

+14-5
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ const node2 = nodes[1]
4444

4545
// Add node's 2 data to the PeerStore
4646
node1.peerStore.addressBook.set(node2.peerId, node2.multiaddrs)
47-
4847
await node1.dial(node2.peerId)
4948

5049
node1.pubsub.on(topic, (msg) => {
5150
console.log(`node1 received: ${uint8ArrayToString(msg.data)}`)
5251
})
5352
await node1.pubsub.subscribe(topic)
5453

54+
// Will not receive own published messages by default
5555
node2.pubsub.on(topic, (msg) => {
5656
console.log(`node2 received: ${uint8ArrayToString(msg.data)}`)
5757
})
@@ -68,25 +68,34 @@ The output of the program should look like:
6868
```
6969
> node 1.js
7070
connected to QmWpvkKm6qHLhoxpWrTswY6UMNWDyn8hN265Qp9ZYvgS82
71-
node2 received: Bird bird bird, bird is the word!
7271
node1 received: Bird bird bird, bird is the word!
73-
node2 received: Bird bird bird, bird is the word!
7472
node1 received: Bird bird bird, bird is the word!
7573
```
7674

77-
You can change the pubsub `emitSelf` option if you don't want the publishing node to receive its own messages.
75+
You can change the pubsub `emitSelf` option if you want the publishing node to receive its own messages.
7876

7977
```JavaScript
8078
const defaults = {
8179
config: {
8280
pubsub: {
8381
enabled: true,
84-
emitSelf: false
82+
emitSelf: true
8583
}
8684
}
8785
}
8886
```
8987

88+
The output of the program should look like:
89+
90+
```
91+
> node 1.js
92+
connected to QmWpvkKm6qHLhoxpWrTswY6UMNWDyn8hN265Qp9ZYvgS82
93+
node1 received: Bird bird bird, bird is the word!
94+
node2 received: Bird bird bird, bird is the word!
95+
node1 received: Bird bird bird, bird is the word!
96+
node2 received: Bird bird bird, bird is the word!
97+
```
98+
9099
## 2. Future work
91100

92101
libp2p/IPFS PubSub is enabling a whole set of Distributed Real Time applications using CRDT (Conflict-Free Replicated Data Types). It is still going through heavy research (and hacking) and we invite you to join the conversation at [research-CRDT](https://github.com/ipfs/research-CRDT). Here is a list of some of the exciting examples:

Diff for: examples/pubsub/message-filtering/1.js

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const createNode = async () => {
4444

4545
//subscribe
4646
node1.pubsub.on(topic, (msg) => {
47+
// Will not receive own published messages by default
4748
console.log(`node1 received: ${uint8ArrayToString(msg.data)}`)
4849
})
4950
await node1.pubsub.subscribe(topic)

Diff for: examples/pubsub/message-filtering/README.md

-3
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,12 @@ Result
9797
```
9898
> node 1.js
9999
############## fruit banana ##############
100-
node1 received: banana
101100
node2 received: banana
102101
node3 received: banana
103102
############## fruit apple ##############
104-
node1 received: apple
105103
node2 received: apple
106104
node3 received: apple
107105
############## fruit car ##############
108-
node1 received: car
109106
############## fruit orange ##############
110107
node1 received: orange
111108
node2 received: orange

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"it-pipe": "^1.1.0",
7171
"it-protocol-buffers": "^0.2.0",
7272
"libp2p-crypto": "^0.18.0",
73-
"libp2p-interfaces": "libp2p/js-libp2p-interfaces#feat/add-types-with-post-install",
73+
"libp2p-interfaces": "^0.8.0",
7474
"libp2p-utils": "^0.2.2",
7575
"mafmt": "^8.0.0",
7676
"merge-options": "^2.0.0",

Diff for: src/circuit/circuit/stream-handler.js

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const { CircuitRelay: CircuitPB } = require('../protocol')
1515
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream
1616
*/
1717

18+
/**
19+
* @template T
20+
*/
1821
class StreamHandler {
1922
/**
2023
* Create a stream handler for connection

Diff for: src/index.js

+21-23
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,32 @@ const IDENTIFY_PROTOCOLS = IdentifyService.multicodecs
8080
* @property {Libp2pConfig} [config]
8181
* @property {PeerId} peerId
8282
*
83+
* @typedef {Object} CreateOptions
84+
* @property {PeerId} peerId
85+
*
8386
* @extends {EventEmitter}
8487
* @fires Libp2p#error Emitted when an error occurs
8588
* @fires Libp2p#peer:discovery Emitted when a peer is discovered
8689
*/
8790
class Libp2p extends EventEmitter {
91+
/**
92+
* Like `new Libp2p(options)` except it will create a `PeerId`
93+
* instance if one is not provided in options.
94+
*
95+
* @param {Libp2pOptions & CreateOptions} options - Libp2p configuration options
96+
* @returns {Promise<Libp2p>}
97+
*/
98+
static async create (options) {
99+
if (options.peerId) {
100+
return new Libp2p(options)
101+
}
102+
103+
const peerId = await PeerId.create()
104+
105+
options.peerId = peerId
106+
return new Libp2p(options)
107+
}
108+
88109
/**
89110
* Libp2p node.
90111
*
@@ -656,27 +677,4 @@ class Libp2p extends EventEmitter {
656677
}
657678
}
658679

659-
/**
660-
* @typedef {Object} CreateOptions
661-
* @property {PeerId} peerId
662-
*/
663-
664-
/**
665-
* Like `new Libp2p(options)` except it will create a `PeerId`
666-
* instance if one is not provided in options.
667-
*
668-
* @param {Libp2pOptions & CreateOptions} options - Libp2p configuration options
669-
* @returns {Promise<Libp2p>}
670-
*/
671-
Libp2p.create = async function create (options) {
672-
if (options.peerId) {
673-
return new Libp2p(options)
674-
}
675-
676-
const peerId = await PeerId.create()
677-
678-
options.peerId = peerId
679-
return new Libp2p(options)
680-
}
681-
682680
module.exports = Libp2p

Diff for: src/peer-store/book.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const passthrough = data => data
1616
/**
1717
* @template Data, GetData, EventData
1818
*/
19+
1920
class Book {
2021
/**
2122
* The Book is the skeleton for the PeerStore books.

Diff for: src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export interface CircuitMessageProto extends MessageProto<CircuitMessage> {
8080
STOP_DST_MULTIADDR_INVALID: STOP_DST_MULTIADDR_INVALID,
8181
STOP_RELAY_REFUSED: STOP_RELAY_REFUSED,
8282
MALFORMED_MESSAGE: MALFORMED_MESSAGE
83-
}
83+
},
8484
Type: {
8585
HOP: HOP,
8686
STOP: STOP,

0 commit comments

Comments
 (0)