@gethashd/bytecave-browser 1.0.27 → 1.0.28

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.
@@ -5726,19 +5726,40 @@ var P2PProtocolClient = class {
5726
5726
  } catch (e) {
5727
5727
  console.warn("[ByteCave P2P] Could not get peer info from peerStore:", e);
5728
5728
  }
5729
- console.log("[ByteCave P2P] Step 2: Opening protocol stream on existing connection...");
5729
+ console.log("[ByteCave P2P] Step 2: Checking if connection upgrade needed...");
5730
5730
  if (existingConns.length === 0) {
5731
5731
  throw new Error("No connection to peer - cannot open protocol stream");
5732
5732
  }
5733
- const connection = existingConns[0];
5734
- console.log("[ByteCave P2P] Using connection:", connection.remoteAddr.toString());
5733
+ let connection = existingConns[0];
5734
+ const isRelayCircuit = connection.remoteAddr.toString().includes("/p2p-circuit");
5735
+ console.log("[ByteCave P2P] Connection type:", isRelayCircuit ? "relay circuit (limited)" : "direct");
5736
+ console.log("[ByteCave P2P] Connection address:", connection.remoteAddr.toString());
5737
+ if (isRelayCircuit) {
5738
+ console.log("[ByteCave P2P] Waiting for DCUtR to upgrade relay circuit to direct WebRTC...");
5739
+ const upgradeStart = Date.now();
5740
+ const hasDirectConnection = await this.waitForDirectConnection(peerId, 5e3);
5741
+ const upgradeDuration = Date.now() - upgradeStart;
5742
+ if (!hasDirectConnection) {
5743
+ console.error("[ByteCave P2P] DCUtR upgrade failed after", upgradeDuration, "ms");
5744
+ throw new Error("Cannot use storage protocol - relay circuit upgrade to WebRTC failed");
5745
+ }
5746
+ console.log("[ByteCave P2P] DCUtR upgrade successful after", upgradeDuration, "ms");
5747
+ const directConns = this.node.getConnections(peerIdObj);
5748
+ const directConn = directConns.find((conn) => !conn.remoteAddr.toString().includes("/p2p-circuit"));
5749
+ if (!directConn) {
5750
+ throw new Error("DCUtR reported success but no direct connection found");
5751
+ }
5752
+ connection = directConn;
5753
+ console.log("[ByteCave P2P] Using direct connection:", connection.remoteAddr.toString());
5754
+ }
5755
+ console.log("[ByteCave P2P] Step 3: Opening protocol stream...");
5735
5756
  const streamStart = Date.now();
5736
5757
  let stream;
5737
5758
  try {
5738
5759
  console.log("[ByteCave P2P] Calling connection.newStream with protocol /bytecave/store/1.0.0...");
5739
5760
  stream = await connection.newStream("/bytecave/store/1.0.0");
5740
5761
  const streamDuration = Date.now() - streamStart;
5741
- console.log("[ByteCave P2P] Step 3: Protocol stream opened in", streamDuration, "ms");
5762
+ console.log("[ByteCave P2P] Step 4: Protocol stream opened in", streamDuration, "ms");
5742
5763
  console.log("[ByteCave P2P] Stream details:", {
5743
5764
  protocol: stream.protocol,
5744
5765
  direction: stream.direction,
package/dist/index.cjs CHANGED
@@ -5794,19 +5794,40 @@ var P2PProtocolClient = class {
5794
5794
  } catch (e) {
5795
5795
  console.warn("[ByteCave P2P] Could not get peer info from peerStore:", e);
5796
5796
  }
5797
- console.log("[ByteCave P2P] Step 2: Opening protocol stream on existing connection...");
5797
+ console.log("[ByteCave P2P] Step 2: Checking if connection upgrade needed...");
5798
5798
  if (existingConns.length === 0) {
5799
5799
  throw new Error("No connection to peer - cannot open protocol stream");
5800
5800
  }
5801
- const connection = existingConns[0];
5802
- console.log("[ByteCave P2P] Using connection:", connection.remoteAddr.toString());
5801
+ let connection = existingConns[0];
5802
+ const isRelayCircuit = connection.remoteAddr.toString().includes("/p2p-circuit");
5803
+ console.log("[ByteCave P2P] Connection type:", isRelayCircuit ? "relay circuit (limited)" : "direct");
5804
+ console.log("[ByteCave P2P] Connection address:", connection.remoteAddr.toString());
5805
+ if (isRelayCircuit) {
5806
+ console.log("[ByteCave P2P] Waiting for DCUtR to upgrade relay circuit to direct WebRTC...");
5807
+ const upgradeStart = Date.now();
5808
+ const hasDirectConnection = await this.waitForDirectConnection(peerId, 5e3);
5809
+ const upgradeDuration = Date.now() - upgradeStart;
5810
+ if (!hasDirectConnection) {
5811
+ console.error("[ByteCave P2P] DCUtR upgrade failed after", upgradeDuration, "ms");
5812
+ throw new Error("Cannot use storage protocol - relay circuit upgrade to WebRTC failed");
5813
+ }
5814
+ console.log("[ByteCave P2P] DCUtR upgrade successful after", upgradeDuration, "ms");
5815
+ const directConns = this.node.getConnections(peerIdObj);
5816
+ const directConn = directConns.find((conn) => !conn.remoteAddr.toString().includes("/p2p-circuit"));
5817
+ if (!directConn) {
5818
+ throw new Error("DCUtR reported success but no direct connection found");
5819
+ }
5820
+ connection = directConn;
5821
+ console.log("[ByteCave P2P] Using direct connection:", connection.remoteAddr.toString());
5822
+ }
5823
+ console.log("[ByteCave P2P] Step 3: Opening protocol stream...");
5803
5824
  const streamStart = Date.now();
5804
5825
  let stream;
5805
5826
  try {
5806
5827
  console.log("[ByteCave P2P] Calling connection.newStream with protocol /bytecave/store/1.0.0...");
5807
5828
  stream = await connection.newStream("/bytecave/store/1.0.0");
5808
5829
  const streamDuration = Date.now() - streamStart;
5809
- console.log("[ByteCave P2P] Step 3: Protocol stream opened in", streamDuration, "ms");
5830
+ console.log("[ByteCave P2P] Step 4: Protocol stream opened in", streamDuration, "ms");
5810
5831
  console.log("[ByteCave P2P] Stream details:", {
5811
5832
  protocol: stream.protocol,
5812
5833
  direction: stream.direction,
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  useHashdImage,
14
14
  useHashdMedia,
15
15
  useHashdUrl
16
- } from "./chunk-AETVOZYQ.js";
16
+ } from "./chunk-OV4Q3HIT.js";
17
17
  import {
18
18
  clearHashdCache,
19
19
  createHashdUrl,
@@ -6049,19 +6049,40 @@ var P2PProtocolClient = class {
6049
6049
  } catch (e) {
6050
6050
  console.warn("[ByteCave P2P] Could not get peer info from peerStore:", e);
6051
6051
  }
6052
- console.log("[ByteCave P2P] Step 2: Opening protocol stream on existing connection...");
6052
+ console.log("[ByteCave P2P] Step 2: Checking if connection upgrade needed...");
6053
6053
  if (existingConns.length === 0) {
6054
6054
  throw new Error("No connection to peer - cannot open protocol stream");
6055
6055
  }
6056
- const connection = existingConns[0];
6057
- console.log("[ByteCave P2P] Using connection:", connection.remoteAddr.toString());
6056
+ let connection = existingConns[0];
6057
+ const isRelayCircuit = connection.remoteAddr.toString().includes("/p2p-circuit");
6058
+ console.log("[ByteCave P2P] Connection type:", isRelayCircuit ? "relay circuit (limited)" : "direct");
6059
+ console.log("[ByteCave P2P] Connection address:", connection.remoteAddr.toString());
6060
+ if (isRelayCircuit) {
6061
+ console.log("[ByteCave P2P] Waiting for DCUtR to upgrade relay circuit to direct WebRTC...");
6062
+ const upgradeStart = Date.now();
6063
+ const hasDirectConnection = await this.waitForDirectConnection(peerId, 5e3);
6064
+ const upgradeDuration = Date.now() - upgradeStart;
6065
+ if (!hasDirectConnection) {
6066
+ console.error("[ByteCave P2P] DCUtR upgrade failed after", upgradeDuration, "ms");
6067
+ throw new Error("Cannot use storage protocol - relay circuit upgrade to WebRTC failed");
6068
+ }
6069
+ console.log("[ByteCave P2P] DCUtR upgrade successful after", upgradeDuration, "ms");
6070
+ const directConns = this.node.getConnections(peerIdObj);
6071
+ const directConn = directConns.find((conn) => !conn.remoteAddr.toString().includes("/p2p-circuit"));
6072
+ if (!directConn) {
6073
+ throw new Error("DCUtR reported success but no direct connection found");
6074
+ }
6075
+ connection = directConn;
6076
+ console.log("[ByteCave P2P] Using direct connection:", connection.remoteAddr.toString());
6077
+ }
6078
+ console.log("[ByteCave P2P] Step 3: Opening protocol stream...");
6058
6079
  const streamStart = Date.now();
6059
6080
  let stream;
6060
6081
  try {
6061
6082
  console.log("[ByteCave P2P] Calling connection.newStream with protocol /bytecave/store/1.0.0...");
6062
6083
  stream = await connection.newStream("/bytecave/store/1.0.0");
6063
6084
  const streamDuration = Date.now() - streamStart;
6064
- console.log("[ByteCave P2P] Step 3: Protocol stream opened in", streamDuration, "ms");
6085
+ console.log("[ByteCave P2P] Step 4: Protocol stream opened in", streamDuration, "ms");
6065
6086
  console.log("[ByteCave P2P] Stream details:", {
6066
6087
  protocol: stream.protocol,
6067
6088
  direction: stream.direction,
@@ -8,7 +8,7 @@ import {
8
8
  useHashdImage,
9
9
  useHashdMedia,
10
10
  useHashdUrl
11
- } from "../chunk-AETVOZYQ.js";
11
+ } from "../chunk-OV4Q3HIT.js";
12
12
  import "../chunk-EEZWRIUI.js";
13
13
  export {
14
14
  HashdAudio,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gethashd/bytecave-browser",
3
- "version": "1.0.27",
3
+ "version": "1.0.28",
4
4
  "description": "ByteCave browser client for WebRTC P2P connections to storage nodes",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -148,24 +148,51 @@ export class P2PProtocolClient {
148
148
  console.warn('[ByteCave P2P] Could not get peer info from peerStore:', e);
149
149
  }
150
150
 
151
- // Step 2: Open protocol stream on existing connection (relay circuits require explicit stream creation)
152
- console.log('[ByteCave P2P] Step 2: Opening protocol stream on existing connection...');
151
+ // Step 2: Wait for connection upgrade from limited relay circuit to full WebRTC
152
+ console.log('[ByteCave P2P] Step 2: Checking if connection upgrade needed...');
153
153
 
154
154
  if (existingConns.length === 0) {
155
155
  throw new Error('No connection to peer - cannot open protocol stream');
156
156
  }
157
157
 
158
- const connection = existingConns[0]; // Use first available connection
159
- console.log('[ByteCave P2P] Using connection:', connection.remoteAddr.toString());
158
+ let connection = existingConns[0];
159
+ const isRelayCircuit = connection.remoteAddr.toString().includes('/p2p-circuit');
160
+ console.log('[ByteCave P2P] Connection type:', isRelayCircuit ? 'relay circuit (limited)' : 'direct');
161
+ console.log('[ByteCave P2P] Connection address:', connection.remoteAddr.toString());
160
162
 
163
+ // If it's a relay circuit, wait for DCUtR to upgrade to direct WebRTC
164
+ if (isRelayCircuit) {
165
+ console.log('[ByteCave P2P] Waiting for DCUtR to upgrade relay circuit to direct WebRTC...');
166
+ const upgradeStart = Date.now();
167
+ const hasDirectConnection = await this.waitForDirectConnection(peerId, 5000);
168
+ const upgradeDuration = Date.now() - upgradeStart;
169
+
170
+ if (!hasDirectConnection) {
171
+ console.error('[ByteCave P2P] DCUtR upgrade failed after', upgradeDuration, 'ms');
172
+ throw new Error('Cannot use storage protocol - relay circuit upgrade to WebRTC failed');
173
+ }
174
+
175
+ console.log('[ByteCave P2P] DCUtR upgrade successful after', upgradeDuration, 'ms');
176
+
177
+ // Get the new direct connection
178
+ const directConns = this.node!.getConnections(peerIdObj);
179
+ const directConn = directConns.find(conn => !conn.remoteAddr.toString().includes('/p2p-circuit'));
180
+ if (!directConn) {
181
+ throw new Error('DCUtR reported success but no direct connection found');
182
+ }
183
+ connection = directConn;
184
+ console.log('[ByteCave P2P] Using direct connection:', connection.remoteAddr.toString());
185
+ }
186
+
187
+ // Step 3: Open protocol stream on the connection
188
+ console.log('[ByteCave P2P] Step 3: Opening protocol stream...');
161
189
  const streamStart = Date.now();
162
190
  let stream;
163
191
  try {
164
- // Open a new stream on the existing connection with the protocol
165
192
  console.log('[ByteCave P2P] Calling connection.newStream with protocol /bytecave/store/1.0.0...');
166
193
  stream = await connection.newStream('/bytecave/store/1.0.0');
167
194
  const streamDuration = Date.now() - streamStart;
168
- console.log('[ByteCave P2P] Step 3: Protocol stream opened in', streamDuration, 'ms');
195
+ console.log('[ByteCave P2P] Step 4: Protocol stream opened in', streamDuration, 'ms');
169
196
  console.log('[ByteCave P2P] Stream details:', {
170
197
  protocol: stream.protocol,
171
198
  direction: stream.direction,