@gethashd/bytecave-browser 1.0.26 → 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,41 +5726,57 @@ 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: Dialing store protocol /bytecave/store/1.0.0...");
5730
- const dialStart = Date.now();
5731
- let stream;
5732
- let lastError;
5733
- for (let attempt = 1; attempt <= 3; attempt++) {
5734
- try {
5735
- console.log(`[ByteCave P2P] Dial attempt ${attempt}/3...`);
5736
- stream = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
5737
- const dialDuration = Date.now() - dialStart;
5738
- console.log("[ByteCave P2P] Step 3: Stream established in", dialDuration, "ms");
5739
- console.log("[ByteCave P2P] Stream details:", {
5740
- protocol: stream.protocol,
5741
- direction: stream.direction,
5742
- timeline: stream.timeline
5743
- });
5744
- break;
5745
- } catch (dialError) {
5746
- lastError = dialError;
5747
- const dialDuration = Date.now() - dialStart;
5748
- console.warn(`[ByteCave P2P] Dial attempt ${attempt} failed after ${dialDuration}ms:`, dialError.message);
5749
- if (attempt < 3) {
5750
- console.log("[ByteCave P2P] Waiting 1s before retry (node may still be registering handlers)...");
5751
- await new Promise((resolve) => setTimeout(resolve, 1e3));
5752
- }
5729
+ console.log("[ByteCave P2P] Step 2: Checking if connection upgrade needed...");
5730
+ if (existingConns.length === 0) {
5731
+ throw new Error("No connection to peer - cannot open protocol stream");
5732
+ }
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");
5753
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
5754
  }
5755
- if (!stream) {
5756
- const dialDuration = Date.now() - dialStart;
5757
- console.error("[ByteCave P2P] All dial attempts FAILED after", dialDuration, "ms:", {
5758
- error: lastError.message,
5759
- code: lastError.code,
5760
- name: lastError.name,
5761
- stack: lastError.stack?.split("\n").slice(0, 3)
5755
+ console.log("[ByteCave P2P] Step 3: Opening protocol stream...");
5756
+ const streamStart = Date.now();
5757
+ let stream;
5758
+ try {
5759
+ console.log("[ByteCave P2P] Calling connection.newStream with protocol /bytecave/store/1.0.0...");
5760
+ stream = await connection.newStream("/bytecave/store/1.0.0");
5761
+ const streamDuration = Date.now() - streamStart;
5762
+ console.log("[ByteCave P2P] Step 4: Protocol stream opened in", streamDuration, "ms");
5763
+ console.log("[ByteCave P2P] Stream details:", {
5764
+ protocol: stream.protocol,
5765
+ direction: stream.direction,
5766
+ id: stream.id,
5767
+ timeline: stream.timeline
5768
+ });
5769
+ } catch (streamError) {
5770
+ const streamDuration = Date.now() - streamStart;
5771
+ console.error("[ByteCave P2P] Failed to open protocol stream after", streamDuration, "ms:", {
5772
+ error: streamError.message,
5773
+ code: streamError.code,
5774
+ name: streamError.name,
5775
+ connectionStatus: connection.status,
5776
+ connectionStreams: connection.streams.length,
5777
+ stack: streamError.stack?.split("\n").slice(0, 3)
5762
5778
  });
5763
- throw lastError;
5779
+ throw streamError;
5764
5780
  }
5765
5781
  const dataCopy = new Uint8Array(ciphertext);
5766
5782
  const hashBuffer = await crypto.subtle.digest("SHA-256", dataCopy);
package/dist/index.cjs CHANGED
@@ -5794,41 +5794,57 @@ 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: Dialing store protocol /bytecave/store/1.0.0...");
5798
- const dialStart = Date.now();
5799
- let stream;
5800
- let lastError;
5801
- for (let attempt = 1; attempt <= 3; attempt++) {
5802
- try {
5803
- console.log(`[ByteCave P2P] Dial attempt ${attempt}/3...`);
5804
- stream = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
5805
- const dialDuration = Date.now() - dialStart;
5806
- console.log("[ByteCave P2P] Step 3: Stream established in", dialDuration, "ms");
5807
- console.log("[ByteCave P2P] Stream details:", {
5808
- protocol: stream.protocol,
5809
- direction: stream.direction,
5810
- timeline: stream.timeline
5811
- });
5812
- break;
5813
- } catch (dialError) {
5814
- lastError = dialError;
5815
- const dialDuration = Date.now() - dialStart;
5816
- console.warn(`[ByteCave P2P] Dial attempt ${attempt} failed after ${dialDuration}ms:`, dialError.message);
5817
- if (attempt < 3) {
5818
- console.log("[ByteCave P2P] Waiting 1s before retry (node may still be registering handlers)...");
5819
- await new Promise((resolve) => setTimeout(resolve, 1e3));
5820
- }
5797
+ console.log("[ByteCave P2P] Step 2: Checking if connection upgrade needed...");
5798
+ if (existingConns.length === 0) {
5799
+ throw new Error("No connection to peer - cannot open protocol stream");
5800
+ }
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");
5821
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
5822
  }
5823
- if (!stream) {
5824
- const dialDuration = Date.now() - dialStart;
5825
- console.error("[ByteCave P2P] All dial attempts FAILED after", dialDuration, "ms:", {
5826
- error: lastError.message,
5827
- code: lastError.code,
5828
- name: lastError.name,
5829
- stack: lastError.stack?.split("\n").slice(0, 3)
5823
+ console.log("[ByteCave P2P] Step 3: Opening protocol stream...");
5824
+ const streamStart = Date.now();
5825
+ let stream;
5826
+ try {
5827
+ console.log("[ByteCave P2P] Calling connection.newStream with protocol /bytecave/store/1.0.0...");
5828
+ stream = await connection.newStream("/bytecave/store/1.0.0");
5829
+ const streamDuration = Date.now() - streamStart;
5830
+ console.log("[ByteCave P2P] Step 4: Protocol stream opened in", streamDuration, "ms");
5831
+ console.log("[ByteCave P2P] Stream details:", {
5832
+ protocol: stream.protocol,
5833
+ direction: stream.direction,
5834
+ id: stream.id,
5835
+ timeline: stream.timeline
5836
+ });
5837
+ } catch (streamError) {
5838
+ const streamDuration = Date.now() - streamStart;
5839
+ console.error("[ByteCave P2P] Failed to open protocol stream after", streamDuration, "ms:", {
5840
+ error: streamError.message,
5841
+ code: streamError.code,
5842
+ name: streamError.name,
5843
+ connectionStatus: connection.status,
5844
+ connectionStreams: connection.streams.length,
5845
+ stack: streamError.stack?.split("\n").slice(0, 3)
5830
5846
  });
5831
- throw lastError;
5847
+ throw streamError;
5832
5848
  }
5833
5849
  const dataCopy = new Uint8Array(ciphertext);
5834
5850
  const hashBuffer = await crypto.subtle.digest("SHA-256", dataCopy);
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  useHashdImage,
14
14
  useHashdMedia,
15
15
  useHashdUrl
16
- } from "./chunk-XMU2N2NN.js";
16
+ } from "./chunk-OV4Q3HIT.js";
17
17
  import {
18
18
  clearHashdCache,
19
19
  createHashdUrl,
@@ -6049,41 +6049,57 @@ 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: Dialing store protocol /bytecave/store/1.0.0...");
6053
- const dialStart = Date.now();
6054
- let stream;
6055
- let lastError;
6056
- for (let attempt = 1; attempt <= 3; attempt++) {
6057
- try {
6058
- console.log(`[ByteCave P2P] Dial attempt ${attempt}/3...`);
6059
- stream = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
6060
- const dialDuration = Date.now() - dialStart;
6061
- console.log("[ByteCave P2P] Step 3: Stream established in", dialDuration, "ms");
6062
- console.log("[ByteCave P2P] Stream details:", {
6063
- protocol: stream.protocol,
6064
- direction: stream.direction,
6065
- timeline: stream.timeline
6066
- });
6067
- break;
6068
- } catch (dialError) {
6069
- lastError = dialError;
6070
- const dialDuration = Date.now() - dialStart;
6071
- console.warn(`[ByteCave P2P] Dial attempt ${attempt} failed after ${dialDuration}ms:`, dialError.message);
6072
- if (attempt < 3) {
6073
- console.log("[ByteCave P2P] Waiting 1s before retry (node may still be registering handlers)...");
6074
- await new Promise((resolve) => setTimeout(resolve, 1e3));
6075
- }
6052
+ console.log("[ByteCave P2P] Step 2: Checking if connection upgrade needed...");
6053
+ if (existingConns.length === 0) {
6054
+ throw new Error("No connection to peer - cannot open protocol stream");
6055
+ }
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");
6076
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
6077
  }
6078
- if (!stream) {
6079
- const dialDuration = Date.now() - dialStart;
6080
- console.error("[ByteCave P2P] All dial attempts FAILED after", dialDuration, "ms:", {
6081
- error: lastError.message,
6082
- code: lastError.code,
6083
- name: lastError.name,
6084
- stack: lastError.stack?.split("\n").slice(0, 3)
6078
+ console.log("[ByteCave P2P] Step 3: Opening protocol stream...");
6079
+ const streamStart = Date.now();
6080
+ let stream;
6081
+ try {
6082
+ console.log("[ByteCave P2P] Calling connection.newStream with protocol /bytecave/store/1.0.0...");
6083
+ stream = await connection.newStream("/bytecave/store/1.0.0");
6084
+ const streamDuration = Date.now() - streamStart;
6085
+ console.log("[ByteCave P2P] Step 4: Protocol stream opened in", streamDuration, "ms");
6086
+ console.log("[ByteCave P2P] Stream details:", {
6087
+ protocol: stream.protocol,
6088
+ direction: stream.direction,
6089
+ id: stream.id,
6090
+ timeline: stream.timeline
6091
+ });
6092
+ } catch (streamError) {
6093
+ const streamDuration = Date.now() - streamStart;
6094
+ console.error("[ByteCave P2P] Failed to open protocol stream after", streamDuration, "ms:", {
6095
+ error: streamError.message,
6096
+ code: streamError.code,
6097
+ name: streamError.name,
6098
+ connectionStatus: connection.status,
6099
+ connectionStreams: connection.streams.length,
6100
+ stack: streamError.stack?.split("\n").slice(0, 3)
6085
6101
  });
6086
- throw lastError;
6102
+ throw streamError;
6087
6103
  }
6088
6104
  const dataCopy = new Uint8Array(ciphertext);
6089
6105
  const hashBuffer = await crypto.subtle.digest("SHA-256", dataCopy);
@@ -8,7 +8,7 @@ import {
8
8
  useHashdImage,
9
9
  useHashdMedia,
10
10
  useHashdUrl
11
- } from "../chunk-XMU2N2NN.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.26",
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,46 +148,68 @@ export class P2PProtocolClient {
148
148
  console.warn('[ByteCave P2P] Could not get peer info from peerStore:', e);
149
149
  }
150
150
 
151
- // Step 2: Dial store protocol with retry (node may need time to register handlers after startup)
152
- console.log('[ByteCave P2P] Step 2: Dialing store protocol /bytecave/store/1.0.0...');
153
- const dialStart = Date.now();
154
- let stream;
155
- let lastError;
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
+
154
+ if (existingConns.length === 0) {
155
+ throw new Error('No connection to peer - cannot open protocol stream');
156
+ }
156
157
 
157
- // Retry up to 3 times with 1s delay - gives node time to register protocol handlers
158
- for (let attempt = 1; attempt <= 3; attempt++) {
159
- try {
160
- console.log(`[ByteCave P2P] Dial attempt ${attempt}/3...`);
161
- stream = await this.node!.dialProtocol(peerIdObj, '/bytecave/store/1.0.0');
162
- const dialDuration = Date.now() - dialStart;
163
- console.log('[ByteCave P2P] Step 3: Stream established in', dialDuration, 'ms');
164
- console.log('[ByteCave P2P] Stream details:', {
165
- protocol: stream.protocol,
166
- direction: stream.direction,
167
- timeline: stream.timeline
168
- });
169
- break; // Success!
170
- } catch (dialError: any) {
171
- lastError = dialError;
172
- const dialDuration = Date.now() - dialStart;
173
- console.warn(`[ByteCave P2P] Dial attempt ${attempt} failed after ${dialDuration}ms:`, dialError.message);
174
-
175
- if (attempt < 3) {
176
- console.log('[ByteCave P2P] Waiting 1s before retry (node may still be registering handlers)...');
177
- await new Promise(resolve => setTimeout(resolve, 1000));
178
- }
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());
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');
179
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());
180
185
  }
181
186
 
182
- if (!stream) {
183
- const dialDuration = Date.now() - dialStart;
184
- console.error('[ByteCave P2P] All dial attempts FAILED after', dialDuration, 'ms:', {
185
- error: lastError.message,
186
- code: lastError.code,
187
- name: lastError.name,
188
- stack: lastError.stack?.split('\n').slice(0, 3)
187
+ // Step 3: Open protocol stream on the connection
188
+ console.log('[ByteCave P2P] Step 3: Opening protocol stream...');
189
+ const streamStart = Date.now();
190
+ let stream;
191
+ try {
192
+ console.log('[ByteCave P2P] Calling connection.newStream with protocol /bytecave/store/1.0.0...');
193
+ stream = await connection.newStream('/bytecave/store/1.0.0');
194
+ const streamDuration = Date.now() - streamStart;
195
+ console.log('[ByteCave P2P] Step 4: Protocol stream opened in', streamDuration, 'ms');
196
+ console.log('[ByteCave P2P] Stream details:', {
197
+ protocol: stream.protocol,
198
+ direction: stream.direction,
199
+ id: stream.id,
200
+ timeline: stream.timeline
201
+ });
202
+ } catch (streamError: any) {
203
+ const streamDuration = Date.now() - streamStart;
204
+ console.error('[ByteCave P2P] Failed to open protocol stream after', streamDuration, 'ms:', {
205
+ error: streamError.message,
206
+ code: streamError.code,
207
+ name: streamError.name,
208
+ connectionStatus: connection.status,
209
+ connectionStreams: connection.streams.length,
210
+ stack: streamError.stack?.split('\n').slice(0, 3)
189
211
  });
190
- throw lastError;
212
+ throw streamError;
191
213
  }
192
214
 
193
215
  // Generate CID using SHA-256 (matches bytecave-core format: 64-char hex)