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
6 changes: 4 additions & 2 deletions cmd/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = async function seed(cmd) {
key: 'contentKey',
label: appendMode ? `${ansi.gray('...')} content key` : 'Content Key:',
initial: loading,
transform: (v) => ansi.gray(v)
transform: (v) => (v === 'pending' ? ansi.yellow(v) : ansi.gray(v))
},
{
key: 'firewalled',
Expand Down Expand Up @@ -151,7 +151,9 @@ module.exports = async function seed(cmd) {
stats.update({
driveKey: hypercoreid.normalize(driveKey),
discoveryKey: hypercoreid.normalize(discoveryKey),
contentKey: contentKey && hypercoreid.normalize(contentKey),
contentKey: hypercoreid.isValid(contentKey)
? hypercoreid.normalize(contentKey)
: contentKey,
firewalled,
natType,
network
Expand Down
4 changes: 2 additions & 2 deletions subsystems/sidecar/ops/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = class Seed extends Opstream {
peers: drive.core.peers.length,
driveKey: drive.key?.toString('hex'),
discoveryKey: drive.discoveryKey?.toString('hex'),
contentKey: drive.contentKey?.toString('hex'),
contentKey: drive.contentKey?.toString('hex') ?? 'pending',
upload: {
totalBytes: this.stats.totals.upload.bytes,
totalBlocks: this.stats.totals.upload.blocks,
Expand Down Expand Up @@ -101,7 +101,7 @@ module.exports = class Seed extends Opstream {

await replicator.join(this.sidecar.swarm, { server: true, client: true })

await drive.get('/package.json')
drive.db.core.download({ start: 0, end: -1 })

this._statsInterval = setInterval(() => {
this.push(this._stats({ drive }))
Expand Down
64 changes: 64 additions & 0 deletions test/03-seed.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,67 @@ test('pear seed announces, join, drop', async function ({
const dropped = await until['peer-remove']
ok(dropped, 'peer drops')
})

test('pear seed empty drive has pending content key', async function ({ is, plan, teardown }) {
plan(1)

const helper = new Helper()
teardown(() => helper.close(), { order: Infinity })
await helper.ready()
const link = await Helper.touchLink(helper)

const seeding = helper.seed({ link })
teardown(() => Helper.teardownStream(seeding))
const stats = await Helper.pick(seeding, { tag: 'stats', data: { contentKey: 'pending' } })

is(stats.contentKey, 'pending', 'content key is pending')
})

test('pear seed fully syncs db and blobs cores', async function ({
is,
plan,
comment,
teardown,
timeout,
tmp
}) {
timeout(180000)
plan(2)

const sourceStore = new Corestore(await tmp())
teardown(() => sourceStore.close())
await sourceStore.ready()
const sourceDrive = new Hyperdrive(sourceStore)
await sourceDrive.ready()
await sourceDrive.put('/index.js', 'module.exports = {}\n')
await sourceDrive.put('/test.txt', 'test')
const sourceBlobs = await sourceDrive.getBlobs()

let dbBlocks = 0
sourceDrive.db.core.on('upload', () => dbBlocks++)

let blobBlocks = 0
sourceBlobs.core.on('upload', () => blobBlocks++)

const sourceSwarm = new Hyperswarm({ bootstrap: Helper.dhtBootstrap })
teardown(() => sourceSwarm.destroy())
sourceSwarm.on('connection', (conn) => {
sourceStore.replicate(conn)
})
const topic = sourceSwarm.join(sourceDrive.discoveryKey, { server: true, client: false })
await topic.flushed()

const helper = new Helper()
teardown(() => helper.close(), { order: Infinity })
await helper.ready()

comment('seeding source drive')
const link = `pear://${hypercoreid.encode(sourceDrive.key)}`
const seeding = helper.seed({ link })
teardown(() => Helper.teardownStream(seeding))
const totalBlocks = sourceDrive.db.core.length + sourceBlobs.core.length
await Helper.pick(seeding, { tag: 'stats', data: { download: { totalBlocks } } })

is(dbBlocks, sourceDrive.db.core.length, 'synced db core')
is(blobBlocks, sourceBlobs.core.length, 'synced blobs core')
})
Loading