Skip to content
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
12 changes: 6 additions & 6 deletions packages/libp2p-daemon-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,19 @@
},
"dependencies": {
"@libp2p/daemon-protocol": "^1.0.0",
"@libp2p/interfaces": "^1.3.17",
"@libp2p/logger": "^1.1.2",
"@libp2p/peer-id": "^1.1.8",
"@libp2p/tcp": "^1.0.6",
"@libp2p/interfaces": "^1.3.22",
"@libp2p/logger": "^1.1.4",
"@libp2p/peer-id": "^1.1.10",
"@libp2p/tcp": "^1.0.8",
"@multiformats/multiaddr": "^10.1.8",
"err-code": "^3.0.1",
"it-stream-types": "^1.0.4",
"multiformats": "^9.6.4"
},
"devDependencies": {
"@libp2p/daemon-server": "^1.0.0",
"@libp2p/interface-compliance-tests": "^1.1.20",
"@libp2p/peer-id-factory": "^1.0.8",
"@libp2p/interface-compliance-tests": "^1.1.23",
"@libp2p/peer-id-factory": "^1.0.9",
"aegir": "^37.0.5",
"it-all": "^1.0.6",
"it-pipe": "^2.0.3",
Expand Down
10 changes: 5 additions & 5 deletions packages/libp2p-daemon-client/test/pubsub.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ describe('daemon pubsub client', function () {

await client.pubsub.publish(topic, data)

expect(pubsub.dispatchEvent.called).to.be.true()
expect(pubsub.publish.called).to.be.true()

const event = pubsub.dispatchEvent.getCall(0).args[0]
const call = pubsub.publish.getCall(0)

expect(event.type).to.equal(topic)
expect(event.detail).to.equalBytes(data)
expect(call).to.have.nested.property('args[0]', topic)
expect(call).to.have.deep.nested.property('args[1]', data)
})

it('should error if receive an error message', async () => {
const topic = 'test-topic'
const data = uint8ArrayFromString('hello world')
pubsub.dispatchEvent.throws(new Error('Urk!'))
pubsub.publish.throws(new Error('Urk!'))

await expect(client.pubsub.publish(topic, data)).to.eventually.be.rejectedWith(/Urk!/)
})
Expand Down
6 changes: 3 additions & 3 deletions packages/libp2p-daemon-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@
"release": "aegir release"
},
"dependencies": {
"protons-runtime": "^1.0.0"
"protons-runtime": "^1.0.3"
},
"devDependencies": {
"aegir": "^37.0.5",
"protons": "^3.0.1"
"aegir": "^37.0.14",
"protons": "^3.0.3"
}
}
8 changes: 4 additions & 4 deletions packages/libp2p-daemon-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@
},
"dependencies": {
"@libp2p/daemon-protocol": "^1.0.0",
"@libp2p/interfaces": "^1.3.17",
"@libp2p/logger": "^1.1.2",
"@libp2p/peer-id": "^1.1.8",
"@libp2p/tcp": "^1.0.6",
"@libp2p/interfaces": "^1.3.22",
"@libp2p/logger": "^1.1.4",
"@libp2p/peer-id": "^1.1.10",
"@libp2p/tcp": "^1.0.8",
"@multiformats/multiaddr": "^10.1.8",
"it-drain": "^1.0.5",
"it-length-prefixed": "^7.0.1",
Expand Down
10 changes: 7 additions & 3 deletions packages/libp2p-daemon-server/src/pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ErrorResponse, OkResponse } from './responses.js'
import type { PubSub } from '@libp2p/interfaces/pubsub'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { pushable } from 'it-pushable'
import { CustomEvent } from '@libp2p/interfaces'
import { logger } from '@libp2p/logger'

const log = logger('libp2p:daemon-server:pubsub')
Expand Down Expand Up @@ -42,10 +41,15 @@ export class PubSubOperations {
async * subscribe (topic: string) {
try {
const onMessage = pushable<Uint8Array>()
this.pubsub.subscribe(topic)

await this.pubsub.addEventListener(topic, (evt) => {
await this.pubsub.addEventListener('message', (evt) => {
const msg = evt.detail

if (msg.topic !== topic) {
return
}

onMessage.push(PSMessage.encode({
from: msg.from.toBytes(),
data: msg.data,
Expand All @@ -66,7 +70,7 @@ export class PubSubOperations {

async * publish (topic: string, data: Uint8Array) {
try {
this.pubsub.dispatchEvent(new CustomEvent(topic, { detail: data }))
this.pubsub.publish(topic, data)
yield OkResponse()
} catch (err: any) {
log.error(err)
Expand Down
2 changes: 1 addition & 1 deletion packages/libp2p-daemon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
},
"dependencies": {
"@libp2p/daemon-server": "^1.0.0",
"@libp2p/interfaces": "^1.3.17",
"@libp2p/interfaces": "^1.3.22",
"@multiformats/multiaddr": "^10.1.8",
"es-main": "^1.0.2",
"yargs": "^17.3.1",
Expand Down