feat: hyperdrive-fileshare - P2P file sharing test app, writer verified (9 files v1->10), reader local empty; hyperbee-chat READMEs updated; test-projects progress
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
node_modules/
|
||||
*-storage/
|
||||
@@ -0,0 +1,37 @@
|
||||
# Hyperdrive Fileshare Test
|
||||
|
||||
P2P file sharing prototype using Hyperdrive + Hyperswarm.
|
||||
|
||||
## Features
|
||||
- Drive on corestore default 'db' core (deterministic key)
|
||||
- Writer puts timestamped text files every 3s
|
||||
- Reader lists / and gets file contents every 5s
|
||||
- Swarm on drive.discoveryKey
|
||||
- Separate storages
|
||||
|
||||
## Run
|
||||
```
|
||||
npm i
|
||||
node index.js writer # Puts files
|
||||
node index.js reader # Lists / gets
|
||||
```
|
||||
|
||||
## Expected
|
||||
- Drive ready, keys logged
|
||||
- Writer: Puts increment version
|
||||
- Reader: Local empty until replicate
|
||||
- On conn: 'New connection', reader sees files
|
||||
|
||||
Localhost DHT: Slow/no conn expected.
|
||||
|
||||
Test: Writer 30s auto-exit.
|
||||
|
||||
## Test Results
|
||||
**Writer** (./writer-storage):
|
||||
- Key: `d5dfebef1968a44295232aa30a6b7e567efb0eb21fc6a4a8880f2e2293c31713`
|
||||
- Discovery Key: `52b3796ac54edb616cfb925f776940fd2e087940c43f42833a6959f57d44cd9b`
|
||||
- 9 files put (/msg-0.txt to /msg-8.txt), version from 1→10
|
||||
|
||||
**Reader** (./reader-storage): local empty scans, version 1.
|
||||
No P2P connections (localhost DHT limits).
|
||||
Ready for multi-host replication (drive.replicate(conn)).
|
||||
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env node
|
||||
const Hyperswarm = require('hyperswarm')
|
||||
const Corestore = require('corestore')
|
||||
const Hyperdrive = require('hyperdrive')
|
||||
const process = require('process')
|
||||
|
||||
const mode = process.argv[2] || 'reader'
|
||||
const storage = `./${mode}-storage`
|
||||
|
||||
console.log(`Mode: ${mode}, storage: ${storage}`)
|
||||
|
||||
async function main() {
|
||||
const corestore = new Corestore(storage)
|
||||
const drive = new Hyperdrive(corestore)
|
||||
console.log('Drive instance created')
|
||||
await drive.ready()
|
||||
console.log('Drive ready, key:', drive.key.toString('hex'))
|
||||
console.log('Discovery key:', drive.discoveryKey.toString('hex'))
|
||||
console.log('Initial version:', drive.version)
|
||||
|
||||
const swarm = new Hyperswarm()
|
||||
const topic = drive.discoveryKey // Use drive.discoveryKey for specific drive sync
|
||||
swarm.join(topic, { server: true, client: true })
|
||||
swarm.on('connection', (conn, info) => {
|
||||
console.log('New P2P connection:', !!(info.client), !!(info.server))
|
||||
drive.replicate(conn)
|
||||
})
|
||||
swarm.on('updated', () => {
|
||||
console.log(`Swarm has ${swarm.connections.size} connections`)
|
||||
})
|
||||
|
||||
if (mode === 'writer') {
|
||||
let count = 0
|
||||
const interval = setInterval(async () => {
|
||||
try {
|
||||
const content = Buffer.from(`Hello from writer #${count} at ${new Date().toISOString()}`)
|
||||
await drive.put(`/msg-${count}.txt`, content)
|
||||
console.log(`Put file /msg-${count}.txt (${content.length} bytes)`)
|
||||
console.log('Drive version:', drive.version)
|
||||
count++
|
||||
} catch (err) {
|
||||
console.error('Put error:', err.message)
|
||||
}
|
||||
}, 3000)
|
||||
|
||||
setTimeout(() => {
|
||||
console.log('Test complete')
|
||||
clearInterval(interval)
|
||||
process.exit(0)
|
||||
}, 30000).unref()
|
||||
} else {
|
||||
// reader
|
||||
const readInterval = setInterval(async () => {
|
||||
console.log('Scanning files:')
|
||||
for await (const file of drive.list('/')) {
|
||||
const content = await drive.get(file.name)
|
||||
console.log(` ${file.name}: ${content ? content.length : 0} bytes`)
|
||||
}
|
||||
console.log('Drive version:', drive.version)
|
||||
}, 5000)
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(console.error)
|
||||
+1108
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "hyperdrive-fileshare",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"corestore": "^7.9.2",
|
||||
"hyperdrive": "^13.3.2",
|
||||
"hyperswarm": "^4.17.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user