Skip to content

Commit

Permalink
fix: add updates to support libp2p 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed Nov 10, 2024
1 parent ad853c6 commit f234082
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion exercises/1_hello_world/problem.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const node = await createLibp2p({
transports: [
tcp()
],
connectionEncryption: [
connectionEncrypters: [
tls()
],
streamMuxers: [
Expand Down
2 changes: 1 addition & 1 deletion exercises/1_hello_world/solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default async function helloWorld (ma) {
transports: [
tcp()
],
connectionEncryption: [
connectionEncrypters: [
tls()
],
streamMuxers: [
Expand Down
6 changes: 3 additions & 3 deletions exercises/2_streams/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ exercise.addVerifyProcessor(verifyProcessor(exercise, async (test) => {
const expected = [2, 4, 8, 0.4, 6]

const stream = {
source: async function * () {
source: (async function * () {
yield * [1, 10, 2, 59, 7, 'hello', 9, 4, {}, 0.2, 8, () => {}, 14, 3]
}(),
}()),
sink: async function (source) {
for await (const val of source ) {
for await (const val of source) {
output.push(val)
}
}
Expand Down
3 changes: 1 addition & 2 deletions exercises/3_custom_protocols/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ async function testRespond (test, libp2p, respond) {
signal: AbortSignal.timeout(1000)
})


const input = [
Uint8Array.from([8, 9, 0, 1]),
Uint8Array.from([4, 5, 6, 7]),
Uint8Array.from([0, 1, 2, 3]),
Uint8Array.from([0, 1, 2, 3])
]

const echoed = []
Expand Down
4 changes: 2 additions & 2 deletions exercises/3_custom_protocols/solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function dial (ma, protocol, data) {
transports: [
tcp()
],
connectionEncryption: [
connectionEncrypters: [
tls()
],
streamMuxers: [
Expand Down Expand Up @@ -39,7 +39,7 @@ export async function respond (protocol) {
transports: [
tcp()
],
connectionEncryption: [
connectionEncrypters: [
tls()
],
streamMuxers: [
Expand Down
2 changes: 1 addition & 1 deletion exercises/4_imperative_protocols/solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default async function imperativeProtocols (ma, protocol) {
transports: [
tcp()
],
connectionEncryption: [
connectionEncrypters: [
tls()
],
streamMuxers: [
Expand Down
2 changes: 1 addition & 1 deletion exercises/5_length_prefixed_data/solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default async function lengthPrefixedData (ma, protocol) {
transports: [
tcp()
],
connectionEncryption: [
connectionEncrypters: [
tls()
],
streamMuxers: [
Expand Down
2 changes: 1 addition & 1 deletion exercises/6_structured_data/solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default async function structuredData (ma, protocol) {
transports: [
tcp()
],
connectionEncryption: [
connectionEncrypters: [
tls()
],
streamMuxers: [
Expand Down
4 changes: 2 additions & 2 deletions exercises/7_rpc/solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function finder (protocol) {
transports: [
tcp()
],
connectionEncryption: [
connectionEncrypters: [
tls()
],
streamMuxers: [
Expand Down Expand Up @@ -56,7 +56,7 @@ export async function resolver (ma, protocol) {
transports: [
tcp()
],
connectionEncryption: [
connectionEncrypters: [
tls()
],
streamMuxers: [
Expand Down
2 changes: 1 addition & 1 deletion lib/libp2p.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default await createLibp2p({
transports: [
tcp()
],
connectionEncryption: [
connectionEncrypters: [
tls()
],
streamMuxers: [
Expand Down
9 changes: 4 additions & 5 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

async function delay (ms) {
await new Promise((resolve) => {
setTimeout(() => {
Expand All @@ -17,7 +16,7 @@ async function bufferArraysEqual (arr1, arr2) {
}

function randomNumber (min, max) {
return Math.round(Math.random() * (max - min) + min);
return Math.round(Math.random() * (max - min) + min)
}

function randomString (length) {
Expand All @@ -34,9 +33,9 @@ function randomString (length) {
function defer () {
let resolve, reject

const promise = new Promise((res, rej) => {
resolve = res
reject = rej
const promise = new Promise((_resolve, _reject) => {
resolve = _resolve
reject = _reject
})

return {
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@libp2p/protocol-adventure",
"version": "0.0.0",
"version": "0.0.1",
"description": "Learn how to develop custom protocols with libp2p",
"repository": {
"type": "git",
Expand All @@ -15,17 +15,17 @@
"postinstall": "patch-package"
},
"dependencies": {
"@chainsafe/libp2p-yamux": "^6.0.2",
"@libp2p/tcp": "^9.1.1",
"@libp2p/tls": "^1.1.1",
"@chainsafe/libp2p-yamux": "^7.0.1",
"@libp2p/tcp": "^10.0.11",
"@libp2p/tls": "^2.0.10",
"cborg": "^4.2.2",
"chalk": "^5.3.0",
"it-byte-stream": "^1.0.12",
"it-filter": "^3.1.1",
"it-map": "^3.1.1",
"it-pipe": "^3.0.1",
"it-rpc": "^1.0.1",
"libp2p": "^1.8.0",
"libp2p": "^2.2.1",
"patch-package": "^8.0.0",
"shortid": "^2.2.8",
"uint8-varint": "^2.0.4",
Expand Down

0 comments on commit f234082

Please sign in to comment.