peerpigeon 1.1.0 → 1.1.1

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.
@@ -0,0 +1,132 @@
1
+ # Cloud Deployment Guide
2
+
3
+ ## Bootstrap Hub Hierarchy
4
+
5
+ For cloud deployments, PeerPigeon uses a hierarchical bootstrap configuration to ensure reliable hub mesh connectivity:
6
+
7
+ ### Hub Roles
8
+
9
+ 1. **Hub B (`pigeonhub-b.fly.dev`)** - Primary Bootstrap Hub
10
+ - Does not connect to any other hubs on startup
11
+ - Acts as the primary bootstrap for all other hubs
12
+ - Should be the most stable/reliable deployment
13
+
14
+ 2. **Hub C (`pigeonhub-c.fly.dev`)** - Secondary Bootstrap Hub
15
+ - Bootstraps from Hub B: `wss://pigeonhub-b.fly.dev`
16
+ - Acts as a secondary bootstrap for other hubs
17
+ - Provides redundancy if Hub B is unreachable
18
+
19
+ 3. **Other Hubs** - Client Hubs
20
+ - Bootstrap from both Hub B and Hub C: `wss://pigeonhub-b.fly.dev`, `wss://pigeonhub-c.fly.dev`
21
+ - Connect to the hub mesh through either bootstrap hub
22
+ - Automatically discover other hubs through the mesh
23
+
24
+ ### Automatic Configuration
25
+
26
+ The `scripts/start-hub.js` script automatically detects the hostname and configures bootstraps:
27
+
28
+ ```bash
29
+ # Hub B (primary) - no bootstraps
30
+ HOSTNAME=pigeonhub-b.fly.dev npm run hub
31
+
32
+ # Hub C (secondary) - bootstraps from B
33
+ HOSTNAME=pigeonhub-c.fly.dev npm run hub
34
+
35
+ # Other hubs - bootstrap from B and C
36
+ HOSTNAME=pigeonhub-d.fly.dev npm run hub
37
+ ```
38
+
39
+ ### Manual Override
40
+
41
+ You can override the automatic configuration with the `BOOTSTRAP_HUBS` environment variable:
42
+
43
+ ```bash
44
+ BOOTSTRAP_HUBS=wss://custom-hub.example.com npm run hub
45
+ ```
46
+
47
+ ### Local Development
48
+
49
+ For local development, use explicit bootstrap configuration:
50
+
51
+ ```bash
52
+ # Primary hub (no bootstrap)
53
+ PORT=3000 npm run hub
54
+
55
+ # Secondary hubs (bootstrap from primary)
56
+ PORT=3001 BOOTSTRAP_HUBS=ws://localhost:3000 npm run hub
57
+ PORT=3002 BOOTSTRAP_HUBS=ws://localhost:3000 npm run hub
58
+ ```
59
+
60
+ ## Deployment Example (Fly.io)
61
+
62
+ ### Hub B Deployment
63
+
64
+ ```toml
65
+ # fly.toml for pigeonhub-b
66
+ app = "pigeonhub-b"
67
+
68
+ [build]
69
+ dockerfile = "Dockerfile"
70
+
71
+ [env]
72
+ PORT = "8080"
73
+ HOST = "0.0.0.0"
74
+
75
+ [[services]]
76
+ internal_port = 8080
77
+ protocol = "tcp"
78
+
79
+ [[services.ports]]
80
+ port = 80
81
+ handlers = ["http"]
82
+
83
+ [[services.ports]]
84
+ port = 443
85
+ handlers = ["tls", "http"]
86
+ ```
87
+
88
+ ### Hub C Deployment
89
+
90
+ ```toml
91
+ # fly.toml for pigeonhub-c
92
+ app = "pigeonhub-c"
93
+
94
+ [build]
95
+ dockerfile = "Dockerfile"
96
+
97
+ [env]
98
+ PORT = "8080"
99
+ HOST = "0.0.0.0"
100
+
101
+ [[services]]
102
+ internal_port = 8080
103
+ protocol = "tcp"
104
+
105
+ [[services.ports]]
106
+ port = 80
107
+ handlers = ["http"]
108
+
109
+ [[services.ports]]
110
+ port = 443
111
+ handlers = ["tls", "http"]
112
+ ```
113
+
114
+ ### Other Hub Deployments
115
+
116
+ Follow the same pattern as Hub C. The bootstrap configuration will be automatic based on the hostname.
117
+
118
+ ## Health Checks
119
+
120
+ All hubs expose health endpoints:
121
+
122
+ - `GET /health` - Basic health check
123
+ - `GET /hubs` - List of connected hubs in the mesh
124
+
125
+ Use these endpoints for monitoring and load balancer health checks.
126
+
127
+ ## WebSocket vs WSS
128
+
129
+ - **Local Development**: Use `ws://` protocol
130
+ - **Production/Cloud**: Use `wss://` protocol (secure WebSocket over TLS)
131
+
132
+ The hub script automatically uses `wss://` for fly.dev/fly.io hostnames.
@@ -43,8 +43,8 @@ class PeerPigeonTestSuite {
43
43
  enableDistributedStorage: true, // Enable distributed storage
44
44
  networkName: 'global', // Default network
45
45
  allowGlobalFallback: true, // Allow fallback to global network
46
- maxPeers: 4,
47
- minPeers: 2,
46
+ maxPeers: 6, // Increased for better cross-hub connectivity
47
+ minPeers: 3, // Increased for partition resistance
48
48
  autoConnect: true,
49
49
  autoDiscovery: true,
50
50
  evictionStrategy: true,
@@ -52,6 +52,20 @@ class PeerPigeonTestSuite {
52
52
  });
53
53
 
54
54
  await this.mesh.init();
55
+
56
+ // CRITICAL: Explicitly set connection manager limits to match test configuration
57
+ if (this.mesh.connectionManager) {
58
+ this.mesh.connectionManager.maxPeers = 6;
59
+ this.mesh.connectionManager.minPeers = 3;
60
+ }
61
+
62
+ // Ensure peer discovery settings match
63
+ if (this.mesh.peerDiscovery) {
64
+ this.mesh.peerDiscovery.maxPeers = 6;
65
+ this.mesh.peerDiscovery.minPeers = 3;
66
+ this.mesh.peerDiscovery.evictionStrategy = true;
67
+ this.mesh.peerDiscovery.xorRouting = true;
68
+ }
55
69
  this.setupEventListeners();
56
70
  this.setupUI();
57
71
  this.updatePeerInfo();
@@ -1607,11 +1621,18 @@ class PeerPigeonTestSuite {
1607
1621
  break;
1608
1622
  case 'disconnected':
1609
1623
  this.log('🔴 Disconnected from signaling server');
1610
- this.updateConnectionButtons(false);
1624
+ // Don't update buttons yet - reconnection will start automatically
1625
+ break;
1626
+ case 'reconnecting':
1627
+ this.log(`🔄 ${data.message}`);
1628
+ // Keep buttons disabled during reconnection
1611
1629
  break;
1612
1630
  case 'connecting':
1613
1631
  this.log('🟡 Connecting to signaling server...');
1614
1632
  break;
1633
+ case 'warning':
1634
+ this.log(`⚠️ ${data.message}`);
1635
+ break;
1615
1636
  case 'error':
1616
1637
  this.log(`❌ ${data.message}`, 'error');
1617
1638
  break;
@@ -1633,11 +1654,24 @@ class PeerPigeonTestSuite {
1633
1654
  if (data.from !== this.mesh.peerId) {
1634
1655
  console.log('🔍 DEBUG handleMessageReceived:', data);
1635
1656
 
1657
+ // Filter out system/signaling messages that shouldn't be displayed
1658
+ const filteredMessageTypes = ['signaling-relay', 'peer-announce-relay', 'bootstrap-keepalive',
1659
+ 'client-peer-announcement', 'cross-bootstrap-signaling', 'gossip',
1660
+ 'dht', 'eviction', 'renegotiation-offer', 'renegotiation-answer',
1661
+ 'signaling', 'binary'];
1662
+
1663
+ // Check if data.data exists (ConnectionManager format) and filter by type
1664
+ if (data.data && data.data.type && filteredMessageTypes.includes(data.data.type)) {
1665
+ console.log('🔇 Filtered system message type:', data.data.type);
1666
+ return;
1667
+ }
1668
+
1636
1669
  const messageType = data.direct ? 'direct' : 'broadcast';
1637
1670
  const sender = data.from.substring(0, 8) + '...';
1638
1671
 
1639
1672
  // Handle content properly - it might be an object or string
1640
- let content = data.content;
1673
+ // Support both data.content (gossip format) and data.data (ConnectionManager format)
1674
+ let content = data.content || (data.data && typeof data.data === 'string' ? data.data : null);
1641
1675
  let isEncrypted = false;
1642
1676
 
1643
1677
  if (typeof content === 'object') {
@@ -1650,12 +1684,26 @@ class PeerPigeonTestSuite {
1650
1684
  } else if (content.broadcast && content.data) {
1651
1685
  content = content.data;
1652
1686
  isEncrypted = content.encrypted || false;
1687
+ } else if (content.event) {
1688
+ // This is likely a media event or system message - don't display it
1689
+ console.log('🔇 Filtered system/media event message:', content);
1690
+ return;
1691
+ } else if (content.type && filteredMessageTypes.includes(content.type)) {
1692
+ // Filter system messages wrapped in content
1693
+ console.log('🔇 Filtered system message in content:', content.type);
1694
+ return;
1653
1695
  } else {
1654
1696
  // Fallback: stringify the object
1655
1697
  content = JSON.stringify(content);
1656
1698
  }
1657
1699
  }
1658
1700
 
1701
+ // Validate that we have actual content to display
1702
+ if (!content || (typeof content === 'string' && content.trim().length === 0)) {
1703
+ console.log('🔇 Filtered empty message from:', sender);
1704
+ return;
1705
+ }
1706
+
1659
1707
  // Also check if data.encrypted flag is set
1660
1708
  if (data.encrypted) {
1661
1709
  isEncrypted = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "peerpigeon",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
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",
@@ -31,6 +31,7 @@
31
31
  "test": "node test/browser-integration-test.js",
32
32
  "test:hub-mesh": "node test/test-hub-mesh.js",
33
33
  "test:cross-browser": "npm run build && node test/cross-browser-hub-test.js",
34
+ "test:cross-browser:5": "npm run build && node scripts/run-cross-browser-multiple.js",
34
35
  "test:simple-cross": "npm run build && node test/simple-cross-browser-test.js",
35
36
  "test:storage": "node examples/node/storage-test.js",
36
37
  "test:browser:visual": "HEADLESS=false node test/browser-integration-test.js",