@ruvector/edge-net 0.1.1 → 0.1.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.
- package/README.md +119 -0
- package/cli.js +17 -0
- package/join.html +985 -0
- package/join.js +1333 -0
- package/network.js +820 -0
- package/networks.js +817 -0
- package/package.json +15 -3
- package/webrtc.js +964 -0
package/README.md
CHANGED
|
@@ -29,12 +29,14 @@ A distributed computing platform that enables collective resource sharing for AI
|
|
|
29
29
|
|
|
30
30
|
## Table of Contents
|
|
31
31
|
|
|
32
|
+
- [WebRTC P2P Networking](#webrtc-p2p-networking)
|
|
32
33
|
- [What is Edge-Net?](#what-is-edge-net)
|
|
33
34
|
- [Key Features](#key-features)
|
|
34
35
|
- [Quick Start](#quick-start)
|
|
35
36
|
- [How It Works](#how-it-works)
|
|
36
37
|
- [AI Computing Tasks](#ai-computing-tasks)
|
|
37
38
|
- [Pi-Key Identity System](#pi-key-identity-system)
|
|
39
|
+
- [Security Architecture](#security-architecture)
|
|
38
40
|
- [Self-Optimization](#self-optimization)
|
|
39
41
|
- [Tutorials](#tutorials)
|
|
40
42
|
- [API Reference](#api-reference)
|
|
@@ -45,6 +47,123 @@ A distributed computing platform that enables collective resource sharing for AI
|
|
|
45
47
|
|
|
46
48
|
---
|
|
47
49
|
|
|
50
|
+
## WebRTC P2P Networking
|
|
51
|
+
|
|
52
|
+
Edge-net implements **real WebRTC peer-to-peer connectivity** for direct browser-to-browser communication, with Google Cloud genesis nodes for global coordination.
|
|
53
|
+
|
|
54
|
+
### P2P Architecture
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
┌─────────────────────────────────────────────────────────────────────────────┐
|
|
58
|
+
│ WEBRTC P2P NETWORK ARCHITECTURE │
|
|
59
|
+
├─────────────────────────────────────────────────────────────────────────────┤
|
|
60
|
+
│ │
|
|
61
|
+
│ ┌─────────────┐ Signaling ┌─────────────┐ │
|
|
62
|
+
│ │ Browser A │◄──────────────────►│ Relay │ (WebSocket) │
|
|
63
|
+
│ │ (Node 1) │ offer/answer │ Server │ │
|
|
64
|
+
│ └──────┬──────┘ ICE candidates └─────────────┘ │
|
|
65
|
+
│ │ │
|
|
66
|
+
│ │ WebRTC Data Channel (DTLS encrypted, direct P2P) │
|
|
67
|
+
│ │ │
|
|
68
|
+
│ ▼ │
|
|
69
|
+
│ ┌─────────────┐ ┌─────────────┐ │
|
|
70
|
+
│ │ Browser B │◄──────────────────►│ Browser C │ │
|
|
71
|
+
│ │ (Node 2) │ Direct P2P │ (Node 3) │ │
|
|
72
|
+
│ └─────────────┘ └─────────────┘ │
|
|
73
|
+
│ │
|
|
74
|
+
│ Genesis Nodes (Google Cloud): │
|
|
75
|
+
│ • us-central1 • europe-west1 • asia-east1 │
|
|
76
|
+
│ │
|
|
77
|
+
└─────────────────────────────────────────────────────────────────────────────┘
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### WebRTC Features
|
|
81
|
+
|
|
82
|
+
| Feature | Description |
|
|
83
|
+
|---------|-------------|
|
|
84
|
+
| **Real P2P Data Channels** | Direct browser-to-browser communication |
|
|
85
|
+
| **ICE/STUN/TURN** | NAT traversal with Google STUN servers |
|
|
86
|
+
| **DTLS Encryption** | End-to-end encrypted data channels |
|
|
87
|
+
| **WebSocket Signaling** | Relay server for connection establishment |
|
|
88
|
+
| **Automatic Reconnection** | Self-healing connections with exponential backoff |
|
|
89
|
+
| **Heartbeat Monitoring** | Connection health with 5s heartbeat |
|
|
90
|
+
| **Connection Quality Metrics** | Latency, throughput, packet loss tracking |
|
|
91
|
+
| **Fallback Simulation** | Offline mode when signaling unavailable |
|
|
92
|
+
|
|
93
|
+
### Genesis Nodes (Google Cloud)
|
|
94
|
+
|
|
95
|
+
| Region | Host | Purpose |
|
|
96
|
+
|--------|------|---------|
|
|
97
|
+
| **us-central1** | edge-net-genesis-us.ruvector.dev | Americas coordination |
|
|
98
|
+
| **europe-west1** | edge-net-genesis-eu.ruvector.dev | EMEA coordination |
|
|
99
|
+
| **asia-east1** | edge-net-genesis-asia.ruvector.dev | APAC coordination |
|
|
100
|
+
|
|
101
|
+
### WebRTC Security
|
|
102
|
+
|
|
103
|
+
| Security Feature | Implementation |
|
|
104
|
+
|-----------------|----------------|
|
|
105
|
+
| **DTLS 1.2+** | Data channel encryption |
|
|
106
|
+
| **SCTP** | Reliable ordered delivery |
|
|
107
|
+
| **Origin Validation** | CORS whitelist for browser connections |
|
|
108
|
+
| **Rate Limiting** | 100 msg/min per node |
|
|
109
|
+
| **Message Size Limits** | 64KB max message size |
|
|
110
|
+
| **Connection Limits** | 5 connections per IP |
|
|
111
|
+
| **Heartbeat Timeout** | 30s stale connection cleanup |
|
|
112
|
+
| **SDP Sanitization** | Prevent injection attacks |
|
|
113
|
+
|
|
114
|
+
### Relay Server
|
|
115
|
+
|
|
116
|
+
The relay server (`relay/index.js`) handles:
|
|
117
|
+
|
|
118
|
+
```javascript
|
|
119
|
+
// WebRTC signaling message types
|
|
120
|
+
'webrtc_offer' // Relay SDP offer to target peer
|
|
121
|
+
'webrtc_answer' // Relay SDP answer back
|
|
122
|
+
'webrtc_ice' // Relay ICE candidates
|
|
123
|
+
'webrtc_disconnect' // Notify peer of disconnection
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Testing & Benchmarks
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
cd examples/edge-net/relay
|
|
130
|
+
npm install
|
|
131
|
+
node index.js &
|
|
132
|
+
|
|
133
|
+
cd ../test
|
|
134
|
+
npm install
|
|
135
|
+
|
|
136
|
+
# Run P2P connectivity test
|
|
137
|
+
npm test
|
|
138
|
+
|
|
139
|
+
# Run security audit
|
|
140
|
+
npm run security
|
|
141
|
+
|
|
142
|
+
# Run latency benchmark
|
|
143
|
+
npm run benchmark
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Browser Integration
|
|
147
|
+
|
|
148
|
+
```javascript
|
|
149
|
+
// join.html implements real WebRTC
|
|
150
|
+
const WEBRTC_CONFIG = {
|
|
151
|
+
iceServers: [
|
|
152
|
+
{ urls: 'stun:stun.l.google.com:19302' },
|
|
153
|
+
{ urls: 'stun:stun1.l.google.com:19302' },
|
|
154
|
+
]
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// Connects to relay server
|
|
158
|
+
const RELAY_URL = 'ws://localhost:8080';
|
|
159
|
+
|
|
160
|
+
// Real peer connections via RTCPeerConnection
|
|
161
|
+
const pc = new RTCPeerConnection(WEBRTC_CONFIG);
|
|
162
|
+
const channel = pc.createDataChannel('edge-net');
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
48
167
|
## What is Edge-Net?
|
|
49
168
|
|
|
50
169
|
Edge-net creates a **collective computing network** where participants share idle browser resources to power distributed AI workloads. Think of it as a cooperative where:
|
package/cli.js
CHANGED
|
@@ -109,6 +109,7 @@ function printHelp() {
|
|
|
109
109
|
|
|
110
110
|
${c('bold', 'COMMANDS:')}
|
|
111
111
|
${c('green', 'start')} Start an edge-net node in the terminal
|
|
112
|
+
${c('green', 'join')} Join network with public key (multi-contributor support)
|
|
112
113
|
${c('green', 'benchmark')} Run performance benchmarks
|
|
113
114
|
${c('green', 'info')} Show package and WASM information
|
|
114
115
|
${c('green', 'demo')} Run interactive demonstration
|
|
@@ -119,6 +120,9 @@ ${c('bold', 'EXAMPLES:')}
|
|
|
119
120
|
${c('dim', '# Start a node')}
|
|
120
121
|
$ npx @ruvector/edge-net start
|
|
121
122
|
|
|
123
|
+
${c('dim', '# Join with new identity (multi-contributor)')}
|
|
124
|
+
$ npx @ruvector/edge-net join --generate
|
|
125
|
+
|
|
122
126
|
${c('dim', '# Run benchmarks')}
|
|
123
127
|
$ npx @ruvector/edge-net benchmark
|
|
124
128
|
|
|
@@ -408,6 +412,16 @@ async function runDemo() {
|
|
|
408
412
|
console.log(`${c('dim', 'For full P2P features, run in a browser environment.')}`);
|
|
409
413
|
}
|
|
410
414
|
|
|
415
|
+
async function runJoin() {
|
|
416
|
+
// Delegate to join.js
|
|
417
|
+
const { spawn } = await import('child_process');
|
|
418
|
+
const args = process.argv.slice(3);
|
|
419
|
+
const child = spawn('node', [join(__dirname, 'join.js'), ...args], {
|
|
420
|
+
stdio: 'inherit'
|
|
421
|
+
});
|
|
422
|
+
child.on('close', (code) => process.exit(code));
|
|
423
|
+
}
|
|
424
|
+
|
|
411
425
|
// Main
|
|
412
426
|
const command = process.argv[2] || 'help';
|
|
413
427
|
|
|
@@ -415,6 +429,9 @@ switch (command) {
|
|
|
415
429
|
case 'start':
|
|
416
430
|
startNode();
|
|
417
431
|
break;
|
|
432
|
+
case 'join':
|
|
433
|
+
runJoin();
|
|
434
|
+
break;
|
|
418
435
|
case 'benchmark':
|
|
419
436
|
case 'bench':
|
|
420
437
|
runBenchmark();
|