Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class Provider {
* @param {GraphsyncMetadata} [metadata] - required if protocol is `graphsync`
*/
encodeMetadata (protocol = this.protocol, metadata = this.metadata) {
if (protocol === 'http') return HTTP_PREFIX
if (protocol === 'http') return concat([HTTP_PREFIX, new Uint8Array(varint.encode(0))])
if (protocol === 'bitswap') return BITSWAP_PREFIX
if (protocol === 'graphsync') {
if (!metadata) throw new Error('metadata is required')
Expand Down
6 changes: 4 additions & 2 deletions test/advertisement.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { readFile } from 'fs/promises'
import { Provider, HTTP_PREFIX, BITSWAP_PREFIX, GRAPHSYNC_PREFIX } from '../provider.js'
import { Advertisement, hashSignableBytes, createExtendedProviderAd } from '../advertisement.js'
import { encode, decode } from '@ipld/dag-json'
import varint from 'varint'
import { concat } from 'uint8arrays/concat'

const schema = await readFile('schema.ipldsch', { encoding: 'utf8' })
const adValidator = createValidator(parseSchema(schema), 'Advertisement')
Expand All @@ -25,7 +27,7 @@ test('one provider', async t => {
Addresses: addresses,
Entries: entries,
ContextID: context,
Metadata: HTTP_PREFIX,
Metadata: concat([HTTP_PREFIX, new Uint8Array(varint.encode(0))]),
IsRm: false
})
t.falsy(encoded.PreviousID, 'previous is not set')
Expand Down Expand Up @@ -103,7 +105,7 @@ test('extended providers', async t => {
t.like(encoded.ExtendedProvider?.Providers[1], {
ID: http.peerId.toString(),
Addresses: [http.addresses[0].toString()],
Metadata: HTTP_PREFIX
Metadata: concat([HTTP_PREFIX, new Uint8Array(varint.encode(0))])
})
t.like(encoded.ExtendedProvider?.Providers[2], {
ID: graph.peerId.toString(),
Expand Down
4 changes: 3 additions & 1 deletion test/provider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import { CID } from 'multiformats/cid'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { Provider, HTTP_PREFIX, BITSWAP_PREFIX, GRAPHSYNC_PREFIX } from '../provider.js'
import { Advertisement } from '../advertisement.js'
import varint from 'varint'
import { concat } from 'uint8arrays/concat'

test('http', async t => {
const peerId = await createEd25519PeerId()
const addresses = '/dns4/example.org/tcp/443/https'
const hp = new Provider({ protocol: 'http', peerId, addresses })

const meta = hp.encodeMetadata()
t.deepEqual(meta, HTTP_PREFIX)
t.deepEqual(meta, concat([HTTP_PREFIX, new Uint8Array(varint.encode(0))]))

const entries = CID.parse('bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354')
const context = new Uint8Array([99])
Expand Down