@gethashd/bytecave-browser 1.0.19 → 1.0.21
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-RR3DUVG7.js → chunk-HKE7DLEO.js} +5 -39
- package/dist/index.cjs +5 -39
- package/dist/index.js +1 -1
- package/dist/p2p-protocols.d.ts +1 -7
- package/dist/react/index.cjs +2 -32
- package/dist/react/index.js +1 -1
- package/package.json +1 -1
- package/src/client.ts +4 -7
- package/src/p2p-protocols.ts +3 -42
|
@@ -5777,47 +5777,16 @@ var P2PProtocolClient = class {
|
|
|
5777
5777
|
return null;
|
|
5778
5778
|
}
|
|
5779
5779
|
}
|
|
5780
|
-
/**
|
|
5781
|
-
* Wait for a direct (non-relay) connection to a peer
|
|
5782
|
-
* Returns true if direct connection is available, false if timeout
|
|
5783
|
-
*/
|
|
5784
|
-
async waitForDirectConnection(peerId, timeoutMs = 3e3) {
|
|
5785
|
-
if (!this.node) return false;
|
|
5786
|
-
const peerIdObj = peerIdFromString(peerId);
|
|
5787
|
-
const startTime = Date.now();
|
|
5788
|
-
while (Date.now() - startTime < timeoutMs) {
|
|
5789
|
-
const connections = this.node.getConnections(peerIdObj);
|
|
5790
|
-
const hasDirectConnection = connections.some((conn) => {
|
|
5791
|
-
const isRelay = conn.remoteAddr.toString().includes("/p2p-circuit");
|
|
5792
|
-
return !isRelay;
|
|
5793
|
-
});
|
|
5794
|
-
if (hasDirectConnection) {
|
|
5795
|
-
console.log("[ByteCave P2P] Direct connection established to", peerId.slice(0, 12));
|
|
5796
|
-
return true;
|
|
5797
|
-
}
|
|
5798
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
5799
|
-
}
|
|
5800
|
-
console.warn("[ByteCave P2P] Timeout waiting for direct connection to", peerId.slice(0, 12));
|
|
5801
|
-
return false;
|
|
5802
|
-
}
|
|
5803
5780
|
/**
|
|
5804
5781
|
* Get health info from a peer via P2P stream
|
|
5805
|
-
* Waits for direct connection upgrade before querying
|
|
5806
5782
|
*/
|
|
5807
|
-
async getHealthFromPeer(peerId
|
|
5783
|
+
async getHealthFromPeer(peerId) {
|
|
5808
5784
|
if (!this.node) {
|
|
5809
5785
|
console.warn("[ByteCave P2P] No node available for health request");
|
|
5810
5786
|
return null;
|
|
5811
5787
|
}
|
|
5812
5788
|
try {
|
|
5813
5789
|
const peerIdObj = peerIdFromString(peerId);
|
|
5814
|
-
if (waitForDirect) {
|
|
5815
|
-
const hasDirect = await this.waitForDirectConnection(peerId, 3e3);
|
|
5816
|
-
if (!hasDirect) {
|
|
5817
|
-
console.warn("[ByteCave P2P] No direct connection available for health query to", peerId.slice(0, 12));
|
|
5818
|
-
return null;
|
|
5819
|
-
}
|
|
5820
|
-
}
|
|
5821
5790
|
const stream = await this.node.dialProtocol(peerIdObj, PROTOCOL_HEALTH);
|
|
5822
5791
|
await this.writeMessage(stream, {});
|
|
5823
5792
|
const response = await this.readMessage(stream);
|
|
@@ -5985,6 +5954,7 @@ import { floodsub } from "@libp2p/floodsub";
|
|
|
5985
5954
|
import { identify } from "@libp2p/identify";
|
|
5986
5955
|
import { bootstrap } from "@libp2p/bootstrap";
|
|
5987
5956
|
import { circuitRelayTransport } from "@libp2p/circuit-relay-v2";
|
|
5957
|
+
import { dcutr } from "@libp2p/dcutr";
|
|
5988
5958
|
import { multiaddr } from "@multiformats/multiaddr";
|
|
5989
5959
|
import { fromString, toString } from "uint8arrays";
|
|
5990
5960
|
import { ethers as ethers2 } from "ethers";
|
|
@@ -6053,7 +6023,8 @@ var ByteCaveClient = class {
|
|
|
6053
6023
|
streamMuxers: [yamux()],
|
|
6054
6024
|
services: {
|
|
6055
6025
|
identify: identify(),
|
|
6056
|
-
pubsub: floodsub()
|
|
6026
|
+
pubsub: floodsub(),
|
|
6027
|
+
dcutr: dcutr()
|
|
6057
6028
|
},
|
|
6058
6029
|
connectionGater: {
|
|
6059
6030
|
denyDialMultiaddr: () => false,
|
|
@@ -6675,12 +6646,7 @@ Nonce: ${nonce}`;
|
|
|
6675
6646
|
blobCount: announcement.blobCount,
|
|
6676
6647
|
timestamp: announcement.timestamp,
|
|
6677
6648
|
multiaddrs: announcement.multiaddrs,
|
|
6678
|
-
relayAddrs: announcement.relayAddrs || existing?.relayAddrs
|
|
6679
|
-
// Store on-chain registration status
|
|
6680
|
-
registeredOnChain: announcement.registeredOnChain || false,
|
|
6681
|
-
onChainNodeId: announcement.onChainNodeId || existing?.onChainNodeId,
|
|
6682
|
-
// Store relay flag so we can filter out relays from storage attempts
|
|
6683
|
-
isRelay: announcement.isRelay || false
|
|
6649
|
+
relayAddrs: announcement.relayAddrs || existing?.relayAddrs
|
|
6684
6650
|
};
|
|
6685
6651
|
this.knownPeers.set(announcement.peerId, peerInfo);
|
|
6686
6652
|
this.emit("peerAnnounce", peerInfo);
|
package/dist/index.cjs
CHANGED
|
@@ -67,6 +67,7 @@ var import_floodsub = require("@libp2p/floodsub");
|
|
|
67
67
|
var import_identify = require("@libp2p/identify");
|
|
68
68
|
var import_bootstrap = require("@libp2p/bootstrap");
|
|
69
69
|
var import_circuit_relay_v2 = require("@libp2p/circuit-relay-v2");
|
|
70
|
+
var import_dcutr = require("@libp2p/dcutr");
|
|
70
71
|
var import_multiaddr = require("@multiformats/multiaddr");
|
|
71
72
|
var import_uint8arrays = require("uint8arrays");
|
|
72
73
|
var import_ethers2 = require("ethers");
|
|
@@ -5844,47 +5845,16 @@ var P2PProtocolClient = class {
|
|
|
5844
5845
|
return null;
|
|
5845
5846
|
}
|
|
5846
5847
|
}
|
|
5847
|
-
/**
|
|
5848
|
-
* Wait for a direct (non-relay) connection to a peer
|
|
5849
|
-
* Returns true if direct connection is available, false if timeout
|
|
5850
|
-
*/
|
|
5851
|
-
async waitForDirectConnection(peerId, timeoutMs = 3e3) {
|
|
5852
|
-
if (!this.node) return false;
|
|
5853
|
-
const peerIdObj = peerIdFromString(peerId);
|
|
5854
|
-
const startTime = Date.now();
|
|
5855
|
-
while (Date.now() - startTime < timeoutMs) {
|
|
5856
|
-
const connections = this.node.getConnections(peerIdObj);
|
|
5857
|
-
const hasDirectConnection = connections.some((conn) => {
|
|
5858
|
-
const isRelay = conn.remoteAddr.toString().includes("/p2p-circuit");
|
|
5859
|
-
return !isRelay;
|
|
5860
|
-
});
|
|
5861
|
-
if (hasDirectConnection) {
|
|
5862
|
-
console.log("[ByteCave P2P] Direct connection established to", peerId.slice(0, 12));
|
|
5863
|
-
return true;
|
|
5864
|
-
}
|
|
5865
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
5866
|
-
}
|
|
5867
|
-
console.warn("[ByteCave P2P] Timeout waiting for direct connection to", peerId.slice(0, 12));
|
|
5868
|
-
return false;
|
|
5869
|
-
}
|
|
5870
5848
|
/**
|
|
5871
5849
|
* Get health info from a peer via P2P stream
|
|
5872
|
-
* Waits for direct connection upgrade before querying
|
|
5873
5850
|
*/
|
|
5874
|
-
async getHealthFromPeer(peerId
|
|
5851
|
+
async getHealthFromPeer(peerId) {
|
|
5875
5852
|
if (!this.node) {
|
|
5876
5853
|
console.warn("[ByteCave P2P] No node available for health request");
|
|
5877
5854
|
return null;
|
|
5878
5855
|
}
|
|
5879
5856
|
try {
|
|
5880
5857
|
const peerIdObj = peerIdFromString(peerId);
|
|
5881
|
-
if (waitForDirect) {
|
|
5882
|
-
const hasDirect = await this.waitForDirectConnection(peerId, 3e3);
|
|
5883
|
-
if (!hasDirect) {
|
|
5884
|
-
console.warn("[ByteCave P2P] No direct connection available for health query to", peerId.slice(0, 12));
|
|
5885
|
-
return null;
|
|
5886
|
-
}
|
|
5887
|
-
}
|
|
5888
5858
|
const stream = await this.node.dialProtocol(peerIdObj, PROTOCOL_HEALTH);
|
|
5889
5859
|
await this.writeMessage(stream, {});
|
|
5890
5860
|
const response = await this.readMessage(stream);
|
|
@@ -6106,7 +6076,8 @@ var ByteCaveClient = class {
|
|
|
6106
6076
|
streamMuxers: [(0, import_libp2p_yamux.yamux)()],
|
|
6107
6077
|
services: {
|
|
6108
6078
|
identify: (0, import_identify.identify)(),
|
|
6109
|
-
pubsub: (0, import_floodsub.floodsub)()
|
|
6079
|
+
pubsub: (0, import_floodsub.floodsub)(),
|
|
6080
|
+
dcutr: (0, import_dcutr.dcutr)()
|
|
6110
6081
|
},
|
|
6111
6082
|
connectionGater: {
|
|
6112
6083
|
denyDialMultiaddr: () => false,
|
|
@@ -6728,12 +6699,7 @@ Nonce: ${nonce}`;
|
|
|
6728
6699
|
blobCount: announcement.blobCount,
|
|
6729
6700
|
timestamp: announcement.timestamp,
|
|
6730
6701
|
multiaddrs: announcement.multiaddrs,
|
|
6731
|
-
relayAddrs: announcement.relayAddrs || existing?.relayAddrs
|
|
6732
|
-
// Store on-chain registration status
|
|
6733
|
-
registeredOnChain: announcement.registeredOnChain || false,
|
|
6734
|
-
onChainNodeId: announcement.onChainNodeId || existing?.onChainNodeId,
|
|
6735
|
-
// Store relay flag so we can filter out relays from storage attempts
|
|
6736
|
-
isRelay: announcement.isRelay || false
|
|
6702
|
+
relayAddrs: announcement.relayAddrs || existing?.relayAddrs
|
|
6737
6703
|
};
|
|
6738
6704
|
this.knownPeers.set(announcement.peerId, peerInfo);
|
|
6739
6705
|
this.emit("peerAnnounce", peerInfo);
|
package/dist/index.js
CHANGED
package/dist/p2p-protocols.d.ts
CHANGED
|
@@ -90,16 +90,10 @@ export declare class P2PProtocolClient {
|
|
|
90
90
|
data: Uint8Array;
|
|
91
91
|
mimeType: string;
|
|
92
92
|
} | null>;
|
|
93
|
-
/**
|
|
94
|
-
* Wait for a direct (non-relay) connection to a peer
|
|
95
|
-
* Returns true if direct connection is available, false if timeout
|
|
96
|
-
*/
|
|
97
|
-
private waitForDirectConnection;
|
|
98
93
|
/**
|
|
99
94
|
* Get health info from a peer via P2P stream
|
|
100
|
-
* Waits for direct connection upgrade before querying
|
|
101
95
|
*/
|
|
102
|
-
getHealthFromPeer(peerId: string
|
|
96
|
+
getHealthFromPeer(peerId: string): Promise<P2PHealthResponse | null>;
|
|
103
97
|
/**
|
|
104
98
|
* Query relay for peer directory
|
|
105
99
|
*/
|
package/dist/react/index.cjs
CHANGED
|
@@ -402,6 +402,7 @@ var import_floodsub = require("@libp2p/floodsub");
|
|
|
402
402
|
var import_identify = require("@libp2p/identify");
|
|
403
403
|
var import_bootstrap = require("@libp2p/bootstrap");
|
|
404
404
|
var import_circuit_relay_v2 = require("@libp2p/circuit-relay-v2");
|
|
405
|
+
var import_dcutr = require("@libp2p/dcutr");
|
|
405
406
|
var import_multiaddr = require("@multiformats/multiaddr");
|
|
406
407
|
var import_uint8arrays = require("uint8arrays");
|
|
407
408
|
var import_ethers2 = require("ethers");
|
|
@@ -6099,47 +6100,16 @@ var P2PProtocolClient = class {
|
|
|
6099
6100
|
return null;
|
|
6100
6101
|
}
|
|
6101
6102
|
}
|
|
6102
|
-
/**
|
|
6103
|
-
* Wait for a direct (non-relay) connection to a peer
|
|
6104
|
-
* Returns true if direct connection is available, false if timeout
|
|
6105
|
-
*/
|
|
6106
|
-
async waitForDirectConnection(peerId, timeoutMs = 3e3) {
|
|
6107
|
-
if (!this.node) return false;
|
|
6108
|
-
const peerIdObj = peerIdFromString(peerId);
|
|
6109
|
-
const startTime = Date.now();
|
|
6110
|
-
while (Date.now() - startTime < timeoutMs) {
|
|
6111
|
-
const connections = this.node.getConnections(peerIdObj);
|
|
6112
|
-
const hasDirectConnection = connections.some((conn) => {
|
|
6113
|
-
const isRelay = conn.remoteAddr.toString().includes("/p2p-circuit");
|
|
6114
|
-
return !isRelay;
|
|
6115
|
-
});
|
|
6116
|
-
if (hasDirectConnection) {
|
|
6117
|
-
console.log("[ByteCave P2P] Direct connection established to", peerId.slice(0, 12));
|
|
6118
|
-
return true;
|
|
6119
|
-
}
|
|
6120
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
6121
|
-
}
|
|
6122
|
-
console.warn("[ByteCave P2P] Timeout waiting for direct connection to", peerId.slice(0, 12));
|
|
6123
|
-
return false;
|
|
6124
|
-
}
|
|
6125
6103
|
/**
|
|
6126
6104
|
* Get health info from a peer via P2P stream
|
|
6127
|
-
* Waits for direct connection upgrade before querying
|
|
6128
6105
|
*/
|
|
6129
|
-
async getHealthFromPeer(peerId
|
|
6106
|
+
async getHealthFromPeer(peerId) {
|
|
6130
6107
|
if (!this.node) {
|
|
6131
6108
|
console.warn("[ByteCave P2P] No node available for health request");
|
|
6132
6109
|
return null;
|
|
6133
6110
|
}
|
|
6134
6111
|
try {
|
|
6135
6112
|
const peerIdObj = peerIdFromString(peerId);
|
|
6136
|
-
if (waitForDirect) {
|
|
6137
|
-
const hasDirect = await this.waitForDirectConnection(peerId, 3e3);
|
|
6138
|
-
if (!hasDirect) {
|
|
6139
|
-
console.warn("[ByteCave P2P] No direct connection available for health query to", peerId.slice(0, 12));
|
|
6140
|
-
return null;
|
|
6141
|
-
}
|
|
6142
|
-
}
|
|
6143
6113
|
const stream = await this.node.dialProtocol(peerIdObj, PROTOCOL_HEALTH);
|
|
6144
6114
|
await this.writeMessage(stream, {});
|
|
6145
6115
|
const response = await this.readMessage(stream);
|
package/dist/react/index.js
CHANGED
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { floodsub } from '@libp2p/floodsub';
|
|
|
13
13
|
import { identify } from '@libp2p/identify';
|
|
14
14
|
import { bootstrap } from '@libp2p/bootstrap';
|
|
15
15
|
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2';
|
|
16
|
+
import { dcutr } from '@libp2p/dcutr';
|
|
16
17
|
import { multiaddr } from '@multiformats/multiaddr';
|
|
17
18
|
import { peerIdFromString } from '@libp2p/peer-id';
|
|
18
19
|
import { fromString, toString } from 'uint8arrays';
|
|
@@ -104,7 +105,8 @@ export class ByteCaveClient {
|
|
|
104
105
|
streamMuxers: [yamux()],
|
|
105
106
|
services: {
|
|
106
107
|
identify: identify(),
|
|
107
|
-
pubsub: floodsub()
|
|
108
|
+
pubsub: floodsub(),
|
|
109
|
+
dcutr: dcutr() as any
|
|
108
110
|
},
|
|
109
111
|
connectionGater: {
|
|
110
112
|
denyDialMultiaddr: () => false,
|
|
@@ -879,12 +881,7 @@ Nonce: ${nonce}`;
|
|
|
879
881
|
blobCount: announcement.blobCount,
|
|
880
882
|
timestamp: announcement.timestamp,
|
|
881
883
|
multiaddrs: announcement.multiaddrs,
|
|
882
|
-
relayAddrs: announcement.relayAddrs || (existing as any)?.relayAddrs
|
|
883
|
-
// Store on-chain registration status
|
|
884
|
-
registeredOnChain: announcement.registeredOnChain || false,
|
|
885
|
-
onChainNodeId: announcement.onChainNodeId || (existing as any)?.onChainNodeId,
|
|
886
|
-
// Store relay flag so we can filter out relays from storage attempts
|
|
887
|
-
isRelay: announcement.isRelay || false
|
|
884
|
+
relayAddrs: announcement.relayAddrs || (existing as any)?.relayAddrs
|
|
888
885
|
};
|
|
889
886
|
|
|
890
887
|
this.knownPeers.set(announcement.peerId, peerInfo);
|
package/src/p2p-protocols.ts
CHANGED
|
@@ -125,7 +125,7 @@ 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: Dialing store protocol...');
|
|
128
|
-
//
|
|
128
|
+
// dialProtocol will upgrade limited relay connections to full connections automatically
|
|
129
129
|
const stream = await this.node!.dialProtocol(peerIdObj, '/bytecave/store/1.0.0');
|
|
130
130
|
console.log('[ByteCave P2P] Step 2: Stream established');
|
|
131
131
|
|
|
@@ -219,59 +219,20 @@ export class P2PProtocolClient {
|
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
/**
|
|
223
|
-
* Wait for a direct (non-relay) connection to a peer
|
|
224
|
-
* Returns true if direct connection is available, false if timeout
|
|
225
|
-
*/
|
|
226
|
-
private async waitForDirectConnection(peerId: string, timeoutMs: number = 3000): Promise<boolean> {
|
|
227
|
-
if (!this.node) return false;
|
|
228
|
-
|
|
229
|
-
const peerIdObj = peerIdFromString(peerId);
|
|
230
|
-
const startTime = Date.now();
|
|
231
|
-
|
|
232
|
-
while (Date.now() - startTime < timeoutMs) {
|
|
233
|
-
const connections = this.node.getConnections(peerIdObj);
|
|
234
|
-
const hasDirectConnection = connections.some(conn => {
|
|
235
|
-
// Check if connection is NOT a relay circuit (direct WebRTC or WebSocket)
|
|
236
|
-
const isRelay = conn.remoteAddr.toString().includes('/p2p-circuit');
|
|
237
|
-
return !isRelay;
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
if (hasDirectConnection) {
|
|
241
|
-
console.log('[ByteCave P2P] Direct connection established to', peerId.slice(0, 12));
|
|
242
|
-
return true;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// Wait 100ms before checking again
|
|
246
|
-
await new Promise(resolve => setTimeout(resolve, 100));
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
console.warn('[ByteCave P2P] Timeout waiting for direct connection to', peerId.slice(0, 12));
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
222
|
/**
|
|
254
223
|
* Get health info from a peer via P2P stream
|
|
255
|
-
* Waits for direct connection upgrade before querying
|
|
256
224
|
*/
|
|
257
|
-
async getHealthFromPeer(peerId: string
|
|
225
|
+
async getHealthFromPeer(peerId: string): Promise<P2PHealthResponse | null> {
|
|
258
226
|
if (!this.node) {
|
|
259
227
|
console.warn('[ByteCave P2P] No node available for health request');
|
|
260
228
|
return null;
|
|
261
229
|
}
|
|
262
230
|
|
|
263
231
|
try {
|
|
232
|
+
|
|
264
233
|
// Convert string peerId to PeerId object
|
|
265
234
|
const peerIdObj = peerIdFromString(peerId);
|
|
266
235
|
|
|
267
|
-
// Wait for DCUtR to upgrade connection to direct WebRTC
|
|
268
|
-
if (waitForDirect) {
|
|
269
|
-
const hasDirect = await this.waitForDirectConnection(peerId, 3000);
|
|
270
|
-
if (!hasDirect) {
|
|
271
|
-
console.warn('[ByteCave P2P] No direct connection available for health query to', peerId.slice(0, 12));
|
|
272
|
-
return null;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
236
|
|
|
276
237
|
const stream = await this.node.dialProtocol(peerIdObj, PROTOCOL_HEALTH);
|
|
277
238
|
|