diff --git a/packages/ipfs-repo-migrations/migrations/index.js b/packages/ipfs-repo-migrations/migrations/index.js index fc10e763..fb92371c 100644 --- a/packages/ipfs-repo-migrations/migrations/index.js +++ b/packages/ipfs-repo-migrations/migrations/index.js @@ -2,6 +2,7 @@ import { migration as migration8 } from './migration-8/index.js' import { migration as migration9 } from './migration-9/index.js' import { migration as migration10 } from './migration-10/index.js' import { migration as migration11 } from './migration-11/index.js' +import { migration as migration12 } from './migration-12/index.js' /** * @type {import('../src/types').Migration} @@ -26,5 +27,6 @@ export default [ migration8, migration9, migration10, - migration11 + migration11, + migration12 ] diff --git a/packages/ipfs-repo-migrations/migrations/migration-12/index.js b/packages/ipfs-repo-migrations/migrations/migration-12/index.js new file mode 100644 index 00000000..9c70af44 --- /dev/null +++ b/packages/ipfs-repo-migrations/migrations/migration-12/index.js @@ -0,0 +1,182 @@ +import $protobuf from "protobufjs/minimal.js" + +// @ts-expect-error Explicitly disable long.js support +$protobuf.util.Long = undefined +$protobuf.configure() + +import { Key } from 'interface-datastore/key' +import { Protocols } from './pb/proto-book.js' +import { Addresses } from './pb/address-book.js' +import { Peer } from './pb/peer.js' +import { Envelope } from './pb/envelope.js' +import { PeerRecord } from './pb/peer-record.js' +import { Multiaddr } from 'multiaddr' + +/** + * @param {import('../../src/types').Backends} backends + * @param {import('../../src/types').MigrationProgressCallback} onProgress + */ +async function storePeerUnderSingleDatastoreKey (backends, onProgress = () => {}) { + onProgress(0, 'Storing each peerstore key under a single datastore key') + + await backends.datastore.open() + + /** @type {Record} */ + const peers = {} + /** @type {Key[]} */ + const keys = [] + + for await (const { key, value } of backends.datastore.query({ + prefix: '/peers' + })) { + keys.push(key) + const keyStr = key.toString() + const [_, prefix, type, peerId, metadataKey] = keyStr.split('/') + + if (prefix !== 'peers') { + console.info('unknown prefix', prefix) + continue + } + + if (!['protos', 'addrs', 'metadata', 'keys'].includes(type)) { + console.info('unknown type', type) + continue + } + + if (!peerId) { + console.info('no peerid') + continue + } + + peers[peerId] = peers[peerId] || { + addresses: [], + protocols: [], + metadata: [] + } + + if (type === 'protos') { + const protos = Protocols.decode(value) + + peers[peerId].protocols = protos.protocols.sort() + } else if (type === 'addrs') { + const addrs = Addresses.decode(value) + + peers[peerId].addresses = addrs.addrs.sort((a, b) => { + return new Multiaddr(a.multiaddr).toString().localeCompare(new Multiaddr(b.multiaddr).toString()) + }) + + if (addrs.certifiedRecord && addrs.certifiedRecord.raw) { + peers[peerId].peerRecordEnvelope = addrs.certifiedRecord.raw + } + } else if (type === 'metadata') { + peers[peerId].metadata.push({ key: metadataKey, value }) + } else if (type === 'keys') { + peers[peerId].pubKey = value + } + } + + onProgress(33, 'Read peer data from store') + + for (const key of keys) { + await backends.datastore.delete(key) + } + + onProgress(66, 'Removed existing peer data from store') + + for (const peerId of Object.keys(peers)) { + const peer = peers[peerId] + peer.metadata = peer.metadata.sort((/** @type {{ key: string }} */ a, /** @type {{ key: string }} */ b) => a.key.localeCompare(b.key)) + + const data = Peer.encode(peer).finish() + + await backends.datastore.put(new Key(`/peers/${peerId}`), data) + } + + await backends.datastore.close() + + onProgress(100, 'Stored each peerstore key under a single datastore key') +} + +/** + * @param {import('../../src/types').Backends} backends + * @param {import('../../src/types').MigrationProgressCallback} onProgress + */ +async function storePeerUnderMultipleDatastoreKeys (backends, onProgress = () => {}) { + onProgress(0, 'Storing each peerstore key under a multiple datastore keys') + + await backends.datastore.open() + + /** @type {Record} */ + const peers = {} + /** @type {Key[]} */ + const keys = [] + + for await (const { key, value } of backends.datastore.query({ + prefix: '/peers' + })) { + keys.push(key) + const keyStr = key.toString() + + const [_, _prefix, peerId] = keyStr.split('/') + + peers[peerId] = Peer.decode(value) + } + + onProgress(33, 'Read peer data from store') + + for (const key of keys) { + await backends.datastore.delete(key) + } + + onProgress(66, 'Removed existing peer data from store') + + for (const [peerId, peer] of Object.entries(peers)) { + if (peer.protocols && peer.protocols.length > 0) { + await backends.datastore.put(new Key(`/peers/protos/${peerId}`), Protocols.encode({ + protocols: peer.protocols + }).finish()) + } + + if (peer.addresses && peer.addresses.length > 0) { + const peerRecordEnvelope = peer.peerRecordEnvelope + let certifiedRecord + + if (peerRecordEnvelope) { + const envelope = Envelope.decode(peerRecordEnvelope) + const record = PeerRecord.decode(envelope.payload) + + certifiedRecord = { + raw: peerRecordEnvelope, + seq: record.seq + } + } + + await backends.datastore.put(new Key(`/peers/addrs/${peerId}`), Addresses.encode({ + addrs: peer.addresses, + certifiedRecord + }).finish()) + } + + if (peer.metadata && peer.metadata.length > 0) { + for (const { key, value } of peer.metadata) { + await backends.datastore.put(new Key(`/peers/metadata/${peerId}/${key}`), value) + } + } + + if (peer.pubKey) { + await backends.datastore.put(new Key(`/peers/keys/${peerId}`), peer.pubKey) + } + } + + await backends.datastore.close() + + onProgress(100, 'Stored each peerstore key under multiple datastore keys') +} + +/** @type {import('../../src/types').Migration} */ +export const migration = { + version: 12, + description: 'Store each peerstore peer under a single datastore key', + migrate: storePeerUnderSingleDatastoreKey, + revert: storePeerUnderMultipleDatastoreKeys +} diff --git a/packages/ipfs-repo-migrations/migrations/migration-12/pb/address-book.d.ts b/packages/ipfs-repo-migrations/migrations/migration-12/pb/address-book.d.ts new file mode 100644 index 00000000..0fa4f3eb --- /dev/null +++ b/packages/ipfs-repo-migrations/migrations/migration-12/pb/address-book.d.ts @@ -0,0 +1,201 @@ +import * as $protobuf from "protobufjs"; +/** Properties of an Addresses. */ +export interface IAddresses { + + /** Addresses addrs */ + addrs?: (Addresses.IAddress[]|null); + + /** Addresses certifiedRecord */ + certifiedRecord?: (Addresses.ICertifiedRecord|null); +} + +/** Represents an Addresses. */ +export class Addresses implements IAddresses { + + /** + * Constructs a new Addresses. + * @param [p] Properties to set + */ + constructor(p?: IAddresses); + + /** Addresses addrs. */ + public addrs: Addresses.IAddress[]; + + /** Addresses certifiedRecord. */ + public certifiedRecord?: (Addresses.ICertifiedRecord|null); + + /** + * Encodes the specified Addresses message. Does not implicitly {@link Addresses.verify|verify} messages. + * @param m Addresses message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: IAddresses, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes an Addresses message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns Addresses + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Addresses; + + /** + * Creates an Addresses message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns Addresses + */ + public static fromObject(d: { [k: string]: any }): Addresses; + + /** + * Creates a plain object from an Addresses message. Also converts values to other types if specified. + * @param m Addresses + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: Addresses, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this Addresses to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; +} + +export namespace Addresses { + + /** Properties of an Address. */ + interface IAddress { + + /** Address multiaddr */ + multiaddr?: (Uint8Array|null); + + /** Address isCertified */ + isCertified?: (boolean|null); + } + + /** Represents an Address. */ + class Address implements IAddress { + + /** + * Constructs a new Address. + * @param [p] Properties to set + */ + constructor(p?: Addresses.IAddress); + + /** Address multiaddr. */ + public multiaddr: Uint8Array; + + /** Address isCertified. */ + public isCertified?: (boolean|null); + + /** Address _isCertified. */ + public _isCertified?: "isCertified"; + + /** + * Encodes the specified Address message. Does not implicitly {@link Addresses.Address.verify|verify} messages. + * @param m Address message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: Addresses.IAddress, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes an Address message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns Address + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Addresses.Address; + + /** + * Creates an Address message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns Address + */ + public static fromObject(d: { [k: string]: any }): Addresses.Address; + + /** + * Creates a plain object from an Address message. Also converts values to other types if specified. + * @param m Address + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: Addresses.Address, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this Address to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } + + /** Properties of a CertifiedRecord. */ + interface ICertifiedRecord { + + /** CertifiedRecord seq */ + seq?: (number|null); + + /** CertifiedRecord raw */ + raw?: (Uint8Array|null); + } + + /** Represents a CertifiedRecord. */ + class CertifiedRecord implements ICertifiedRecord { + + /** + * Constructs a new CertifiedRecord. + * @param [p] Properties to set + */ + constructor(p?: Addresses.ICertifiedRecord); + + /** CertifiedRecord seq. */ + public seq: number; + + /** CertifiedRecord raw. */ + public raw: Uint8Array; + + /** + * Encodes the specified CertifiedRecord message. Does not implicitly {@link Addresses.CertifiedRecord.verify|verify} messages. + * @param m CertifiedRecord message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: Addresses.ICertifiedRecord, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a CertifiedRecord message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns CertifiedRecord + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Addresses.CertifiedRecord; + + /** + * Creates a CertifiedRecord message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns CertifiedRecord + */ + public static fromObject(d: { [k: string]: any }): Addresses.CertifiedRecord; + + /** + * Creates a plain object from a CertifiedRecord message. Also converts values to other types if specified. + * @param m CertifiedRecord + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: Addresses.CertifiedRecord, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this CertifiedRecord to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } +} diff --git a/packages/ipfs-repo-migrations/migrations/migration-12/pb/address-book.js b/packages/ipfs-repo-migrations/migrations/migration-12/pb/address-book.js new file mode 100644 index 00000000..bac47bd4 --- /dev/null +++ b/packages/ipfs-repo-migrations/migrations/migration-12/pb/address-book.js @@ -0,0 +1,535 @@ +/*eslint-disable*/ +import $protobuf from "protobufjs/minimal.js"; + +// Common aliases +const $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; + +// Exported root namespace +const $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {}); + +export const Addresses = $root.Addresses = (() => { + + /** + * Properties of an Addresses. + * @exports IAddresses + * @interface IAddresses + * @property {Array.|null} [addrs] Addresses addrs + * @property {Addresses.ICertifiedRecord|null} [certifiedRecord] Addresses certifiedRecord + */ + + /** + * Constructs a new Addresses. + * @exports Addresses + * @classdesc Represents an Addresses. + * @implements IAddresses + * @constructor + * @param {IAddresses=} [p] Properties to set + */ + function Addresses(p) { + this.addrs = []; + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * Addresses addrs. + * @member {Array.} addrs + * @memberof Addresses + * @instance + */ + Addresses.prototype.addrs = $util.emptyArray; + + /** + * Addresses certifiedRecord. + * @member {Addresses.ICertifiedRecord|null|undefined} certifiedRecord + * @memberof Addresses + * @instance + */ + Addresses.prototype.certifiedRecord = null; + + /** + * Encodes the specified Addresses message. Does not implicitly {@link Addresses.verify|verify} messages. + * @function encode + * @memberof Addresses + * @static + * @param {IAddresses} m Addresses message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Addresses.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.addrs != null && m.addrs.length) { + for (var i = 0; i < m.addrs.length; ++i) + $root.Addresses.Address.encode(m.addrs[i], w.uint32(10).fork()).ldelim(); + } + if (m.certifiedRecord != null && Object.hasOwnProperty.call(m, "certifiedRecord")) + $root.Addresses.CertifiedRecord.encode(m.certifiedRecord, w.uint32(18).fork()).ldelim(); + return w; + }; + + /** + * Decodes an Addresses message from the specified reader or buffer. + * @function decode + * @memberof Addresses + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {Addresses} Addresses + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Addresses.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.Addresses(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + if (!(m.addrs && m.addrs.length)) + m.addrs = []; + m.addrs.push($root.Addresses.Address.decode(r, r.uint32())); + break; + case 2: + m.certifiedRecord = $root.Addresses.CertifiedRecord.decode(r, r.uint32()); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates an Addresses message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof Addresses + * @static + * @param {Object.} d Plain object + * @returns {Addresses} Addresses + */ + Addresses.fromObject = function fromObject(d) { + if (d instanceof $root.Addresses) + return d; + var m = new $root.Addresses(); + if (d.addrs) { + if (!Array.isArray(d.addrs)) + throw TypeError(".Addresses.addrs: array expected"); + m.addrs = []; + for (var i = 0; i < d.addrs.length; ++i) { + if (typeof d.addrs[i] !== "object") + throw TypeError(".Addresses.addrs: object expected"); + m.addrs[i] = $root.Addresses.Address.fromObject(d.addrs[i]); + } + } + if (d.certifiedRecord != null) { + if (typeof d.certifiedRecord !== "object") + throw TypeError(".Addresses.certifiedRecord: object expected"); + m.certifiedRecord = $root.Addresses.CertifiedRecord.fromObject(d.certifiedRecord); + } + return m; + }; + + /** + * Creates a plain object from an Addresses message. Also converts values to other types if specified. + * @function toObject + * @memberof Addresses + * @static + * @param {Addresses} m Addresses + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + Addresses.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.arrays || o.defaults) { + d.addrs = []; + } + if (o.defaults) { + d.certifiedRecord = null; + } + if (m.addrs && m.addrs.length) { + d.addrs = []; + for (var j = 0; j < m.addrs.length; ++j) { + d.addrs[j] = $root.Addresses.Address.toObject(m.addrs[j], o); + } + } + if (m.certifiedRecord != null && m.hasOwnProperty("certifiedRecord")) { + d.certifiedRecord = $root.Addresses.CertifiedRecord.toObject(m.certifiedRecord, o); + } + return d; + }; + + /** + * Converts this Addresses to JSON. + * @function toJSON + * @memberof Addresses + * @instance + * @returns {Object.} JSON object + */ + Addresses.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + Addresses.Address = (function() { + + /** + * Properties of an Address. + * @memberof Addresses + * @interface IAddress + * @property {Uint8Array|null} [multiaddr] Address multiaddr + * @property {boolean|null} [isCertified] Address isCertified + */ + + /** + * Constructs a new Address. + * @memberof Addresses + * @classdesc Represents an Address. + * @implements IAddress + * @constructor + * @param {Addresses.IAddress=} [p] Properties to set + */ + function Address(p) { + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * Address multiaddr. + * @member {Uint8Array} multiaddr + * @memberof Addresses.Address + * @instance + */ + Address.prototype.multiaddr = $util.newBuffer([]); + + /** + * Address isCertified. + * @member {boolean|null|undefined} isCertified + * @memberof Addresses.Address + * @instance + */ + Address.prototype.isCertified = null; + + // OneOf field names bound to virtual getters and setters + let $oneOfFields; + + /** + * Address _isCertified. + * @member {"isCertified"|undefined} _isCertified + * @memberof Addresses.Address + * @instance + */ + Object.defineProperty(Address.prototype, "_isCertified", { + get: $util.oneOfGetter($oneOfFields = ["isCertified"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Encodes the specified Address message. Does not implicitly {@link Addresses.Address.verify|verify} messages. + * @function encode + * @memberof Addresses.Address + * @static + * @param {Addresses.IAddress} m Address message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Address.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.multiaddr != null && Object.hasOwnProperty.call(m, "multiaddr")) + w.uint32(10).bytes(m.multiaddr); + if (m.isCertified != null && Object.hasOwnProperty.call(m, "isCertified")) + w.uint32(16).bool(m.isCertified); + return w; + }; + + /** + * Decodes an Address message from the specified reader or buffer. + * @function decode + * @memberof Addresses.Address + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {Addresses.Address} Address + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Address.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.Addresses.Address(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + m.multiaddr = r.bytes(); + break; + case 2: + m.isCertified = r.bool(); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates an Address message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof Addresses.Address + * @static + * @param {Object.} d Plain object + * @returns {Addresses.Address} Address + */ + Address.fromObject = function fromObject(d) { + if (d instanceof $root.Addresses.Address) + return d; + var m = new $root.Addresses.Address(); + if (d.multiaddr != null) { + if (typeof d.multiaddr === "string") + $util.base64.decode(d.multiaddr, m.multiaddr = $util.newBuffer($util.base64.length(d.multiaddr)), 0); + else if (d.multiaddr.length) + m.multiaddr = d.multiaddr; + } + if (d.isCertified != null) { + m.isCertified = Boolean(d.isCertified); + } + return m; + }; + + /** + * Creates a plain object from an Address message. Also converts values to other types if specified. + * @function toObject + * @memberof Addresses.Address + * @static + * @param {Addresses.Address} m Address + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + Address.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.defaults) { + if (o.bytes === String) + d.multiaddr = ""; + else { + d.multiaddr = []; + if (o.bytes !== Array) + d.multiaddr = $util.newBuffer(d.multiaddr); + } + } + if (m.multiaddr != null && m.hasOwnProperty("multiaddr")) { + d.multiaddr = o.bytes === String ? $util.base64.encode(m.multiaddr, 0, m.multiaddr.length) : o.bytes === Array ? Array.prototype.slice.call(m.multiaddr) : m.multiaddr; + } + if (m.isCertified != null && m.hasOwnProperty("isCertified")) { + d.isCertified = m.isCertified; + if (o.oneofs) + d._isCertified = "isCertified"; + } + return d; + }; + + /** + * Converts this Address to JSON. + * @function toJSON + * @memberof Addresses.Address + * @instance + * @returns {Object.} JSON object + */ + Address.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return Address; + })(); + + Addresses.CertifiedRecord = (function() { + + /** + * Properties of a CertifiedRecord. + * @memberof Addresses + * @interface ICertifiedRecord + * @property {number|null} [seq] CertifiedRecord seq + * @property {Uint8Array|null} [raw] CertifiedRecord raw + */ + + /** + * Constructs a new CertifiedRecord. + * @memberof Addresses + * @classdesc Represents a CertifiedRecord. + * @implements ICertifiedRecord + * @constructor + * @param {Addresses.ICertifiedRecord=} [p] Properties to set + */ + function CertifiedRecord(p) { + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * CertifiedRecord seq. + * @member {number} seq + * @memberof Addresses.CertifiedRecord + * @instance + */ + CertifiedRecord.prototype.seq = $util.Long ? $util.Long.fromBits(0,0,true) : 0; + + /** + * CertifiedRecord raw. + * @member {Uint8Array} raw + * @memberof Addresses.CertifiedRecord + * @instance + */ + CertifiedRecord.prototype.raw = $util.newBuffer([]); + + /** + * Encodes the specified CertifiedRecord message. Does not implicitly {@link Addresses.CertifiedRecord.verify|verify} messages. + * @function encode + * @memberof Addresses.CertifiedRecord + * @static + * @param {Addresses.ICertifiedRecord} m CertifiedRecord message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + CertifiedRecord.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.seq != null && Object.hasOwnProperty.call(m, "seq")) + w.uint32(8).uint64(m.seq); + if (m.raw != null && Object.hasOwnProperty.call(m, "raw")) + w.uint32(18).bytes(m.raw); + return w; + }; + + /** + * Decodes a CertifiedRecord message from the specified reader or buffer. + * @function decode + * @memberof Addresses.CertifiedRecord + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {Addresses.CertifiedRecord} CertifiedRecord + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + CertifiedRecord.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.Addresses.CertifiedRecord(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + m.seq = r.uint64(); + break; + case 2: + m.raw = r.bytes(); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates a CertifiedRecord message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof Addresses.CertifiedRecord + * @static + * @param {Object.} d Plain object + * @returns {Addresses.CertifiedRecord} CertifiedRecord + */ + CertifiedRecord.fromObject = function fromObject(d) { + if (d instanceof $root.Addresses.CertifiedRecord) + return d; + var m = new $root.Addresses.CertifiedRecord(); + if (d.seq != null) { + if ($util.Long) + (m.seq = $util.Long.fromValue(d.seq)).unsigned = true; + else if (typeof d.seq === "string") + m.seq = parseInt(d.seq, 10); + else if (typeof d.seq === "number") + m.seq = d.seq; + else if (typeof d.seq === "object") + m.seq = new $util.LongBits(d.seq.low >>> 0, d.seq.high >>> 0).toNumber(true); + } + if (d.raw != null) { + if (typeof d.raw === "string") + $util.base64.decode(d.raw, m.raw = $util.newBuffer($util.base64.length(d.raw)), 0); + else if (d.raw.length) + m.raw = d.raw; + } + return m; + }; + + /** + * Creates a plain object from a CertifiedRecord message. Also converts values to other types if specified. + * @function toObject + * @memberof Addresses.CertifiedRecord + * @static + * @param {Addresses.CertifiedRecord} m CertifiedRecord + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + CertifiedRecord.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.defaults) { + if ($util.Long) { + var n = new $util.Long(0, 0, true); + d.seq = o.longs === String ? n.toString() : o.longs === Number ? n.toNumber() : n; + } else + d.seq = o.longs === String ? "0" : 0; + if (o.bytes === String) + d.raw = ""; + else { + d.raw = []; + if (o.bytes !== Array) + d.raw = $util.newBuffer(d.raw); + } + } + if (m.seq != null && m.hasOwnProperty("seq")) { + if (typeof m.seq === "number") + d.seq = o.longs === String ? String(m.seq) : m.seq; + else + d.seq = o.longs === String ? $util.Long.prototype.toString.call(m.seq) : o.longs === Number ? new $util.LongBits(m.seq.low >>> 0, m.seq.high >>> 0).toNumber(true) : m.seq; + } + if (m.raw != null && m.hasOwnProperty("raw")) { + d.raw = o.bytes === String ? $util.base64.encode(m.raw, 0, m.raw.length) : o.bytes === Array ? Array.prototype.slice.call(m.raw) : m.raw; + } + return d; + }; + + /** + * Converts this CertifiedRecord to JSON. + * @function toJSON + * @memberof Addresses.CertifiedRecord + * @instance + * @returns {Object.} JSON object + */ + CertifiedRecord.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return CertifiedRecord; + })(); + + return Addresses; +})(); + +export { $root as default }; diff --git a/packages/ipfs-repo-migrations/migrations/migration-12/pb/address-book.proto b/packages/ipfs-repo-migrations/migrations/migration-12/pb/address-book.proto new file mode 100644 index 00000000..d154bf0d --- /dev/null +++ b/packages/ipfs-repo-migrations/migrations/migration-12/pb/address-book.proto @@ -0,0 +1,27 @@ +syntax = "proto3"; + +message Addresses { + // Address represents a single multiaddr. + message Address { + bytes multiaddr = 1; + + // Flag to indicate if the address comes from a certified source. + optional bool isCertified = 2; + } + + // CertifiedRecord contains a serialized signed PeerRecord used to + // populate the signedAddrs list. + message CertifiedRecord { + // The Seq counter from the signed PeerRecord envelope + uint64 seq = 1; + + // The serialized bytes of the SignedEnvelope containing the PeerRecord. + bytes raw = 2; + } + + // The known multiaddrs. + repeated Address addrs = 1; + + // The most recently received signed PeerRecord. + CertifiedRecord certified_record = 2; +} \ No newline at end of file diff --git a/packages/ipfs-repo-migrations/migrations/migration-12/pb/envelope.d.ts b/packages/ipfs-repo-migrations/migrations/migration-12/pb/envelope.d.ts new file mode 100644 index 00000000..440590c1 --- /dev/null +++ b/packages/ipfs-repo-migrations/migrations/migration-12/pb/envelope.d.ts @@ -0,0 +1,77 @@ +import * as $protobuf from "protobufjs"; +/** Properties of an Envelope. */ +export interface IEnvelope { + + /** Envelope publicKey */ + publicKey?: (Uint8Array|null); + + /** Envelope payloadType */ + payloadType?: (Uint8Array|null); + + /** Envelope payload */ + payload?: (Uint8Array|null); + + /** Envelope signature */ + signature?: (Uint8Array|null); +} + +/** Represents an Envelope. */ +export class Envelope implements IEnvelope { + + /** + * Constructs a new Envelope. + * @param [p] Properties to set + */ + constructor(p?: IEnvelope); + + /** Envelope publicKey. */ + public publicKey: Uint8Array; + + /** Envelope payloadType. */ + public payloadType: Uint8Array; + + /** Envelope payload. */ + public payload: Uint8Array; + + /** Envelope signature. */ + public signature: Uint8Array; + + /** + * Encodes the specified Envelope message. Does not implicitly {@link Envelope.verify|verify} messages. + * @param m Envelope message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: IEnvelope, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes an Envelope message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns Envelope + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Envelope; + + /** + * Creates an Envelope message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns Envelope + */ + public static fromObject(d: { [k: string]: any }): Envelope; + + /** + * Creates a plain object from an Envelope message. Also converts values to other types if specified. + * @param m Envelope + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: Envelope, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this Envelope to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; +} diff --git a/packages/ipfs-repo-migrations/migrations/migration-12/pb/envelope.js b/packages/ipfs-repo-migrations/migrations/migration-12/pb/envelope.js new file mode 100644 index 00000000..7d675a33 --- /dev/null +++ b/packages/ipfs-repo-migrations/migrations/migration-12/pb/envelope.js @@ -0,0 +1,241 @@ +/*eslint-disable*/ +import $protobuf from "protobufjs/minimal.js"; + +// Common aliases +const $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; + +// Exported root namespace +const $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {}); + +export const Envelope = $root.Envelope = (() => { + + /** + * Properties of an Envelope. + * @exports IEnvelope + * @interface IEnvelope + * @property {Uint8Array|null} [publicKey] Envelope publicKey + * @property {Uint8Array|null} [payloadType] Envelope payloadType + * @property {Uint8Array|null} [payload] Envelope payload + * @property {Uint8Array|null} [signature] Envelope signature + */ + + /** + * Constructs a new Envelope. + * @exports Envelope + * @classdesc Represents an Envelope. + * @implements IEnvelope + * @constructor + * @param {IEnvelope=} [p] Properties to set + */ + function Envelope(p) { + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * Envelope publicKey. + * @member {Uint8Array} publicKey + * @memberof Envelope + * @instance + */ + Envelope.prototype.publicKey = $util.newBuffer([]); + + /** + * Envelope payloadType. + * @member {Uint8Array} payloadType + * @memberof Envelope + * @instance + */ + Envelope.prototype.payloadType = $util.newBuffer([]); + + /** + * Envelope payload. + * @member {Uint8Array} payload + * @memberof Envelope + * @instance + */ + Envelope.prototype.payload = $util.newBuffer([]); + + /** + * Envelope signature. + * @member {Uint8Array} signature + * @memberof Envelope + * @instance + */ + Envelope.prototype.signature = $util.newBuffer([]); + + /** + * Encodes the specified Envelope message. Does not implicitly {@link Envelope.verify|verify} messages. + * @function encode + * @memberof Envelope + * @static + * @param {IEnvelope} m Envelope message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Envelope.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.publicKey != null && Object.hasOwnProperty.call(m, "publicKey")) + w.uint32(10).bytes(m.publicKey); + if (m.payloadType != null && Object.hasOwnProperty.call(m, "payloadType")) + w.uint32(18).bytes(m.payloadType); + if (m.payload != null && Object.hasOwnProperty.call(m, "payload")) + w.uint32(26).bytes(m.payload); + if (m.signature != null && Object.hasOwnProperty.call(m, "signature")) + w.uint32(42).bytes(m.signature); + return w; + }; + + /** + * Decodes an Envelope message from the specified reader or buffer. + * @function decode + * @memberof Envelope + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {Envelope} Envelope + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Envelope.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.Envelope(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + m.publicKey = r.bytes(); + break; + case 2: + m.payloadType = r.bytes(); + break; + case 3: + m.payload = r.bytes(); + break; + case 5: + m.signature = r.bytes(); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates an Envelope message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof Envelope + * @static + * @param {Object.} d Plain object + * @returns {Envelope} Envelope + */ + Envelope.fromObject = function fromObject(d) { + if (d instanceof $root.Envelope) + return d; + var m = new $root.Envelope(); + if (d.publicKey != null) { + if (typeof d.publicKey === "string") + $util.base64.decode(d.publicKey, m.publicKey = $util.newBuffer($util.base64.length(d.publicKey)), 0); + else if (d.publicKey.length) + m.publicKey = d.publicKey; + } + if (d.payloadType != null) { + if (typeof d.payloadType === "string") + $util.base64.decode(d.payloadType, m.payloadType = $util.newBuffer($util.base64.length(d.payloadType)), 0); + else if (d.payloadType.length) + m.payloadType = d.payloadType; + } + if (d.payload != null) { + if (typeof d.payload === "string") + $util.base64.decode(d.payload, m.payload = $util.newBuffer($util.base64.length(d.payload)), 0); + else if (d.payload.length) + m.payload = d.payload; + } + if (d.signature != null) { + if (typeof d.signature === "string") + $util.base64.decode(d.signature, m.signature = $util.newBuffer($util.base64.length(d.signature)), 0); + else if (d.signature.length) + m.signature = d.signature; + } + return m; + }; + + /** + * Creates a plain object from an Envelope message. Also converts values to other types if specified. + * @function toObject + * @memberof Envelope + * @static + * @param {Envelope} m Envelope + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + Envelope.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.defaults) { + if (o.bytes === String) + d.publicKey = ""; + else { + d.publicKey = []; + if (o.bytes !== Array) + d.publicKey = $util.newBuffer(d.publicKey); + } + if (o.bytes === String) + d.payloadType = ""; + else { + d.payloadType = []; + if (o.bytes !== Array) + d.payloadType = $util.newBuffer(d.payloadType); + } + if (o.bytes === String) + d.payload = ""; + else { + d.payload = []; + if (o.bytes !== Array) + d.payload = $util.newBuffer(d.payload); + } + if (o.bytes === String) + d.signature = ""; + else { + d.signature = []; + if (o.bytes !== Array) + d.signature = $util.newBuffer(d.signature); + } + } + if (m.publicKey != null && m.hasOwnProperty("publicKey")) { + d.publicKey = o.bytes === String ? $util.base64.encode(m.publicKey, 0, m.publicKey.length) : o.bytes === Array ? Array.prototype.slice.call(m.publicKey) : m.publicKey; + } + if (m.payloadType != null && m.hasOwnProperty("payloadType")) { + d.payloadType = o.bytes === String ? $util.base64.encode(m.payloadType, 0, m.payloadType.length) : o.bytes === Array ? Array.prototype.slice.call(m.payloadType) : m.payloadType; + } + if (m.payload != null && m.hasOwnProperty("payload")) { + d.payload = o.bytes === String ? $util.base64.encode(m.payload, 0, m.payload.length) : o.bytes === Array ? Array.prototype.slice.call(m.payload) : m.payload; + } + if (m.signature != null && m.hasOwnProperty("signature")) { + d.signature = o.bytes === String ? $util.base64.encode(m.signature, 0, m.signature.length) : o.bytes === Array ? Array.prototype.slice.call(m.signature) : m.signature; + } + return d; + }; + + /** + * Converts this Envelope to JSON. + * @function toJSON + * @memberof Envelope + * @instance + * @returns {Object.} JSON object + */ + Envelope.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return Envelope; +})(); + +export { $root as default }; diff --git a/packages/ipfs-repo-migrations/migrations/migration-12/pb/envelope.proto b/packages/ipfs-repo-migrations/migrations/migration-12/pb/envelope.proto new file mode 100644 index 00000000..5b80cf50 --- /dev/null +++ b/packages/ipfs-repo-migrations/migrations/migration-12/pb/envelope.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; + +message Envelope { + // public_key is the public key of the keypair the enclosed payload was + // signed with. + bytes public_key = 1; + + // payload_type encodes the type of payload, so that it can be deserialized + // deterministically. + bytes payload_type = 2; + + // payload is the actual payload carried inside this envelope. + bytes payload = 3; + + // signature is the signature produced by the private key corresponding to + // the enclosed public key, over the payload, prefixing a domain string for + // additional security. + bytes signature = 5; +} \ No newline at end of file diff --git a/packages/ipfs-repo-migrations/migrations/migration-12/pb/peer-record.d.ts b/packages/ipfs-repo-migrations/migrations/migration-12/pb/peer-record.d.ts new file mode 100644 index 00000000..a851b533 --- /dev/null +++ b/packages/ipfs-repo-migrations/migrations/migration-12/pb/peer-record.d.ts @@ -0,0 +1,133 @@ +import * as $protobuf from "protobufjs"; +/** Properties of a PeerRecord. */ +export interface IPeerRecord { + + /** PeerRecord peerId */ + peerId?: (Uint8Array|null); + + /** PeerRecord seq */ + seq?: (number|null); + + /** PeerRecord addresses */ + addresses?: (PeerRecord.IAddressInfo[]|null); +} + +/** Represents a PeerRecord. */ +export class PeerRecord implements IPeerRecord { + + /** + * Constructs a new PeerRecord. + * @param [p] Properties to set + */ + constructor(p?: IPeerRecord); + + /** PeerRecord peerId. */ + public peerId: Uint8Array; + + /** PeerRecord seq. */ + public seq: number; + + /** PeerRecord addresses. */ + public addresses: PeerRecord.IAddressInfo[]; + + /** + * Encodes the specified PeerRecord message. Does not implicitly {@link PeerRecord.verify|verify} messages. + * @param m PeerRecord message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: IPeerRecord, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a PeerRecord message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns PeerRecord + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): PeerRecord; + + /** + * Creates a PeerRecord message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns PeerRecord + */ + public static fromObject(d: { [k: string]: any }): PeerRecord; + + /** + * Creates a plain object from a PeerRecord message. Also converts values to other types if specified. + * @param m PeerRecord + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: PeerRecord, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this PeerRecord to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; +} + +export namespace PeerRecord { + + /** Properties of an AddressInfo. */ + interface IAddressInfo { + + /** AddressInfo multiaddr */ + multiaddr?: (Uint8Array|null); + } + + /** Represents an AddressInfo. */ + class AddressInfo implements IAddressInfo { + + /** + * Constructs a new AddressInfo. + * @param [p] Properties to set + */ + constructor(p?: PeerRecord.IAddressInfo); + + /** AddressInfo multiaddr. */ + public multiaddr: Uint8Array; + + /** + * Encodes the specified AddressInfo message. Does not implicitly {@link PeerRecord.AddressInfo.verify|verify} messages. + * @param m AddressInfo message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: PeerRecord.IAddressInfo, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes an AddressInfo message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns AddressInfo + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): PeerRecord.AddressInfo; + + /** + * Creates an AddressInfo message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns AddressInfo + */ + public static fromObject(d: { [k: string]: any }): PeerRecord.AddressInfo; + + /** + * Creates a plain object from an AddressInfo message. Also converts values to other types if specified. + * @param m AddressInfo + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: PeerRecord.AddressInfo, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this AddressInfo to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } +} diff --git a/packages/ipfs-repo-migrations/migrations/migration-12/pb/peer-record.js b/packages/ipfs-repo-migrations/migrations/migration-12/pb/peer-record.js new file mode 100644 index 00000000..ef692c3e --- /dev/null +++ b/packages/ipfs-repo-migrations/migrations/migration-12/pb/peer-record.js @@ -0,0 +1,365 @@ +/*eslint-disable*/ +import $protobuf from "protobufjs/minimal.js"; + +// Common aliases +const $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; + +// Exported root namespace +const $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {}); + +export const PeerRecord = $root.PeerRecord = (() => { + + /** + * Properties of a PeerRecord. + * @exports IPeerRecord + * @interface IPeerRecord + * @property {Uint8Array|null} [peerId] PeerRecord peerId + * @property {number|null} [seq] PeerRecord seq + * @property {Array.|null} [addresses] PeerRecord addresses + */ + + /** + * Constructs a new PeerRecord. + * @exports PeerRecord + * @classdesc Represents a PeerRecord. + * @implements IPeerRecord + * @constructor + * @param {IPeerRecord=} [p] Properties to set + */ + function PeerRecord(p) { + this.addresses = []; + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * PeerRecord peerId. + * @member {Uint8Array} peerId + * @memberof PeerRecord + * @instance + */ + PeerRecord.prototype.peerId = $util.newBuffer([]); + + /** + * PeerRecord seq. + * @member {number} seq + * @memberof PeerRecord + * @instance + */ + PeerRecord.prototype.seq = $util.Long ? $util.Long.fromBits(0,0,true) : 0; + + /** + * PeerRecord addresses. + * @member {Array.} addresses + * @memberof PeerRecord + * @instance + */ + PeerRecord.prototype.addresses = $util.emptyArray; + + /** + * Encodes the specified PeerRecord message. Does not implicitly {@link PeerRecord.verify|verify} messages. + * @function encode + * @memberof PeerRecord + * @static + * @param {IPeerRecord} m PeerRecord message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + PeerRecord.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.peerId != null && Object.hasOwnProperty.call(m, "peerId")) + w.uint32(10).bytes(m.peerId); + if (m.seq != null && Object.hasOwnProperty.call(m, "seq")) + w.uint32(16).uint64(m.seq); + if (m.addresses != null && m.addresses.length) { + for (var i = 0; i < m.addresses.length; ++i) + $root.PeerRecord.AddressInfo.encode(m.addresses[i], w.uint32(26).fork()).ldelim(); + } + return w; + }; + + /** + * Decodes a PeerRecord message from the specified reader or buffer. + * @function decode + * @memberof PeerRecord + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {PeerRecord} PeerRecord + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + PeerRecord.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.PeerRecord(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + m.peerId = r.bytes(); + break; + case 2: + m.seq = r.uint64(); + break; + case 3: + if (!(m.addresses && m.addresses.length)) + m.addresses = []; + m.addresses.push($root.PeerRecord.AddressInfo.decode(r, r.uint32())); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates a PeerRecord message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof PeerRecord + * @static + * @param {Object.} d Plain object + * @returns {PeerRecord} PeerRecord + */ + PeerRecord.fromObject = function fromObject(d) { + if (d instanceof $root.PeerRecord) + return d; + var m = new $root.PeerRecord(); + if (d.peerId != null) { + if (typeof d.peerId === "string") + $util.base64.decode(d.peerId, m.peerId = $util.newBuffer($util.base64.length(d.peerId)), 0); + else if (d.peerId.length) + m.peerId = d.peerId; + } + if (d.seq != null) { + if ($util.Long) + (m.seq = $util.Long.fromValue(d.seq)).unsigned = true; + else if (typeof d.seq === "string") + m.seq = parseInt(d.seq, 10); + else if (typeof d.seq === "number") + m.seq = d.seq; + else if (typeof d.seq === "object") + m.seq = new $util.LongBits(d.seq.low >>> 0, d.seq.high >>> 0).toNumber(true); + } + if (d.addresses) { + if (!Array.isArray(d.addresses)) + throw TypeError(".PeerRecord.addresses: array expected"); + m.addresses = []; + for (var i = 0; i < d.addresses.length; ++i) { + if (typeof d.addresses[i] !== "object") + throw TypeError(".PeerRecord.addresses: object expected"); + m.addresses[i] = $root.PeerRecord.AddressInfo.fromObject(d.addresses[i]); + } + } + return m; + }; + + /** + * Creates a plain object from a PeerRecord message. Also converts values to other types if specified. + * @function toObject + * @memberof PeerRecord + * @static + * @param {PeerRecord} m PeerRecord + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + PeerRecord.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.arrays || o.defaults) { + d.addresses = []; + } + if (o.defaults) { + if (o.bytes === String) + d.peerId = ""; + else { + d.peerId = []; + if (o.bytes !== Array) + d.peerId = $util.newBuffer(d.peerId); + } + if ($util.Long) { + var n = new $util.Long(0, 0, true); + d.seq = o.longs === String ? n.toString() : o.longs === Number ? n.toNumber() : n; + } else + d.seq = o.longs === String ? "0" : 0; + } + if (m.peerId != null && m.hasOwnProperty("peerId")) { + d.peerId = o.bytes === String ? $util.base64.encode(m.peerId, 0, m.peerId.length) : o.bytes === Array ? Array.prototype.slice.call(m.peerId) : m.peerId; + } + if (m.seq != null && m.hasOwnProperty("seq")) { + if (typeof m.seq === "number") + d.seq = o.longs === String ? String(m.seq) : m.seq; + else + d.seq = o.longs === String ? $util.Long.prototype.toString.call(m.seq) : o.longs === Number ? new $util.LongBits(m.seq.low >>> 0, m.seq.high >>> 0).toNumber(true) : m.seq; + } + if (m.addresses && m.addresses.length) { + d.addresses = []; + for (var j = 0; j < m.addresses.length; ++j) { + d.addresses[j] = $root.PeerRecord.AddressInfo.toObject(m.addresses[j], o); + } + } + return d; + }; + + /** + * Converts this PeerRecord to JSON. + * @function toJSON + * @memberof PeerRecord + * @instance + * @returns {Object.} JSON object + */ + PeerRecord.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + PeerRecord.AddressInfo = (function() { + + /** + * Properties of an AddressInfo. + * @memberof PeerRecord + * @interface IAddressInfo + * @property {Uint8Array|null} [multiaddr] AddressInfo multiaddr + */ + + /** + * Constructs a new AddressInfo. + * @memberof PeerRecord + * @classdesc Represents an AddressInfo. + * @implements IAddressInfo + * @constructor + * @param {PeerRecord.IAddressInfo=} [p] Properties to set + */ + function AddressInfo(p) { + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * AddressInfo multiaddr. + * @member {Uint8Array} multiaddr + * @memberof PeerRecord.AddressInfo + * @instance + */ + AddressInfo.prototype.multiaddr = $util.newBuffer([]); + + /** + * Encodes the specified AddressInfo message. Does not implicitly {@link PeerRecord.AddressInfo.verify|verify} messages. + * @function encode + * @memberof PeerRecord.AddressInfo + * @static + * @param {PeerRecord.IAddressInfo} m AddressInfo message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + AddressInfo.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.multiaddr != null && Object.hasOwnProperty.call(m, "multiaddr")) + w.uint32(10).bytes(m.multiaddr); + return w; + }; + + /** + * Decodes an AddressInfo message from the specified reader or buffer. + * @function decode + * @memberof PeerRecord.AddressInfo + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {PeerRecord.AddressInfo} AddressInfo + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + AddressInfo.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.PeerRecord.AddressInfo(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + m.multiaddr = r.bytes(); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates an AddressInfo message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof PeerRecord.AddressInfo + * @static + * @param {Object.} d Plain object + * @returns {PeerRecord.AddressInfo} AddressInfo + */ + AddressInfo.fromObject = function fromObject(d) { + if (d instanceof $root.PeerRecord.AddressInfo) + return d; + var m = new $root.PeerRecord.AddressInfo(); + if (d.multiaddr != null) { + if (typeof d.multiaddr === "string") + $util.base64.decode(d.multiaddr, m.multiaddr = $util.newBuffer($util.base64.length(d.multiaddr)), 0); + else if (d.multiaddr.length) + m.multiaddr = d.multiaddr; + } + return m; + }; + + /** + * Creates a plain object from an AddressInfo message. Also converts values to other types if specified. + * @function toObject + * @memberof PeerRecord.AddressInfo + * @static + * @param {PeerRecord.AddressInfo} m AddressInfo + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + AddressInfo.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.defaults) { + if (o.bytes === String) + d.multiaddr = ""; + else { + d.multiaddr = []; + if (o.bytes !== Array) + d.multiaddr = $util.newBuffer(d.multiaddr); + } + } + if (m.multiaddr != null && m.hasOwnProperty("multiaddr")) { + d.multiaddr = o.bytes === String ? $util.base64.encode(m.multiaddr, 0, m.multiaddr.length) : o.bytes === Array ? Array.prototype.slice.call(m.multiaddr) : m.multiaddr; + } + return d; + }; + + /** + * Converts this AddressInfo to JSON. + * @function toJSON + * @memberof PeerRecord.AddressInfo + * @instance + * @returns {Object.} JSON object + */ + AddressInfo.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return AddressInfo; + })(); + + return PeerRecord; +})(); + +export { $root as default }; diff --git a/packages/ipfs-repo-migrations/migrations/migration-12/pb/peer-record.proto b/packages/ipfs-repo-migrations/migrations/migration-12/pb/peer-record.proto new file mode 100644 index 00000000..6b740dc8 --- /dev/null +++ b/packages/ipfs-repo-migrations/migrations/migration-12/pb/peer-record.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +message PeerRecord { + // AddressInfo is a wrapper around a binary multiaddr. It is defined as a + // separate message to allow us to add per-address metadata in the future. + message AddressInfo { + bytes multiaddr = 1; + } + + // peer_id contains a libp2p peer id in its binary representation. + bytes peer_id = 1; + + // seq contains a monotonically-increasing sequence counter to order PeerRecords in time. + uint64 seq = 2; + + // addresses is a list of public listen addresses for the peer. + repeated AddressInfo addresses = 3; +} \ No newline at end of file diff --git a/packages/ipfs-repo-migrations/migrations/migration-12/pb/peer.d.ts b/packages/ipfs-repo-migrations/migrations/migration-12/pb/peer.d.ts new file mode 100644 index 00000000..e6ccdfe6 --- /dev/null +++ b/packages/ipfs-repo-migrations/migrations/migration-12/pb/peer.d.ts @@ -0,0 +1,222 @@ +import * as $protobuf from "protobufjs"; +/** Properties of a Peer. */ +export interface IPeer { + + /** Peer addresses */ + addresses?: (IAddress[]|null); + + /** Peer protocols */ + protocols?: (string[]|null); + + /** Peer metadata */ + metadata?: (IMetadata[]|null); + + /** Peer pubKey */ + pubKey?: (Uint8Array|null); + + /** Peer peerRecordEnvelope */ + peerRecordEnvelope?: (Uint8Array|null); +} + +/** Represents a Peer. */ +export class Peer implements IPeer { + + /** + * Constructs a new Peer. + * @param [p] Properties to set + */ + constructor(p?: IPeer); + + /** Peer addresses. */ + public addresses: IAddress[]; + + /** Peer protocols. */ + public protocols: string[]; + + /** Peer metadata. */ + public metadata: IMetadata[]; + + /** Peer pubKey. */ + public pubKey?: (Uint8Array|null); + + /** Peer peerRecordEnvelope. */ + public peerRecordEnvelope?: (Uint8Array|null); + + /** Peer _pubKey. */ + public _pubKey?: "pubKey"; + + /** Peer _peerRecordEnvelope. */ + public _peerRecordEnvelope?: "peerRecordEnvelope"; + + /** + * Encodes the specified Peer message. Does not implicitly {@link Peer.verify|verify} messages. + * @param m Peer message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: IPeer, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a Peer message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns Peer + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Peer; + + /** + * Creates a Peer message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns Peer + */ + public static fromObject(d: { [k: string]: any }): Peer; + + /** + * Creates a plain object from a Peer message. Also converts values to other types if specified. + * @param m Peer + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: Peer, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this Peer to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; +} + +/** Properties of an Address. */ +export interface IAddress { + + /** Address multiaddr */ + multiaddr?: (Uint8Array|null); + + /** Address isCertified */ + isCertified?: (boolean|null); +} + +/** Represents an Address. */ +export class Address implements IAddress { + + /** + * Constructs a new Address. + * @param [p] Properties to set + */ + constructor(p?: IAddress); + + /** Address multiaddr. */ + public multiaddr: Uint8Array; + + /** Address isCertified. */ + public isCertified?: (boolean|null); + + /** Address _isCertified. */ + public _isCertified?: "isCertified"; + + /** + * Encodes the specified Address message. Does not implicitly {@link Address.verify|verify} messages. + * @param m Address message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: IAddress, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes an Address message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns Address + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Address; + + /** + * Creates an Address message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns Address + */ + public static fromObject(d: { [k: string]: any }): Address; + + /** + * Creates a plain object from an Address message. Also converts values to other types if specified. + * @param m Address + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: Address, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this Address to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; +} + +/** Properties of a Metadata. */ +export interface IMetadata { + + /** Metadata key */ + key?: (string|null); + + /** Metadata value */ + value?: (Uint8Array|null); +} + +/** Represents a Metadata. */ +export class Metadata implements IMetadata { + + /** + * Constructs a new Metadata. + * @param [p] Properties to set + */ + constructor(p?: IMetadata); + + /** Metadata key. */ + public key: string; + + /** Metadata value. */ + public value: Uint8Array; + + /** + * Encodes the specified Metadata message. Does not implicitly {@link Metadata.verify|verify} messages. + * @param m Metadata message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: IMetadata, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a Metadata message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns Metadata + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Metadata; + + /** + * Creates a Metadata message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns Metadata + */ + public static fromObject(d: { [k: string]: any }): Metadata; + + /** + * Creates a plain object from a Metadata message. Also converts values to other types if specified. + * @param m Metadata + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: Metadata, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this Metadata to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; +} diff --git a/packages/ipfs-repo-migrations/migrations/migration-12/pb/peer.js b/packages/ipfs-repo-migrations/migrations/migration-12/pb/peer.js new file mode 100644 index 00000000..28c89cb6 --- /dev/null +++ b/packages/ipfs-repo-migrations/migrations/migration-12/pb/peer.js @@ -0,0 +1,641 @@ +/*eslint-disable*/ +import $protobuf from "protobufjs/minimal.js"; + +// Common aliases +const $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; + +// Exported root namespace +const $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {}); + +export const Peer = $root.Peer = (() => { + + /** + * Properties of a Peer. + * @exports IPeer + * @interface IPeer + * @property {Array.|null} [addresses] Peer addresses + * @property {Array.|null} [protocols] Peer protocols + * @property {Array.|null} [metadata] Peer metadata + * @property {Uint8Array|null} [pubKey] Peer pubKey + * @property {Uint8Array|null} [peerRecordEnvelope] Peer peerRecordEnvelope + */ + + /** + * Constructs a new Peer. + * @exports Peer + * @classdesc Represents a Peer. + * @implements IPeer + * @constructor + * @param {IPeer=} [p] Properties to set + */ + function Peer(p) { + this.addresses = []; + this.protocols = []; + this.metadata = []; + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * Peer addresses. + * @member {Array.} addresses + * @memberof Peer + * @instance + */ + Peer.prototype.addresses = $util.emptyArray; + + /** + * Peer protocols. + * @member {Array.} protocols + * @memberof Peer + * @instance + */ + Peer.prototype.protocols = $util.emptyArray; + + /** + * Peer metadata. + * @member {Array.} metadata + * @memberof Peer + * @instance + */ + Peer.prototype.metadata = $util.emptyArray; + + /** + * Peer pubKey. + * @member {Uint8Array|null|undefined} pubKey + * @memberof Peer + * @instance + */ + Peer.prototype.pubKey = null; + + /** + * Peer peerRecordEnvelope. + * @member {Uint8Array|null|undefined} peerRecordEnvelope + * @memberof Peer + * @instance + */ + Peer.prototype.peerRecordEnvelope = null; + + // OneOf field names bound to virtual getters and setters + let $oneOfFields; + + /** + * Peer _pubKey. + * @member {"pubKey"|undefined} _pubKey + * @memberof Peer + * @instance + */ + Object.defineProperty(Peer.prototype, "_pubKey", { + get: $util.oneOfGetter($oneOfFields = ["pubKey"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Peer _peerRecordEnvelope. + * @member {"peerRecordEnvelope"|undefined} _peerRecordEnvelope + * @memberof Peer + * @instance + */ + Object.defineProperty(Peer.prototype, "_peerRecordEnvelope", { + get: $util.oneOfGetter($oneOfFields = ["peerRecordEnvelope"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Encodes the specified Peer message. Does not implicitly {@link Peer.verify|verify} messages. + * @function encode + * @memberof Peer + * @static + * @param {IPeer} m Peer message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Peer.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.addresses != null && m.addresses.length) { + for (var i = 0; i < m.addresses.length; ++i) + $root.Address.encode(m.addresses[i], w.uint32(10).fork()).ldelim(); + } + if (m.protocols != null && m.protocols.length) { + for (var i = 0; i < m.protocols.length; ++i) + w.uint32(18).string(m.protocols[i]); + } + if (m.metadata != null && m.metadata.length) { + for (var i = 0; i < m.metadata.length; ++i) + $root.Metadata.encode(m.metadata[i], w.uint32(26).fork()).ldelim(); + } + if (m.pubKey != null && Object.hasOwnProperty.call(m, "pubKey")) + w.uint32(34).bytes(m.pubKey); + if (m.peerRecordEnvelope != null && Object.hasOwnProperty.call(m, "peerRecordEnvelope")) + w.uint32(42).bytes(m.peerRecordEnvelope); + return w; + }; + + /** + * Decodes a Peer message from the specified reader or buffer. + * @function decode + * @memberof Peer + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {Peer} Peer + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Peer.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.Peer(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + if (!(m.addresses && m.addresses.length)) + m.addresses = []; + m.addresses.push($root.Address.decode(r, r.uint32())); + break; + case 2: + if (!(m.protocols && m.protocols.length)) + m.protocols = []; + m.protocols.push(r.string()); + break; + case 3: + if (!(m.metadata && m.metadata.length)) + m.metadata = []; + m.metadata.push($root.Metadata.decode(r, r.uint32())); + break; + case 4: + m.pubKey = r.bytes(); + break; + case 5: + m.peerRecordEnvelope = r.bytes(); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates a Peer message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof Peer + * @static + * @param {Object.} d Plain object + * @returns {Peer} Peer + */ + Peer.fromObject = function fromObject(d) { + if (d instanceof $root.Peer) + return d; + var m = new $root.Peer(); + if (d.addresses) { + if (!Array.isArray(d.addresses)) + throw TypeError(".Peer.addresses: array expected"); + m.addresses = []; + for (var i = 0; i < d.addresses.length; ++i) { + if (typeof d.addresses[i] !== "object") + throw TypeError(".Peer.addresses: object expected"); + m.addresses[i] = $root.Address.fromObject(d.addresses[i]); + } + } + if (d.protocols) { + if (!Array.isArray(d.protocols)) + throw TypeError(".Peer.protocols: array expected"); + m.protocols = []; + for (var i = 0; i < d.protocols.length; ++i) { + m.protocols[i] = String(d.protocols[i]); + } + } + if (d.metadata) { + if (!Array.isArray(d.metadata)) + throw TypeError(".Peer.metadata: array expected"); + m.metadata = []; + for (var i = 0; i < d.metadata.length; ++i) { + if (typeof d.metadata[i] !== "object") + throw TypeError(".Peer.metadata: object expected"); + m.metadata[i] = $root.Metadata.fromObject(d.metadata[i]); + } + } + if (d.pubKey != null) { + if (typeof d.pubKey === "string") + $util.base64.decode(d.pubKey, m.pubKey = $util.newBuffer($util.base64.length(d.pubKey)), 0); + else if (d.pubKey.length) + m.pubKey = d.pubKey; + } + if (d.peerRecordEnvelope != null) { + if (typeof d.peerRecordEnvelope === "string") + $util.base64.decode(d.peerRecordEnvelope, m.peerRecordEnvelope = $util.newBuffer($util.base64.length(d.peerRecordEnvelope)), 0); + else if (d.peerRecordEnvelope.length) + m.peerRecordEnvelope = d.peerRecordEnvelope; + } + return m; + }; + + /** + * Creates a plain object from a Peer message. Also converts values to other types if specified. + * @function toObject + * @memberof Peer + * @static + * @param {Peer} m Peer + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + Peer.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.arrays || o.defaults) { + d.addresses = []; + d.protocols = []; + d.metadata = []; + } + if (m.addresses && m.addresses.length) { + d.addresses = []; + for (var j = 0; j < m.addresses.length; ++j) { + d.addresses[j] = $root.Address.toObject(m.addresses[j], o); + } + } + if (m.protocols && m.protocols.length) { + d.protocols = []; + for (var j = 0; j < m.protocols.length; ++j) { + d.protocols[j] = m.protocols[j]; + } + } + if (m.metadata && m.metadata.length) { + d.metadata = []; + for (var j = 0; j < m.metadata.length; ++j) { + d.metadata[j] = $root.Metadata.toObject(m.metadata[j], o); + } + } + if (m.pubKey != null && m.hasOwnProperty("pubKey")) { + d.pubKey = o.bytes === String ? $util.base64.encode(m.pubKey, 0, m.pubKey.length) : o.bytes === Array ? Array.prototype.slice.call(m.pubKey) : m.pubKey; + if (o.oneofs) + d._pubKey = "pubKey"; + } + if (m.peerRecordEnvelope != null && m.hasOwnProperty("peerRecordEnvelope")) { + d.peerRecordEnvelope = o.bytes === String ? $util.base64.encode(m.peerRecordEnvelope, 0, m.peerRecordEnvelope.length) : o.bytes === Array ? Array.prototype.slice.call(m.peerRecordEnvelope) : m.peerRecordEnvelope; + if (o.oneofs) + d._peerRecordEnvelope = "peerRecordEnvelope"; + } + return d; + }; + + /** + * Converts this Peer to JSON. + * @function toJSON + * @memberof Peer + * @instance + * @returns {Object.} JSON object + */ + Peer.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return Peer; +})(); + +export const Address = $root.Address = (() => { + + /** + * Properties of an Address. + * @exports IAddress + * @interface IAddress + * @property {Uint8Array|null} [multiaddr] Address multiaddr + * @property {boolean|null} [isCertified] Address isCertified + */ + + /** + * Constructs a new Address. + * @exports Address + * @classdesc Represents an Address. + * @implements IAddress + * @constructor + * @param {IAddress=} [p] Properties to set + */ + function Address(p) { + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * Address multiaddr. + * @member {Uint8Array} multiaddr + * @memberof Address + * @instance + */ + Address.prototype.multiaddr = $util.newBuffer([]); + + /** + * Address isCertified. + * @member {boolean|null|undefined} isCertified + * @memberof Address + * @instance + */ + Address.prototype.isCertified = null; + + // OneOf field names bound to virtual getters and setters + let $oneOfFields; + + /** + * Address _isCertified. + * @member {"isCertified"|undefined} _isCertified + * @memberof Address + * @instance + */ + Object.defineProperty(Address.prototype, "_isCertified", { + get: $util.oneOfGetter($oneOfFields = ["isCertified"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Encodes the specified Address message. Does not implicitly {@link Address.verify|verify} messages. + * @function encode + * @memberof Address + * @static + * @param {IAddress} m Address message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Address.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.multiaddr != null && Object.hasOwnProperty.call(m, "multiaddr")) + w.uint32(10).bytes(m.multiaddr); + if (m.isCertified != null && Object.hasOwnProperty.call(m, "isCertified")) + w.uint32(16).bool(m.isCertified); + return w; + }; + + /** + * Decodes an Address message from the specified reader or buffer. + * @function decode + * @memberof Address + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {Address} Address + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Address.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.Address(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + m.multiaddr = r.bytes(); + break; + case 2: + m.isCertified = r.bool(); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates an Address message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof Address + * @static + * @param {Object.} d Plain object + * @returns {Address} Address + */ + Address.fromObject = function fromObject(d) { + if (d instanceof $root.Address) + return d; + var m = new $root.Address(); + if (d.multiaddr != null) { + if (typeof d.multiaddr === "string") + $util.base64.decode(d.multiaddr, m.multiaddr = $util.newBuffer($util.base64.length(d.multiaddr)), 0); + else if (d.multiaddr.length) + m.multiaddr = d.multiaddr; + } + if (d.isCertified != null) { + m.isCertified = Boolean(d.isCertified); + } + return m; + }; + + /** + * Creates a plain object from an Address message. Also converts values to other types if specified. + * @function toObject + * @memberof Address + * @static + * @param {Address} m Address + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + Address.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.defaults) { + if (o.bytes === String) + d.multiaddr = ""; + else { + d.multiaddr = []; + if (o.bytes !== Array) + d.multiaddr = $util.newBuffer(d.multiaddr); + } + } + if (m.multiaddr != null && m.hasOwnProperty("multiaddr")) { + d.multiaddr = o.bytes === String ? $util.base64.encode(m.multiaddr, 0, m.multiaddr.length) : o.bytes === Array ? Array.prototype.slice.call(m.multiaddr) : m.multiaddr; + } + if (m.isCertified != null && m.hasOwnProperty("isCertified")) { + d.isCertified = m.isCertified; + if (o.oneofs) + d._isCertified = "isCertified"; + } + return d; + }; + + /** + * Converts this Address to JSON. + * @function toJSON + * @memberof Address + * @instance + * @returns {Object.} JSON object + */ + Address.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return Address; +})(); + +export const Metadata = $root.Metadata = (() => { + + /** + * Properties of a Metadata. + * @exports IMetadata + * @interface IMetadata + * @property {string|null} [key] Metadata key + * @property {Uint8Array|null} [value] Metadata value + */ + + /** + * Constructs a new Metadata. + * @exports Metadata + * @classdesc Represents a Metadata. + * @implements IMetadata + * @constructor + * @param {IMetadata=} [p] Properties to set + */ + function Metadata(p) { + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * Metadata key. + * @member {string} key + * @memberof Metadata + * @instance + */ + Metadata.prototype.key = ""; + + /** + * Metadata value. + * @member {Uint8Array} value + * @memberof Metadata + * @instance + */ + Metadata.prototype.value = $util.newBuffer([]); + + /** + * Encodes the specified Metadata message. Does not implicitly {@link Metadata.verify|verify} messages. + * @function encode + * @memberof Metadata + * @static + * @param {IMetadata} m Metadata message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Metadata.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.key != null && Object.hasOwnProperty.call(m, "key")) + w.uint32(10).string(m.key); + if (m.value != null && Object.hasOwnProperty.call(m, "value")) + w.uint32(18).bytes(m.value); + return w; + }; + + /** + * Decodes a Metadata message from the specified reader or buffer. + * @function decode + * @memberof Metadata + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {Metadata} Metadata + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Metadata.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.Metadata(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + m.key = r.string(); + break; + case 2: + m.value = r.bytes(); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates a Metadata message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof Metadata + * @static + * @param {Object.} d Plain object + * @returns {Metadata} Metadata + */ + Metadata.fromObject = function fromObject(d) { + if (d instanceof $root.Metadata) + return d; + var m = new $root.Metadata(); + if (d.key != null) { + m.key = String(d.key); + } + if (d.value != null) { + if (typeof d.value === "string") + $util.base64.decode(d.value, m.value = $util.newBuffer($util.base64.length(d.value)), 0); + else if (d.value.length) + m.value = d.value; + } + return m; + }; + + /** + * Creates a plain object from a Metadata message. Also converts values to other types if specified. + * @function toObject + * @memberof Metadata + * @static + * @param {Metadata} m Metadata + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + Metadata.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.defaults) { + d.key = ""; + if (o.bytes === String) + d.value = ""; + else { + d.value = []; + if (o.bytes !== Array) + d.value = $util.newBuffer(d.value); + } + } + if (m.key != null && m.hasOwnProperty("key")) { + d.key = m.key; + } + if (m.value != null && m.hasOwnProperty("value")) { + d.value = o.bytes === String ? $util.base64.encode(m.value, 0, m.value.length) : o.bytes === Array ? Array.prototype.slice.call(m.value) : m.value; + } + return d; + }; + + /** + * Converts this Metadata to JSON. + * @function toJSON + * @memberof Metadata + * @instance + * @returns {Object.} JSON object + */ + Metadata.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return Metadata; +})(); + +export { $root as default }; diff --git a/packages/ipfs-repo-migrations/migrations/migration-12/pb/peer.proto b/packages/ipfs-repo-migrations/migrations/migration-12/pb/peer.proto new file mode 100644 index 00000000..1c9cc166 --- /dev/null +++ b/packages/ipfs-repo-migrations/migrations/migration-12/pb/peer.proto @@ -0,0 +1,31 @@ +syntax = "proto3"; + +message Peer { + // Multiaddrs we know about + repeated Address addresses = 1; + + // The protocols the peer supports + repeated string protocols = 2; + + // Any peer metadata + repeated Metadata metadata = 3; + + // The public key of the peer + optional bytes pub_key = 4; + + // The most recently received signed PeerRecord + optional bytes peer_record_envelope = 5; +} + +// Address represents a single multiaddr +message Address { + bytes multiaddr = 1; + + // Flag to indicate if the address comes from a certified source + optional bool isCertified = 2; +} + +message Metadata { + string key = 1; + bytes value = 2; +} diff --git a/packages/ipfs-repo-migrations/migrations/migration-12/pb/proto-book.d.ts b/packages/ipfs-repo-migrations/migrations/migration-12/pb/proto-book.d.ts new file mode 100644 index 00000000..f3590f87 --- /dev/null +++ b/packages/ipfs-repo-migrations/migrations/migration-12/pb/proto-book.d.ts @@ -0,0 +1,59 @@ +import * as $protobuf from "protobufjs"; +/** Properties of a Protocols. */ +export interface IProtocols { + + /** Protocols protocols */ + protocols?: (string[]|null); +} + +/** Represents a Protocols. */ +export class Protocols implements IProtocols { + + /** + * Constructs a new Protocols. + * @param [p] Properties to set + */ + constructor(p?: IProtocols); + + /** Protocols protocols. */ + public protocols: string[]; + + /** + * Encodes the specified Protocols message. Does not implicitly {@link Protocols.verify|verify} messages. + * @param m Protocols message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: IProtocols, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a Protocols message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns Protocols + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Protocols; + + /** + * Creates a Protocols message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns Protocols + */ + public static fromObject(d: { [k: string]: any }): Protocols; + + /** + * Creates a plain object from a Protocols message. Also converts values to other types if specified. + * @param m Protocols + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: Protocols, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this Protocols to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; +} diff --git a/packages/ipfs-repo-migrations/migrations/migration-12/pb/proto-book.js b/packages/ipfs-repo-migrations/migrations/migration-12/pb/proto-book.js new file mode 100644 index 00000000..c6edfc3e --- /dev/null +++ b/packages/ipfs-repo-migrations/migrations/migration-12/pb/proto-book.js @@ -0,0 +1,155 @@ +/*eslint-disable*/ +import $protobuf from "protobufjs/minimal.js"; + +// Common aliases +const $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; + +// Exported root namespace +const $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {}); + +export const Protocols = $root.Protocols = (() => { + + /** + * Properties of a Protocols. + * @exports IProtocols + * @interface IProtocols + * @property {Array.|null} [protocols] Protocols protocols + */ + + /** + * Constructs a new Protocols. + * @exports Protocols + * @classdesc Represents a Protocols. + * @implements IProtocols + * @constructor + * @param {IProtocols=} [p] Properties to set + */ + function Protocols(p) { + this.protocols = []; + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * Protocols protocols. + * @member {Array.} protocols + * @memberof Protocols + * @instance + */ + Protocols.prototype.protocols = $util.emptyArray; + + /** + * Encodes the specified Protocols message. Does not implicitly {@link Protocols.verify|verify} messages. + * @function encode + * @memberof Protocols + * @static + * @param {IProtocols} m Protocols message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Protocols.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.protocols != null && m.protocols.length) { + for (var i = 0; i < m.protocols.length; ++i) + w.uint32(10).string(m.protocols[i]); + } + return w; + }; + + /** + * Decodes a Protocols message from the specified reader or buffer. + * @function decode + * @memberof Protocols + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {Protocols} Protocols + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Protocols.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.Protocols(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + if (!(m.protocols && m.protocols.length)) + m.protocols = []; + m.protocols.push(r.string()); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates a Protocols message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof Protocols + * @static + * @param {Object.} d Plain object + * @returns {Protocols} Protocols + */ + Protocols.fromObject = function fromObject(d) { + if (d instanceof $root.Protocols) + return d; + var m = new $root.Protocols(); + if (d.protocols) { + if (!Array.isArray(d.protocols)) + throw TypeError(".Protocols.protocols: array expected"); + m.protocols = []; + for (var i = 0; i < d.protocols.length; ++i) { + m.protocols[i] = String(d.protocols[i]); + } + } + return m; + }; + + /** + * Creates a plain object from a Protocols message. Also converts values to other types if specified. + * @function toObject + * @memberof Protocols + * @static + * @param {Protocols} m Protocols + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + Protocols.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.arrays || o.defaults) { + d.protocols = []; + } + if (m.protocols && m.protocols.length) { + d.protocols = []; + for (var j = 0; j < m.protocols.length; ++j) { + d.protocols[j] = m.protocols[j]; + } + } + return d; + }; + + /** + * Converts this Protocols to JSON. + * @function toJSON + * @memberof Protocols + * @instance + * @returns {Object.} JSON object + */ + Protocols.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return Protocols; +})(); + +export { $root as default }; diff --git a/packages/ipfs-repo-migrations/migrations/migration-12/pb/proto-book.proto b/packages/ipfs-repo-migrations/migrations/migration-12/pb/proto-book.proto new file mode 100644 index 00000000..a452f0ca --- /dev/null +++ b/packages/ipfs-repo-migrations/migrations/migration-12/pb/proto-book.proto @@ -0,0 +1,5 @@ +syntax = "proto3"; + +message Protocols { + repeated string protocols = 1; +} \ No newline at end of file diff --git a/packages/ipfs-repo-migrations/package.json b/packages/ipfs-repo-migrations/package.json index b1a7916b..9b32b3e0 100644 --- a/packages/ipfs-repo-migrations/package.json +++ b/packages/ipfs-repo-migrations/package.json @@ -37,9 +37,19 @@ }, "scripts": { "clean": "rimraf types dist", - "generate": "run-s generate:*", - "generate:proto": "pbjs -t static-module -w es6 --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o migrations/migration-9/pin.js migrations/migration-9/pin.proto", - "generate:proto-types": "pbts -o migrations/migration-9/pin.d.ts migrations/migration-9/pin.js", + "generate": "run-s generate:*:*", + "generate:proto:pins": "pbjs -t static-module -w es6 --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o migrations/migration-9/pin.js migrations/migration-9/pin.proto", + "generate:proto-types:pins": "pbts -o migrations/migration-9/pin.d.ts migrations/migration-9/pin.js", + "generate:proto:address-book": "pbjs -t static-module -w es6 --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o migrations/migration-12/pb/address-book.js migrations/migration-12/pb/address-book.proto", + "generate:proto-types:address-book": "pbts -o migrations/migration-12/pb/address-book.d.ts migrations/migration-12/pb/address-book.js", + "generate:proto:peer": "pbjs -t static-module -w es6 --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o migrations/migration-12/pb/peer.js migrations/migration-12/pb/peer.proto", + "generate:proto-types:peer": "pbts -o migrations/migration-12/pb/peer.d.ts migrations/migration-12/pb/peer.js", + "generate:proto:proto-book": "pbjs -t static-module -w es6 --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o migrations/migration-12/pb/proto-book.js migrations/migration-12/pb/proto-book.proto", + "generate:proto-types:proto-book": "pbts -o migrations/migration-12/pb/proto-book.d.ts migrations/migration-12/pb/proto-book.js", + "generate:proto:envelope": "pbjs -t static-module -w es6 --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o migrations/migration-12/pb/envelope.js migrations/migration-12/pb/envelope.proto", + "generate:proto-types:envelope": "pbts -o migrations/migration-12/pb/envelope.d.ts migrations/migration-12/pb/envelope.js", + "generate:proto:peer-record": "pbjs -t static-module -w es6 --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o migrations/migration-12/pb/peer-record.js migrations/migration-12/pb/peer-record.proto", + "generate:proto-types:peer-record": "pbts -o migrations/migration-12/pb/peer-record.d.ts migrations/migration-12/pb/peer-record.js", "prepublishOnly": "npm run build", "build": "aegir build", "pretest": "aegir build --esm-tests", @@ -59,6 +69,7 @@ "interface-blockstore": "^2.0.2", "interface-datastore": "^6.0.2", "it-length": "^1.0.1", + "multiaddr": "^10.0.1", "multiformats": "^9.0.0", "protobufjs": "^6.10.2", "uint8arrays": "^3.0.0", @@ -73,7 +84,7 @@ "assert": "^2.0.0", "aws-sdk": "^2.884.0", "blockstore-core": "^1.0.2", - "blockstore-datastore-adapter": "2.0.1", + "blockstore-datastore-adapter": "^2.0.1", "datastore-fs": "^6.0.1", "datastore-level": "^7.0.1", "datastore-s3": "^8.0.0", @@ -83,7 +94,7 @@ "level-6": "npm:level@^6.0.0", "npm-run-all": "^4.1.5", "rimraf": "^3.0.0", - "sinon": "^11.1.1", + "sinon": "^12.0.1", "util": "^0.12.3" } } diff --git a/packages/ipfs-repo-migrations/test/migrations/index.js b/packages/ipfs-repo-migrations/test/migrations/index.js index 253fcf07..d7c4bd8c 100644 --- a/packages/ipfs-repo-migrations/test/migrations/index.js +++ b/packages/ipfs-repo-migrations/test/migrations/index.js @@ -2,6 +2,7 @@ import { test as migration8Test } from './migration-8-test.js' import { test as migration9Test } from './migration-9-test.js' import { test as migration10Test } from './migration-10-test.js' import { test as migration11Test } from './migration-11-test.js' +import { test as migration12Test } from './migration-12-test.js' /** * @param {import('../types').SetupFunction} setup @@ -12,4 +13,5 @@ export function test (setup, cleanup) { migration9Test(setup, cleanup) migration10Test(setup, cleanup) migration11Test(setup, cleanup) + migration12Test(setup, cleanup) } diff --git a/packages/ipfs-repo-migrations/test/migrations/migration-12-test.js b/packages/ipfs-repo-migrations/test/migrations/migration-12-test.js new file mode 100644 index 00000000..08069f2c --- /dev/null +++ b/packages/ipfs-repo-migrations/test/migrations/migration-12-test.js @@ -0,0 +1,143 @@ +/* eslint-env mocha */ +/* eslint-disable max-nested-callbacks */ + +import { expect } from 'aegir/utils/chai.js' +import { migration } from '../../migrations/migration-12/index.js' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { toString as uint8ArrayToString } from 'uint8arrays/to-string' +import { Key } from 'interface-datastore/key' + +/** + * @typedef {object} DatastoreData + * @property {string} key + * @property {string} value + */ + +/** @type {DatastoreData[]} */ +const migratedPeers = [ + { key: '/peers/bafzbeihho5x3vk5bujrcindezq3vjnfk4yoavps4va34ceo4imojwb3aa4', value: '0a0c0a08047f00000106a8ae10010a0c0a0804d3e691fc06a8ae1001120e2f697066732f69642f312e302e3012132f697066732f69642f707573682f312e302e30120f2f697066732f6b61642f312e302e3012102f697066732f70696e672f312e302e3012152f6c69627032702f6175746f6e61742f312e302e30121b2f6c69627032702f636972637569742f72656c61792f302e312e3012132f7032702f69642f64656c74612f312e302e30120c2f73627074702f312e302e30120b2f736673742f312e302e301a250a0c4167656e7456657273696f6e1215676f2d697066732f302e382e302f343866393465321a1d0a0f50726f746f636f6c56657273696f6e120a697066732f302e312e3022ab02080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010100b7e451e5da240ea1181707697ad4052b035ebabab1145bd619b9ad9d0018df0a185e9d4cb2fb6026f73fe5c3bf7edda419718a1a78e0f0313cdea0f6de6f4b2aaddbbba5765c3cb4bc8c4d340857acd8dbe462db538420e356b5112758027717ec2472f6e2f5ee814920f795d4a44d40d45f79ac055e3ccc031897e866d573d2bf6be0d84bf2899705f507a6bb4e29004800ec21a826d911e3a13c4b664431627082e79f5535afed20c7f227037fdeec65b0932de821071eddf0b32a5668851b3b5551691ddcb06aaf9f27b98fc540cac408a0c8f9921b044e43291d85ca09c5cd05419fadbbbb097cedffa45cdf7c8cc72c76ab0f49cac13177ab9572f7fd7f02030100012afd040aab02080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010100b7e451e5da240ea1181707697ad4052b035ebabab1145bd619b9ad9d0018df0a185e9d4cb2fb6026f73fe5c3bf7edda419718a1a78e0f0313cdea0f6de6f4b2aaddbbba5765c3cb4bc8c4d340857acd8dbe462db538420e356b5112758027717ec2472f6e2f5ee814920f795d4a44d40d45f79ac055e3ccc031897e866d573d2bf6be0d84bf2899705f507a6bb4e29004800ec21a826d911e3a13c4b664431627082e79f5535afed20c7f227037fdeec65b0932de821071eddf0b32a5668851b3b5551691ddcb06aaf9f27b98fc540cac408a0c8f9921b044e43291d85ca09c5cd05419fadbbbb097cedffa45cdf7c8cc72c76ab0f49cac13177ab9572f7fd7f0203010001120203011a460a221220e7776fbaaba1a262243464cc3754b4aae61c0abe5ca837c111dc431c9b076007108095ac9a8c8bd5e5161a0a0a0804d3e691fc06a8ae1a0a0a08047f00000106a8ae2a8002816156091db9311138f5ec92a30899238f5b1457e4116c54ef757774a8ed459ace54cd502cba5c5c12733f0774218a6c6fd01d8775079ae221af8c3921dcbceae820b965473b34b5f290e04c0149a283793f087d75d499f658da84aad96ce2c84c61ef7f3fce277c8fca4c29fd9b43329bc1d7eb3e23a094a005e1f99bb704e6e2e2e13c43eba3057887ac580c41ec603827e515be62a023cbc24a00e6d3cf14bb8afef22dfd1fddfb896c8a8cb589859315510d900a10d8729f6521fea289a095ce4971da1c1a87179d35c4e112372e27d15a1fd17707599d53ed74b9e66fef3c7ee888c9f0f3ae5d7c578d2d59299b58f7d7bdf87d395d26700a8ca42b81fa' }, + { key: '/peers/bafzbeihhpqtnbaaiiwtwlmn3r5kxenbcdlvkgtyhtahmer54kp6242cr2a', value: '0a0c0a08047f000001060fa110000a0c0a0804b9b4df9d060fa110000a0c0a0804b9b4dfaa060fa110000a180a142900000000000000000000000000000001060fa11000' }, + { key: '/peers/bafzbeihiqt2rpqwnkxpqitt6ybwiduno5umrqaaxmvl6lb5sbhrrnedu2i', value: '0a0c0a08047f00000106903510000a0c0a080455f04f030690351000' }, + { key: '/peers/bafzbeihqbhumy7v63ytnhdg3ngaionngdpubywwp66ghryik2iagur3f7e', value: '0a0c0a08047f00000106bfde10010a0c0a0804da665e9406bfde1001120e2f697066732f69642f312e302e3012132f697066732f69642f707573682f312e302e30120f2f697066732f6b61642f312e302e3012102f697066732f70696e672f312e302e3012152f6c69627032702f6175746f6e61742f312e302e30121b2f6c69627032702f636972637569742f72656c61792f302e312e3012132f7032702f69642f64656c74612f312e302e30120c2f73627074702f312e302e30120b2f736673742f322e302e301a250a0c4167656e7456657273696f6e1215676f2d697066732f302e382e302f343866393465321a1d0a0f50726f746f636f6c56657273696f6e120a697066732f302e312e3022ab02080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010100c0f0e616121315b8ee7c0690c2676cfb6b3c9b4344b6503a577b1053265730aea6c11bd4d1e442db6468454b555f3dc00fe35b06f95edff92edac9cc6854c44cad27c081c83e727ddc09bf6256718ec69abbe3fcff5e7e8a801f6b8007014cad3df649393300b74ff18e0d128aa00da13a57bf37ad0fe84538b06965bc6cd379f3a52ca55aafbadd4d9de289744b43143c9532168a1cce23e9dad79b2882cf11ab01f1d0c50b19796dfd481eb7a63dd475d9f23c2083025d50fcaea45f59df22dac7faa22a17993be906e0f149696bcee1cb32974e56a8901dd6a627a120c3c0f8c1df016ea017e4cd1e2ce60a6ab48799739ccd9d0cfd0cd241aee4c37faed102030100012afd040aab02080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010100c0f0e616121315b8ee7c0690c2676cfb6b3c9b4344b6503a577b1053265730aea6c11bd4d1e442db6468454b555f3dc00fe35b06f95edff92edac9cc6854c44cad27c081c83e727ddc09bf6256718ec69abbe3fcff5e7e8a801f6b8007014cad3df649393300b74ff18e0d128aa00da13a57bf37ad0fe84538b06965bc6cd379f3a52ca55aafbadd4d9de289744b43143c9532168a1cce23e9dad79b2882cf11ab01f1d0c50b19796dfd481eb7a63dd475d9f23c2083025d50fcaea45f59df22dac7faa22a17993be906e0f149696bcee1cb32974e56a8901dd6a627a120c3c0f8c1df016ea017e4cd1e2ce60a6ab48799739ccd9d0cfd0cd241aee4c37faed10203010001120203011a460a221220f009e8cc7ebede26d38cdb69808735a61be81c5acff78c78e10ad2006a4765f910efc6affcfcabb5e5161a0a0a0804da665e9406bfde1a0a0a08047f00000106bfde2a800224b0de2afc7b7c79071a7330c916feaa658007051ce24dd64ef5e7c2af584c4cd94da4f11c7e5e7bcb58aa2bbe9b8acba85e581df95678e567f2521c14c0dd944d14c7db96afc256c9d2eab17b517824a61eb6bfa8f87249c46eef571ccd489ad02ca6b0d226cbf3065663fe884511f45375076bc1450105266afe5e56823f94dd9a069d1dab97712263f758c9416d9fdf5b831cc5f7f88f726d6541f15c62069a4bdd017c9245062c35d176c2b1fcbe13168dcf36602966f052b44d17e992937fd6c3546a93f8816ce5b117f65a6795d0c22d733f91c392ea7249d2b27052163096e6261e81c56d7d64f2bff196f6022b5404e33377752489395b05949954dc' }, + { key: '/peers/bafzbeihr3r2ikkzwdzl65ammco5vzgfvbhscjgg2ynd4i5rdcjm6yw2hvy', value: '0a0c0a08047f000001060fa110000a0e0a0a047f000001060fa2dd0310000a0f0a0b047f00000191020fa1cc0310000a0c0a08048ac50724060fa110000a0e0a0a048ac50724060fa2dd0310000a0f0a0b048ac5072491020fa1cc0310000a180a142900000000000000000000000000000001060fa110000a1a0a162900000000000000000000000000000001060fa2dd0310000a1b0a17290000000000000000000000000000000191020fa1cc0310000a180a14292604a880080000a100000000004e1001060fa110000a1a0a16292604a880080000a100000000004e1001060fa2dd0310000a1b0a17292604a880080000a100000000004e100191020fa1cc031000' }, + { key: '/peers/bafzbeihrnlu4ohkv2rcz2u76x5wiedmg2cftlyiuzzudbdlptdvgmwwjmm', value: '0a0c0a08046f5a941c0601bb10000a0c0a0804b28407660601bb1000' }, + { key: '/peers/bafzbeihvxlgjmagropbw6tqkzkwdggvjfmiwgjofm25arzuimcxvc76qxa', value: '0a0c0a0804759237fc06909410010a0c0a08047f0000010690941001120e2f697066732f69642f312e302e3012132f697066732f69642f707573682f312e302e30120f2f697066732f6b61642f312e302e3012102f697066732f70696e672f312e302e3012152f6c69627032702f6175746f6e61742f312e302e30121b2f6c69627032702f636972637569742f72656c61792f302e312e3012132f7032702f69642f64656c74612f312e302e30120c2f73627074702f312e302e301a250a0c4167656e7456657273696f6e1215676f2d697066732f302e382e302f343866393465321a1d0a0f50726f746f636f6c56657273696f6e120a697066732f302e312e3022ab02080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010100a5abee5f90b44525b2ecc4c8d6f455dafe7f0e90e45bdfe5e423568932925699551bc44a04b709f4ccba071ef6122174a0937e8a8a5f940a19d909a3a7b9b1dde7bee761f3cc9f64f4a52818ab2f2da36437b51289a217cac69682dd3d891e920297779d0e269a1741f4bf6ebe86e8a349ec2b39442ca0408f3eb790e0a15f4d23244fa5bde695ab202f488d48f4275b781c1f1181211de0fb729c166bb11ba8e5914a325d5bd33966902a108eb8881081c65220b82af6c96e7620eef89146a655a1968741b3269678778aa40922cbac1c493744cc8057f3b7599dad846b8bf28add2b797cd4dfa8e49eb96c1fd972d4a9a84479f7fd15116a5c6d60f13fcaeb02030100012afd040aab02080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010100a5abee5f90b44525b2ecc4c8d6f455dafe7f0e90e45bdfe5e423568932925699551bc44a04b709f4ccba071ef6122174a0937e8a8a5f940a19d909a3a7b9b1dde7bee761f3cc9f64f4a52818ab2f2da36437b51289a217cac69682dd3d891e920297779d0e269a1741f4bf6ebe86e8a349ec2b39442ca0408f3eb790e0a15f4d23244fa5bde695ab202f488d48f4275b781c1f1181211de0fb729c166bb11ba8e5914a325d5bd33966902a108eb8881081c65220b82af6c96e7620eef89146a655a1968741b3269678778aa40922cbac1c493744cc8057f3b7599dad846b8bf28add2b797cd4dfa8e49eb96c1fd972d4a9a84479f7fd15116a5c6d60f13fcaeb0203010001120203011a460a221220f5bacc9600d173c36f4e0acaac331aa92b116325c566ba08e68860af517fd0b810f6a4ab91cff9bbe5161a0a0a0804759237fc0690941a0a0a08047f0000010690942a8002a1dfaadc3330c4d3c9399063c79fa433149f642ea5a763c869dd68bb46d3071e44ed4b82823599f2a6ff0c460de2b1caf5a302c01c089a9cde392d825e696ff85e2dc09808ec5dc02b6721ea216594aa2c7a695a4640b991e9bf0df06dd8f393b44a60e68a6a2e5b1b3a4e259c03e9b050084af76dfee8c36e5b280d3c61ab89506c929d76efe09d4d851f7544e18e75f6d1cb3eaa2259d453e0defa0e89047e1b6bbdc2549f9ef21bc7d1313e435f20bdd9faa25fd5801ad3af873151764f9822f4db8566eaa91147b226aafb89abd9de87bdb202019f1a22ed6c46482449bafb3683b430280bb72ca40f18f021c21dde148881ff5cefa7c28806cee99efb19' }, + { key: '/peers/bafzbeihwfzza3ydyne5xibiwhb6aoy3bzenslr42fbu5pqmuxydzxuonbm', value: '0a0c0a08047f000001060fa110000a0c0a08049df559f0060fa110000a180a142900000000000000000000000000000001060fa110000a180a14292604a880040000d00000000020ebe001060fa110000a180a14290064ff9b00000000000000009df559f0060fa11000' }, + { key: '/peers/bafzbeihwudzcftctd3tu62zsb4f6kqbz4ozqkopb2y34qdowkooezcesre', value: '0a0c0a08047f000001060fa110000a0f0a0b047f00000191020fa1cc0310000a0c0a080459e969b8060fa110000a0f0a0b0459e969b891020fa1cc0310000a180a142900000000000000000000000000000001060fa110000a1b0a17290000000000000000000000000000000191020fa1cc0310000a180a14292602ff16000500000001005700000001060fa110000a1b0a17292602ff1600050000000100570000000191020fa1cc031000' }, + { key: '/peers/bafzbeihxtwpulx7e5ey7sxipzmwjie2m42iv72gptpjqb3z3gwa2rjob3y', value: '0a0c0a080401a0abfd06a06610010a0c0a08047f00000106a0661001120e2f697066732f69642f312e302e3012132f697066732f69642f707573682f312e302e30120f2f697066732f6b61642f312e302e3012102f697066732f70696e672f312e302e3012152f6c69627032702f6175746f6e61742f312e302e30121b2f6c69627032702f636972637569742f72656c61792f302e312e3012132f7032702f69642f64656c74612f312e302e30120c2f73627074702f312e302e30120b2f736673742f322e302e301a250a0c4167656e7456657273696f6e1215676f2d697066732f302e382e302f343866393465321a1d0a0f50726f746f636f6c56657273696f6e120a697066732f302e312e3022ab02080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010100d27d7b23c408b548353d7b0d99397ff591e6c2fc82d7c568909d2c5f7c6c4e1a4475b8ff28e322313dedf7fbaa83be4cc04fde726674b13e469e5531e1339d56a9574b689243b6637ce7b40249570c821bc656b3a9469cbfce932a37d2ae2b86beab671dd23b84ae65a88b94374853bc56ab27c10e958a2821bec8bac7bcbd27c7e5eccb83cc40f31de8f3a63cccb55056f808b466b2ff3e14b5dd4efae1426b85c41a15db741c687b64af3fa2a7858cb923583d640bfae859d1f1c2259051b544e137861ce5640641cd796a0da9b5b06054f1bd8ff77bd3e3b5fd226b488d5eb7a1a86c409a767dcdff8f6c1363f4f9f5d60aa28bc7ac7f4bb2706c1ae569d502030100012afd040aab02080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010100d27d7b23c408b548353d7b0d99397ff591e6c2fc82d7c568909d2c5f7c6c4e1a4475b8ff28e322313dedf7fbaa83be4cc04fde726674b13e469e5531e1339d56a9574b689243b6637ce7b40249570c821bc656b3a9469cbfce932a37d2ae2b86beab671dd23b84ae65a88b94374853bc56ab27c10e958a2821bec8bac7bcbd27c7e5eccb83cc40f31de8f3a63cccb55056f808b466b2ff3e14b5dd4efae1426b85c41a15db741c687b64af3fa2a7858cb923583d640bfae859d1f1c2259051b544e137861ce5640641cd796a0da9b5b06054f1bd8ff77bd3e3b5fd226b488d5eb7a1a86c409a767dcdff8f6c1363f4f9f5d60aa28bc7ac7f4bb2706c1ae569d50203010001120203011a460a221220f79d9f45dfe4e931f95d0fcb2c94134ce6915fe8cf9bd300ef3b3581a8a5c1de10d9d49bc99fe4d8e5161a0a0a080401a0abfd06a0661a0a0a08047f00000106a0662a8002cfcc1bda81d61b14ce80ad2cb5903036216fde5092869aea548e3be677d16cac2f424ac21d0dfc7af3459032045eceef089cdbc4ae1f31090eb42a2e197b6d330a24f78ccc1ec90a1f2f5d4a2d4622e31c9a5c76a165397b2eaf6d74c562f430debe50e433b64c8e1d3ce2e3085ed1c18f82c1a80c9f15bbbc270f2ed35ce3b4bdd9233001ad2306ba1fed82d0885a0298589f6bc84fda2c4546a9755fe25800eeaac814cc077a250337e254d783a3b74d5045c8b14ed282c2ac88e6fa8ed6640622b94454de753aca479539243fa2c9899604f8b2ebae9c0b5d29620cf0057bb1b7385ea3cd0cb9a48349ac8a78ff644112e7973fdb756245124860e2a230e6' } +] + +/** @type {DatastoreData[]} */ +const unmigratedPeers = [ + { key: '/peers/addrs/bafzbeihho5x3vk5bujrcindezq3vjnfk4yoavps4va34ceo4imojwb3aa4', value: '0a0c0a08047f00000106a8ae10010a0c0a0804d3e691fc06a8ae1001128a05088094ac9a8c8bd5e51612fd040aab02080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010100b7e451e5da240ea1181707697ad4052b035ebabab1145bd619b9ad9d0018df0a185e9d4cb2fb6026f73fe5c3bf7edda419718a1a78e0f0313cdea0f6de6f4b2aaddbbba5765c3cb4bc8c4d340857acd8dbe462db538420e356b5112758027717ec2472f6e2f5ee814920f795d4a44d40d45f79ac055e3ccc031897e866d573d2bf6be0d84bf2899705f507a6bb4e29004800ec21a826d911e3a13c4b664431627082e79f5535afed20c7f227037fdeec65b0932de821071eddf0b32a5668851b3b5551691ddcb06aaf9f27b98fc540cac408a0c8f9921b044e43291d85ca09c5cd05419fadbbbb097cedffa45cdf7c8cc72c76ab0f49cac13177ab9572f7fd7f0203010001120203011a460a221220e7776fbaaba1a262243464cc3754b4aae61c0abe5ca837c111dc431c9b076007108095ac9a8c8bd5e5161a0a0a0804d3e691fc06a8ae1a0a0a08047f00000106a8ae2a8002816156091db9311138f5ec92a30899238f5b1457e4116c54ef757774a8ed459ace54cd502cba5c5c12733f0774218a6c6fd01d8775079ae221af8c3921dcbceae820b965473b34b5f290e04c0149a283793f087d75d499f658da84aad96ce2c84c61ef7f3fce277c8fca4c29fd9b43329bc1d7eb3e23a094a005e1f99bb704e6e2e2e13c43eba3057887ac580c41ec603827e515be62a023cbc24a00e6d3cf14bb8afef22dfd1fddfb896c8a8cb589859315510d900a10d8729f6521fea289a095ce4971da1c1a87179d35c4e112372e27d15a1fd17707599d53ed74b9e66fef3c7ee888c9f0f3ae5d7c578d2d59299b58f7d7bdf87d395d26700a8ca42b81fa' }, + { key: '/peers/addrs/bafzbeihhpqtnbaaiiwtwlmn3r5kxenbcdlvkgtyhtahmer54kp6242cr2a', value: '0a0c0a08047f000001060fa110000a0c0a0804b9b4df9d060fa110000a0c0a0804b9b4dfaa060fa110000a180a142900000000000000000000000000000001060fa11000' }, + { key: '/peers/addrs/bafzbeihiqt2rpqwnkxpqitt6ybwiduno5umrqaaxmvl6lb5sbhrrnedu2i', value: '0a0c0a08047f00000106903510000a0c0a080455f04f030690351000' }, + { key: '/peers/addrs/bafzbeihqbhumy7v63ytnhdg3ngaionngdpubywwp66ghryik2iagur3f7e', value: '0a0c0a08047f00000106bfde10010a0c0a0804da665e9406bfde1001128a050880c6affcfcabb5e51612fd040aab02080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010100c0f0e616121315b8ee7c0690c2676cfb6b3c9b4344b6503a577b1053265730aea6c11bd4d1e442db6468454b555f3dc00fe35b06f95edff92edac9cc6854c44cad27c081c83e727ddc09bf6256718ec69abbe3fcff5e7e8a801f6b8007014cad3df649393300b74ff18e0d128aa00da13a57bf37ad0fe84538b06965bc6cd379f3a52ca55aafbadd4d9de289744b43143c9532168a1cce23e9dad79b2882cf11ab01f1d0c50b19796dfd481eb7a63dd475d9f23c2083025d50fcaea45f59df22dac7faa22a17993be906e0f149696bcee1cb32974e56a8901dd6a627a120c3c0f8c1df016ea017e4cd1e2ce60a6ab48799739ccd9d0cfd0cd241aee4c37faed10203010001120203011a460a221220f009e8cc7ebede26d38cdb69808735a61be81c5acff78c78e10ad2006a4765f910efc6affcfcabb5e5161a0a0a0804da665e9406bfde1a0a0a08047f00000106bfde2a800224b0de2afc7b7c79071a7330c916feaa658007051ce24dd64ef5e7c2af584c4cd94da4f11c7e5e7bcb58aa2bbe9b8acba85e581df95678e567f2521c14c0dd944d14c7db96afc256c9d2eab17b517824a61eb6bfa8f87249c46eef571ccd489ad02ca6b0d226cbf3065663fe884511f45375076bc1450105266afe5e56823f94dd9a069d1dab97712263f758c9416d9fdf5b831cc5f7f88f726d6541f15c62069a4bdd017c9245062c35d176c2b1fcbe13168dcf36602966f052b44d17e992937fd6c3546a93f8816ce5b117f65a6795d0c22d733f91c392ea7249d2b27052163096e6261e81c56d7d64f2bff196f6022b5404e33377752489395b05949954dc' }, + { key: '/peers/addrs/bafzbeihr3r2ikkzwdzl65ammco5vzgfvbhscjgg2ynd4i5rdcjm6yw2hvy', value: '0a0c0a08047f000001060fa110000a0e0a0a047f000001060fa2dd0310000a0f0a0b047f00000191020fa1cc0310000a0c0a08048ac50724060fa110000a0e0a0a048ac50724060fa2dd0310000a0f0a0b048ac5072491020fa1cc0310000a180a142900000000000000000000000000000001060fa110000a1a0a162900000000000000000000000000000001060fa2dd0310000a1b0a17290000000000000000000000000000000191020fa1cc0310000a180a14292604a880080000a100000000004e1001060fa110000a1a0a16292604a880080000a100000000004e1001060fa2dd0310000a1b0a17292604a880080000a100000000004e100191020fa1cc031000' }, + { key: '/peers/addrs/bafzbeihrnlu4ohkv2rcz2u76x5wiedmg2cftlyiuzzudbdlptdvgmwwjmm', value: '0a0c0a08046f5a941c0601bb10000a0c0a0804b28407660601bb1000' }, + { key: '/peers/addrs/bafzbeihvxlgjmagropbw6tqkzkwdggvjfmiwgjofm25arzuimcxvc76qxa', value: '0a0c0a0804759237fc06909410010a0c0a08047f0000010690941001128a050880a4ab91cff9bbe51612fd040aab02080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010100a5abee5f90b44525b2ecc4c8d6f455dafe7f0e90e45bdfe5e423568932925699551bc44a04b709f4ccba071ef6122174a0937e8a8a5f940a19d909a3a7b9b1dde7bee761f3cc9f64f4a52818ab2f2da36437b51289a217cac69682dd3d891e920297779d0e269a1741f4bf6ebe86e8a349ec2b39442ca0408f3eb790e0a15f4d23244fa5bde695ab202f488d48f4275b781c1f1181211de0fb729c166bb11ba8e5914a325d5bd33966902a108eb8881081c65220b82af6c96e7620eef89146a655a1968741b3269678778aa40922cbac1c493744cc8057f3b7599dad846b8bf28add2b797cd4dfa8e49eb96c1fd972d4a9a84479f7fd15116a5c6d60f13fcaeb0203010001120203011a460a221220f5bacc9600d173c36f4e0acaac331aa92b116325c566ba08e68860af517fd0b810f6a4ab91cff9bbe5161a0a0a0804759237fc0690941a0a0a08047f0000010690942a8002a1dfaadc3330c4d3c9399063c79fa433149f642ea5a763c869dd68bb46d3071e44ed4b82823599f2a6ff0c460de2b1caf5a302c01c089a9cde392d825e696ff85e2dc09808ec5dc02b6721ea216594aa2c7a695a4640b991e9bf0df06dd8f393b44a60e68a6a2e5b1b3a4e259c03e9b050084af76dfee8c36e5b280d3c61ab89506c929d76efe09d4d851f7544e18e75f6d1cb3eaa2259d453e0defa0e89047e1b6bbdc2549f9ef21bc7d1313e435f20bdd9faa25fd5801ad3af873151764f9822f4db8566eaa91147b226aafb89abd9de87bdb202019f1a22ed6c46482449bafb3683b430280bb72ca40f18f021c21dde148881ff5cefa7c28806cee99efb19' }, + { key: '/peers/addrs/bafzbeihwfzza3ydyne5xibiwhb6aoy3bzenslr42fbu5pqmuxydzxuonbm', value: '0a0c0a08047f000001060fa110000a0c0a08049df559f0060fa110000a180a142900000000000000000000000000000001060fa110000a180a14292604a880040000d00000000020ebe001060fa110000a180a14290064ff9b00000000000000009df559f0060fa11000' }, + { key: '/peers/addrs/bafzbeihwudzcftctd3tu62zsb4f6kqbz4ozqkopb2y34qdowkooezcesre', value: '0a0c0a08047f000001060fa110000a0f0a0b047f00000191020fa1cc0310000a0c0a080459e969b8060fa110000a0f0a0b0459e969b891020fa1cc0310000a180a142900000000000000000000000000000001060fa110000a1b0a17290000000000000000000000000000000191020fa1cc0310000a180a14292602ff16000500000001005700000001060fa110000a1b0a17292602ff1600050000000100570000000191020fa1cc031000' }, + { key: '/peers/addrs/bafzbeihxtwpulx7e5ey7sxipzmwjie2m42iv72gptpjqb3z3gwa2rjob3y', value: '0a0c0a080401a0abfd06a06610010a0c0a08047f00000106a0661001128a050880d49bc99fe4d8e51612fd040aab02080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010100d27d7b23c408b548353d7b0d99397ff591e6c2fc82d7c568909d2c5f7c6c4e1a4475b8ff28e322313dedf7fbaa83be4cc04fde726674b13e469e5531e1339d56a9574b689243b6637ce7b40249570c821bc656b3a9469cbfce932a37d2ae2b86beab671dd23b84ae65a88b94374853bc56ab27c10e958a2821bec8bac7bcbd27c7e5eccb83cc40f31de8f3a63cccb55056f808b466b2ff3e14b5dd4efae1426b85c41a15db741c687b64af3fa2a7858cb923583d640bfae859d1f1c2259051b544e137861ce5640641cd796a0da9b5b06054f1bd8ff77bd3e3b5fd226b488d5eb7a1a86c409a767dcdff8f6c1363f4f9f5d60aa28bc7ac7f4bb2706c1ae569d50203010001120203011a460a221220f79d9f45dfe4e931f95d0fcb2c94134ce6915fe8cf9bd300ef3b3581a8a5c1de10d9d49bc99fe4d8e5161a0a0a080401a0abfd06a0661a0a0a08047f00000106a0662a8002cfcc1bda81d61b14ce80ad2cb5903036216fde5092869aea548e3be677d16cac2f424ac21d0dfc7af3459032045eceef089cdbc4ae1f31090eb42a2e197b6d330a24f78ccc1ec90a1f2f5d4a2d4622e31c9a5c76a165397b2eaf6d74c562f430debe50e433b64c8e1d3ce2e3085ed1c18f82c1a80c9f15bbbc270f2ed35ce3b4bdd9233001ad2306ba1fed82d0885a0298589f6bc84fda2c4546a9755fe25800eeaac814cc077a250337e254d783a3b74d5045c8b14ed282c2ac88e6fa8ed6640622b94454de753aca479539243fa2c9899604f8b2ebae9c0b5d29620cf0057bb1b7385ea3cd0cb9a48349ac8a78ff644112e7973fdb756245124860e2a230e6' }, + { key: '/peers/keys/bafzbeihho5x3vk5bujrcindezq3vjnfk4yoavps4va34ceo4imojwb3aa4', value: '080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010100b7e451e5da240ea1181707697ad4052b035ebabab1145bd619b9ad9d0018df0a185e9d4cb2fb6026f73fe5c3bf7edda419718a1a78e0f0313cdea0f6de6f4b2aaddbbba5765c3cb4bc8c4d340857acd8dbe462db538420e356b5112758027717ec2472f6e2f5ee814920f795d4a44d40d45f79ac055e3ccc031897e866d573d2bf6be0d84bf2899705f507a6bb4e29004800ec21a826d911e3a13c4b664431627082e79f5535afed20c7f227037fdeec65b0932de821071eddf0b32a5668851b3b5551691ddcb06aaf9f27b98fc540cac408a0c8f9921b044e43291d85ca09c5cd05419fadbbbb097cedffa45cdf7c8cc72c76ab0f49cac13177ab9572f7fd7f0203010001' }, + { key: '/peers/keys/bafzbeihqbhumy7v63ytnhdg3ngaionngdpubywwp66ghryik2iagur3f7e', value: '080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010100c0f0e616121315b8ee7c0690c2676cfb6b3c9b4344b6503a577b1053265730aea6c11bd4d1e442db6468454b555f3dc00fe35b06f95edff92edac9cc6854c44cad27c081c83e727ddc09bf6256718ec69abbe3fcff5e7e8a801f6b8007014cad3df649393300b74ff18e0d128aa00da13a57bf37ad0fe84538b06965bc6cd379f3a52ca55aafbadd4d9de289744b43143c9532168a1cce23e9dad79b2882cf11ab01f1d0c50b19796dfd481eb7a63dd475d9f23c2083025d50fcaea45f59df22dac7faa22a17993be906e0f149696bcee1cb32974e56a8901dd6a627a120c3c0f8c1df016ea017e4cd1e2ce60a6ab48799739ccd9d0cfd0cd241aee4c37faed10203010001' }, + { key: '/peers/keys/bafzbeihvxlgjmagropbw6tqkzkwdggvjfmiwgjofm25arzuimcxvc76qxa', value: '080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010100a5abee5f90b44525b2ecc4c8d6f455dafe7f0e90e45bdfe5e423568932925699551bc44a04b709f4ccba071ef6122174a0937e8a8a5f940a19d909a3a7b9b1dde7bee761f3cc9f64f4a52818ab2f2da36437b51289a217cac69682dd3d891e920297779d0e269a1741f4bf6ebe86e8a349ec2b39442ca0408f3eb790e0a15f4d23244fa5bde695ab202f488d48f4275b781c1f1181211de0fb729c166bb11ba8e5914a325d5bd33966902a108eb8881081c65220b82af6c96e7620eef89146a655a1968741b3269678778aa40922cbac1c493744cc8057f3b7599dad846b8bf28add2b797cd4dfa8e49eb96c1fd972d4a9a84479f7fd15116a5c6d60f13fcaeb0203010001' }, + { key: '/peers/keys/bafzbeihxtwpulx7e5ey7sxipzmwjie2m42iv72gptpjqb3z3gwa2rjob3y', value: '080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010100d27d7b23c408b548353d7b0d99397ff591e6c2fc82d7c568909d2c5f7c6c4e1a4475b8ff28e322313dedf7fbaa83be4cc04fde726674b13e469e5531e1339d56a9574b689243b6637ce7b40249570c821bc656b3a9469cbfce932a37d2ae2b86beab671dd23b84ae65a88b94374853bc56ab27c10e958a2821bec8bac7bcbd27c7e5eccb83cc40f31de8f3a63cccb55056f808b466b2ff3e14b5dd4efae1426b85c41a15db741c687b64af3fa2a7858cb923583d640bfae859d1f1c2259051b544e137861ce5640641cd796a0da9b5b06054f1bd8ff77bd3e3b5fd226b488d5eb7a1a86c409a767dcdff8f6c1363f4f9f5d60aa28bc7ac7f4bb2706c1ae569d50203010001' }, + { key: '/peers/metadata/bafzbeihho5x3vk5bujrcindezq3vjnfk4yoavps4va34ceo4imojwb3aa4/AgentVersion', value: '676f2d697066732f302e382e302f34386639346532' }, + { key: '/peers/metadata/bafzbeihho5x3vk5bujrcindezq3vjnfk4yoavps4va34ceo4imojwb3aa4/ProtocolVersion', value: '697066732f302e312e30' }, + { key: '/peers/metadata/bafzbeihqbhumy7v63ytnhdg3ngaionngdpubywwp66ghryik2iagur3f7e/AgentVersion', value: '676f2d697066732f302e382e302f34386639346532' }, + { key: '/peers/metadata/bafzbeihqbhumy7v63ytnhdg3ngaionngdpubywwp66ghryik2iagur3f7e/ProtocolVersion', value: '697066732f302e312e30' }, + { key: '/peers/metadata/bafzbeihvxlgjmagropbw6tqkzkwdggvjfmiwgjofm25arzuimcxvc76qxa/AgentVersion', value: '676f2d697066732f302e382e302f34386639346532' }, + { key: '/peers/metadata/bafzbeihvxlgjmagropbw6tqkzkwdggvjfmiwgjofm25arzuimcxvc76qxa/ProtocolVersion', value: '697066732f302e312e30' }, + { key: '/peers/metadata/bafzbeihxtwpulx7e5ey7sxipzmwjie2m42iv72gptpjqb3z3gwa2rjob3y/AgentVersion', value: '676f2d697066732f302e382e302f34386639346532' }, + { key: '/peers/metadata/bafzbeihxtwpulx7e5ey7sxipzmwjie2m42iv72gptpjqb3z3gwa2rjob3y/ProtocolVersion', value: '697066732f302e312e30' }, + { key: '/peers/protos/bafzbeihho5x3vk5bujrcindezq3vjnfk4yoavps4va34ceo4imojwb3aa4', value: '0a0e2f697066732f69642f312e302e300a132f697066732f69642f707573682f312e302e300a0f2f697066732f6b61642f312e302e300a102f697066732f70696e672f312e302e300a152f6c69627032702f6175746f6e61742f312e302e300a1b2f6c69627032702f636972637569742f72656c61792f302e312e300a132f7032702f69642f64656c74612f312e302e300a0c2f73627074702f312e302e300a0b2f736673742f312e302e30' }, + { key: '/peers/protos/bafzbeihqbhumy7v63ytnhdg3ngaionngdpubywwp66ghryik2iagur3f7e', value: '0a0e2f697066732f69642f312e302e300a132f697066732f69642f707573682f312e302e300a0f2f697066732f6b61642f312e302e300a102f697066732f70696e672f312e302e300a152f6c69627032702f6175746f6e61742f312e302e300a1b2f6c69627032702f636972637569742f72656c61792f302e312e300a132f7032702f69642f64656c74612f312e302e300a0c2f73627074702f312e302e300a0b2f736673742f322e302e30' }, + { key: '/peers/protos/bafzbeihvxlgjmagropbw6tqkzkwdggvjfmiwgjofm25arzuimcxvc76qxa', value: '0a0e2f697066732f69642f312e302e300a132f697066732f69642f707573682f312e302e300a0f2f697066732f6b61642f312e302e300a102f697066732f70696e672f312e302e300a152f6c69627032702f6175746f6e61742f312e302e300a1b2f6c69627032702f636972637569742f72656c61792f302e312e300a132f7032702f69642f64656c74612f312e302e300a0c2f73627074702f312e302e30' }, + { key: '/peers/protos/bafzbeihxtwpulx7e5ey7sxipzmwjie2m42iv72gptpjqb3z3gwa2rjob3y', value: '0a0e2f697066732f69642f312e302e300a132f697066732f69642f707573682f312e302e300a0f2f697066732f6b61642f312e302e300a102f697066732f70696e672f312e302e300a152f6c69627032702f6175746f6e61742f312e302e300a1b2f6c69627032702f636972637569742f72656c61792f302e312e300a132f7032702f69642f64656c74612f312e302e300a0c2f73627074702f312e302e300a0b2f736673742f322e302e30' } +] + +/** + * @param {import('../types').SetupFunction} setup + * @param {import('../types').CleanupFunction} cleanup + */ +export function test (setup, cleanup) { + describe('migration 12', function () { + this.timeout(1024 * 1000) + /** @type {string} */ + let dir + /** @type {import('../../src/types').Backends} */ + let backends + + beforeEach(async () => { + ({ dir, backends } = await setup()) + }) + + afterEach(async () => { + await cleanup(dir) + }) + + describe('forwards', () => { + beforeEach(async () => { + await backends.datastore.open() + + for (const { key, value } of unmigratedPeers) { + await backends.datastore.put(new Key(key), uint8ArrayFromString(value, 'hex')) + } + + await backends.datastore.close() + }) + + it('should migrate peerstore forward', async () => { + await migration.migrate(backends, () => {}) + + await backends.datastore.open() + + /** @type {DatastoreData[]} */ + const data = [] + + for await (const { key, value } of backends.datastore.query({ + prefix: '/peers' + })) { + data.push({ key: key.toString(), value: uint8ArrayToString(value, 'hex') }) + } + + await backends.datastore.close() + + expect(data.sort((a, b) => a.key.localeCompare(b.key))).to.deep.equal(migratedPeers.sort((a, b) => a.key.localeCompare(b.key))) + }) + }) + + describe('backwards', () => { + beforeEach(async () => { + await backends.datastore.open() + + for (const { key, value } of migratedPeers) { + await backends.datastore.put(new Key(key), uint8ArrayFromString(value, 'hex')) + } + + await backends.datastore.close() + }) + + it('should migrate peerstore backward', async () => { + await migration.revert(backends, () => {}) + + await backends.root.open() + await backends.datastore.open() + + /** @type {DatastoreData[]} */ + const data = [] + + for await (const { key, value } of backends.datastore.query({ + prefix: '/peers' + })) { + data.push({ key: key.toString(), value: uint8ArrayToString(value, 'hex') }) + } + + await backends.datastore.close() + + expect(data.sort((a, b) => a.key.localeCompare(b.key))).to.deep.equal(unmigratedPeers.sort((a, b) => a.key.localeCompare(b.key))) + }) + }) + }) +} diff --git a/packages/ipfs-repo-migrations/tsconfig.json b/packages/ipfs-repo-migrations/tsconfig.json index b1ffcdd5..5160b3c3 100644 --- a/packages/ipfs-repo-migrations/tsconfig.json +++ b/packages/ipfs-repo-migrations/tsconfig.json @@ -10,6 +10,7 @@ ], "exclude": [ "migrations/migration-9/pin.js", - "migrations/migration-9/pin.d.ts" + "migrations/migration-9/pin.d.ts", + "migrations/migration-12/pb" ] } diff --git a/packages/ipfs-repo/package.json b/packages/ipfs-repo/package.json index 475f0bf4..a8fd1d3a 100644 --- a/packages/ipfs-repo/package.json +++ b/packages/ipfs-repo/package.json @@ -99,7 +99,7 @@ "it-all": "^1.0.2", "just-range": "^2.1.0", "rimraf": "^3.0.0", - "sinon": "^11.1.1", + "sinon": "^12.0.1", "util": "^0.12.3" }, "dependencies": { diff --git a/packages/ipfs-repo/src/constants.js b/packages/ipfs-repo/src/constants.js index 32bd6c1f..06c13935 100644 --- a/packages/ipfs-repo/src/constants.js +++ b/packages/ipfs-repo/src/constants.js @@ -1,2 +1,2 @@ -export const repoVersion = 11 +export const repoVersion = 12