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

Commit 196dd4c

Browse files
committed
fix: remove libp2p-record for pubsub
1 parent 664f595 commit 196dd4c

File tree

4 files changed

+6
-21
lines changed

4 files changed

+6
-21
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"cids": "~0.5.5",
9191
"class-is": "^1.1.0",
9292
"datastore-core": "~0.6.0",
93-
"datastore-pubsub": "ipfs/js-datastore-pubsub#feat/encode-record-store-keys",
93+
"datastore-pubsub": "~0.1.1",
9494
"debug": "^4.1.0",
9595
"deep-extend": "~0.6.0",
9696
"err-code": "^1.1.2",

src/core/ipns/publisher.js

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22

33
const PeerId = require('peer-id')
4-
const Record = require('libp2p-record').Record
54
const { Key } = require('interface-datastore')
65
const series = require('async/series')
76
const errcode = require('err-code')
@@ -97,19 +96,17 @@ class IpnsPublisher {
9796
return callback(errcode(new Error(errMsg), 'ERR_INVALID_DATASTORE_KEY'))
9897
}
9998

100-
let rec
99+
let entryData
101100
try {
102101
// Marshal record
103-
const entryData = ipns.marshal(entry)
104-
// Marshal to libp2p record
105-
rec = new Record(key.toBuffer(), entryData)
102+
entryData = ipns.marshal(entry)
106103
} catch (err) {
107104
log.error(err)
108105
return callback(err)
109106
}
110107

111108
// Add record to routing (buffer key)
112-
this._routing.put(key.toBuffer(), rec.serialize(), (err, res) => {
109+
this._routing.put(key.toBuffer(), entryData, (err, res) => {
113110
if (err) {
114111
const errMsg = `ipns record for ${key.toString()} could not be stored in the routing`
115112

@@ -137,17 +134,8 @@ class IpnsPublisher {
137134
return callback(errcode(new Error(errMsg), 'ERR_UNDEFINED_PARAMETER'))
138135
}
139136

140-
let rec
141-
try {
142-
// Marshal to libp2p record
143-
rec = new Record(key.toBuffer(), publicKey.bytes)
144-
} catch (err) {
145-
log.error(err)
146-
return callback(err)
147-
}
148-
149137
// Add public key to routing (buffer key)
150-
this._routing.put(key.toBuffer(), rec.serialize(), (err, res) => {
138+
this._routing.put(key.toBuffer(), publicKey.bytes, (err, res) => {
151139
if (err) {
152140
const errMsg = `public key for ${key.toString()} could not be stored in the routing`
153141

src/core/ipns/resolver.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22

33
const ipns = require('ipns')
4-
const Record = require('libp2p-record').Record
54
const PeerId = require('peer-id')
65
const errcode = require('err-code')
76

@@ -119,8 +118,7 @@ class IpnsResolver {
119118

120119
let ipnsEntry
121120
try {
122-
const record = Record.deserialize(res)
123-
ipnsEntry = ipns.unmarshal(record.value)
121+
ipnsEntry = ipns.unmarshal(res)
124122
} catch (err) {
125123
const errMsg = `found ipns record that we couldn't convert to a value`
126124

src/core/ipns/routing/pubsub-datastore.js

-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ class IpnsPubsubDatastore {
8989
}
9090

9191
// Modify subscription key to have a proper encoding
92-
// Without this, the utf-8 encoding gets the key broken
9392
_handleSubscriptionKey (key, callback) {
9493
const subscriber = this._subscriptions[key]
9594

0 commit comments

Comments
 (0)