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

deps: update libp2p deps to v2 #170

Merged
merged 3 commits into from
Sep 18, 2024
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
5 changes: 1 addition & 4 deletions examples/js-libp2p-example-browser-pubsub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const libp2p = await createLibp2p({
})
],
// a connection encrypter is necessary to dial the relay
connectionEncryption: [noise()],
connectionEncrypters: [noise()],
// a stream muxer is necessary to dial the relay
streamMuxers: [yamux()],
connectionGater: {
Expand All @@ -75,9 +75,6 @@ const libp2p = await createLibp2p({
identify: identify(),
pubsub: gossipsub(),
dcutr: dcutr()
},
connectionManager: {
minConnections: 0
}
})

Expand Down
21 changes: 10 additions & 11 deletions examples/js-libp2p-example-browser-pubsub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@
"test": "npm run build && test-browser-example test"
},
"dependencies": {
"@chainsafe/libp2p-gossipsub": "^13.0.0",
"@chainsafe/libp2p-noise": "^15.0.0",
"@chainsafe/libp2p-yamux": "^6.0.1",
"@libp2p/circuit-relay-v2": "^1.0.4",
"@libp2p/dcutr": "^1.0.3",
"@libp2p/identify": "^2.1.0",
"@libp2p/mplex": "^10.1.0",
"@libp2p/webrtc": "^4.0.5",
"@libp2p/websockets": "^8.0.4",
"@multiformats/multiaddr": "^12.1.11",
"libp2p": "^1.0.8",
"@chainsafe/libp2p-gossipsub": "^14.0.0",
"@chainsafe/libp2p-noise": "^16.0.0",
"@chainsafe/libp2p-yamux": "^7.0.0",
"@libp2p/circuit-relay-v2": "^2.0.0",
"@libp2p/dcutr": "^2.0.0",
"@libp2p/identify": "^3.0.0",
"@libp2p/webrtc": "^5.0.0",
"@libp2p/websockets": "^9.0.0",
"@multiformats/multiaddr": "^12.3.1",
"libp2p": "^2.0.0",
"vite": "^5.3.1"
},
"devDependencies": {
Expand Down
8 changes: 2 additions & 6 deletions examples/js-libp2p-example-browser-pubsub/relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { circuitRelayServer } from '@libp2p/circuit-relay-v2'
import { identify } from '@libp2p/identify'
import { mplex } from '@libp2p/mplex'
import { webSockets } from '@libp2p/websockets'
import * as filters from '@libp2p/websockets/filters'
import { createLibp2p } from 'libp2p'
Expand All @@ -18,18 +17,15 @@ const server = await createLibp2p({
filter: filters.all
})
],
connectionEncryption: [noise()],
streamMuxers: [yamux(), mplex()],
connectionEncrypters: [noise()],
streamMuxers: [yamux()],
services: {
identify: identify(),
relay: circuitRelayServer({
reservations: {
maxReservations: Infinity
}
})
},
connectionManager: {
minConnections: 0
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function spawnRelay () {
filter: filters.all
})
],
connectionEncryption: [noise()],
connectionEncrypters: [noise()],
streamMuxers: [yamux()],
services: {
identify: identify(),
Expand Down
5 changes: 3 additions & 2 deletions examples/js-libp2p-example-chat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@

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

## License

Expand Down
14 changes: 7 additions & 7 deletions examples/js-libp2p-example-chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
"test": "test-node-example test/*"
},
"dependencies": {
"@chainsafe/libp2p-noise": "^15.0.0",
"@chainsafe/libp2p-yamux": "^6.0.1",
"@libp2p/peer-id-factory": "^4.0.0",
"@libp2p/tcp": "^9.0.4",
"@libp2p/websockets": "^8.0.4",
"@multiformats/multiaddr": "^12.1.11",
"@chainsafe/libp2p-noise": "^16.0.0",
"@chainsafe/libp2p-yamux": "^7.0.0",
"@libp2p/mdns": "^11.0.1",
"@libp2p/tcp": "^10.0.0",
"@libp2p/websockets": "^9.0.0",
"@multiformats/multiaddr": "^12.3.1",
"@nodeutils/defaults-deep": "^1.1.0",
"it-length-prefixed": "^9.0.1",
"it-map": "^3.0.3",
"it-pipe": "^3.0.1",
"libp2p": "^1.0.8",
"libp2p": "^2.0.0",
"p-defer": "^4.0.0",
"uint8arrays": "^5.1.0"
},
Expand Down
36 changes: 15 additions & 21 deletions examples/js-libp2p-example-chat/src/dialer.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,37 @@
/* eslint-disable no-console */

import { createFromJSON } from '@libp2p/peer-id-factory'
import { multiaddr } from '@multiformats/multiaddr'
import { createLibp2p } from './libp2p.js'
import peerIdDialerJson from './peer-id-dialer.js'
import peerIdListenerJson from './peer-id-listener.js'
import { stdinToStream, streamToConsole } from './stream.js'

async function run () {
const [idDialer, idListener] = await Promise.all([
createFromJSON(peerIdDialerJson),
createFromJSON(peerIdListenerJson)
])

// Create a new libp2p node on localhost with a randomly chosen port
const nodeDialer = await createLibp2p({
peerId: idDialer,
const dialer = await createLibp2p({
addresses: {
listen: ['/ip4/0.0.0.0/tcp/0']
}
})

// Output this node's address
console.log('Dialer ready, listening on:')
nodeDialer.getMultiaddrs().forEach((ma) => {
dialer.getMultiaddrs().forEach((ma) => {
console.log(ma.toString())
})

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

console.log('Dialer dialed to listener on protocol: /chat/1.0.0')
console.log('Type a message and see what happens')
// Dial to the remote peer (the "listener")
dialer.dialProtocol(evt.detail.multiaddrs, '/chat/1.0.0')
.then(stream => {
console.log('Dialer dialed to listener on protocol: /chat/1.0.0')
console.log('Type a message and see what happens')

// Send stdin to the stream
stdinToStream(stream)
// Read the stream and output to console
streamToConsole(stream)
// Send stdin to the stream
stdinToStream(stream)
// Read the stream and output to console
streamToConsole(stream)
})
})
}

run()
6 changes: 5 additions & 1 deletion examples/js-libp2p-example-chat/src/libp2p.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { mdns } from '@libp2p/mdns'
import { tcp } from '@libp2p/tcp'
import { webSockets } from '@libp2p/websockets'
import defaultsDeep from '@nodeutils/defaults-deep'
Expand All @@ -14,8 +15,11 @@ export async function createLibp2p (_options) {
streamMuxers: [
yamux()
],
connectionEncryption: [
connectionEncrypters: [
noise()
],
peerDiscovery: [
mdns()
]
}

Expand Down
12 changes: 4 additions & 8 deletions examples/js-libp2p-example-chat/src/listener.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
/* eslint-disable no-console */

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

async function run () {
// Create a new libp2p node with the given multi-address
const idListener = await createFromJSON(peerIdListenerJson)
const nodeListener = await createLibp2p({
peerId: idListener,
const listener = await createLibp2p({
addresses: {
listen: ['/ip4/0.0.0.0/tcp/10333']
}
})

// Log a message when a remote peer connects to us
nodeListener.addEventListener('peer:connect', (evt) => {
listener.addEventListener('peer:connect', (evt) => {
const remotePeer = evt.detail
console.log('connected to: ', remotePeer.toString())
})

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

// Output listen addresses to the console
console.log('Listener ready, listening on:')
nodeListener.getMultiaddrs().forEach((ma) => {
listener.getMultiaddrs().forEach((ma) => {
console.log(ma.toString())
})
}
Expand Down
5 changes: 0 additions & 5 deletions examples/js-libp2p-example-chat/src/peer-id-dialer.js

This file was deleted.

5 changes: 0 additions & 5 deletions examples/js-libp2p-example-chat/src/peer-id-listener.js

This file was deleted.

9 changes: 4 additions & 5 deletions examples/js-libp2p-example-circuit-relay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const node = await createLibp2p({
transports: [
webSockets()
],
connectionEncryption: [
connectionEncrypters: [
noise()
],
streamMuxers: [
Expand Down Expand Up @@ -116,7 +116,7 @@ const node = await createLibp2p({
discoverRelays: 2
})
],
connectionEncryption: [
connectionEncrypters: [
noise()
],
streamMuxers: [
Expand Down Expand Up @@ -176,7 +176,6 @@ connecting to the auto relay node via the relay.
import { createLibp2p } from 'libp2p'
import { webSockets } from '@libp2p/websockets'
import { noise } from '@chainsafe/libp2p-noise'
import { mplex } from '@libp2p/mplex'
import { yamux } from '@chainsafe/libp2p-yamux',

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

const node = await createLibp2p({
transports: [webSockets()],
connectionEncryption: [noise()],
streamMuxers: [yamux(), mplex()]
connectionEncrypters: [noise()],
streamMuxers: [yamux()]
})

console.log(`Node started with id ${node.peerId.toString()}`)
Expand Down
2 changes: 1 addition & 1 deletion examples/js-libp2p-example-circuit-relay/dialer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function main () {
webSockets(),
circuitRelayTransport()
],
connectionEncryption: [
connectionEncrypters: [
noise()
],
streamMuxers: [
Expand Down
2 changes: 1 addition & 1 deletion examples/js-libp2p-example-circuit-relay/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function main () {
discoverRelays: 2
})
],
connectionEncryption: [
connectionEncrypters: [
noise()
],
streamMuxers: [
Expand Down
14 changes: 7 additions & 7 deletions examples/js-libp2p-example-circuit-relay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
"test": "test-node-example test/*"
},
"dependencies": {
"@chainsafe/libp2p-noise": "^15.0.0",
"@chainsafe/libp2p-yamux": "^6.0.1",
"@libp2p/circuit-relay-v2": "^1.0.4",
"@libp2p/identify": "^2.1.0",
"@libp2p/websockets": "^8.0.4",
"@multiformats/multiaddr": "^12.1.11",
"libp2p": "^1.0.8 "
"@chainsafe/libp2p-noise": "^16.0.0",
"@chainsafe/libp2p-yamux": "^7.0.0",
"@libp2p/circuit-relay-v2": "^2.0.0",
"@libp2p/identify": "^3.0.0",
"@libp2p/websockets": "^9.0.0",
"@multiformats/multiaddr": "^12.3.1",
"libp2p": "^2.0.0"
},
"devDependencies": {
"test-ipfs-example": "^1.1.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/js-libp2p-example-circuit-relay/relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function main () {
transports: [
webSockets()
],
connectionEncryption: [
connectionEncrypters: [
noise()
],
streamMuxers: [
Expand Down
2 changes: 1 addition & 1 deletion examples/js-libp2p-example-connection-encryption/noise.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const createNode = async () => {
},
transports: [tcp()],
streamMuxers: [yamux()],
connectionEncryption: [noise()]
connectionEncrypters: [noise()]
})

return node
Expand Down
10 changes: 5 additions & 5 deletions examples/js-libp2p-example-connection-encryption/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
"test": "test-node-example test/*"
},
"dependencies": {
"@chainsafe/libp2p-noise": "^15.0.0",
"@chainsafe/libp2p-yamux": "^6.0.1",
"@libp2p/plaintext": "^1.0.4",
"@libp2p/tcp": "^9.0.4",
"@chainsafe/libp2p-noise": "^16.0.0",
"@chainsafe/libp2p-yamux": "^7.0.0",
"@libp2p/plaintext": "^2.0.0",
"@libp2p/tcp": "^10.0.0",
"it-pipe": "^3.0.1",
"libp2p": "^1.0.8",
"libp2p": "^2.0.0",
"uint8arrays": "^5.1.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const createNode = async () => {
},
transports: [tcp()],
streamMuxers: [yamux()],
connectionEncryption: [plaintext()]
connectionEncrypters: [plaintext()]
})

return node
Expand Down
2 changes: 1 addition & 1 deletion examples/js-libp2p-example-custom-protocols/1-echo.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function createNode () {
'/ip4/0.0.0.0/tcp/0'
]
},
connectionEncryption: [
connectionEncrypters: [
noise()
],
streamMuxers: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function createNode () {
'/ip4/0.0.0.0/tcp/0'
]
},
connectionEncryption: [
connectionEncrypters: [
noise()
],
streamMuxers: [
Expand Down
Loading
Loading