Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 00bd3dd

Browse files
authoredJun 24, 2022
fix: make pubsub message types consistent (#4145)
From field should be a peer id as per the types.
1 parent c1cbc81 commit 00bd3dd

File tree

8 files changed

+11
-5
lines changed

8 files changed

+11
-5
lines changed
 

‎docs/core-api/PUBSUB.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
| Name | Type | Description |
3333
| ---- | ---- | ----------- |
3434
| topic | `String` | The topic name |
35-
| handler | `Function<(msg) => {}>` | Event handler which will be called with a message object everytime one is received. The `msg` has the format `{from: String, sequenceNumber: bigint, data: Uint8Array, topicIDs: Array<String>}` |
35+
| handler | `Function<(msg) => {}>` | Event handler which will be called with a message object everytime one is received. The `msg` has the format `{from: PeerId, sequenceNumber: bigint, data: Uint8Array, topicIDs: Array<String>}` |
3636

3737
### Options
3838

‎packages/interface-ipfs-core/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"@ipld/dag-cbor": "^7.0.0",
6767
"@ipld/dag-pb": "^2.1.3",
6868
"@libp2p/crypto": "^0.22.9",
69+
"@libp2p/interfaces": "^2.0.4",
6970
"@libp2p/peer-id": "^1.1.10",
7071
"@libp2p/peer-id-factory": "^1.0.10",
7172
"@libp2p/websockets": "^1.0.8",

‎packages/interface-ipfs-core/src/pubsub/subscribe.js

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { isWebWorker, isNode } from 'ipfs-utils/src/env.js'
1313
import sinon from 'sinon'
1414
import defer from 'p-defer'
1515
import pWaitFor from 'p-wait-for'
16+
import { isPeerId } from '@libp2p/interfaces/peer-id'
1617

1718
/**
1819
* @typedef {import('ipfsd-ctl').Factory} Factory
@@ -87,6 +88,7 @@ export function testSubscribe (factory, options) {
8788
expect(msg).to.have.property('sequenceNumber')
8889
expect(msg.sequenceNumber).to.be.a('BigInt')
8990
expect(msg.topic).to.eq(topic)
91+
expect(isPeerId(msg.from)).to.be.true()
9092
expect(msg.from.toString()).to.equal(ipfs1Id.id.toString())
9193
})
9294

‎packages/ipfs-core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"@libp2p/crypto": "^0.22.9",
7676
"@libp2p/delegated-content-routing": "^1.0.3",
7777
"@libp2p/delegated-peer-routing": "^1.0.3",
78-
"@libp2p/interfaces": "^2.0.2",
78+
"@libp2p/interfaces": "^2.0.4",
7979
"@libp2p/kad-dht": "^1.0.3",
8080
"@libp2p/logger": "^1.1.4",
8181
"@libp2p/mplex": "^1.0.5",

‎packages/ipfs-grpc-client/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"dependencies": {
5252
"@improbable-eng/grpc-web": "^0.15.0",
5353
"@libp2p/logger": "^1.1.4",
54+
"@libp2p/peer-id": "^1.1.10",
5455
"change-case": "^4.1.1",
5556
"err-code": "^3.0.1",
5657
"ipfs-core-types": "^0.11.1",

‎packages/ipfs-grpc-client/src/core-api/pubsub/subscribe.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option'
33
import { subscriptions } from './subscriptions.js'
44
import defer from 'p-defer'
55
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
6+
import { peerIdFromString } from '@libp2p/peer-id'
67

78
/**
89
* @param {import('@improbable-eng/grpc-web').grpc} grpc
@@ -37,7 +38,7 @@ export function grpcPubsubSubscribe (grpc, service, opts) {
3738
} else {
3839
/** @type {import('@libp2p/interfaces/pubsub').Message} */
3940
const msg = {
40-
from: result.from,
41+
from: peerIdFromString(result.from),
4142
sequenceNumber: result.sequenceNumber == null ? undefined : BigInt(`0x${uint8ArrayToString(result.sequenceNumber, 'base16')}`),
4243
data: result.data,
4344
topic: result.topic

‎packages/ipfs-http-client/src/pubsub/subscribe.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { logger } from '@libp2p/logger'
22
import { configure } from '../lib/configure.js'
33
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
44
import { textToUrlSafeRpc, rpcToText, rpcToBytes, rpcToBigInt } from '../lib/http-rpc-wire-format.js'
5+
import { peerIdFromString } from '@libp2p/peer-id'
56
const log = logger('ipfs-http-client:pubsub:subscribe')
67

78
/**
@@ -107,7 +108,7 @@ async function readMessages (response, { onMessage, onEnd, onError }) {
107108
}
108109

109110
onMessage({
110-
from: msg.from,
111+
from: peerIdFromString(msg.from),
111112
data: rpcToBytes(msg.data),
112113
sequenceNumber: rpcToBigInt(msg.seqno),
113114
topic: rpcToText(msg.topicIDs[0])

‎packages/ipfs-http-server/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"@hapi/content": "^5.0.2",
4646
"@hapi/hapi": "^20.0.0",
4747
"@ipld/dag-pb": "^2.1.3",
48-
"@libp2p/interfaces": "^2.0.2",
48+
"@libp2p/interfaces": "^2.0.4",
4949
"@libp2p/logger": "^1.1.4",
5050
"@libp2p/peer-id": "^1.1.10",
5151
"any-signal": "^3.0.0",

0 commit comments

Comments
 (0)
This repository has been archived.