peerpigeon 0.1.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/README.md +141 -1365
  2. package/cli.js +1382 -0
  3. package/dist/peerpigeon-browser.js +12450 -0
  4. package/dist/peerpigeon-browser.js.map +7 -0
  5. package/docs/API_DOCUMENTATION.md +1976 -0
  6. package/docs/BOOTSTRAP_HUBS.md +319 -0
  7. package/docs/CLI_README.md +371 -0
  8. package/docs/CUSTOM_HUB_NAMESPACES.md +182 -0
  9. package/docs/CUSTOM_NAMESPACE_IMPLEMENTATION.md +187 -0
  10. package/docs/DOCUMENTATION_REORGANIZATION.md +172 -0
  11. package/docs/HUB_QUICK_REF.md +108 -0
  12. package/docs/HUB_SCRIPTS.md +341 -0
  13. package/docs/HUB_SYSTEM.md +599 -0
  14. package/docs/MIGRATION_COMPLETE.md +93 -0
  15. package/docs/NETWORK_NAMESPACES.md +212 -0
  16. package/docs/PIGEONRTC_MIGRATION.md +280 -0
  17. package/docs/README.md +108 -0
  18. package/docs/SELECTIVE_STREAMING_GUIDE.md +427 -0
  19. package/docs/TEST_CLEANUP_COMPLETE.md +80 -0
  20. package/examples/bootstrap-hub-example.js +292 -0
  21. package/examples/browser/README.md +278 -0
  22. package/examples/browser/app.js +2426 -49
  23. package/examples/browser/index.html +481 -630
  24. package/examples/browser/minimal/README.md +55 -0
  25. package/examples/browser/minimal/index.html +75 -0
  26. package/examples/browser/minimal/minimal.js +234 -0
  27. package/examples/browser/styles.css +687 -1425
  28. package/examples/browser/test-bundle.html +35 -0
  29. package/examples/browser-2/index.html +30 -0
  30. package/examples/browser-2/package.json +21 -0
  31. package/examples/browser-2/src/App-simple.vue +21 -0
  32. package/examples/browser-2/src/App.vue +420 -0
  33. package/examples/browser-2/src/components/CryptoView.vue +1661 -0
  34. package/examples/browser-2/src/components/DHTView.vue +1281 -0
  35. package/examples/browser-2/src/components/DebugView.vue +1773 -0
  36. package/examples/browser-2/src/components/MediaView.vue +1048 -0
  37. package/examples/browser-2/src/components/MessagingView.vue +775 -0
  38. package/examples/browser-2/src/components/NetworkView.vue +930 -0
  39. package/examples/browser-2/src/components/StorageView.vue +1376 -0
  40. package/examples/browser-2/src/main.js +5 -0
  41. package/examples/browser-2/src/stores/peerpigeon.js +895 -0
  42. package/examples/browser-2/vite.config.js +6 -0
  43. package/examples/hub-example.js +189 -0
  44. package/examples/multi-hub-test.js +186 -0
  45. package/examples/node/README.md +2 -2
  46. package/examples/programmatic-namespace-example.js +108 -0
  47. package/examples/selective-streaming-demo.html +698 -0
  48. package/examples/standard-events-demo.js +126 -0
  49. package/index.js +7 -1
  50. package/package.json +34 -16
  51. package/server/index.js +1058 -98
  52. package/server/start.js +52 -0
  53. package/src/ConnectionManager.js +239 -225
  54. package/src/CryptoManager.js +147 -18
  55. package/src/DebugLogger.js +0 -7
  56. package/src/DistributedStorageManager.js +224 -205
  57. package/src/EnvironmentDetector.js +88 -4
  58. package/src/EventEmitter.js +79 -1
  59. package/src/EvictionManager.js +10 -9
  60. package/src/GossipManager.js +163 -11
  61. package/src/MediaManager.js +12 -2
  62. package/src/PeerConnection.js +343 -311
  63. package/src/PeerPigeonMesh.js +576 -135
  64. package/src/PigeonRTC-browser.js +247 -0
  65. package/src/SignalingClient.js +14 -243
  66. package/src/SignalingHandler.js +31 -10
  67. package/src/StorageManager.js +0 -39
  68. package/src/WebDHT-Simple.js +389 -0
  69. package/src/WebDHT.js +363 -1165
  70. package/src/browser-entry.js +58 -0
  71. package/examples/browser/assets/images/favicon.png +0 -0
  72. package/examples/browser/assets/images/pigeon.png +0 -0
  73. package/examples/browser/crypto-test.html +0 -427
  74. package/examples/browser/ui-old.js +0 -1926
  75. package/examples/browser/ui.js +0 -3391
  76. package/websocket-server/README.md +0 -247
  77. package/websocket-server/server.js +0 -391
@@ -0,0 +1,1281 @@
1
+ <template>
2
+ <div class="dht-view">
3
+ <div class="section-header">
4
+ <h2>🗄️ Distributed Hash Table (WebDHT)</h2>
5
+ <p>Store and retrieve data across the mesh network with automatic replication and pub/sub</p>
6
+ </div>
7
+
8
+ <!-- DHT Operations -->
9
+ <div class="dht-operations">
10
+ <h3>📝 DHT Operations</h3>
11
+
12
+ <div class="operation-tabs">
13
+ <button
14
+ @click="activeTab = 'put'"
15
+ :class="['tab-btn', { active: activeTab === 'put' }]"
16
+ >
17
+ PUT (Store)
18
+ </button>
19
+ <button
20
+ @click="activeTab = 'get'"
21
+ :class="['tab-btn', { active: activeTab === 'get' }]"
22
+ >
23
+ GET (Retrieve)
24
+ </button>
25
+ <button
26
+ @click="activeTab = 'subscribe'"
27
+ :class="['tab-btn', { active: activeTab === 'subscribe' }]"
28
+ >
29
+ SUBSCRIBE
30
+ </button>
31
+ <button
32
+ @click="activeTab = 'update'"
33
+ :class="['tab-btn', { active: activeTab === 'update' }]"
34
+ >
35
+ UPDATE
36
+ </button>
37
+ </div>
38
+
39
+ <!-- PUT Operation -->
40
+ <div v-if="activeTab === 'put'" class="operation-panel">
41
+ <h4>📤 Store Data in DHT</h4>
42
+ <p class="operation-description">
43
+ Store key-value pairs in the distributed hash table. Data is automatically replicated across peers.
44
+ </p>
45
+
46
+ <div class="form-group">
47
+ <label>Key:</label>
48
+ <input
49
+ v-model="putKey"
50
+ placeholder="e.g., user:settings, app:config, shared:counter"
51
+ class="form-input"
52
+ >
53
+ </div>
54
+
55
+ <div class="form-group">
56
+ <label>Value (JSON):</label>
57
+ <textarea
58
+ v-model="putValue"
59
+ placeholder='{"theme": "dark", "language": "en"}'
60
+ rows="4"
61
+ class="form-textarea"
62
+ ></textarea>
63
+ </div>
64
+
65
+ <div class="form-group">
66
+ <label>TTL (seconds, optional):</label>
67
+ <input
68
+ v-model.number="putTTL"
69
+ type="number"
70
+ placeholder="Leave empty for no expiration"
71
+ class="form-input"
72
+ >
73
+ </div>
74
+
75
+ <button
76
+ @click="performPut"
77
+ :disabled="!putKey || !putValue || !isConnected"
78
+ class="btn btn-primary"
79
+ >
80
+ <span class="btn-icon">💾</span>
81
+ Store in DHT
82
+ </button>
83
+ </div>
84
+
85
+ <!-- GET Operation -->
86
+ <div v-if="activeTab === 'get'" class="operation-panel">
87
+ <h4>📥 Retrieve Data from DHT</h4>
88
+ <p class="operation-description">
89
+ Retrieve values by key from the distributed hash table. Data is fetched from available peers.
90
+ </p>
91
+
92
+ <div class="form-group">
93
+ <label>Key:</label>
94
+ <input
95
+ v-model="getKey"
96
+ placeholder="Enter key to retrieve"
97
+ class="form-input"
98
+ >
99
+ </div>
100
+
101
+ <div class="form-group">
102
+ <label>
103
+ <input type="checkbox" v-model="forceRefresh">
104
+ Force refresh from network
105
+ </label>
106
+ </div>
107
+
108
+ <button
109
+ @click="performGet"
110
+ :disabled="!getKey || !isConnected"
111
+ class="btn btn-primary"
112
+ >
113
+ <span class="btn-icon">🔍</span>
114
+ Retrieve from DHT
115
+ </button>
116
+
117
+ <div v-if="getResult" class="result-panel">
118
+ <h5>Result:</h5>
119
+ <pre class="result-content">{{ JSON.stringify(getResult, null, 2) }}</pre>
120
+ </div>
121
+ </div>
122
+
123
+ <!-- SUBSCRIBE Operation -->
124
+ <div v-if="activeTab === 'subscribe'" class="operation-panel">
125
+ <h4>🔔 Subscribe to Key Changes</h4>
126
+ <p class="operation-description">
127
+ Subscribe to real-time notifications when a key's value changes in the DHT.
128
+ </p>
129
+
130
+ <div class="form-group">
131
+ <label>Key to subscribe:</label>
132
+ <input
133
+ v-model="subscribeKey"
134
+ placeholder="Enter key to watch for changes"
135
+ class="form-input"
136
+ >
137
+ </div>
138
+
139
+ <div class="subscription-controls">
140
+ <button
141
+ @click="performSubscribe"
142
+ :disabled="!subscribeKey || isSubscribed(subscribeKey) || !isConnected"
143
+ class="btn btn-success"
144
+ >
145
+ <span class="btn-icon">🔔</span>
146
+ Subscribe
147
+ </button>
148
+
149
+ <button
150
+ @click="performUnsubscribe"
151
+ :disabled="!subscribeKey || !isSubscribed(subscribeKey) || !isConnected"
152
+ class="btn btn-warning"
153
+ >
154
+ <span class="btn-icon">🔕</span>
155
+ Unsubscribe
156
+ </button>
157
+ </div>
158
+
159
+ <div class="subscriptions-list">
160
+ <h5>Active Subscriptions ({{ subscriptions.size }}):</h5>
161
+ <div v-if="subscriptions.size === 0" class="empty-state">
162
+ No active subscriptions
163
+ </div>
164
+ <div v-else class="subscription-items">
165
+ <div
166
+ v-for="sub in Array.from(subscriptions)"
167
+ :key="sub"
168
+ class="subscription-item"
169
+ >
170
+ <span class="subscription-key">{{ sub }}</span>
171
+ <button
172
+ @click="unsubscribeFromKey(sub)"
173
+ class="btn btn-sm btn-danger"
174
+ >
175
+ Remove
176
+ </button>
177
+ </div>
178
+ </div>
179
+ </div>
180
+ </div>
181
+
182
+ <!-- UPDATE Operation -->
183
+ <div v-if="activeTab === 'update'" class="operation-panel">
184
+ <h4>🔄 Update Existing Data</h4>
185
+ <p class="operation-description">
186
+ Update existing data in the DHT and notify all subscribers of the change.
187
+ </p>
188
+
189
+ <div class="form-group">
190
+ <label>Key:</label>
191
+ <input
192
+ v-model="updateKey"
193
+ placeholder="Key to update"
194
+ class="form-input"
195
+ >
196
+ </div>
197
+
198
+ <div class="form-group">
199
+ <label>New Value (JSON):</label>
200
+ <textarea
201
+ v-model="updateValue"
202
+ placeholder='{"updated": true, "timestamp": 1234567890}'
203
+ rows="4"
204
+ class="form-textarea"
205
+ ></textarea>
206
+ </div>
207
+
208
+ <button
209
+ @click="performUpdate"
210
+ :disabled="!updateKey || !updateValue || !isConnected"
211
+ class="btn btn-primary"
212
+ >
213
+ <span class="btn-icon">🔄</span>
214
+ Update in DHT
215
+ </button>
216
+ </div>
217
+ </div>
218
+
219
+ <!-- Stored Data Display -->
220
+ <div class="stored-data">
221
+ <div class="section-title">
222
+ <h3>💾 Stored Data ({{ dhtData.size }})</h3>
223
+ <div class="data-controls">
224
+ <button @click="refreshAllData" class="btn btn-secondary">
225
+ <span class="btn-icon">🔄</span>
226
+ Refresh All
227
+ </button>
228
+ <button @click="clearLocalData" class="btn btn-danger">
229
+ <span class="btn-icon">🗑️</span>
230
+ Clear Local
231
+ </button>
232
+ </div>
233
+ </div>
234
+
235
+ <div v-if="dhtData.size === 0" class="empty-data">
236
+ <div class="empty-icon">📭</div>
237
+ <p>No data stored yet</p>
238
+ <p class="empty-meta">Store some data using the PUT operation above</p>
239
+ </div>
240
+
241
+ <div v-else class="data-grid">
242
+ <div
243
+ v-for="[key, data] in Array.from(dhtData.entries())"
244
+ :key="key"
245
+ class="data-item"
246
+ >
247
+ <div class="data-header">
248
+ <h4 class="data-key">{{ key }}</h4>
249
+ <div class="data-badges">
250
+ <span v-if="data.local" class="badge badge-local">Local</span>
251
+ <span v-else class="badge badge-remote">Remote</span>
252
+ <span v-if="isSubscribed(key)" class="badge badge-subscribed">Subscribed</span>
253
+ </div>
254
+ </div>
255
+
256
+ <div class="data-meta">
257
+ <span class="data-timestamp">{{ formatTime(data.timestamp) }}</span>
258
+ <span v-if="data.version" class="data-version">v{{ data.version }}</span>
259
+ </div>
260
+
261
+ <div class="data-content">
262
+ <pre>{{ JSON.stringify(data.value, null, 2) }}</pre>
263
+ </div>
264
+
265
+ <div class="data-actions">
266
+ <button @click="copyKey(key)" class="btn btn-sm btn-secondary">
267
+ <span class="btn-icon">📋</span>
268
+ Copy Key
269
+ </button>
270
+ <button @click="refreshSingleData(key)" class="btn btn-sm btn-secondary">
271
+ <span class="btn-icon">🔄</span>
272
+ Refresh
273
+ </button>
274
+ <button
275
+ v-if="!isSubscribed(key)"
276
+ @click="quickSubscribe(key)"
277
+ class="btn btn-sm btn-success"
278
+ >
279
+ <span class="btn-icon">🔔</span>
280
+ Subscribe
281
+ </button>
282
+ <button
283
+ v-else
284
+ @click="quickUnsubscribe(key)"
285
+ class="btn btn-sm btn-warning"
286
+ >
287
+ <span class="btn-icon">🔕</span>
288
+ Unsubscribe
289
+ </button>
290
+ </div>
291
+ </div>
292
+ </div>
293
+ </div>
294
+
295
+ <!-- Change Notifications -->
296
+ <div class="notifications" v-if="notifications.length > 0">
297
+ <h3>🔔 Recent Change Notifications</h3>
298
+ <div class="notifications-list">
299
+ <div
300
+ v-for="notification in notifications.slice().reverse()"
301
+ :key="notification.id"
302
+ class="notification-item"
303
+ >
304
+ <div class="notification-header">
305
+ <span class="notification-key">{{ notification.key }}</span>
306
+ <span class="notification-time">{{ formatTime(notification.timestamp) }}</span>
307
+ </div>
308
+ <div class="notification-content">
309
+ <strong>Old:</strong> <code>{{ JSON.stringify(notification.oldValue) }}</code><br>
310
+ <strong>New:</strong> <code>{{ JSON.stringify(notification.newValue) }}</code>
311
+ </div>
312
+ </div>
313
+ </div>
314
+ <button @click="clearNotifications" class="btn btn-secondary btn-sm">
315
+ Clear Notifications
316
+ </button>
317
+ </div>
318
+
319
+ <!-- DHT Statistics -->
320
+ <div class="stats-section">
321
+ <h3>📊 DHT Statistics</h3>
322
+ <div class="stats-grid">
323
+ <div class="stat-card">
324
+ <div class="stat-icon">🗄️</div>
325
+ <div class="stat-content">
326
+ <h4>Local Data</h4>
327
+ <div class="stat-value">{{ localDataCount }}</div>
328
+ <div class="stat-meta">Keys stored locally</div>
329
+ </div>
330
+ </div>
331
+
332
+ <div class="stat-card">
333
+ <div class="stat-icon">🌐</div>
334
+ <div class="stat-content">
335
+ <h4>Remote Data</h4>
336
+ <div class="stat-value">{{ remoteDataCount }}</div>
337
+ <div class="stat-meta">Keys from other peers</div>
338
+ </div>
339
+ </div>
340
+
341
+ <div class="stat-card">
342
+ <div class="stat-icon">🔔</div>
343
+ <div class="stat-content">
344
+ <h4>Subscriptions</h4>
345
+ <div class="stat-value">{{ subscriptions.size }}</div>
346
+ <div class="stat-meta">Active key watchers</div>
347
+ </div>
348
+ </div>
349
+
350
+ <div class="stat-card">
351
+ <div class="stat-icon">📈</div>
352
+ <div class="stat-content">
353
+ <h4>Notifications</h4>
354
+ <div class="stat-value">{{ notifications.length }}</div>
355
+ <div class="stat-meta">Change notifications received</div>
356
+ </div>
357
+ </div>
358
+ </div>
359
+
360
+ <div class="dht-stats-detail" v-if="dhtStats">
361
+ <h4>Detailed DHT Statistics:</h4>
362
+ <pre class="stats-json">{{ JSON.stringify(dhtStats, null, 2) }}</pre>
363
+ </div>
364
+ </div>
365
+
366
+ <!-- Quick Actions -->
367
+ <div class="quick-actions">
368
+ <h3>⚡ Quick Actions</h3>
369
+ <div class="action-buttons">
370
+ <button @click="storeUserPreferences" class="btn btn-secondary">
371
+ <span class="btn-icon">👤</span>
372
+ Store User Preferences
373
+ </button>
374
+
375
+ <button @click="storeSharedCounter" class="btn btn-secondary">
376
+ <span class="btn-icon">🔢</span>
377
+ Create Shared Counter
378
+ </button>
379
+
380
+ <button @click="storeSystemInfo" class="btn btn-secondary">
381
+ <span class="btn-icon">ℹ️</span>
382
+ Store System Info
383
+ </button>
384
+
385
+ <button @click="performStressTest" class="btn btn-secondary">
386
+ <span class="btn-icon">🧪</span>
387
+ DHT Stress Test
388
+ </button>
389
+
390
+ <button @click="demonstrateReplication" class="btn btn-secondary">
391
+ <span class="btn-icon">🔄</span>
392
+ Test Replication
393
+ </button>
394
+ </div>
395
+ </div>
396
+ </div>
397
+ </template>
398
+
399
+ <script setup>
400
+ import { ref, computed, onMounted } from 'vue';
401
+ import { usePeerPigeonStore } from '../stores/peerpigeon.js';
402
+
403
+ const store = usePeerPigeonStore();
404
+
405
+ // Local reactive state
406
+ const activeTab = ref('put');
407
+ const putKey = ref('');
408
+ const putValue = ref('');
409
+ const putTTL = ref(null);
410
+ const getKey = ref('');
411
+ const getResult = ref(null);
412
+ const forceRefresh = ref(false);
413
+ const subscribeKey = ref('');
414
+ const updateKey = ref('');
415
+ const updateValue = ref('');
416
+ const subscriptions = ref(new Set());
417
+ const notifications = ref([]);
418
+
419
+ // Computed properties
420
+ const dhtData = computed(() => store.dhtData);
421
+ const dhtStats = computed(() => store.getDHTStats());
422
+ const isConnected = computed(() => store.isConnected);
423
+
424
+ const localDataCount = computed(() => {
425
+ return Array.from(dhtData.value.values()).filter(data => data.local).length;
426
+ });
427
+
428
+ const remoteDataCount = computed(() => {
429
+ return Array.from(dhtData.value.values()).filter(data => !data.local).length;
430
+ });
431
+
432
+ // Methods
433
+ const performPut = async () => {
434
+ try {
435
+ let value;
436
+ try {
437
+ value = JSON.parse(putValue.value);
438
+ } catch (e) {
439
+ // If not valid JSON, store as string
440
+ value = putValue.value;
441
+ }
442
+
443
+ const options = {};
444
+ if (putTTL.value && putTTL.value > 0) {
445
+ options.ttl = putTTL.value;
446
+ }
447
+
448
+ const success = await store.dhtPut(putKey.value, value, options);
449
+ if (success) {
450
+ store.addDebugLog(`DHT PUT successful: ${putKey.value}`, 'success');
451
+ putKey.value = '';
452
+ putValue.value = '';
453
+ putTTL.value = null;
454
+ }
455
+ } catch (error) {
456
+ store.addDebugLog(`DHT PUT failed: ${error.message}`, 'error');
457
+ }
458
+ };
459
+
460
+ const performGet = async () => {
461
+ try {
462
+ const options = { forceRefresh: forceRefresh.value };
463
+ const result = await store.dhtGet(getKey.value, options);
464
+ getResult.value = result;
465
+
466
+ if (result !== null) {
467
+ store.addDebugLog(`DHT GET successful: ${getKey.value}`, 'success');
468
+ } else {
469
+ store.addDebugLog(`DHT GET returned null for key: ${getKey.value}`, 'warning');
470
+ }
471
+ } catch (error) {
472
+ store.addDebugLog(`DHT GET failed: ${error.message}`, 'error');
473
+ getResult.value = null;
474
+ }
475
+ };
476
+
477
+ const performSubscribe = async () => {
478
+ try {
479
+ if (store.mesh) {
480
+ await store.mesh.dhtSubscribe(subscribeKey.value);
481
+ subscriptions.value.add(subscribeKey.value);
482
+ store.addDebugLog(`Subscribed to DHT key: ${subscribeKey.value}`, 'success');
483
+ subscribeKey.value = '';
484
+ }
485
+ } catch (error) {
486
+ store.addDebugLog(`DHT SUBSCRIBE failed: ${error.message}`, 'error');
487
+ }
488
+ };
489
+
490
+ const performUnsubscribe = async () => {
491
+ try {
492
+ if (store.mesh) {
493
+ await store.mesh.dhtUnsubscribe(subscribeKey.value);
494
+ subscriptions.value.delete(subscribeKey.value);
495
+ store.addDebugLog(`Unsubscribed from DHT key: ${subscribeKey.value}`, 'success');
496
+ subscribeKey.value = '';
497
+ }
498
+ } catch (error) {
499
+ store.addDebugLog(`DHT UNSUBSCRIBE failed: ${error.message}`, 'error');
500
+ }
501
+ };
502
+
503
+ const performUpdate = async () => {
504
+ try {
505
+ let value;
506
+ try {
507
+ value = JSON.parse(updateValue.value);
508
+ } catch (e) {
509
+ value = updateValue.value;
510
+ }
511
+
512
+ if (store.mesh) {
513
+ const success = await store.mesh.dhtUpdate(updateKey.value, value);
514
+ if (success) {
515
+ store.addDebugLog(`DHT UPDATE successful: ${updateKey.value}`, 'success');
516
+ updateKey.value = '';
517
+ updateValue.value = '';
518
+ }
519
+ }
520
+ } catch (error) {
521
+ store.addDebugLog(`DHT UPDATE failed: ${error.message}`, 'error');
522
+ }
523
+ };
524
+
525
+ const isSubscribed = (key) => {
526
+ return subscriptions.value.has(key);
527
+ };
528
+
529
+ const unsubscribeFromKey = async (key) => {
530
+ try {
531
+ if (store.mesh) {
532
+ await store.mesh.dhtUnsubscribe(key);
533
+ subscriptions.value.delete(key);
534
+ store.addDebugLog(`Unsubscribed from DHT key: ${key}`, 'success');
535
+ }
536
+ } catch (error) {
537
+ store.addDebugLog(`DHT UNSUBSCRIBE failed: ${error.message}`, 'error');
538
+ }
539
+ };
540
+
541
+ const quickSubscribe = async (key) => {
542
+ try {
543
+ if (store.mesh) {
544
+ await store.mesh.dhtSubscribe(key);
545
+ subscriptions.value.add(key);
546
+ store.addDebugLog(`Subscribed to DHT key: ${key}`, 'success');
547
+ }
548
+ } catch (error) {
549
+ store.addDebugLog(`DHT SUBSCRIBE failed: ${error.message}`, 'error');
550
+ }
551
+ };
552
+
553
+ const quickUnsubscribe = async (key) => {
554
+ await unsubscribeFromKey(key);
555
+ };
556
+
557
+ const refreshAllData = async () => {
558
+ for (const key of dhtData.value.keys()) {
559
+ await refreshSingleData(key);
560
+ }
561
+ store.addDebugLog('Refreshed all DHT data', 'info');
562
+ };
563
+
564
+ const refreshSingleData = async (key) => {
565
+ try {
566
+ const result = await store.dhtGet(key, { forceRefresh: true });
567
+ if (result !== null) {
568
+ store.addDebugLog(`Refreshed DHT key: ${key}`, 'success');
569
+ }
570
+ } catch (error) {
571
+ store.addDebugLog(`Failed to refresh DHT key ${key}: ${error.message}`, 'error');
572
+ }
573
+ };
574
+
575
+ const clearLocalData = () => {
576
+ store.dhtData.clear();
577
+ store.addDebugLog('Cleared local DHT data', 'info');
578
+ };
579
+
580
+ const copyKey = async (key) => {
581
+ try {
582
+ await navigator.clipboard.writeText(key);
583
+ store.addDebugLog(`Copied key to clipboard: ${key}`, 'success');
584
+ } catch (error) {
585
+ store.addDebugLog('Failed to copy to clipboard', 'error');
586
+ }
587
+ };
588
+
589
+ const clearNotifications = () => {
590
+ notifications.value = [];
591
+ store.addDebugLog('Cleared DHT notifications', 'info');
592
+ };
593
+
594
+ const formatTime = (timestamp) => {
595
+ return new Date(timestamp).toLocaleTimeString();
596
+ };
597
+
598
+ // Quick Actions
599
+ const storeUserPreferences = async () => {
600
+ const prefs = {
601
+ theme: 'dark',
602
+ language: 'en',
603
+ notifications: true,
604
+ autoConnect: true,
605
+ maxPeers: 5
606
+ };
607
+
608
+ await store.dhtPut('user:preferences', prefs);
609
+ store.addDebugLog('Stored user preferences in DHT', 'success');
610
+ };
611
+
612
+ const storeSharedCounter = async () => {
613
+ const counter = {
614
+ value: 0,
615
+ lastUpdated: Date.now(),
616
+ updatedBy: store.peerId.substring(0, 8) + '...'
617
+ };
618
+
619
+ await store.dhtPut('shared:counter', counter);
620
+
621
+ // Subscribe to counter changes
622
+ if (store.mesh) {
623
+ await store.mesh.dhtSubscribe('shared:counter');
624
+ subscriptions.value.add('shared:counter');
625
+ }
626
+
627
+ store.addDebugLog('Created shared counter in DHT', 'success');
628
+ };
629
+
630
+ const storeSystemInfo = async () => {
631
+ const systemInfo = {
632
+ userAgent: navigator.userAgent,
633
+ platform: navigator.platform,
634
+ language: navigator.language,
635
+ online: navigator.onLine,
636
+ timestamp: Date.now(),
637
+ peerId: store.peerId.substring(0, 8) + '...',
638
+ connectedPeers: store.networkStatus.connectedCount
639
+ };
640
+
641
+ await store.dhtPut('system:info', systemInfo);
642
+ store.addDebugLog('Stored system info in DHT', 'success');
643
+ };
644
+
645
+ const performStressTest = async () => {
646
+ const testCount = 10;
647
+ const results = [];
648
+
649
+ store.addDebugLog(`Starting DHT stress test with ${testCount} operations...`, 'info');
650
+
651
+ for (let i = 0; i < testCount; i++) {
652
+ const key = `test:stress:${i}`;
653
+ const value = {
654
+ index: i,
655
+ data: Array(100).fill(0).map(() => Math.random()),
656
+ timestamp: Date.now()
657
+ };
658
+
659
+ const start = performance.now();
660
+ try {
661
+ await store.dhtPut(key, value);
662
+ const end = performance.now();
663
+ results.push(end - start);
664
+ } catch (error) {
665
+ store.addDebugLog(`Stress test operation ${i} failed: ${error.message}`, 'error');
666
+ }
667
+ }
668
+
669
+ const avgTime = results.reduce((a, b) => a + b, 0) / results.length;
670
+ store.addDebugLog(`DHT stress test completed. Average time: ${avgTime.toFixed(2)}ms`, 'success');
671
+ };
672
+
673
+ const demonstrateReplication = async () => {
674
+ const testKey = 'demo:replication';
675
+ const testValue = {
676
+ message: 'This data should be replicated across all peers',
677
+ timestamp: Date.now(),
678
+ source: store.peerId.substring(0, 8) + '...'
679
+ };
680
+
681
+ // Store the data
682
+ await store.dhtPut(testKey, testValue);
683
+
684
+ // Subscribe to changes
685
+ if (store.mesh) {
686
+ await store.mesh.dhtSubscribe(testKey);
687
+ subscriptions.value.add(testKey);
688
+ }
689
+
690
+ store.addDebugLog('Stored replication demo data. Other peers should receive this automatically.', 'success');
691
+ };
692
+
693
+ // Listen for DHT value changes
694
+ const handleDHTValueChange = (event) => {
695
+ const notification = {
696
+ id: Date.now() + Math.random(),
697
+ key: event.key,
698
+ oldValue: event.oldValue,
699
+ newValue: event.newValue,
700
+ timestamp: new Date()
701
+ };
702
+
703
+ notifications.value.push(notification);
704
+
705
+ // Keep only last 20 notifications
706
+ if (notifications.value.length > 20) {
707
+ notifications.value.shift();
708
+ }
709
+
710
+ store.addDebugLog(`DHT value changed: ${event.key}`, 'info');
711
+ };
712
+
713
+ onMounted(() => {
714
+ // Listen for DHT events
715
+ if (store.mesh) {
716
+ store.mesh.addEventListener('dhtValueChanged', handleDHTValueChange);
717
+ }
718
+ });
719
+ </script>
720
+
721
+ <style scoped>
722
+ .dht-view {
723
+ max-width: 1200px;
724
+ margin: 0 auto;
725
+ }
726
+
727
+ .section-header {
728
+ text-align: center;
729
+ margin-bottom: 30px;
730
+ }
731
+
732
+ .section-header h2 {
733
+ font-size: 28px;
734
+ color: #333;
735
+ margin-bottom: 8px;
736
+ }
737
+
738
+ .section-header p {
739
+ color: #666;
740
+ font-size: 16px;
741
+ }
742
+
743
+ .dht-operations {
744
+ background: white;
745
+ border-radius: 12px;
746
+ padding: 24px;
747
+ margin-bottom: 30px;
748
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
749
+ }
750
+
751
+ .dht-operations h3 {
752
+ margin: 0 0 20px 0;
753
+ color: #333;
754
+ }
755
+
756
+ .operation-tabs {
757
+ display: flex;
758
+ gap: 2px;
759
+ margin-bottom: 20px;
760
+ border-bottom: 1px solid #eee;
761
+ }
762
+
763
+ .tab-btn {
764
+ padding: 12px 20px;
765
+ border: none;
766
+ background: none;
767
+ color: #666;
768
+ cursor: pointer;
769
+ border-bottom: 3px solid transparent;
770
+ transition: all 0.2s;
771
+ font-weight: 500;
772
+ }
773
+
774
+ .tab-btn:hover {
775
+ color: #3b82f6;
776
+ background: rgba(59, 130, 246, 0.05);
777
+ }
778
+
779
+ .tab-btn.active {
780
+ color: #3b82f6;
781
+ border-bottom-color: #3b82f6;
782
+ }
783
+
784
+ .operation-panel {
785
+ padding: 20px;
786
+ border: 1px solid #eee;
787
+ border-radius: 8px;
788
+ background: #fafafa;
789
+ }
790
+
791
+ .operation-panel h4 {
792
+ margin: 0 0 8px 0;
793
+ color: #333;
794
+ }
795
+
796
+ .operation-description {
797
+ color: #666;
798
+ font-size: 14px;
799
+ margin-bottom: 20px;
800
+ line-height: 1.5;
801
+ }
802
+
803
+ .form-group {
804
+ margin-bottom: 16px;
805
+ }
806
+
807
+ .form-group label {
808
+ display: block;
809
+ margin-bottom: 6px;
810
+ font-weight: 500;
811
+ color: #333;
812
+ font-size: 14px;
813
+ }
814
+
815
+ .form-input,
816
+ .form-textarea {
817
+ width: 100%;
818
+ padding: 10px 12px;
819
+ border: 1px solid #ddd;
820
+ border-radius: 6px;
821
+ font-size: 14px;
822
+ font-family: inherit;
823
+ }
824
+
825
+ .form-textarea {
826
+ resize: vertical;
827
+ font-family: monospace;
828
+ }
829
+
830
+ .form-input:focus,
831
+ .form-textarea:focus {
832
+ outline: none;
833
+ border-color: #3b82f6;
834
+ box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
835
+ }
836
+
837
+ .subscription-controls {
838
+ display: flex;
839
+ gap: 12px;
840
+ margin-bottom: 20px;
841
+ }
842
+
843
+ .subscriptions-list h5 {
844
+ margin: 0 0 12px 0;
845
+ color: #333;
846
+ }
847
+
848
+ .subscription-items {
849
+ display: flex;
850
+ flex-direction: column;
851
+ gap: 8px;
852
+ }
853
+
854
+ .subscription-item {
855
+ display: flex;
856
+ justify-content: space-between;
857
+ align-items: center;
858
+ padding: 8px 12px;
859
+ background: white;
860
+ border: 1px solid #eee;
861
+ border-radius: 6px;
862
+ }
863
+
864
+ .subscription-key {
865
+ font-family: monospace;
866
+ font-size: 13px;
867
+ color: #333;
868
+ }
869
+
870
+ .result-panel {
871
+ margin-top: 16px;
872
+ padding: 16px;
873
+ background: white;
874
+ border: 1px solid #eee;
875
+ border-radius: 6px;
876
+ }
877
+
878
+ .result-panel h5 {
879
+ margin: 0 0 12px 0;
880
+ color: #333;
881
+ }
882
+
883
+ .result-content {
884
+ margin: 0;
885
+ padding: 12px;
886
+ background: #f8f9fa;
887
+ border-radius: 4px;
888
+ font-size: 13px;
889
+ overflow-x: auto;
890
+ }
891
+
892
+ .btn {
893
+ padding: 8px 16px;
894
+ border: none;
895
+ border-radius: 6px;
896
+ font-size: 14px;
897
+ font-weight: 500;
898
+ cursor: pointer;
899
+ transition: all 0.2s;
900
+ display: inline-flex;
901
+ align-items: center;
902
+ gap: 6px;
903
+ }
904
+
905
+ .btn:disabled {
906
+ opacity: 0.6;
907
+ cursor: not-allowed;
908
+ }
909
+
910
+ .btn-primary {
911
+ background: #3b82f6;
912
+ color: white;
913
+ }
914
+
915
+ .btn-primary:hover:not(:disabled) {
916
+ background: #2563eb;
917
+ }
918
+
919
+ .btn-secondary {
920
+ background: #6b7280;
921
+ color: white;
922
+ }
923
+
924
+ .btn-secondary:hover:not(:disabled) {
925
+ background: #4b5563;
926
+ }
927
+
928
+ .btn-success {
929
+ background: #10b981;
930
+ color: white;
931
+ }
932
+
933
+ .btn-success:hover:not(:disabled) {
934
+ background: #059669;
935
+ }
936
+
937
+ .btn-warning {
938
+ background: #f59e0b;
939
+ color: white;
940
+ }
941
+
942
+ .btn-warning:hover:not(:disabled) {
943
+ background: #d97706;
944
+ }
945
+
946
+ .btn-danger {
947
+ background: #ef4444;
948
+ color: white;
949
+ }
950
+
951
+ .btn-danger:hover:not(:disabled) {
952
+ background: #dc2626;
953
+ }
954
+
955
+ .btn-sm {
956
+ padding: 4px 8px;
957
+ font-size: 12px;
958
+ }
959
+
960
+ .btn-icon {
961
+ font-size: 14px;
962
+ }
963
+
964
+ .stored-data {
965
+ background: white;
966
+ border-radius: 12px;
967
+ padding: 24px;
968
+ margin-bottom: 30px;
969
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
970
+ }
971
+
972
+ .section-title {
973
+ display: flex;
974
+ justify-content: space-between;
975
+ align-items: center;
976
+ margin-bottom: 20px;
977
+ }
978
+
979
+ .section-title h3 {
980
+ margin: 0;
981
+ color: #333;
982
+ }
983
+
984
+ .data-controls {
985
+ display: flex;
986
+ gap: 8px;
987
+ }
988
+
989
+ .empty-data {
990
+ text-align: center;
991
+ padding: 60px 20px;
992
+ color: #666;
993
+ }
994
+
995
+ .empty-icon {
996
+ font-size: 48px;
997
+ margin-bottom: 16px;
998
+ }
999
+
1000
+ .empty-data p {
1001
+ margin: 0 0 8px 0;
1002
+ }
1003
+
1004
+ .empty-meta {
1005
+ font-size: 14px;
1006
+ color: #999;
1007
+ }
1008
+
1009
+ .data-grid {
1010
+ display: grid;
1011
+ gap: 16px;
1012
+ }
1013
+
1014
+ .data-item {
1015
+ border: 1px solid #eee;
1016
+ border-radius: 8px;
1017
+ padding: 16px;
1018
+ background: #fafafa;
1019
+ }
1020
+
1021
+ .data-header {
1022
+ display: flex;
1023
+ justify-content: space-between;
1024
+ align-items: flex-start;
1025
+ margin-bottom: 8px;
1026
+ }
1027
+
1028
+ .data-key {
1029
+ margin: 0;
1030
+ font-family: monospace;
1031
+ font-size: 14px;
1032
+ color: #333;
1033
+ word-break: break-all;
1034
+ }
1035
+
1036
+ .data-badges {
1037
+ display: flex;
1038
+ gap: 6px;
1039
+ flex-shrink: 0;
1040
+ }
1041
+
1042
+ .badge {
1043
+ padding: 2px 6px;
1044
+ border-radius: 3px;
1045
+ font-size: 10px;
1046
+ text-transform: uppercase;
1047
+ font-weight: 500;
1048
+ }
1049
+
1050
+ .badge-local {
1051
+ background: #10b981;
1052
+ color: white;
1053
+ }
1054
+
1055
+ .badge-remote {
1056
+ background: #6b7280;
1057
+ color: white;
1058
+ }
1059
+
1060
+ .badge-subscribed {
1061
+ background: #3b82f6;
1062
+ color: white;
1063
+ }
1064
+
1065
+ .data-meta {
1066
+ display: flex;
1067
+ justify-content: space-between;
1068
+ align-items: center;
1069
+ margin-bottom: 12px;
1070
+ font-size: 12px;
1071
+ color: #999;
1072
+ }
1073
+
1074
+ .data-content {
1075
+ margin-bottom: 12px;
1076
+ }
1077
+
1078
+ .data-content pre {
1079
+ margin: 0;
1080
+ padding: 12px;
1081
+ background: white;
1082
+ border: 1px solid #eee;
1083
+ border-radius: 4px;
1084
+ font-size: 12px;
1085
+ overflow-x: auto;
1086
+ max-height: 200px;
1087
+ overflow-y: auto;
1088
+ }
1089
+
1090
+ .data-actions {
1091
+ display: flex;
1092
+ flex-wrap: wrap;
1093
+ gap: 6px;
1094
+ }
1095
+
1096
+ .notifications {
1097
+ background: white;
1098
+ border-radius: 12px;
1099
+ padding: 24px;
1100
+ margin-bottom: 30px;
1101
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
1102
+ }
1103
+
1104
+ .notifications h3 {
1105
+ margin: 0 0 16px 0;
1106
+ color: #333;
1107
+ }
1108
+
1109
+ .notifications-list {
1110
+ display: flex;
1111
+ flex-direction: column;
1112
+ gap: 12px;
1113
+ margin-bottom: 16px;
1114
+ max-height: 300px;
1115
+ overflow-y: auto;
1116
+ }
1117
+
1118
+ .notification-item {
1119
+ padding: 12px;
1120
+ background: #f0f9ff;
1121
+ border: 1px solid #e0f2fe;
1122
+ border-radius: 6px;
1123
+ }
1124
+
1125
+ .notification-header {
1126
+ display: flex;
1127
+ justify-content: space-between;
1128
+ align-items: center;
1129
+ margin-bottom: 8px;
1130
+ }
1131
+
1132
+ .notification-key {
1133
+ font-family: monospace;
1134
+ font-weight: 500;
1135
+ color: #0369a1;
1136
+ }
1137
+
1138
+ .notification-time {
1139
+ font-size: 12px;
1140
+ color: #64748b;
1141
+ }
1142
+
1143
+ .notification-content {
1144
+ font-size: 13px;
1145
+ line-height: 1.4;
1146
+ }
1147
+
1148
+ .notification-content code {
1149
+ background: rgba(0, 0, 0, 0.05);
1150
+ padding: 2px 4px;
1151
+ border-radius: 2px;
1152
+ font-size: 12px;
1153
+ }
1154
+
1155
+ .stats-section {
1156
+ background: white;
1157
+ border-radius: 12px;
1158
+ padding: 24px;
1159
+ margin-bottom: 30px;
1160
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
1161
+ }
1162
+
1163
+ .stats-section h3 {
1164
+ margin: 0 0 20px 0;
1165
+ color: #333;
1166
+ }
1167
+
1168
+ .stats-grid {
1169
+ display: grid;
1170
+ grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
1171
+ gap: 16px;
1172
+ margin-bottom: 20px;
1173
+ }
1174
+
1175
+ .stat-card {
1176
+ display: flex;
1177
+ align-items: center;
1178
+ gap: 16px;
1179
+ padding: 16px;
1180
+ background: #f8f9fa;
1181
+ border-radius: 8px;
1182
+ border: 1px solid #eee;
1183
+ }
1184
+
1185
+ .stat-icon {
1186
+ font-size: 24px;
1187
+ opacity: 0.8;
1188
+ }
1189
+
1190
+ .stat-content h4 {
1191
+ margin: 0 0 4px 0;
1192
+ font-size: 13px;
1193
+ color: #666;
1194
+ text-transform: uppercase;
1195
+ letter-spacing: 0.5px;
1196
+ }
1197
+
1198
+ .stat-value {
1199
+ font-size: 20px;
1200
+ font-weight: 600;
1201
+ color: #333;
1202
+ margin-bottom: 2px;
1203
+ }
1204
+
1205
+ .stat-meta {
1206
+ font-size: 11px;
1207
+ color: #999;
1208
+ }
1209
+
1210
+ .dht-stats-detail h4 {
1211
+ margin: 0 0 12px 0;
1212
+ color: #333;
1213
+ }
1214
+
1215
+ .stats-json {
1216
+ margin: 0;
1217
+ padding: 16px;
1218
+ background: #f8f9fa;
1219
+ border: 1px solid #eee;
1220
+ border-radius: 6px;
1221
+ font-size: 12px;
1222
+ overflow-x: auto;
1223
+ max-height: 300px;
1224
+ overflow-y: auto;
1225
+ }
1226
+
1227
+ .quick-actions {
1228
+ background: white;
1229
+ border-radius: 12px;
1230
+ padding: 24px;
1231
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
1232
+ }
1233
+
1234
+ .quick-actions h3 {
1235
+ margin: 0 0 20px 0;
1236
+ color: #333;
1237
+ }
1238
+
1239
+ .action-buttons {
1240
+ display: flex;
1241
+ flex-wrap: wrap;
1242
+ gap: 12px;
1243
+ }
1244
+
1245
+ .empty-state {
1246
+ color: #999;
1247
+ font-style: italic;
1248
+ text-align: center;
1249
+ padding: 20px;
1250
+ }
1251
+
1252
+ /* Responsive design */
1253
+ @media (max-width: 768px) {
1254
+ .operation-tabs {
1255
+ flex-wrap: wrap;
1256
+ }
1257
+
1258
+ .tab-btn {
1259
+ flex: 1;
1260
+ min-width: 120px;
1261
+ }
1262
+
1263
+ .subscription-controls {
1264
+ flex-direction: column;
1265
+ }
1266
+
1267
+ .data-header {
1268
+ flex-direction: column;
1269
+ align-items: flex-start;
1270
+ gap: 8px;
1271
+ }
1272
+
1273
+ .data-actions {
1274
+ justify-content: center;
1275
+ }
1276
+
1277
+ .action-buttons {
1278
+ flex-direction: column;
1279
+ }
1280
+ }
1281
+ </style>