Skip to content

Commit 83dd9df

Browse files
authored
deps: update libp2p deps to v2 (#170)
Updates examples to use the new libp2p release
1 parent d006979 commit 83dd9df

File tree

28 files changed

+101
-131
lines changed

28 files changed

+101
-131
lines changed

examples/js-libp2p-example-browser-pubsub/index.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const libp2p = await createLibp2p({
5959
})
6060
],
6161
// a connection encrypter is necessary to dial the relay
62-
connectionEncryption: [noise()],
62+
connectionEncrypters: [noise()],
6363
// a stream muxer is necessary to dial the relay
6464
streamMuxers: [yamux()],
6565
connectionGater: {
@@ -75,9 +75,6 @@ const libp2p = await createLibp2p({
7575
identify: identify(),
7676
pubsub: gossipsub(),
7777
dcutr: dcutr()
78-
},
79-
connectionManager: {
80-
minConnections: 0
8178
}
8279
})
8380

examples/js-libp2p-example-browser-pubsub/package.json

+10-11
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,16 @@
2121
"test": "npm run build && test-browser-example test"
2222
},
2323
"dependencies": {
24-
"@chainsafe/libp2p-gossipsub": "^13.0.0",
25-
"@chainsafe/libp2p-noise": "^15.0.0",
26-
"@chainsafe/libp2p-yamux": "^6.0.1",
27-
"@libp2p/circuit-relay-v2": "^1.0.4",
28-
"@libp2p/dcutr": "^1.0.3",
29-
"@libp2p/identify": "^2.1.0",
30-
"@libp2p/mplex": "^10.1.0",
31-
"@libp2p/webrtc": "^4.0.5",
32-
"@libp2p/websockets": "^8.0.4",
33-
"@multiformats/multiaddr": "^12.1.11",
34-
"libp2p": "^1.0.8",
24+
"@chainsafe/libp2p-gossipsub": "^14.0.0",
25+
"@chainsafe/libp2p-noise": "^16.0.0",
26+
"@chainsafe/libp2p-yamux": "^7.0.0",
27+
"@libp2p/circuit-relay-v2": "^2.0.0",
28+
"@libp2p/dcutr": "^2.0.0",
29+
"@libp2p/identify": "^3.0.0",
30+
"@libp2p/webrtc": "^5.0.0",
31+
"@libp2p/websockets": "^9.0.0",
32+
"@multiformats/multiaddr": "^12.3.1",
33+
"libp2p": "^2.0.0",
3534
"vite": "^5.3.1"
3635
},
3736
"devDependencies": {

examples/js-libp2p-example-browser-pubsub/relay.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { noise } from '@chainsafe/libp2p-noise'
44
import { yamux } from '@chainsafe/libp2p-yamux'
55
import { circuitRelayServer } from '@libp2p/circuit-relay-v2'
66
import { identify } from '@libp2p/identify'
7-
import { mplex } from '@libp2p/mplex'
87
import { webSockets } from '@libp2p/websockets'
98
import * as filters from '@libp2p/websockets/filters'
109
import { createLibp2p } from 'libp2p'
@@ -18,18 +17,15 @@ const server = await createLibp2p({
1817
filter: filters.all
1918
})
2019
],
21-
connectionEncryption: [noise()],
22-
streamMuxers: [yamux(), mplex()],
20+
connectionEncrypters: [noise()],
21+
streamMuxers: [yamux()],
2322
services: {
2423
identify: identify(),
2524
relay: circuitRelayServer({
2625
reservations: {
2726
maxReservations: Infinity
2827
}
2928
})
30-
},
31-
connectionManager: {
32-
minConnections: 0
3329
}
3430
})
3531

examples/js-libp2p-example-browser-pubsub/test/index.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async function spawnRelay () {
3636
filter: filters.all
3737
})
3838
],
39-
connectionEncryption: [noise()],
39+
connectionEncrypters: [noise()],
4040
streamMuxers: [yamux()],
4141
services: {
4242
identify: identify(),

examples/js-libp2p-example-chat/README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626

2727
1. Run the listener in window 1, `node listener.js`
2828
2. Run the dialer in window 2, `node dialer.js`
29-
3. Type a message in either window and hit *enter*
30-
4. Tell yourself secrets to your hearts content!
29+
3. Wait until the two peers discover each other
30+
4. Type a message in either window and hit *enter*
31+
5. Tell yourself secrets to your hearts content!
3132

3233
## License
3334

examples/js-libp2p-example-chat/package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
"test": "test-node-example test/*"
1717
},
1818
"dependencies": {
19-
"@chainsafe/libp2p-noise": "^15.0.0",
20-
"@chainsafe/libp2p-yamux": "^6.0.1",
21-
"@libp2p/peer-id-factory": "^4.0.0",
22-
"@libp2p/tcp": "^9.0.4",
23-
"@libp2p/websockets": "^8.0.4",
24-
"@multiformats/multiaddr": "^12.1.11",
19+
"@chainsafe/libp2p-noise": "^16.0.0",
20+
"@chainsafe/libp2p-yamux": "^7.0.0",
21+
"@libp2p/mdns": "^11.0.1",
22+
"@libp2p/tcp": "^10.0.0",
23+
"@libp2p/websockets": "^9.0.0",
24+
"@multiformats/multiaddr": "^12.3.1",
2525
"@nodeutils/defaults-deep": "^1.1.0",
2626
"it-length-prefixed": "^9.0.1",
2727
"it-map": "^3.0.3",
2828
"it-pipe": "^3.0.1",
29-
"libp2p": "^1.0.8",
29+
"libp2p": "^2.0.0",
3030
"p-defer": "^4.0.0",
3131
"uint8arrays": "^5.1.0"
3232
},
+15-21
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,37 @@
11
/* eslint-disable no-console */
22

3-
import { createFromJSON } from '@libp2p/peer-id-factory'
4-
import { multiaddr } from '@multiformats/multiaddr'
53
import { createLibp2p } from './libp2p.js'
6-
import peerIdDialerJson from './peer-id-dialer.js'
7-
import peerIdListenerJson from './peer-id-listener.js'
84
import { stdinToStream, streamToConsole } from './stream.js'
95

106
async function run () {
11-
const [idDialer, idListener] = await Promise.all([
12-
createFromJSON(peerIdDialerJson),
13-
createFromJSON(peerIdListenerJson)
14-
])
15-
167
// Create a new libp2p node on localhost with a randomly chosen port
17-
const nodeDialer = await createLibp2p({
18-
peerId: idDialer,
8+
const dialer = await createLibp2p({
199
addresses: {
2010
listen: ['/ip4/0.0.0.0/tcp/0']
2111
}
2212
})
2313

2414
// Output this node's address
2515
console.log('Dialer ready, listening on:')
26-
nodeDialer.getMultiaddrs().forEach((ma) => {
16+
dialer.getMultiaddrs().forEach((ma) => {
2717
console.log(ma.toString())
2818
})
2919

30-
// Dial to the remote peer (the "listener")
31-
const listenerMa = multiaddr(`/ip4/127.0.0.1/tcp/10333/p2p/${idListener.toString()}`)
32-
const stream = await nodeDialer.dialProtocol(listenerMa, '/chat/1.0.0')
20+
dialer.addEventListener('peer:discovery', (evt) => {
21+
console.info('peer:discovery', evt.detail)
3322

34-
console.log('Dialer dialed to listener on protocol: /chat/1.0.0')
35-
console.log('Type a message and see what happens')
23+
// Dial to the remote peer (the "listener")
24+
dialer.dialProtocol(evt.detail.multiaddrs, '/chat/1.0.0')
25+
.then(stream => {
26+
console.log('Dialer dialed to listener on protocol: /chat/1.0.0')
27+
console.log('Type a message and see what happens')
3628

37-
// Send stdin to the stream
38-
stdinToStream(stream)
39-
// Read the stream and output to console
40-
streamToConsole(stream)
29+
// Send stdin to the stream
30+
stdinToStream(stream)
31+
// Read the stream and output to console
32+
streamToConsole(stream)
33+
})
34+
})
4135
}
4236

4337
run()

examples/js-libp2p-example-chat/src/libp2p.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { noise } from '@chainsafe/libp2p-noise'
22
import { yamux } from '@chainsafe/libp2p-yamux'
3+
import { mdns } from '@libp2p/mdns'
34
import { tcp } from '@libp2p/tcp'
45
import { webSockets } from '@libp2p/websockets'
56
import defaultsDeep from '@nodeutils/defaults-deep'
@@ -14,8 +15,11 @@ export async function createLibp2p (_options) {
1415
streamMuxers: [
1516
yamux()
1617
],
17-
connectionEncryption: [
18+
connectionEncrypters: [
1819
noise()
20+
],
21+
peerDiscovery: [
22+
mdns()
1923
]
2024
}
2125

examples/js-libp2p-example-chat/src/listener.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
/* eslint-disable no-console */
22

3-
import { createFromJSON } from '@libp2p/peer-id-factory'
43
import { createLibp2p } from './libp2p.js'
5-
import peerIdListenerJson from './peer-id-listener.js'
64
import { stdinToStream, streamToConsole } from './stream.js'
75

86
async function run () {
97
// Create a new libp2p node with the given multi-address
10-
const idListener = await createFromJSON(peerIdListenerJson)
11-
const nodeListener = await createLibp2p({
12-
peerId: idListener,
8+
const listener = await createLibp2p({
139
addresses: {
1410
listen: ['/ip4/0.0.0.0/tcp/10333']
1511
}
1612
})
1713

1814
// Log a message when a remote peer connects to us
19-
nodeListener.addEventListener('peer:connect', (evt) => {
15+
listener.addEventListener('peer:connect', (evt) => {
2016
const remotePeer = evt.detail
2117
console.log('connected to: ', remotePeer.toString())
2218
})
2319

2420
// Handle messages for the protocol
25-
await nodeListener.handle('/chat/1.0.0', async ({ stream }) => {
21+
await listener.handle('/chat/1.0.0', async ({ stream }) => {
2622
// Send stdin to the stream
2723
stdinToStream(stream)
2824
// Read the stream and output to console
@@ -31,7 +27,7 @@ async function run () {
3127

3228
// Output listen addresses to the console
3329
console.log('Listener ready, listening on:')
34-
nodeListener.getMultiaddrs().forEach((ma) => {
30+
listener.getMultiaddrs().forEach((ma) => {
3531
console.log(ma.toString())
3632
})
3733
}

examples/js-libp2p-example-chat/src/peer-id-dialer.js

-5
This file was deleted.

examples/js-libp2p-example-chat/src/peer-id-listener.js

-5
This file was deleted.

examples/js-libp2p-example-circuit-relay/README.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const node = await createLibp2p({
5555
transports: [
5656
webSockets()
5757
],
58-
connectionEncryption: [
58+
connectionEncrypters: [
5959
noise()
6060
],
6161
streamMuxers: [
@@ -116,7 +116,7 @@ const node = await createLibp2p({
116116
discoverRelays: 2
117117
})
118118
],
119-
connectionEncryption: [
119+
connectionEncrypters: [
120120
noise()
121121
],
122122
streamMuxers: [
@@ -176,7 +176,6 @@ connecting to the auto relay node via the relay.
176176
import { createLibp2p } from 'libp2p'
177177
import { webSockets } from '@libp2p/websockets'
178178
import { noise } from '@chainsafe/libp2p-noise'
179-
import { mplex } from '@libp2p/mplex'
180179
import { yamux } from '@chainsafe/libp2p-yamux',
181180

182181
const autoRelayNodeAddr = process.argv[2]
@@ -186,8 +185,8 @@ if (!autoRelayNodeAddr) {
186185

187186
const node = await createLibp2p({
188187
transports: [webSockets()],
189-
connectionEncryption: [noise()],
190-
streamMuxers: [yamux(), mplex()]
188+
connectionEncrypters: [noise()],
189+
streamMuxers: [yamux()]
191190
})
192191

193192
console.log(`Node started with id ${node.peerId.toString()}`)

examples/js-libp2p-example-circuit-relay/dialer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async function main () {
1919
webSockets(),
2020
circuitRelayTransport()
2121
],
22-
connectionEncryption: [
22+
connectionEncrypters: [
2323
noise()
2424
],
2525
streamMuxers: [

examples/js-libp2p-example-circuit-relay/listener.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async function main () {
2121
discoverRelays: 2
2222
})
2323
],
24-
connectionEncryption: [
24+
connectionEncrypters: [
2525
noise()
2626
],
2727
streamMuxers: [

examples/js-libp2p-example-circuit-relay/package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
"test": "test-node-example test/*"
1717
},
1818
"dependencies": {
19-
"@chainsafe/libp2p-noise": "^15.0.0",
20-
"@chainsafe/libp2p-yamux": "^6.0.1",
21-
"@libp2p/circuit-relay-v2": "^1.0.4",
22-
"@libp2p/identify": "^2.1.0",
23-
"@libp2p/websockets": "^8.0.4",
24-
"@multiformats/multiaddr": "^12.1.11",
25-
"libp2p": "^1.0.8 "
19+
"@chainsafe/libp2p-noise": "^16.0.0",
20+
"@chainsafe/libp2p-yamux": "^7.0.0",
21+
"@libp2p/circuit-relay-v2": "^2.0.0",
22+
"@libp2p/identify": "^3.0.0",
23+
"@libp2p/websockets": "^9.0.0",
24+
"@multiformats/multiaddr": "^12.3.1",
25+
"libp2p": "^2.0.0"
2626
},
2727
"devDependencies": {
2828
"test-ipfs-example": "^1.1.0"

examples/js-libp2p-example-circuit-relay/relay.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async function main () {
1717
transports: [
1818
webSockets()
1919
],
20-
connectionEncryption: [
20+
connectionEncrypters: [
2121
noise()
2222
],
2323
streamMuxers: [

examples/js-libp2p-example-connection-encryption/noise.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const createNode = async () => {
1515
},
1616
transports: [tcp()],
1717
streamMuxers: [yamux()],
18-
connectionEncryption: [noise()]
18+
connectionEncrypters: [noise()]
1919
})
2020

2121
return node

examples/js-libp2p-example-connection-encryption/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
"test": "test-node-example test/*"
1717
},
1818
"dependencies": {
19-
"@chainsafe/libp2p-noise": "^15.0.0",
20-
"@chainsafe/libp2p-yamux": "^6.0.1",
21-
"@libp2p/plaintext": "^1.0.4",
22-
"@libp2p/tcp": "^9.0.4",
19+
"@chainsafe/libp2p-noise": "^16.0.0",
20+
"@chainsafe/libp2p-yamux": "^7.0.0",
21+
"@libp2p/plaintext": "^2.0.0",
22+
"@libp2p/tcp": "^10.0.0",
2323
"it-pipe": "^3.0.1",
24-
"libp2p": "^1.0.8",
24+
"libp2p": "^2.0.0",
2525
"uint8arrays": "^5.1.0"
2626
},
2727
"devDependencies": {

examples/js-libp2p-example-connection-encryption/plaintext.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const createNode = async () => {
1515
},
1616
transports: [tcp()],
1717
streamMuxers: [yamux()],
18-
connectionEncryption: [plaintext()]
18+
connectionEncrypters: [plaintext()]
1919
})
2020

2121
return node

examples/js-libp2p-example-custom-protocols/1-echo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async function createNode () {
1313
'/ip4/0.0.0.0/tcp/0'
1414
]
1515
},
16-
connectionEncryption: [
16+
connectionEncrypters: [
1717
noise()
1818
],
1919
streamMuxers: [

examples/js-libp2p-example-custom-protocols/2-request-response.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async function createNode () {
1313
'/ip4/0.0.0.0/tcp/0'
1414
]
1515
},
16-
connectionEncryption: [
16+
connectionEncrypters: [
1717
noise()
1818
],
1919
streamMuxers: [

0 commit comments

Comments
 (0)