@gethashd/bytecave-browser 1.0.25 → 1.0.27

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.
@@ -5706,51 +5706,56 @@ var P2PProtocolClient = class {
5706
5706
  console.log(`[ByteCave P2P] Store timeout: ${Math.round(timeoutMs / 1e3)}s for ${fileSizeMB.toFixed(2)}MB`);
5707
5707
  const storePromise = (async () => {
5708
5708
  console.log("[ByteCave P2P] Step 1: Checking existing connections to peer", peerId.slice(0, 12));
5709
+ console.log("[ByteCave P2P] Full peer ID:", peerId);
5709
5710
  const existingConns = this.node.getConnections(peerIdObj);
5710
5711
  console.log("[ByteCave P2P] Existing connections:", existingConns.length);
5711
5712
  existingConns.forEach((conn, idx) => {
5712
5713
  console.log(`[ByteCave P2P] Connection ${idx}:`, {
5713
5714
  remoteAddr: conn.remoteAddr.toString(),
5715
+ remotePeer: conn.remotePeer.toString(),
5714
5716
  status: conn.status,
5715
5717
  direction: conn.direction,
5718
+ streams: conn.streams.length,
5716
5719
  timeline: conn.timeline
5717
5720
  });
5718
5721
  });
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
- }
5722
+ const peerStore = this.node.peerStore;
5723
+ try {
5724
+ const peer = await peerStore.get(peerIdObj);
5725
+ console.log("[ByteCave P2P] Peer protocols from peerStore:", peer.protocols);
5726
+ } catch (e) {
5727
+ console.warn("[ByteCave P2P] Could not get peer info from peerStore:", e);
5728
+ }
5729
+ console.log("[ByteCave P2P] Step 2: Opening protocol stream on existing connection...");
5730
+ if (existingConns.length === 0) {
5731
+ throw new Error("No connection to peer - cannot open protocol stream");
5744
5732
  }
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)
5733
+ const connection = existingConns[0];
5734
+ console.log("[ByteCave P2P] Using connection:", connection.remoteAddr.toString());
5735
+ const streamStart = Date.now();
5736
+ let stream;
5737
+ try {
5738
+ console.log("[ByteCave P2P] Calling connection.newStream with protocol /bytecave/store/1.0.0...");
5739
+ stream = await connection.newStream("/bytecave/store/1.0.0");
5740
+ const streamDuration = Date.now() - streamStart;
5741
+ console.log("[ByteCave P2P] Step 3: Protocol stream opened in", streamDuration, "ms");
5742
+ console.log("[ByteCave P2P] Stream details:", {
5743
+ protocol: stream.protocol,
5744
+ direction: stream.direction,
5745
+ id: stream.id,
5746
+ timeline: stream.timeline
5747
+ });
5748
+ } catch (streamError) {
5749
+ const streamDuration = Date.now() - streamStart;
5750
+ console.error("[ByteCave P2P] Failed to open protocol stream after", streamDuration, "ms:", {
5751
+ error: streamError.message,
5752
+ code: streamError.code,
5753
+ name: streamError.name,
5754
+ connectionStatus: connection.status,
5755
+ connectionStreams: connection.streams.length,
5756
+ stack: streamError.stack?.split("\n").slice(0, 3)
5752
5757
  });
5753
- throw lastError;
5758
+ throw streamError;
5754
5759
  }
5755
5760
  const dataCopy = new Uint8Array(ciphertext);
5756
5761
  const hashBuffer = await crypto.subtle.digest("SHA-256", dataCopy);
package/dist/index.cjs CHANGED
@@ -5774,51 +5774,56 @@ var P2PProtocolClient = class {
5774
5774
  console.log(`[ByteCave P2P] Store timeout: ${Math.round(timeoutMs / 1e3)}s for ${fileSizeMB.toFixed(2)}MB`);
5775
5775
  const storePromise = (async () => {
5776
5776
  console.log("[ByteCave P2P] Step 1: Checking existing connections to peer", peerId.slice(0, 12));
5777
+ console.log("[ByteCave P2P] Full peer ID:", peerId);
5777
5778
  const existingConns = this.node.getConnections(peerIdObj);
5778
5779
  console.log("[ByteCave P2P] Existing connections:", existingConns.length);
5779
5780
  existingConns.forEach((conn, idx) => {
5780
5781
  console.log(`[ByteCave P2P] Connection ${idx}:`, {
5781
5782
  remoteAddr: conn.remoteAddr.toString(),
5783
+ remotePeer: conn.remotePeer.toString(),
5782
5784
  status: conn.status,
5783
5785
  direction: conn.direction,
5786
+ streams: conn.streams.length,
5784
5787
  timeline: conn.timeline
5785
5788
  });
5786
5789
  });
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
- }
5790
+ const peerStore = this.node.peerStore;
5791
+ try {
5792
+ const peer = await peerStore.get(peerIdObj);
5793
+ console.log("[ByteCave P2P] Peer protocols from peerStore:", peer.protocols);
5794
+ } catch (e) {
5795
+ console.warn("[ByteCave P2P] Could not get peer info from peerStore:", e);
5796
+ }
5797
+ console.log("[ByteCave P2P] Step 2: Opening protocol stream on existing connection...");
5798
+ if (existingConns.length === 0) {
5799
+ throw new Error("No connection to peer - cannot open protocol stream");
5812
5800
  }
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)
5801
+ const connection = existingConns[0];
5802
+ console.log("[ByteCave P2P] Using connection:", connection.remoteAddr.toString());
5803
+ const streamStart = Date.now();
5804
+ let stream;
5805
+ try {
5806
+ console.log("[ByteCave P2P] Calling connection.newStream with protocol /bytecave/store/1.0.0...");
5807
+ stream = await connection.newStream("/bytecave/store/1.0.0");
5808
+ const streamDuration = Date.now() - streamStart;
5809
+ console.log("[ByteCave P2P] Step 3: Protocol stream opened in", streamDuration, "ms");
5810
+ console.log("[ByteCave P2P] Stream details:", {
5811
+ protocol: stream.protocol,
5812
+ direction: stream.direction,
5813
+ id: stream.id,
5814
+ timeline: stream.timeline
5815
+ });
5816
+ } catch (streamError) {
5817
+ const streamDuration = Date.now() - streamStart;
5818
+ console.error("[ByteCave P2P] Failed to open protocol stream after", streamDuration, "ms:", {
5819
+ error: streamError.message,
5820
+ code: streamError.code,
5821
+ name: streamError.name,
5822
+ connectionStatus: connection.status,
5823
+ connectionStreams: connection.streams.length,
5824
+ stack: streamError.stack?.split("\n").slice(0, 3)
5820
5825
  });
5821
- throw lastError;
5826
+ throw streamError;
5822
5827
  }
5823
5828
  const dataCopy = new Uint8Array(ciphertext);
5824
5829
  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-MVXA47HN.js";
16
+ } from "./chunk-AETVOZYQ.js";
17
17
  import {
18
18
  clearHashdCache,
19
19
  createHashdUrl,
@@ -6029,51 +6029,56 @@ var P2PProtocolClient = class {
6029
6029
  console.log(`[ByteCave P2P] Store timeout: ${Math.round(timeoutMs / 1e3)}s for ${fileSizeMB.toFixed(2)}MB`);
6030
6030
  const storePromise = (async () => {
6031
6031
  console.log("[ByteCave P2P] Step 1: Checking existing connections to peer", peerId.slice(0, 12));
6032
+ console.log("[ByteCave P2P] Full peer ID:", peerId);
6032
6033
  const existingConns = this.node.getConnections(peerIdObj);
6033
6034
  console.log("[ByteCave P2P] Existing connections:", existingConns.length);
6034
6035
  existingConns.forEach((conn, idx) => {
6035
6036
  console.log(`[ByteCave P2P] Connection ${idx}:`, {
6036
6037
  remoteAddr: conn.remoteAddr.toString(),
6038
+ remotePeer: conn.remotePeer.toString(),
6037
6039
  status: conn.status,
6038
6040
  direction: conn.direction,
6041
+ streams: conn.streams.length,
6039
6042
  timeline: conn.timeline
6040
6043
  });
6041
6044
  });
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
- }
6045
+ const peerStore = this.node.peerStore;
6046
+ try {
6047
+ const peer = await peerStore.get(peerIdObj);
6048
+ console.log("[ByteCave P2P] Peer protocols from peerStore:", peer.protocols);
6049
+ } catch (e) {
6050
+ console.warn("[ByteCave P2P] Could not get peer info from peerStore:", e);
6067
6051
  }
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)
6052
+ console.log("[ByteCave P2P] Step 2: Opening protocol stream on existing connection...");
6053
+ if (existingConns.length === 0) {
6054
+ throw new Error("No connection to peer - cannot open protocol stream");
6055
+ }
6056
+ const connection = existingConns[0];
6057
+ console.log("[ByteCave P2P] Using connection:", connection.remoteAddr.toString());
6058
+ const streamStart = Date.now();
6059
+ let stream;
6060
+ try {
6061
+ console.log("[ByteCave P2P] Calling connection.newStream with protocol /bytecave/store/1.0.0...");
6062
+ stream = await connection.newStream("/bytecave/store/1.0.0");
6063
+ const streamDuration = Date.now() - streamStart;
6064
+ console.log("[ByteCave P2P] Step 3: Protocol stream opened in", streamDuration, "ms");
6065
+ console.log("[ByteCave P2P] Stream details:", {
6066
+ protocol: stream.protocol,
6067
+ direction: stream.direction,
6068
+ id: stream.id,
6069
+ timeline: stream.timeline
6070
+ });
6071
+ } catch (streamError) {
6072
+ const streamDuration = Date.now() - streamStart;
6073
+ console.error("[ByteCave P2P] Failed to open protocol stream after", streamDuration, "ms:", {
6074
+ error: streamError.message,
6075
+ code: streamError.code,
6076
+ name: streamError.name,
6077
+ connectionStatus: connection.status,
6078
+ connectionStreams: connection.streams.length,
6079
+ stack: streamError.stack?.split("\n").slice(0, 3)
6075
6080
  });
6076
- throw lastError;
6081
+ throw streamError;
6077
6082
  }
6078
6083
  const dataCopy = new Uint8Array(ciphertext);
6079
6084
  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-MVXA47HN.js";
11
+ } from "../chunk-AETVOZYQ.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.25",
3
+ "version": "1.0.27",
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",
@@ -125,57 +125,64 @@ export class P2PProtocolClient {
125
125
  // Wrap the entire operation in a timeout
126
126
  const storePromise = (async () => {
127
127
  console.log('[ByteCave P2P] Step 1: Checking existing connections to peer', peerId.slice(0, 12));
128
+ console.log('[ByteCave P2P] Full peer ID:', peerId);
128
129
  const existingConns = this.node!.getConnections(peerIdObj);
129
130
  console.log('[ByteCave P2P] Existing connections:', existingConns.length);
130
131
  existingConns.forEach((conn, idx) => {
131
132
  console.log(`[ByteCave P2P] Connection ${idx}:`, {
132
133
  remoteAddr: conn.remoteAddr.toString(),
134
+ remotePeer: conn.remotePeer.toString(),
133
135
  status: conn.status,
134
136
  direction: conn.direction,
137
+ streams: conn.streams.length,
135
138
  timeline: conn.timeline
136
139
  });
137
140
  });
138
141
 
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;
142
+ // Check what protocols the peer supports
143
+ const peerStore = this.node!.peerStore;
144
+ try {
145
+ const peer = await peerStore.get(peerIdObj);
146
+ console.log('[ByteCave P2P] Peer protocols from peerStore:', peer.protocols);
147
+ } catch (e) {
148
+ console.warn('[ByteCave P2P] Could not get peer info from peerStore:', e);
149
+ }
144
150
 
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
- }
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...');
153
+
154
+ if (existingConns.length === 0) {
155
+ throw new Error('No connection to peer - cannot open protocol stream');
168
156
  }
169
157
 
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)
158
+ const connection = existingConns[0]; // Use first available connection
159
+ console.log('[ByteCave P2P] Using connection:', connection.remoteAddr.toString());
160
+
161
+ const streamStart = Date.now();
162
+ let stream;
163
+ try {
164
+ // Open a new stream on the existing connection with the protocol
165
+ console.log('[ByteCave P2P] Calling connection.newStream with protocol /bytecave/store/1.0.0...');
166
+ stream = await connection.newStream('/bytecave/store/1.0.0');
167
+ const streamDuration = Date.now() - streamStart;
168
+ console.log('[ByteCave P2P] Step 3: Protocol stream opened in', streamDuration, 'ms');
169
+ console.log('[ByteCave P2P] Stream details:', {
170
+ protocol: stream.protocol,
171
+ direction: stream.direction,
172
+ id: stream.id,
173
+ timeline: stream.timeline
174
+ });
175
+ } catch (streamError: any) {
176
+ const streamDuration = Date.now() - streamStart;
177
+ console.error('[ByteCave P2P] Failed to open protocol stream after', streamDuration, 'ms:', {
178
+ error: streamError.message,
179
+ code: streamError.code,
180
+ name: streamError.name,
181
+ connectionStatus: connection.status,
182
+ connectionStreams: connection.streams.length,
183
+ stack: streamError.stack?.split('\n').slice(0, 3)
177
184
  });
178
- throw lastError;
185
+ throw streamError;
179
186
  }
180
187
 
181
188
  // Generate CID using SHA-256 (matches bytecave-core format: 64-char hex)