@gethashd/bytecave-browser 1.0.27 → 1.0.29
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.
- package/dist/{chunk-AETVOZYQ.js → chunk-CTI3NP4T.js} +35 -12
- package/dist/index.cjs +35 -12
- package/dist/index.js +1 -1
- package/dist/react/index.cjs +25 -4
- package/dist/react/index.js +1 -1
- package/package.json +1 -1
- package/src/client.ts +13 -8
- package/src/p2p-protocols.ts +33 -6
|
@@ -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:
|
|
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
|
-
|
|
5734
|
-
|
|
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
|
|
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,
|
|
@@ -6626,9 +6647,16 @@ Nonce: ${nonce}`;
|
|
|
6626
6647
|
const peerInfo = this.knownPeers.get(peerId);
|
|
6627
6648
|
const relayAddrs = peerInfo?.relayAddrs;
|
|
6628
6649
|
if (relayAddrs && relayAddrs.length > 0 && this.node) {
|
|
6629
|
-
|
|
6650
|
+
const webrtcRelayAddrs = relayAddrs.filter((addr) => addr.includes("/webrtc"));
|
|
6651
|
+
const plainRelayAddrs = relayAddrs.filter((addr) => !addr.includes("/webrtc"));
|
|
6652
|
+
const addrToUse = webrtcRelayAddrs.length > 0 ? webrtcRelayAddrs[0] : plainRelayAddrs[0];
|
|
6653
|
+
console.log("[ByteCave] Dialing peer through relay:", peerId.slice(0, 12), {
|
|
6654
|
+
webrtcAvailable: webrtcRelayAddrs.length,
|
|
6655
|
+
plainAvailable: plainRelayAddrs.length,
|
|
6656
|
+
using: addrToUse
|
|
6657
|
+
});
|
|
6630
6658
|
try {
|
|
6631
|
-
const ma = multiaddr(
|
|
6659
|
+
const ma = multiaddr(addrToUse);
|
|
6632
6660
|
await this.node.dial(ma);
|
|
6633
6661
|
console.log("[ByteCave] Successfully dialed peer through relay");
|
|
6634
6662
|
} catch (dialError) {
|
|
@@ -6733,12 +6761,7 @@ Nonce: ${nonce}`;
|
|
|
6733
6761
|
blobCount: announcement.blobCount,
|
|
6734
6762
|
timestamp: announcement.timestamp,
|
|
6735
6763
|
multiaddrs: announcement.multiaddrs,
|
|
6736
|
-
relayAddrs: announcement.relayAddrs || existing?.relayAddrs
|
|
6737
|
-
// Store on-chain registration status
|
|
6738
|
-
registeredOnChain: announcement.registeredOnChain || false,
|
|
6739
|
-
onChainNodeId: announcement.onChainNodeId || existing?.onChainNodeId,
|
|
6740
|
-
// Store relay flag
|
|
6741
|
-
isRelay: announcement.isRelay || false
|
|
6764
|
+
relayAddrs: announcement.relayAddrs || existing?.relayAddrs
|
|
6742
6765
|
};
|
|
6743
6766
|
this.knownPeers.set(announcement.peerId, peerInfo);
|
|
6744
6767
|
this.emit("peerAnnounce", peerInfo);
|
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:
|
|
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
|
-
|
|
5802
|
-
|
|
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
|
|
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,
|
|
@@ -6679,9 +6700,16 @@ Nonce: ${nonce}`;
|
|
|
6679
6700
|
const peerInfo = this.knownPeers.get(peerId);
|
|
6680
6701
|
const relayAddrs = peerInfo?.relayAddrs;
|
|
6681
6702
|
if (relayAddrs && relayAddrs.length > 0 && this.node) {
|
|
6682
|
-
|
|
6703
|
+
const webrtcRelayAddrs = relayAddrs.filter((addr) => addr.includes("/webrtc"));
|
|
6704
|
+
const plainRelayAddrs = relayAddrs.filter((addr) => !addr.includes("/webrtc"));
|
|
6705
|
+
const addrToUse = webrtcRelayAddrs.length > 0 ? webrtcRelayAddrs[0] : plainRelayAddrs[0];
|
|
6706
|
+
console.log("[ByteCave] Dialing peer through relay:", peerId.slice(0, 12), {
|
|
6707
|
+
webrtcAvailable: webrtcRelayAddrs.length,
|
|
6708
|
+
plainAvailable: plainRelayAddrs.length,
|
|
6709
|
+
using: addrToUse
|
|
6710
|
+
});
|
|
6683
6711
|
try {
|
|
6684
|
-
const ma = (0, import_multiaddr.multiaddr)(
|
|
6712
|
+
const ma = (0, import_multiaddr.multiaddr)(addrToUse);
|
|
6685
6713
|
await this.node.dial(ma);
|
|
6686
6714
|
console.log("[ByteCave] Successfully dialed peer through relay");
|
|
6687
6715
|
} catch (dialError) {
|
|
@@ -6786,12 +6814,7 @@ Nonce: ${nonce}`;
|
|
|
6786
6814
|
blobCount: announcement.blobCount,
|
|
6787
6815
|
timestamp: announcement.timestamp,
|
|
6788
6816
|
multiaddrs: announcement.multiaddrs,
|
|
6789
|
-
relayAddrs: announcement.relayAddrs || existing?.relayAddrs
|
|
6790
|
-
// Store on-chain registration status
|
|
6791
|
-
registeredOnChain: announcement.registeredOnChain || false,
|
|
6792
|
-
onChainNodeId: announcement.onChainNodeId || existing?.onChainNodeId,
|
|
6793
|
-
// Store relay flag
|
|
6794
|
-
isRelay: announcement.isRelay || false
|
|
6817
|
+
relayAddrs: announcement.relayAddrs || existing?.relayAddrs
|
|
6795
6818
|
};
|
|
6796
6819
|
this.knownPeers.set(announcement.peerId, peerInfo);
|
|
6797
6820
|
this.emit("peerAnnounce", peerInfo);
|
package/dist/index.js
CHANGED
package/dist/react/index.cjs
CHANGED
|
@@ -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:
|
|
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
|
-
|
|
6057
|
-
|
|
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
|
|
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,
|
package/dist/react/index.js
CHANGED
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -750,10 +750,20 @@ Nonce: ${nonce}`;
|
|
|
750
750
|
const relayAddrs = (peerInfo as any)?.relayAddrs;
|
|
751
751
|
|
|
752
752
|
// If we have relay addresses, dial through relay first
|
|
753
|
+
// Prefer WebRTC circuit relay addresses for direct connections
|
|
753
754
|
if (relayAddrs && relayAddrs.length > 0 && this.node) {
|
|
754
|
-
|
|
755
|
+
const webrtcRelayAddrs = relayAddrs.filter((addr: string) => addr.includes('/webrtc'));
|
|
756
|
+
const plainRelayAddrs = relayAddrs.filter((addr: string) => !addr.includes('/webrtc'));
|
|
757
|
+
const addrToUse = webrtcRelayAddrs.length > 0 ? webrtcRelayAddrs[0] : plainRelayAddrs[0];
|
|
758
|
+
|
|
759
|
+
console.log('[ByteCave] Dialing peer through relay:', peerId.slice(0, 12), {
|
|
760
|
+
webrtcAvailable: webrtcRelayAddrs.length,
|
|
761
|
+
plainAvailable: plainRelayAddrs.length,
|
|
762
|
+
using: addrToUse
|
|
763
|
+
});
|
|
764
|
+
|
|
755
765
|
try {
|
|
756
|
-
const ma = multiaddr(
|
|
766
|
+
const ma = multiaddr(addrToUse);
|
|
757
767
|
await this.node.dial(ma as any);
|
|
758
768
|
console.log('[ByteCave] Successfully dialed peer through relay');
|
|
759
769
|
} catch (dialError) {
|
|
@@ -881,12 +891,7 @@ Nonce: ${nonce}`;
|
|
|
881
891
|
blobCount: announcement.blobCount,
|
|
882
892
|
timestamp: announcement.timestamp,
|
|
883
893
|
multiaddrs: announcement.multiaddrs,
|
|
884
|
-
relayAddrs: announcement.relayAddrs || (existing as any)?.relayAddrs
|
|
885
|
-
// Store on-chain registration status
|
|
886
|
-
registeredOnChain: announcement.registeredOnChain || false,
|
|
887
|
-
onChainNodeId: announcement.onChainNodeId || (existing as any)?.onChainNodeId,
|
|
888
|
-
// Store relay flag
|
|
889
|
-
isRelay: announcement.isRelay || false
|
|
894
|
+
relayAddrs: announcement.relayAddrs || (existing as any)?.relayAddrs
|
|
890
895
|
};
|
|
891
896
|
|
|
892
897
|
this.knownPeers.set(announcement.peerId, peerInfo);
|
package/src/p2p-protocols.ts
CHANGED
|
@@ -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:
|
|
152
|
-
console.log('[ByteCave P2P] Step 2:
|
|
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
|
-
|
|
159
|
-
|
|
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
|
|
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,
|