peerpigeon 0.0.8 โ 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 +34 -0
- package/examples/browser/index.html +16 -16
- package/examples/debug-configuration.js +171 -0
- package/examples/node/storage-spaces-test.js +329 -0
- package/index.js +3 -0
- package/package.json +13 -8
- 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 +469 -102
- 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 +241 -33
- 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
|
@@ -152,6 +152,40 @@ mesh.addEventListener('messageReceived', (data) => {
|
|
|
152
152
|
});
|
|
153
153
|
```
|
|
154
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
|
+
|
|
155
189
|
### WebDHT (Distributed Hash Table) Examples
|
|
156
190
|
|
|
157
191
|
```javascript
|
|
@@ -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>
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PeerPigeon Debug Configuration Example
|
|
3
|
+
*
|
|
4
|
+
* This example shows how to configure the debug logging system
|
|
5
|
+
* to control console output from PeerPigeon modules.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { PeerPigeonMesh, DebugLogger } from './index.js';
|
|
9
|
+
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// Debug Configuration Examples
|
|
12
|
+
// ============================================================================
|
|
13
|
+
|
|
14
|
+
// 1. Enable all debugging (shows all console output)
|
|
15
|
+
// DebugLogger.enableAll();
|
|
16
|
+
|
|
17
|
+
// 2. Enable specific modules only
|
|
18
|
+
DebugLogger.enableModules([
|
|
19
|
+
'GossipManager', // Message propagation debugging
|
|
20
|
+
'ConnectionManager', // Connection management debugging
|
|
21
|
+
'PeerConnection' // WebRTC connection debugging
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
// 3. Enable individual modules
|
|
25
|
+
// DebugLogger.enable('PeerPigeonMesh');
|
|
26
|
+
// DebugLogger.enable('SignalingHandler');
|
|
27
|
+
// DebugLogger.enable('WebDHT');
|
|
28
|
+
|
|
29
|
+
// 4. Disable all debugging (default state - no console output)
|
|
30
|
+
// DebugLogger.disableAll();
|
|
31
|
+
|
|
32
|
+
// 5. Disable specific modules
|
|
33
|
+
// DebugLogger.disable('DistributedStorageManager');
|
|
34
|
+
// DebugLogger.disable('CryptoManager');
|
|
35
|
+
|
|
36
|
+
// 6. Configure using options object
|
|
37
|
+
DebugLogger.configure({
|
|
38
|
+
// First disable all, then enable specific ones
|
|
39
|
+
disableAll: true,
|
|
40
|
+
enable: [
|
|
41
|
+
'PeerPigeonMesh',
|
|
42
|
+
'GossipManager',
|
|
43
|
+
'ConnectionManager'
|
|
44
|
+
]
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// ============================================================================
|
|
48
|
+
// Create and Use PeerPigeon with Debug Configuration
|
|
49
|
+
// ============================================================================
|
|
50
|
+
|
|
51
|
+
const mesh = new PeerPigeonMesh({
|
|
52
|
+
signalingUrl: 'ws://localhost:3000',
|
|
53
|
+
minPeers: 2,
|
|
54
|
+
maxPeers: 10,
|
|
55
|
+
autoConnect: true
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// ============================================================================
|
|
59
|
+
// Runtime Debug Control Examples
|
|
60
|
+
// ============================================================================
|
|
61
|
+
|
|
62
|
+
// You can change debug settings at runtime
|
|
63
|
+
setTimeout(() => {
|
|
64
|
+
console.log('Current debug state:', DebugLogger.getState());
|
|
65
|
+
|
|
66
|
+
// Enable more debugging after 5 seconds
|
|
67
|
+
DebugLogger.enable('WebDHT');
|
|
68
|
+
DebugLogger.enable('DistributedStorageManager');
|
|
69
|
+
|
|
70
|
+
console.log('Available modules:', DebugLogger.getModules());
|
|
71
|
+
}, 5000);
|
|
72
|
+
|
|
73
|
+
// ============================================================================
|
|
74
|
+
// Event Handlers (these will show debug output based on configuration)
|
|
75
|
+
// ============================================================================
|
|
76
|
+
|
|
77
|
+
mesh.on('ready', (peerId) => {
|
|
78
|
+
console.log(`๐ Mesh ready! Peer ID: ${peerId}`);
|
|
79
|
+
|
|
80
|
+
// Test different functionality that will show debug output
|
|
81
|
+
mesh.broadcastMessage('Hello from debug example!');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
mesh.on('peerConnected', (peerId) => {
|
|
85
|
+
console.log(`๐ Peer connected: ${peerId}`);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
mesh.on('messageReceived', (message) => {
|
|
89
|
+
console.log('๐จ Message received:', message);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Start the mesh
|
|
93
|
+
mesh.connect();
|
|
94
|
+
|
|
95
|
+
// ============================================================================
|
|
96
|
+
// Example Debug Output Control in Production
|
|
97
|
+
// ============================================================================
|
|
98
|
+
|
|
99
|
+
// For production, you might want to conditionally enable debugging
|
|
100
|
+
const isDevelopment = process.env.NODE_ENV === 'development';
|
|
101
|
+
const debugFromQuery = new URLSearchParams(window?.location?.search || '').get('debug');
|
|
102
|
+
|
|
103
|
+
if (isDevelopment || debugFromQuery) {
|
|
104
|
+
// Enable debugging in development or when ?debug=true
|
|
105
|
+
if (debugFromQuery) {
|
|
106
|
+
// Parse debug modules from query: ?debug=GossipManager,ConnectionManager
|
|
107
|
+
const modules = debugFromQuery.split(',').filter(m => m && m !== 'true');
|
|
108
|
+
if (modules.length > 0) {
|
|
109
|
+
DebugLogger.enableModules(modules);
|
|
110
|
+
} else {
|
|
111
|
+
DebugLogger.enableAll();
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
DebugLogger.enableAll();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
console.log('๐ Debug mode enabled:', DebugLogger.getState());
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ============================================================================
|
|
121
|
+
// Available Modules for Debugging
|
|
122
|
+
// ============================================================================
|
|
123
|
+
|
|
124
|
+
/*
|
|
125
|
+
Available debug modules:
|
|
126
|
+
|
|
127
|
+
Core Components:
|
|
128
|
+
- PeerPigeonMesh - Main mesh instance and lifecycle
|
|
129
|
+
- ConnectionManager - Peer connection management
|
|
130
|
+
- PeerConnection - Individual WebRTC connections
|
|
131
|
+
- SignalingHandler - Signaling message processing
|
|
132
|
+
- SignalingClient - WebSocket signaling client
|
|
133
|
+
|
|
134
|
+
Networking & Discovery:
|
|
135
|
+
- GossipManager - Message propagation and gossip protocol
|
|
136
|
+
- PeerDiscovery - Peer discovery and announcement
|
|
137
|
+
- MeshOptimizer - Network topology optimization
|
|
138
|
+
- EvictionManager - Peer eviction strategies
|
|
139
|
+
|
|
140
|
+
Data & Storage:
|
|
141
|
+
- WebDHT - Distributed hash table operations
|
|
142
|
+
- DistributedStorageManager - P2P storage layer
|
|
143
|
+
- StorageManager - Local storage management
|
|
144
|
+
|
|
145
|
+
Security & Media:
|
|
146
|
+
- CryptoManager - End-to-end encryption
|
|
147
|
+
- MediaManager - Audio/video stream management
|
|
148
|
+
|
|
149
|
+
Utilities:
|
|
150
|
+
- CleanupManager - Resource cleanup and garbage collection
|
|
151
|
+
- EnvironmentDetector - Runtime environment detection
|
|
152
|
+
- EventEmitter - Event system
|
|
153
|
+
- TimerUtils - Timer utilities
|
|
154
|
+
|
|
155
|
+
Usage patterns:
|
|
156
|
+
|
|
157
|
+
// Debug everything
|
|
158
|
+
DebugLogger.enableAll();
|
|
159
|
+
|
|
160
|
+
// Debug networking only
|
|
161
|
+
DebugLogger.enableModules(['GossipManager', 'ConnectionManager', 'PeerConnection']);
|
|
162
|
+
|
|
163
|
+
// Debug storage only
|
|
164
|
+
DebugLogger.enableModules(['WebDHT', 'DistributedStorageManager', 'StorageManager']);
|
|
165
|
+
|
|
166
|
+
// Debug security only
|
|
167
|
+
DebugLogger.enableModules(['CryptoManager']);
|
|
168
|
+
|
|
169
|
+
// Production - no debugging (default)
|
|
170
|
+
DebugLogger.disableAll();
|
|
171
|
+
*/
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* PeerPigeon Storage Spaces Test
|
|
5
|
+
*
|
|
6
|
+
* This example demonstrates the new storage space separation feature:
|
|
7
|
+
* - Private space: Only owner can read/write, encrypted
|
|
8
|
+
* - Public space: Anyone can read, only owner can write
|
|
9
|
+
* - Frozen space: Immutable once set, anyone can read
|
|
10
|
+
*
|
|
11
|
+
* Key protection: prevents overwrites across different spaces
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { PeerPigeonMesh } from '../../src/PeerPigeonMesh.js';
|
|
15
|
+
|
|
16
|
+
class StorageSpacesTest {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.mesh = null;
|
|
19
|
+
this.storage = null;
|
|
20
|
+
this.testResults = [];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async init() {
|
|
24
|
+
console.log('๐ Initializing PeerPigeon Mesh with Storage Spaces...');
|
|
25
|
+
|
|
26
|
+
// Initialize mesh with all features enabled
|
|
27
|
+
this.mesh = new PeerPigeonMesh({
|
|
28
|
+
enableWebDHT: true,
|
|
29
|
+
enableCrypto: true,
|
|
30
|
+
enableDistributedStorage: true
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
await this.mesh.init();
|
|
34
|
+
this.storage = this.mesh.distributedStorage;
|
|
35
|
+
|
|
36
|
+
console.log(`โ
Mesh initialized with peer ID: ${this.mesh.peerId.substring(0, 16)}...`);
|
|
37
|
+
console.log(`๐ฆ Storage enabled: ${this.storage.isEnabled()}`);
|
|
38
|
+
console.log(`๐ง Space enforcement: ${this.storage.config.spaceEnforcement}`);
|
|
39
|
+
console.log('');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async runTest(testName, testFn) {
|
|
43
|
+
console.log(`๐งช Running test: ${testName}`);
|
|
44
|
+
try {
|
|
45
|
+
await testFn();
|
|
46
|
+
console.log(`โ
Test passed: ${testName}`);
|
|
47
|
+
this.testResults.push({ name: testName, status: 'PASS' });
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error(`โ Test failed: ${testName} - ${error.message}`);
|
|
50
|
+
this.testResults.push({ name: testName, status: 'FAIL', error: error.message });
|
|
51
|
+
}
|
|
52
|
+
console.log('');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async testPrivateSpace() {
|
|
56
|
+
await this.runTest('Private Space Storage', async () => {
|
|
57
|
+
const key = 'user-profile';
|
|
58
|
+
const value = { name: 'Alice', secret: 'my-password' };
|
|
59
|
+
|
|
60
|
+
// Store in private space (default)
|
|
61
|
+
await this.storage.store(key, value);
|
|
62
|
+
|
|
63
|
+
// Should be accessible to owner
|
|
64
|
+
const retrieved = await this.storage.retrieve(key);
|
|
65
|
+
if (JSON.stringify(retrieved) !== JSON.stringify(value)) {
|
|
66
|
+
throw new Error('Private data not properly stored/retrieved');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
console.log(' โ Private space data stored and retrieved by owner');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
await this.runTest('Private Space Explicit', async () => {
|
|
73
|
+
const key = 'explicit-private';
|
|
74
|
+
const value = { confidential: 'data' };
|
|
75
|
+
|
|
76
|
+
// Store explicitly in private space
|
|
77
|
+
await this.storage.store(key, value, { space: 'private' });
|
|
78
|
+
|
|
79
|
+
const retrieved = await this.storage.retrieve('private:explicit-private');
|
|
80
|
+
if (JSON.stringify(retrieved) !== JSON.stringify(value)) {
|
|
81
|
+
throw new Error('Explicit private space data not working');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
console.log(' โ Explicit private space storage working');
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async testPublicSpace() {
|
|
89
|
+
await this.runTest('Public Space Storage', async () => {
|
|
90
|
+
const key = 'app-config';
|
|
91
|
+
const value = { version: '1.0.0', features: ['chat', 'files'] };
|
|
92
|
+
|
|
93
|
+
// Store in public space
|
|
94
|
+
await this.storage.store(key, value, { space: 'public' });
|
|
95
|
+
|
|
96
|
+
// Retrieve with space prefix
|
|
97
|
+
const retrieved = await this.storage.retrieve('public:app-config');
|
|
98
|
+
if (JSON.stringify(retrieved) !== JSON.stringify(value)) {
|
|
99
|
+
throw new Error('Public space data not properly stored/retrieved');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
console.log(' โ Public space data stored and retrieved');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
await this.runTest('Public Space Legacy', async () => {
|
|
106
|
+
const key = 'legacy-public';
|
|
107
|
+
const value = { public: true };
|
|
108
|
+
|
|
109
|
+
// Store using legacy isPublic option
|
|
110
|
+
await this.storage.store(key, value, { isPublic: true });
|
|
111
|
+
|
|
112
|
+
const retrieved = await this.storage.retrieve(key);
|
|
113
|
+
if (JSON.stringify(retrieved) !== JSON.stringify(value)) {
|
|
114
|
+
throw new Error('Legacy public storage not working');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
console.log(' โ Legacy public storage compatibility working');
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async testFrozenSpace() {
|
|
122
|
+
await this.runTest('Frozen Space Storage', async () => {
|
|
123
|
+
const key = 'immutable-data';
|
|
124
|
+
const value = { constant: 'never-changes', timestamp: Date.now() };
|
|
125
|
+
|
|
126
|
+
// Store in frozen space
|
|
127
|
+
await this.storage.store(key, value, { space: 'frozen' });
|
|
128
|
+
|
|
129
|
+
const retrieved = await this.storage.retrieve('frozen:immutable-data');
|
|
130
|
+
if (JSON.stringify(retrieved) !== JSON.stringify(value)) {
|
|
131
|
+
throw new Error('Frozen space data not properly stored/retrieved');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
console.log(' โ Frozen space data stored and retrieved');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
await this.runTest('Frozen Space Write Protection', async () => {
|
|
138
|
+
const key = 'immutable-data';
|
|
139
|
+
|
|
140
|
+
try {
|
|
141
|
+
// Try to overwrite frozen data in a different space - should fail
|
|
142
|
+
await this.storage.store(key, { modified: 'data' }, { space: 'private' });
|
|
143
|
+
throw new Error('Frozen space allowed overwrite - this should not happen');
|
|
144
|
+
} catch (error) {
|
|
145
|
+
if (error.message.includes('already exists in space') || error.message.includes('Write access denied')) {
|
|
146
|
+
console.log(' โ Frozen space properly protected from overwrites');
|
|
147
|
+
} else {
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async testSpaceSeparation() {
|
|
155
|
+
await this.runTest('Space Separation Protection', async () => {
|
|
156
|
+
const baseKey = 'protected-key';
|
|
157
|
+
|
|
158
|
+
// Store in private space first
|
|
159
|
+
await this.storage.store(baseKey, { space: 'private', data: 'secret' });
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
// Try to store same base key in public space - should fail
|
|
163
|
+
await this.storage.store(baseKey, { space: 'public', data: 'public' }, { space: 'public' });
|
|
164
|
+
throw new Error('Space separation failed - allowed cross-space overwrite');
|
|
165
|
+
} catch (error) {
|
|
166
|
+
if (error.message.includes('already exists in space')) {
|
|
167
|
+
console.log(' โ Space separation properly prevents cross-space overwrites');
|
|
168
|
+
} else {
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
await this.runTest('Different Base Keys Work', async () => {
|
|
175
|
+
// These should all work as they have different base keys
|
|
176
|
+
await this.storage.store('key1', { data: 'private' }); // private:key1
|
|
177
|
+
await this.storage.store('key2', { data: 'public' }, { space: 'public' }); // public:key2
|
|
178
|
+
await this.storage.store('key3', { data: 'frozen' }, { space: 'frozen' }); // frozen:key3
|
|
179
|
+
|
|
180
|
+
const private1 = await this.storage.retrieve('key1');
|
|
181
|
+
const public2 = await this.storage.retrieve('public:key2');
|
|
182
|
+
const frozen3 = await this.storage.retrieve('frozen:key3');
|
|
183
|
+
|
|
184
|
+
if (!private1 || !public2 || !frozen3) {
|
|
185
|
+
throw new Error('Different base keys not working properly');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
console.log(' โ Different base keys work in all spaces');
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async testSpaceAwareRetrieval() {
|
|
193
|
+
await this.runTest('Space-Aware Retrieval', async () => {
|
|
194
|
+
// Store data in specific spaces
|
|
195
|
+
await this.storage.store('test-key', { space: 'private' }); // private:test-key
|
|
196
|
+
await this.storage.store('other-key', { space: 'public' }, { space: 'public' }); // public:other-key
|
|
197
|
+
|
|
198
|
+
// Test retrieval with and without space prefixes
|
|
199
|
+
const privateData = await this.storage.retrieve('private:test-key');
|
|
200
|
+
const publicData = await this.storage.retrieve('public:other-key');
|
|
201
|
+
|
|
202
|
+
if (!privateData || !publicData) {
|
|
203
|
+
throw new Error('Space-aware retrieval not working');
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Test automatic space detection
|
|
207
|
+
const autoPrivate = await this.storage.retrieve('test-key'); // Should find private:test-key
|
|
208
|
+
if (!autoPrivate) {
|
|
209
|
+
throw new Error('Automatic space detection not working');
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
console.log(' โ Space-aware retrieval working correctly');
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
async testDisableSpaceEnforcement() {
|
|
217
|
+
await this.runTest('Disable Space Enforcement', async () => {
|
|
218
|
+
// Disable space enforcement
|
|
219
|
+
this.storage.config.spaceEnforcement = false;
|
|
220
|
+
|
|
221
|
+
try {
|
|
222
|
+
// This should work now
|
|
223
|
+
await this.storage.store('enforcement-test', { data: 'private' });
|
|
224
|
+
await this.storage.store('enforcement-test', { data: 'public' }, { space: 'public' });
|
|
225
|
+
|
|
226
|
+
console.log(' โ Space enforcement can be disabled');
|
|
227
|
+
} finally {
|
|
228
|
+
// Re-enable for other tests
|
|
229
|
+
this.storage.config.spaceEnforcement = true;
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async runAllTests() {
|
|
235
|
+
console.log('๐งช Starting Storage Spaces Test Suite');
|
|
236
|
+
console.log('='.repeat(60));
|
|
237
|
+
console.log('');
|
|
238
|
+
|
|
239
|
+
await this.testPrivateSpace();
|
|
240
|
+
await this.testPublicSpace();
|
|
241
|
+
await this.testFrozenSpace();
|
|
242
|
+
await this.testSpaceSeparation();
|
|
243
|
+
await this.testSpaceAwareRetrieval();
|
|
244
|
+
await this.testDisableSpaceEnforcement();
|
|
245
|
+
|
|
246
|
+
this.printSummary();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
printSummary() {
|
|
250
|
+
console.log('='.repeat(60));
|
|
251
|
+
console.log('๐ STORAGE SPACES TEST SUMMARY');
|
|
252
|
+
console.log('='.repeat(60));
|
|
253
|
+
|
|
254
|
+
const passed = this.testResults.filter(r => r.status === 'PASS').length;
|
|
255
|
+
const failed = this.testResults.filter(r => r.status === 'FAIL').length;
|
|
256
|
+
const total = this.testResults.length;
|
|
257
|
+
|
|
258
|
+
console.log(`Total Tests: ${total}`);
|
|
259
|
+
console.log(`โ
Passed: ${passed}`);
|
|
260
|
+
console.log(`โ Failed: ${failed}`);
|
|
261
|
+
console.log(`Success Rate: ${((passed / total) * 100).toFixed(1)}%`);
|
|
262
|
+
console.log('');
|
|
263
|
+
|
|
264
|
+
if (failed > 0) {
|
|
265
|
+
console.log('Failed Tests:');
|
|
266
|
+
this.testResults.filter(r => r.status === 'FAIL').forEach(result => {
|
|
267
|
+
console.log(` โ ${result.name}: ${result.error}`);
|
|
268
|
+
});
|
|
269
|
+
console.log('');
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (passed === total) {
|
|
273
|
+
console.log('๐ All tests passed! Storage spaces are working perfectly.');
|
|
274
|
+
} else {
|
|
275
|
+
console.log('โ ๏ธ Some tests failed. Please review the errors above.');
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
console.log('');
|
|
279
|
+
console.log('๐ Storage Spaces Features Tested:');
|
|
280
|
+
console.log(' โข Private space (encrypted, owner-only access)');
|
|
281
|
+
console.log(' โข Public space (readable by all, owner-writable)');
|
|
282
|
+
console.log(' โข Frozen space (immutable, readable by all)');
|
|
283
|
+
console.log(' โข Cross-space overwrite protection');
|
|
284
|
+
console.log(' โข Space-aware key retrieval');
|
|
285
|
+
console.log(' โข Legacy compatibility');
|
|
286
|
+
console.log(' โข Space enforcement toggle');
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
async cleanup() {
|
|
290
|
+
if (this.mesh) {
|
|
291
|
+
console.log('๐งน Cleaning up test environment...');
|
|
292
|
+
try {
|
|
293
|
+
await this.storage.clear();
|
|
294
|
+
console.log('โ
Test data cleared');
|
|
295
|
+
} catch (error) {
|
|
296
|
+
console.warn('โ ๏ธ Failed to clear test data:', error.message);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Main execution
|
|
303
|
+
async function main() {
|
|
304
|
+
const test = new StorageSpacesTest();
|
|
305
|
+
|
|
306
|
+
try {
|
|
307
|
+
await test.init();
|
|
308
|
+
await test.runAllTests();
|
|
309
|
+
} catch (error) {
|
|
310
|
+
console.error('๐ฅ Test suite failed to run:', error);
|
|
311
|
+
} finally {
|
|
312
|
+
await test.cleanup();
|
|
313
|
+
process.exit(0);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Handle graceful shutdown
|
|
318
|
+
process.on('SIGINT', async () => {
|
|
319
|
+
console.log('\n๐ Received SIGINT, shutting down gracefully...');
|
|
320
|
+
process.exit(0);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
process.on('SIGTERM', async () => {
|
|
324
|
+
console.log('\n๐ Received SIGTERM, shutting down gracefully...');
|
|
325
|
+
process.exit(0);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// Run the test suite
|
|
329
|
+
main().catch(console.error);
|
package/index.js
CHANGED
|
@@ -5,6 +5,9 @@ export { SignalingClient } from './src/SignalingClient.js';
|
|
|
5
5
|
export { WebDHT } from './src/WebDHT.js';
|
|
6
6
|
export { DistributedStorageManager } from './src/DistributedStorageManager.js';
|
|
7
7
|
|
|
8
|
+
// Export debug logger for controlling console output
|
|
9
|
+
export { default as DebugLogger } from './src/DebugLogger.js';
|
|
10
|
+
|
|
8
11
|
// Export environment detection utilities
|
|
9
12
|
export {
|
|
10
13
|
EnvironmentDetector,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "peerpigeon",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "WebRTC-based peer-to-peer mesh networking library with intelligent routing and signaling server",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -10,13 +10,17 @@
|
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
|
-
"dev": "
|
|
13
|
+
"dev": "concurrently \"npm run server\" \"npm run dev:http\" --names \"signaling,http\" --prefix-colors \"blue,green\"",
|
|
14
|
+
"dev:http": "node dev-server.js",
|
|
14
15
|
"start": "node websocket-server/server.js",
|
|
15
16
|
"server": "node websocket-server/server.js",
|
|
16
|
-
"lint": "
|
|
17
|
-
"lint:fix": "eslint src/ examples/ websocket-server/ --ext .js --fix",
|
|
18
|
-
"test": "node
|
|
19
|
-
"test:storage": "node examples/
|
|
17
|
+
"lint": "node -c src/*.js examples/**/*.js websocket-server/*.js",
|
|
18
|
+
"lint:fix": "eslint --cache --cache-location .eslintcache src/ examples/ websocket-server/ --ext .js --fix",
|
|
19
|
+
"test": "node test/test-reporter.js",
|
|
20
|
+
"test:storage": "node examples/node/storage-test.js",
|
|
21
|
+
"test:browser": "node test/browser-integration-test.js",
|
|
22
|
+
"test:browser:headless": "HEADLESS=true node test/browser-integration-test.js",
|
|
23
|
+
"test:legacy": "npm run test:storage && npm run test:browser:headless",
|
|
20
24
|
"ci": "npm run lint && npm run test",
|
|
21
25
|
"prepublishOnly": "npm run ci"
|
|
22
26
|
},
|
|
@@ -63,11 +67,12 @@
|
|
|
63
67
|
"yamljs": "^0.3.0"
|
|
64
68
|
},
|
|
65
69
|
"devDependencies": {
|
|
70
|
+
"concurrently": "^9.2.0",
|
|
66
71
|
"eslint": "^8.57.1",
|
|
67
72
|
"eslint-config-standard": "^17.1.0",
|
|
68
|
-
"
|
|
73
|
+
"express": "^4.19.2",
|
|
69
74
|
"jsdoc": "^4.0.4",
|
|
70
|
-
"
|
|
75
|
+
"puppeteer": "^22.0.0"
|
|
71
76
|
},
|
|
72
77
|
"engines": {
|
|
73
78
|
"node": ">=14.0.0"
|