Skip to content

Commit

Permalink
chore: pull block to pin from relay server instead of peer (#261)
Browse files Browse the repository at this point in the history
We previously had a circuit relay connection to the peer in the
test, but circuit relay connections are transient (e.g. time/data
limited) so we can't run bitswap over it.

Instead pull the block from the relay server as we can have a regular
(non-transient) websocket connection to that peer.
  • Loading branch information
achingbrain authored Sep 14, 2023
1 parent 5c4b570 commit d9ee6ff
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
11 changes: 10 additions & 1 deletion packages/helia/.aegir.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { circuitRelayServer } from 'libp2p/circuit-relay'
import { identifyService } from 'libp2p/identify'
import { WebSockets } from '@multiformats/mafmt'
import { CID } from 'multiformats/cid'
import { sha256 } from 'multiformats/hashes/sha2'
import * as raw from 'multiformats/codecs/raw'

/** @type {import('aegir').PartialOptions} */
const options = {
Expand Down Expand Up @@ -28,12 +31,18 @@ const options = {
}
})

const block = Uint8Array.from([0, 1, 2, 3])
const mh = await sha256.digest(block)
const cid = CID.createV1(raw.code, mh)
await helia.blockstore.put(cid, block)

return {
env: {
RELAY_SERVER: helia.libp2p.getMultiaddrs()
.filter(ma => WebSockets.matches(ma))
.map(ma => ma.toString())
.pop()
.pop(),
BLOCK_CID: cid.toString()
},
helia
}
Expand Down
1 change: 1 addition & 0 deletions packages/helia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
},
"devDependencies": {
"@multiformats/mafmt": "^12.1.5",
"@multiformats/multiaddr": "^12.1.7",
"@types/sinon": "^10.0.14",
"aegir": "^40.0.8",
"delay": "^6.0.0",
Expand Down
17 changes: 5 additions & 12 deletions packages/helia/test/pins.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import * as dagCbor from '@ipld/dag-cbor'
import * as dagJson from '@ipld/dag-json'
import * as dagPb from '@ipld/dag-pb'
import { multiaddr } from '@multiformats/multiaddr'
import { expect } from 'aegir/chai'
import all from 'it-all'
import { CID } from 'multiformats/cid'
Expand All @@ -15,21 +16,15 @@ import type { ProgressEvent } from 'progress-events'

describe('pins', () => {
let helia: Helia
let remote: Helia

beforeEach(async () => {
helia = await createHelia()
remote = await createHelia()
})

afterEach(async () => {
if (helia != null) {
await helia.stop()
}

if (remote != null) {
await remote.stop()
}
})

it('pins a block', async () => {
Expand Down Expand Up @@ -147,16 +142,14 @@ describe('pins', () => {
})

it('pins a block from another node', async () => {
await helia.libp2p.dial(remote.libp2p.getMultiaddrs())

const cid1 = await createAndPutBlock(raw.code, Uint8Array.from([0, 1, 2, 3]), remote.blockstore)

await helia.pins.add(cid1)
const cid = CID.parse(process.env.BLOCK_CID ?? '')
await helia.libp2p.dial(multiaddr(process.env.RELAY_SERVER))
await helia.pins.add(cid)

const pins = await all(helia.pins.ls())

expect(pins).to.have.lengthOf(1)
expect(pins).to.have.nested.property('[0].cid').that.eql(cid1)
expect(pins).to.have.nested.property('[0].cid').that.eql(cid)
expect(pins).to.have.nested.property('[0].depth', Infinity)
expect(pins).to.have.nested.property('[0].metadata').that.eql({})
})
Expand Down

0 comments on commit d9ee6ff

Please sign in to comment.