peerpigeon 0.0.7 → 0.1.0
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.
- package/README.md +93 -1
- package/examples/browser/app.js +3 -2
- package/examples/browser/index.html +179 -16
- package/examples/browser/styles.css +279 -47
- package/examples/browser/ui.js +560 -14
- package/examples/debug-configuration.js +171 -0
- package/examples/node/README.md +110 -0
- package/examples/node/basic-storage-example.js +90 -0
- package/examples/node/package.json +17 -0
- package/examples/node/storage-spaces-test.js +329 -0
- package/examples/node/storage-test.js +520 -0
- package/index.js +13 -9
- package/package.json +14 -7
- package/server/index.js +12 -12
- package/src/CleanupManager.js +20 -18
- package/src/ConnectionManager.js +407 -102
- package/src/CryptoManager.js +28 -26
- package/src/DebugLogger.js +211 -0
- package/src/DistributedStorageManager.js +1701 -0
- package/src/EnvironmentDetector.js +3 -1
- package/src/EventEmitter.js +1 -0
- package/src/EvictionManager.js +26 -24
- package/src/GossipManager.js +69 -33
- package/src/MediaManager.js +12 -10
- package/src/MeshOptimizer.js +30 -28
- package/src/PeerConnection.js +621 -159
- package/src/PeerDiscovery.js +19 -17
- package/src/PeerPigeonMesh.js +281 -32
- package/src/SignalingClient.js +59 -44
- package/src/SignalingHandler.js +280 -51
- package/src/StorageManager.js +7 -5
- package/src/TimerUtils.js +1 -0
- package/src/WebDHT.js +125 -123
- package/websocket-server/server.js +31 -103
package/README.md
CHANGED
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
- **🧠 Smart Eviction Strategy**: Automatically replaces distant peers with closer ones to optimize mesh topology
|
|
17
17
|
- **🔍 Auto-Discovery**: Seamlessly connects to peers as they join the network
|
|
18
18
|
- **⚡ WebSocket Signaling**: Real-time bidirectional communication for optimal performance
|
|
19
|
-
-
|
|
19
|
+
- **🗄️ Distributed Hash Table (WebDHT)**: Store and retrieve data across the mesh with automatic replication
|
|
20
|
+
- **📦 Distributed Storage Layer**: Encrypted, access-controlled storage with CRDT support for collaborative editing
|
|
20
21
|
- **🎥 Media Streaming**: Built-in support for audio/video streaming between peers
|
|
21
22
|
- **💬 Messaging System**: Direct messages and broadcast gossip protocol messaging
|
|
22
23
|
- **🔧 Modular Architecture**: Clean separation of concerns with event-driven components
|
|
@@ -151,6 +152,40 @@ mesh.addEventListener('messageReceived', (data) => {
|
|
|
151
152
|
});
|
|
152
153
|
```
|
|
153
154
|
|
|
155
|
+
### 🐛 Debug Configuration
|
|
156
|
+
|
|
157
|
+
PeerPigeon includes a comprehensive debug system that allows you to control console output at a granular level. **By default, all console logging is disabled** to prevent noise in production.
|
|
158
|
+
|
|
159
|
+
```javascript
|
|
160
|
+
import { PeerPigeonMesh, DebugLogger } from 'peerpigeon';
|
|
161
|
+
|
|
162
|
+
// Enable debugging for specific modules
|
|
163
|
+
DebugLogger.enableModules(['GossipManager', 'ConnectionManager']);
|
|
164
|
+
|
|
165
|
+
// Enable all debugging (development mode)
|
|
166
|
+
DebugLogger.enableAll();
|
|
167
|
+
|
|
168
|
+
// Enable debugging conditionally
|
|
169
|
+
if (process.env.NODE_ENV === 'development') {
|
|
170
|
+
DebugLogger.enableAll();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Create your mesh with debug output enabled
|
|
174
|
+
const mesh = new PeerPigeonMesh(options);
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Available Debug Modules:**
|
|
178
|
+
- `PeerPigeonMesh` - Main mesh lifecycle events
|
|
179
|
+
- `GossipManager` - Message propagation debugging
|
|
180
|
+
- `ConnectionManager` - Peer connection management
|
|
181
|
+
- `PeerConnection` - Individual WebRTC connections
|
|
182
|
+
- `WebDHT` - Distributed hash table operations
|
|
183
|
+
- `CryptoManager` - Encryption operations
|
|
184
|
+
- `MediaManager` - Audio/video streaming
|
|
185
|
+
- And many more...
|
|
186
|
+
|
|
187
|
+
See [docs/DEBUG.md](docs/DEBUG.md) for complete documentation.
|
|
188
|
+
|
|
154
189
|
### WebDHT (Distributed Hash Table) Examples
|
|
155
190
|
|
|
156
191
|
```javascript
|
|
@@ -170,6 +205,63 @@ mesh.addEventListener('dhtValueChanged', (data) => {
|
|
|
170
205
|
await mesh.dhtUpdate('shared-counter', 42);
|
|
171
206
|
```
|
|
172
207
|
|
|
208
|
+
### Distributed Storage Layer Examples
|
|
209
|
+
|
|
210
|
+
```javascript
|
|
211
|
+
// Enable crypto for encryption support
|
|
212
|
+
const mesh = new PeerPigeonMesh({
|
|
213
|
+
enableCrypto: true,
|
|
214
|
+
enableWebDHT: true
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
await mesh.cryptoManager.init();
|
|
218
|
+
await mesh.connect('ws://localhost:3000');
|
|
219
|
+
|
|
220
|
+
// Store private encrypted data
|
|
221
|
+
await mesh.distributedStorage.store('user:profile', {
|
|
222
|
+
name: 'Alice',
|
|
223
|
+
email: 'alice@example.com'
|
|
224
|
+
}, {
|
|
225
|
+
isPublic: false, // Private (encrypted)
|
|
226
|
+
isImmutable: false // Mutable for owner
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// Store public data
|
|
230
|
+
await mesh.distributedStorage.store('app:config', {
|
|
231
|
+
version: '1.0.0',
|
|
232
|
+
features: ['chat', 'files']
|
|
233
|
+
}, {
|
|
234
|
+
isPublic: true, // Public (not encrypted)
|
|
235
|
+
isImmutable: true // Immutable for other peers
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
// Store collaborative document with CRDT
|
|
239
|
+
await mesh.distributedStorage.store('doc:shared', {
|
|
240
|
+
title: 'Shared Document',
|
|
241
|
+
content: 'Initial content'
|
|
242
|
+
}, {
|
|
243
|
+
isPublic: true,
|
|
244
|
+
enableCRDT: true // Enable collaborative editing
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
// Grant access to private data
|
|
248
|
+
await mesh.distributedStorage.grantAccess('user:profile', otherPeer.peerId);
|
|
249
|
+
|
|
250
|
+
// Retrieve data
|
|
251
|
+
const profile = await mesh.distributedStorage.retrieve('user:profile');
|
|
252
|
+
|
|
253
|
+
// Update data (owner only, or CRDT-enabled)
|
|
254
|
+
await mesh.distributedStorage.update('user:profile', {
|
|
255
|
+
name: 'Alice Smith',
|
|
256
|
+
email: 'alice.smith@example.com'
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
// Listen for storage events
|
|
260
|
+
mesh.addEventListener('storageDataUpdated', (event) => {
|
|
261
|
+
console.log(`Data updated: ${event.key} (version ${event.version})`);
|
|
262
|
+
});
|
|
263
|
+
```
|
|
264
|
+
|
|
173
265
|
### Media Streaming Examples
|
|
174
266
|
|
|
175
267
|
```javascript
|
package/examples/browser/app.js
CHANGED
|
@@ -3,10 +3,11 @@ import { PeerPigeonUI } from './ui.js';
|
|
|
3
3
|
|
|
4
4
|
class PeerPigeonApp {
|
|
5
5
|
constructor() {
|
|
6
|
-
// Initialize mesh with crypto and
|
|
6
|
+
// Initialize mesh with crypto, WebDHT, and distributed storage enabled
|
|
7
7
|
this.mesh = new PeerPigeonMesh({
|
|
8
8
|
enableWebDHT: true,
|
|
9
|
-
enableCrypto: true
|
|
9
|
+
enableCrypto: true,
|
|
10
|
+
enableDistributedStorage: true
|
|
10
11
|
});
|
|
11
12
|
|
|
12
13
|
this.ui = new PeerPigeonUI(this.mesh);
|
|
@@ -51,6 +51,22 @@
|
|
|
51
51
|
</div>
|
|
52
52
|
</div>
|
|
53
53
|
|
|
54
|
+
<div class="connected-peers" aria-expanded="false">
|
|
55
|
+
<div class="section-header">
|
|
56
|
+
<h2>
|
|
57
|
+
<button id="connected-peers-toggle" class="toggle-btn" aria-expanded="false">
|
|
58
|
+
▶ Connected Peers
|
|
59
|
+
</button>
|
|
60
|
+
<span id="connected-peers-count" class="count-badge">0</span>
|
|
61
|
+
</h2>
|
|
62
|
+
</div>
|
|
63
|
+
<div id="connected-peers-content" class="collapsible-content" style="display: none;">
|
|
64
|
+
<div id="peers-list" class="peers-list">
|
|
65
|
+
<p class="empty-state">No peers connected</p>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
|
|
54
70
|
<div class="media" aria-expanded="false">
|
|
55
71
|
<div class="section-header">
|
|
56
72
|
<h2>
|
|
@@ -132,22 +148,6 @@
|
|
|
132
148
|
</div>
|
|
133
149
|
</div>
|
|
134
150
|
|
|
135
|
-
<div class="connected-peers" aria-expanded="false">
|
|
136
|
-
<div class="section-header">
|
|
137
|
-
<h2>
|
|
138
|
-
<button id="connected-peers-toggle" class="toggle-btn" aria-expanded="false">
|
|
139
|
-
▶ Connected Peers
|
|
140
|
-
</button>
|
|
141
|
-
<span id="connected-peers-count" class="count-badge">0</span>
|
|
142
|
-
</h2>
|
|
143
|
-
</div>
|
|
144
|
-
<div id="connected-peers-content" class="collapsible-content" style="display: none;">
|
|
145
|
-
<div id="peers-list" class="peers-list">
|
|
146
|
-
<p class="empty-state">No peers connected</p>
|
|
147
|
-
</div>
|
|
148
|
-
</div>
|
|
149
|
-
</div>
|
|
150
|
-
|
|
151
151
|
<div class="manual-connection" aria-expanded="false">
|
|
152
152
|
<div class="section-header">
|
|
153
153
|
<h2>
|
|
@@ -484,6 +484,169 @@
|
|
|
484
484
|
</div>
|
|
485
485
|
</div>
|
|
486
486
|
|
|
487
|
+
<div class="storage" aria-expanded="false">
|
|
488
|
+
<div class="section-header">
|
|
489
|
+
<h2>
|
|
490
|
+
<button id="storage-toggle" class="toggle-btn" aria-expanded="false">
|
|
491
|
+
▶ Distributed Storage - Encrypted P2P Storage Layer
|
|
492
|
+
</button>
|
|
493
|
+
</h2>
|
|
494
|
+
</div>
|
|
495
|
+
<div id="storage-content" class="collapsible-content" style="display: none;">
|
|
496
|
+
<!-- Storage Status -->
|
|
497
|
+
<div class="storage-status">
|
|
498
|
+
<h3>Storage Status</h3>
|
|
499
|
+
<div class="info-group">
|
|
500
|
+
<label>Storage Layer:</label>
|
|
501
|
+
<span id="storage-status">Disabled</span>
|
|
502
|
+
</div>
|
|
503
|
+
<div class="info-group">
|
|
504
|
+
<label>Stored Items:</label>
|
|
505
|
+
<span id="storage-item-count">0</span>
|
|
506
|
+
</div>
|
|
507
|
+
<div class="info-group">
|
|
508
|
+
<label>Total Size:</label>
|
|
509
|
+
<span id="storage-total-size">0 bytes</span>
|
|
510
|
+
</div>
|
|
511
|
+
</div>
|
|
512
|
+
|
|
513
|
+
<!-- Storage Controls -->
|
|
514
|
+
<div class="storage-controls">
|
|
515
|
+
<h3>Storage Controls</h3>
|
|
516
|
+
<div class="button-group">
|
|
517
|
+
<button id="storage-enable-btn" class="btn primary">Enable Storage</button>
|
|
518
|
+
<button id="storage-disable-btn" class="btn warning">Disable Storage</button>
|
|
519
|
+
<button id="storage-clear-btn" class="btn quaternary">Clear All</button>
|
|
520
|
+
</div>
|
|
521
|
+
</div>
|
|
522
|
+
|
|
523
|
+
<!-- Store Data -->
|
|
524
|
+
<div class="storage-operations">
|
|
525
|
+
<h3>Store Data</h3>
|
|
526
|
+
<div class="input-group">
|
|
527
|
+
<label for="storage-key">Key:</label>
|
|
528
|
+
<input type="text" id="storage-key" placeholder="Storage key">
|
|
529
|
+
</div>
|
|
530
|
+
<div class="input-group">
|
|
531
|
+
<label for="storage-value">Value:</label>
|
|
532
|
+
<textarea id="storage-value" placeholder="Data to store (JSON or text)" rows="3"></textarea>
|
|
533
|
+
</div>
|
|
534
|
+
|
|
535
|
+
<!-- Storage Options -->
|
|
536
|
+
<div class="storage-options">
|
|
537
|
+
<h4>Storage Options</h4>
|
|
538
|
+
<div class="input-group">
|
|
539
|
+
<label class="checkbox-label">
|
|
540
|
+
<input type="checkbox" id="storage-encrypt" checked>
|
|
541
|
+
<span class="checkmark"></span>
|
|
542
|
+
Encrypt data
|
|
543
|
+
</label>
|
|
544
|
+
</div>
|
|
545
|
+
<div class="input-group">
|
|
546
|
+
<label class="checkbox-label">
|
|
547
|
+
<input type="checkbox" id="storage-public">
|
|
548
|
+
<span class="checkmark"></span>
|
|
549
|
+
Public access (readable by anyone)
|
|
550
|
+
</label>
|
|
551
|
+
</div>
|
|
552
|
+
<div class="input-group">
|
|
553
|
+
<label class="checkbox-label">
|
|
554
|
+
<input type="checkbox" id="storage-immutable">
|
|
555
|
+
<span class="checkmark"></span>
|
|
556
|
+
Immutable (cannot be updated)
|
|
557
|
+
</label>
|
|
558
|
+
</div>
|
|
559
|
+
<div class="input-group">
|
|
560
|
+
<label class="checkbox-label">
|
|
561
|
+
<input type="checkbox" id="storage-crdt">
|
|
562
|
+
<span class="checkmark"></span>
|
|
563
|
+
Enable CRDT (conflict-free updates)
|
|
564
|
+
</label>
|
|
565
|
+
</div>
|
|
566
|
+
<div class="input-group">
|
|
567
|
+
<label for="storage-ttl">TTL (seconds, 0 = no expiration):</label>
|
|
568
|
+
<input type="number" id="storage-ttl" value="0" min="0">
|
|
569
|
+
</div>
|
|
570
|
+
</div>
|
|
571
|
+
|
|
572
|
+
<div class="button-group">
|
|
573
|
+
<button id="storage-store-btn" class="btn primary">Store Data</button>
|
|
574
|
+
<button id="storage-update-btn" class="btn secondary">Update Data</button>
|
|
575
|
+
</div>
|
|
576
|
+
</div>
|
|
577
|
+
|
|
578
|
+
<!-- Retrieve Data -->
|
|
579
|
+
<div class="storage-retrieve">
|
|
580
|
+
<h3>Retrieve Data</h3>
|
|
581
|
+
<div class="input-group horizontal">
|
|
582
|
+
<input type="text" id="storage-get-key" placeholder="Key to retrieve">
|
|
583
|
+
<button id="storage-get-btn" class="btn secondary">Get Data</button>
|
|
584
|
+
<button id="storage-delete-btn" class="btn warning">Delete</button>
|
|
585
|
+
</div>
|
|
586
|
+
</div>
|
|
587
|
+
|
|
588
|
+
<!-- Access Control -->
|
|
589
|
+
<div class="storage-access">
|
|
590
|
+
<h3>Access Control</h3>
|
|
591
|
+
<div class="input-group horizontal">
|
|
592
|
+
<input type="text" id="storage-access-key" placeholder="Key for access control">
|
|
593
|
+
<input type="text" id="storage-access-peer" placeholder="Peer ID to grant access">
|
|
594
|
+
<select id="storage-access-level">
|
|
595
|
+
<option value="read">Read</option>
|
|
596
|
+
<option value="write">Write</option>
|
|
597
|
+
<option value="admin">Admin</option>
|
|
598
|
+
</select>
|
|
599
|
+
<button id="storage-grant-access-btn" class="btn tertiary">Grant Access</button>
|
|
600
|
+
</div>
|
|
601
|
+
<div class="input-group horizontal">
|
|
602
|
+
<input type="text" id="storage-revoke-key" placeholder="Key for access revocation">
|
|
603
|
+
<input type="text" id="storage-revoke-peer" placeholder="Peer ID to revoke access">
|
|
604
|
+
<button id="storage-revoke-access-btn" class="btn quaternary">Revoke Access</button>
|
|
605
|
+
</div>
|
|
606
|
+
</div>
|
|
607
|
+
|
|
608
|
+
<!-- Bulk Operations -->
|
|
609
|
+
<div class="storage-bulk">
|
|
610
|
+
<h3>Bulk Operations</h3>
|
|
611
|
+
<div class="input-group horizontal">
|
|
612
|
+
<input type="text" id="storage-prefix" placeholder="Key prefix for bulk operations">
|
|
613
|
+
<button id="storage-list-btn" class="btn tertiary">List Keys</button>
|
|
614
|
+
<button id="storage-bulk-delete-btn" class="btn warning">Bulk Delete</button>
|
|
615
|
+
</div>
|
|
616
|
+
</div>
|
|
617
|
+
|
|
618
|
+
<!-- Search -->
|
|
619
|
+
<div class="storage-search">
|
|
620
|
+
<h3>Search</h3>
|
|
621
|
+
<div class="input-group horizontal">
|
|
622
|
+
<input type="text" id="storage-search-query" placeholder="Search query">
|
|
623
|
+
<select id="storage-search-type">
|
|
624
|
+
<option value="key">Search Keys</option>
|
|
625
|
+
<option value="value">Search Values</option>
|
|
626
|
+
<option value="metadata">Search Metadata</option>
|
|
627
|
+
</select>
|
|
628
|
+
<button id="storage-search-btn" class="btn tertiary">Search</button>
|
|
629
|
+
</div>
|
|
630
|
+
</div>
|
|
631
|
+
|
|
632
|
+
<!-- Backup/Restore -->
|
|
633
|
+
<div class="storage-backup">
|
|
634
|
+
<h3>Backup & Restore</h3>
|
|
635
|
+
<div class="button-group">
|
|
636
|
+
<button id="storage-backup-btn" class="btn tertiary">Create Backup</button>
|
|
637
|
+
<button id="storage-restore-btn" class="btn tertiary">Restore from Backup</button>
|
|
638
|
+
</div>
|
|
639
|
+
<input type="file" id="storage-restore-file" accept=".json" style="display: none;">
|
|
640
|
+
</div>
|
|
641
|
+
|
|
642
|
+
<!-- Storage Log -->
|
|
643
|
+
<div class="storage-results">
|
|
644
|
+
<h3>Storage Operations Log</h3>
|
|
645
|
+
<div id="storage-log" class="storage-log"></div>
|
|
646
|
+
</div>
|
|
647
|
+
</div>
|
|
648
|
+
</div>
|
|
649
|
+
|
|
487
650
|
<div class="messages">
|
|
488
651
|
<h2>Messages</h2>
|
|
489
652
|
<div class="input-group horizontal">
|