@gethashd/bytecave-browser 1.0.23 → 1.0.25

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.
@@ -5705,14 +5705,58 @@ var P2PProtocolClient = class {
5705
5705
  const timeoutMs = 3e4 + fileSizeMB * 1e4;
5706
5706
  console.log(`[ByteCave P2P] Store timeout: ${Math.round(timeoutMs / 1e3)}s for ${fileSizeMB.toFixed(2)}MB`);
5707
5707
  const storePromise = (async () => {
5708
- console.log("[ByteCave P2P] Step 1: Dialing store protocol...");
5709
- const stream = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
5710
- console.log("[ByteCave P2P] Step 2: Stream established");
5708
+ console.log("[ByteCave P2P] Step 1: Checking existing connections to peer", peerId.slice(0, 12));
5709
+ const existingConns = this.node.getConnections(peerIdObj);
5710
+ console.log("[ByteCave P2P] Existing connections:", existingConns.length);
5711
+ existingConns.forEach((conn, idx) => {
5712
+ console.log(`[ByteCave P2P] Connection ${idx}:`, {
5713
+ remoteAddr: conn.remoteAddr.toString(),
5714
+ status: conn.status,
5715
+ direction: conn.direction,
5716
+ timeline: conn.timeline
5717
+ });
5718
+ });
5719
+ console.log("[ByteCave P2P] Step 2: Dialing store protocol /bytecave/store/1.0.0...");
5720
+ const dialStart = Date.now();
5721
+ let stream;
5722
+ let lastError;
5723
+ for (let attempt = 1; attempt <= 3; attempt++) {
5724
+ try {
5725
+ console.log(`[ByteCave P2P] Dial attempt ${attempt}/3...`);
5726
+ stream = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
5727
+ const dialDuration = Date.now() - dialStart;
5728
+ console.log("[ByteCave P2P] Step 3: Stream established in", dialDuration, "ms");
5729
+ console.log("[ByteCave P2P] Stream details:", {
5730
+ protocol: stream.protocol,
5731
+ direction: stream.direction,
5732
+ timeline: stream.timeline
5733
+ });
5734
+ break;
5735
+ } catch (dialError) {
5736
+ lastError = dialError;
5737
+ const dialDuration = Date.now() - dialStart;
5738
+ console.warn(`[ByteCave P2P] Dial attempt ${attempt} failed after ${dialDuration}ms:`, dialError.message);
5739
+ if (attempt < 3) {
5740
+ console.log("[ByteCave P2P] Waiting 1s before retry (node may still be registering handlers)...");
5741
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
5742
+ }
5743
+ }
5744
+ }
5745
+ if (!stream) {
5746
+ const dialDuration = Date.now() - dialStart;
5747
+ console.error("[ByteCave P2P] All dial attempts FAILED after", dialDuration, "ms:", {
5748
+ error: lastError.message,
5749
+ code: lastError.code,
5750
+ name: lastError.name,
5751
+ stack: lastError.stack?.split("\n").slice(0, 3)
5752
+ });
5753
+ throw lastError;
5754
+ }
5711
5755
  const dataCopy = new Uint8Array(ciphertext);
5712
5756
  const hashBuffer = await crypto.subtle.digest("SHA-256", dataCopy);
5713
5757
  const hashArray = Array.from(new Uint8Array(hashBuffer));
5714
5758
  const cid = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
5715
- console.log("[ByteCave P2P] Step 3: CID generated:", cid.slice(0, 16) + "...");
5759
+ console.log("[ByteCave P2P] Step 5: CID generated:", cid.slice(0, 16) + "...");
5716
5760
  const request = {
5717
5761
  cid,
5718
5762
  mimeType,
@@ -5723,13 +5767,20 @@ var P2PProtocolClient = class {
5723
5767
  timestamp: authorization?.timestamp || Date.now(),
5724
5768
  authorization
5725
5769
  };
5726
- console.log("[ByteCave P2P] Step 4: Request prepared, size:", JSON.stringify(request).length, "bytes");
5727
- console.log("[ByteCave P2P] Step 5: Writing message to stream...");
5770
+ console.log("[ByteCave P2P] Step 5: Request prepared, size:", JSON.stringify(request).length, "bytes");
5771
+ console.log("[ByteCave P2P] Step 6: Writing message to stream...");
5772
+ const writeStart = Date.now();
5728
5773
  await this.writeMessage(stream, request);
5729
- console.log("[ByteCave P2P] Step 6: Message written, waiting for response...");
5774
+ const writeDuration = Date.now() - writeStart;
5775
+ console.log("[ByteCave P2P] Request written in", writeDuration, "ms");
5776
+ console.log("[ByteCave P2P] Step 7: Waiting for response from node...");
5777
+ const readStart = Date.now();
5730
5778
  const response = await this.readMessage(stream);
5731
- console.log("[ByteCave P2P] Step 7: Response received:", response);
5779
+ const readDuration = Date.now() - readStart;
5780
+ console.log("[ByteCave P2P] Response received in", readDuration, "ms:", response);
5781
+ console.log("[ByteCave P2P] Step 8: Closing stream...");
5732
5782
  await stream.close();
5783
+ console.log("[ByteCave P2P] Stream closed successfully");
5733
5784
  if (response?.success) {
5734
5785
  return { success: true, cid };
5735
5786
  } else {
package/dist/index.cjs CHANGED
@@ -5773,14 +5773,58 @@ var P2PProtocolClient = class {
5773
5773
  const timeoutMs = 3e4 + fileSizeMB * 1e4;
5774
5774
  console.log(`[ByteCave P2P] Store timeout: ${Math.round(timeoutMs / 1e3)}s for ${fileSizeMB.toFixed(2)}MB`);
5775
5775
  const storePromise = (async () => {
5776
- console.log("[ByteCave P2P] Step 1: Dialing store protocol...");
5777
- const stream = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
5778
- console.log("[ByteCave P2P] Step 2: Stream established");
5776
+ console.log("[ByteCave P2P] Step 1: Checking existing connections to peer", peerId.slice(0, 12));
5777
+ const existingConns = this.node.getConnections(peerIdObj);
5778
+ console.log("[ByteCave P2P] Existing connections:", existingConns.length);
5779
+ existingConns.forEach((conn, idx) => {
5780
+ console.log(`[ByteCave P2P] Connection ${idx}:`, {
5781
+ remoteAddr: conn.remoteAddr.toString(),
5782
+ status: conn.status,
5783
+ direction: conn.direction,
5784
+ timeline: conn.timeline
5785
+ });
5786
+ });
5787
+ console.log("[ByteCave P2P] Step 2: Dialing store protocol /bytecave/store/1.0.0...");
5788
+ const dialStart = Date.now();
5789
+ let stream;
5790
+ let lastError;
5791
+ for (let attempt = 1; attempt <= 3; attempt++) {
5792
+ try {
5793
+ console.log(`[ByteCave P2P] Dial attempt ${attempt}/3...`);
5794
+ stream = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
5795
+ const dialDuration = Date.now() - dialStart;
5796
+ console.log("[ByteCave P2P] Step 3: Stream established in", dialDuration, "ms");
5797
+ console.log("[ByteCave P2P] Stream details:", {
5798
+ protocol: stream.protocol,
5799
+ direction: stream.direction,
5800
+ timeline: stream.timeline
5801
+ });
5802
+ break;
5803
+ } catch (dialError) {
5804
+ lastError = dialError;
5805
+ const dialDuration = Date.now() - dialStart;
5806
+ console.warn(`[ByteCave P2P] Dial attempt ${attempt} failed after ${dialDuration}ms:`, dialError.message);
5807
+ if (attempt < 3) {
5808
+ console.log("[ByteCave P2P] Waiting 1s before retry (node may still be registering handlers)...");
5809
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
5810
+ }
5811
+ }
5812
+ }
5813
+ if (!stream) {
5814
+ const dialDuration = Date.now() - dialStart;
5815
+ console.error("[ByteCave P2P] All dial attempts FAILED after", dialDuration, "ms:", {
5816
+ error: lastError.message,
5817
+ code: lastError.code,
5818
+ name: lastError.name,
5819
+ stack: lastError.stack?.split("\n").slice(0, 3)
5820
+ });
5821
+ throw lastError;
5822
+ }
5779
5823
  const dataCopy = new Uint8Array(ciphertext);
5780
5824
  const hashBuffer = await crypto.subtle.digest("SHA-256", dataCopy);
5781
5825
  const hashArray = Array.from(new Uint8Array(hashBuffer));
5782
5826
  const cid = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
5783
- console.log("[ByteCave P2P] Step 3: CID generated:", cid.slice(0, 16) + "...");
5827
+ console.log("[ByteCave P2P] Step 5: CID generated:", cid.slice(0, 16) + "...");
5784
5828
  const request = {
5785
5829
  cid,
5786
5830
  mimeType,
@@ -5791,13 +5835,20 @@ var P2PProtocolClient = class {
5791
5835
  timestamp: authorization?.timestamp || Date.now(),
5792
5836
  authorization
5793
5837
  };
5794
- console.log("[ByteCave P2P] Step 4: Request prepared, size:", JSON.stringify(request).length, "bytes");
5795
- console.log("[ByteCave P2P] Step 5: Writing message to stream...");
5838
+ console.log("[ByteCave P2P] Step 5: Request prepared, size:", JSON.stringify(request).length, "bytes");
5839
+ console.log("[ByteCave P2P] Step 6: Writing message to stream...");
5840
+ const writeStart = Date.now();
5796
5841
  await this.writeMessage(stream, request);
5797
- console.log("[ByteCave P2P] Step 6: Message written, waiting for response...");
5842
+ const writeDuration = Date.now() - writeStart;
5843
+ console.log("[ByteCave P2P] Request written in", writeDuration, "ms");
5844
+ console.log("[ByteCave P2P] Step 7: Waiting for response from node...");
5845
+ const readStart = Date.now();
5798
5846
  const response = await this.readMessage(stream);
5799
- console.log("[ByteCave P2P] Step 7: Response received:", response);
5847
+ const readDuration = Date.now() - readStart;
5848
+ console.log("[ByteCave P2P] Response received in", readDuration, "ms:", response);
5849
+ console.log("[ByteCave P2P] Step 8: Closing stream...");
5800
5850
  await stream.close();
5851
+ console.log("[ByteCave P2P] Stream closed successfully");
5801
5852
  if (response?.success) {
5802
5853
  return { success: true, cid };
5803
5854
  } else {
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  useHashdImage,
14
14
  useHashdMedia,
15
15
  useHashdUrl
16
- } from "./chunk-VICLADDD.js";
16
+ } from "./chunk-MVXA47HN.js";
17
17
  import {
18
18
  clearHashdCache,
19
19
  createHashdUrl,
@@ -6028,14 +6028,58 @@ var P2PProtocolClient = class {
6028
6028
  const timeoutMs = 3e4 + fileSizeMB * 1e4;
6029
6029
  console.log(`[ByteCave P2P] Store timeout: ${Math.round(timeoutMs / 1e3)}s for ${fileSizeMB.toFixed(2)}MB`);
6030
6030
  const storePromise = (async () => {
6031
- console.log("[ByteCave P2P] Step 1: Dialing store protocol...");
6032
- const stream = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
6033
- console.log("[ByteCave P2P] Step 2: Stream established");
6031
+ console.log("[ByteCave P2P] Step 1: Checking existing connections to peer", peerId.slice(0, 12));
6032
+ const existingConns = this.node.getConnections(peerIdObj);
6033
+ console.log("[ByteCave P2P] Existing connections:", existingConns.length);
6034
+ existingConns.forEach((conn, idx) => {
6035
+ console.log(`[ByteCave P2P] Connection ${idx}:`, {
6036
+ remoteAddr: conn.remoteAddr.toString(),
6037
+ status: conn.status,
6038
+ direction: conn.direction,
6039
+ timeline: conn.timeline
6040
+ });
6041
+ });
6042
+ console.log("[ByteCave P2P] Step 2: Dialing store protocol /bytecave/store/1.0.0...");
6043
+ const dialStart = Date.now();
6044
+ let stream;
6045
+ let lastError;
6046
+ for (let attempt = 1; attempt <= 3; attempt++) {
6047
+ try {
6048
+ console.log(`[ByteCave P2P] Dial attempt ${attempt}/3...`);
6049
+ stream = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
6050
+ const dialDuration = Date.now() - dialStart;
6051
+ console.log("[ByteCave P2P] Step 3: Stream established in", dialDuration, "ms");
6052
+ console.log("[ByteCave P2P] Stream details:", {
6053
+ protocol: stream.protocol,
6054
+ direction: stream.direction,
6055
+ timeline: stream.timeline
6056
+ });
6057
+ break;
6058
+ } catch (dialError) {
6059
+ lastError = dialError;
6060
+ const dialDuration = Date.now() - dialStart;
6061
+ console.warn(`[ByteCave P2P] Dial attempt ${attempt} failed after ${dialDuration}ms:`, dialError.message);
6062
+ if (attempt < 3) {
6063
+ console.log("[ByteCave P2P] Waiting 1s before retry (node may still be registering handlers)...");
6064
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
6065
+ }
6066
+ }
6067
+ }
6068
+ if (!stream) {
6069
+ const dialDuration = Date.now() - dialStart;
6070
+ console.error("[ByteCave P2P] All dial attempts FAILED after", dialDuration, "ms:", {
6071
+ error: lastError.message,
6072
+ code: lastError.code,
6073
+ name: lastError.name,
6074
+ stack: lastError.stack?.split("\n").slice(0, 3)
6075
+ });
6076
+ throw lastError;
6077
+ }
6034
6078
  const dataCopy = new Uint8Array(ciphertext);
6035
6079
  const hashBuffer = await crypto.subtle.digest("SHA-256", dataCopy);
6036
6080
  const hashArray = Array.from(new Uint8Array(hashBuffer));
6037
6081
  const cid = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
6038
- console.log("[ByteCave P2P] Step 3: CID generated:", cid.slice(0, 16) + "...");
6082
+ console.log("[ByteCave P2P] Step 5: CID generated:", cid.slice(0, 16) + "...");
6039
6083
  const request = {
6040
6084
  cid,
6041
6085
  mimeType,
@@ -6046,13 +6090,20 @@ var P2PProtocolClient = class {
6046
6090
  timestamp: authorization?.timestamp || Date.now(),
6047
6091
  authorization
6048
6092
  };
6049
- console.log("[ByteCave P2P] Step 4: Request prepared, size:", JSON.stringify(request).length, "bytes");
6050
- console.log("[ByteCave P2P] Step 5: Writing message to stream...");
6093
+ console.log("[ByteCave P2P] Step 5: Request prepared, size:", JSON.stringify(request).length, "bytes");
6094
+ console.log("[ByteCave P2P] Step 6: Writing message to stream...");
6095
+ const writeStart = Date.now();
6051
6096
  await this.writeMessage(stream, request);
6052
- console.log("[ByteCave P2P] Step 6: Message written, waiting for response...");
6097
+ const writeDuration = Date.now() - writeStart;
6098
+ console.log("[ByteCave P2P] Request written in", writeDuration, "ms");
6099
+ console.log("[ByteCave P2P] Step 7: Waiting for response from node...");
6100
+ const readStart = Date.now();
6053
6101
  const response = await this.readMessage(stream);
6054
- console.log("[ByteCave P2P] Step 7: Response received:", response);
6102
+ const readDuration = Date.now() - readStart;
6103
+ console.log("[ByteCave P2P] Response received in", readDuration, "ms:", response);
6104
+ console.log("[ByteCave P2P] Step 8: Closing stream...");
6055
6105
  await stream.close();
6106
+ console.log("[ByteCave P2P] Stream closed successfully");
6056
6107
  if (response?.success) {
6057
6108
  return { success: true, cid };
6058
6109
  } else {
@@ -8,7 +8,7 @@ import {
8
8
  useHashdImage,
9
9
  useHashdMedia,
10
10
  useHashdUrl
11
- } from "../chunk-VICLADDD.js";
11
+ } from "../chunk-MVXA47HN.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.23",
3
+ "version": "1.0.25",
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",
@@ -124,17 +124,66 @@ export class P2PProtocolClient {
124
124
 
125
125
  // Wrap the entire operation in a timeout
126
126
  const storePromise = (async () => {
127
- console.log('[ByteCave P2P] Step 1: Dialing store protocol...');
128
- // dialProtocol will upgrade limited relay connections to full connections automatically
129
- const stream = await this.node!.dialProtocol(peerIdObj, '/bytecave/store/1.0.0');
130
- console.log('[ByteCave P2P] Step 2: Stream established');
127
+ console.log('[ByteCave P2P] Step 1: Checking existing connections to peer', peerId.slice(0, 12));
128
+ const existingConns = this.node!.getConnections(peerIdObj);
129
+ console.log('[ByteCave P2P] Existing connections:', existingConns.length);
130
+ existingConns.forEach((conn, idx) => {
131
+ console.log(`[ByteCave P2P] Connection ${idx}:`, {
132
+ remoteAddr: conn.remoteAddr.toString(),
133
+ status: conn.status,
134
+ direction: conn.direction,
135
+ timeline: conn.timeline
136
+ });
137
+ });
138
+
139
+ // Step 2: Dial store protocol with retry (node may need time to register handlers after startup)
140
+ console.log('[ByteCave P2P] Step 2: Dialing store protocol /bytecave/store/1.0.0...');
141
+ const dialStart = Date.now();
142
+ let stream;
143
+ let lastError;
144
+
145
+ // Retry up to 3 times with 1s delay - gives node time to register protocol handlers
146
+ for (let attempt = 1; attempt <= 3; attempt++) {
147
+ try {
148
+ console.log(`[ByteCave P2P] Dial attempt ${attempt}/3...`);
149
+ stream = await this.node!.dialProtocol(peerIdObj, '/bytecave/store/1.0.0');
150
+ const dialDuration = Date.now() - dialStart;
151
+ console.log('[ByteCave P2P] Step 3: Stream established in', dialDuration, 'ms');
152
+ console.log('[ByteCave P2P] Stream details:', {
153
+ protocol: stream.protocol,
154
+ direction: stream.direction,
155
+ timeline: stream.timeline
156
+ });
157
+ break; // Success!
158
+ } catch (dialError: any) {
159
+ lastError = dialError;
160
+ const dialDuration = Date.now() - dialStart;
161
+ console.warn(`[ByteCave P2P] Dial attempt ${attempt} failed after ${dialDuration}ms:`, dialError.message);
162
+
163
+ if (attempt < 3) {
164
+ console.log('[ByteCave P2P] Waiting 1s before retry (node may still be registering handlers)...');
165
+ await new Promise(resolve => setTimeout(resolve, 1000));
166
+ }
167
+ }
168
+ }
169
+
170
+ if (!stream) {
171
+ const dialDuration = Date.now() - dialStart;
172
+ console.error('[ByteCave P2P] All dial attempts FAILED after', dialDuration, 'ms:', {
173
+ error: lastError.message,
174
+ code: lastError.code,
175
+ name: lastError.name,
176
+ stack: lastError.stack?.split('\n').slice(0, 3)
177
+ });
178
+ throw lastError;
179
+ }
131
180
 
132
181
  // Generate CID using SHA-256 (matches bytecave-core format: 64-char hex)
133
182
  const dataCopy = new Uint8Array(ciphertext);
134
183
  const hashBuffer = await crypto.subtle.digest('SHA-256', dataCopy);
135
184
  const hashArray = Array.from(new Uint8Array(hashBuffer));
136
185
  const cid = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
137
- console.log('[ByteCave P2P] Step 3: CID generated:', cid.slice(0, 16) + '...');
186
+ console.log('[ByteCave P2P] Step 5: CID generated:', cid.slice(0, 16) + '...');
138
187
 
139
188
  const request: StoreRequest = {
140
189
  cid,
@@ -146,15 +195,23 @@ export class P2PProtocolClient {
146
195
  timestamp: authorization?.timestamp || Date.now(),
147
196
  authorization
148
197
  };
149
- console.log('[ByteCave P2P] Step 4: Request prepared, size:', JSON.stringify(request).length, 'bytes');
198
+ console.log('[ByteCave P2P] Step 5: Request prepared, size:', JSON.stringify(request).length, 'bytes');
150
199
 
151
- console.log('[ByteCave P2P] Step 5: Writing message to stream...');
200
+ console.log('[ByteCave P2P] Step 6: Writing message to stream...');
201
+ const writeStart = Date.now();
152
202
  await this.writeMessage(stream, request);
153
- console.log('[ByteCave P2P] Step 6: Message written, waiting for response...');
203
+ const writeDuration = Date.now() - writeStart;
204
+ console.log('[ByteCave P2P] Request written in', writeDuration, 'ms');
205
+
206
+ console.log('[ByteCave P2P] Step 7: Waiting for response from node...');
207
+ const readStart = Date.now();
154
208
  const response = await this.readMessage<StoreResponse>(stream);
155
- console.log('[ByteCave P2P] Step 7: Response received:', response);
209
+ const readDuration = Date.now() - readStart;
210
+ console.log('[ByteCave P2P] Response received in', readDuration, 'ms:', response);
156
211
 
212
+ console.log('[ByteCave P2P] Step 8: Closing stream...');
157
213
  await stream.close();
214
+ console.log('[ByteCave P2P] Stream closed successfully');
158
215
 
159
216
  if (response?.success) {
160
217
  return { success: true, cid };