@hive-p2p/server 1.0.24 → 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.
package/core/arbiter.mjs CHANGED
@@ -67,7 +67,7 @@ export class Arbiter {
67
67
  adjustTrust(peerId, delta, reason = 'na') { // Internal and API use - return true if peer isn't banished
68
68
  if (peerId === this.id) return; // self
69
69
  if (delta) this.trustBalances[peerId] = Math.min(MAX_TRUST, (this.trustBalances[peerId] || 0) + delta);
70
- if (delta && this.verbose > 2) console.log(`%c(Arbiter: ${this.id}) ${peerId} +${delta}ms (${reason}). Updated: ${this.trustBalances[peerId]}ms.`, LOG_CSS.ARBITER);
70
+ if (delta && this.verbose > 3) console.log(`%c(Arbiter: ${this.id}) ${peerId} +${delta}ms (${reason}). Updated: ${this.trustBalances[peerId]}ms.`, LOG_CSS.ARBITER);
71
71
  if (this.isBanished(peerId) && this.verbose > 1) console.log(`%c(Arbiter: ${this.id}) Peer ${peerId} is now banished.`, LOG_CSS.ARBITER);
72
72
  }
73
73
  isBanished(peerId = 'toto') { return (this.trustBalances[peerId] || 0) < 0; }
package/core/config.mjs CHANGED
@@ -104,7 +104,7 @@ export const TRANSPORTS = {
104
104
  /** Time to wait for signal before destroying WTRC connection | Default: 8_000 (8 seconds) */
105
105
  SIGNAL_CREATION_TIMEOUT: 8_000,
106
106
  /** Time to consider an SDP offer as valid | Default: 40_000 (40 seconds) */
107
- SDP_OFFER_EXPIRATION: 40_000,
107
+ SDP_OFFER_EXPIRATION: 40_000,
108
108
 
109
109
  WS_CLIENT: WebSocket,
110
110
  WS_SERVER: isNode ? (await import('ws')).WebSocketServer : null,
@@ -188,7 +188,7 @@ export class CryptoCodex {
188
188
  /** @param {Uint8Array | ArrayBuffer} serialized @return {GossipMessage | null } */
189
189
  readGossipMessage(serialized) {
190
190
  if (this.verbose > 3) console.log(`%creadGossipMessage ${serialized.byteLength} bytes`, LOG_CSS.CRYPTO_CODEX);
191
- if (this.verbose > 3) console.log(`%c${serialized}`, LOG_CSS.CRYPTO_CODEX);
191
+ if (this.verbose > 4) console.log(`%c${serialized}`, LOG_CSS.CRYPTO_CODEX);
192
192
  try { // 1, 1, 1, 8, 4, 32, X, 64, 1
193
193
  const { marker, dataCode, neighLength, timestamp, dataLength, pubkey, associatedId } = this.readBufferHeader(serialized);
194
194
  const topic = GOSSIP.MARKERS_BYTES[marker];
@@ -208,7 +208,7 @@ export class CryptoCodex {
208
208
  /** @param {Uint8Array | ArrayBuffer} serialized @return {DirectMessage | ReroutedDirectMessage | null} */
209
209
  readUnicastMessage(serialized) {
210
210
  if (this.verbose > 3) console.log(`%creadUnicastMessage ${serialized.byteLength} bytes`, LOG_CSS.CRYPTO_CODEX);
211
- if (this.verbose > 3) console.log(`%c${serialized}`, LOG_CSS.CRYPTO_CODEX);
211
+ if (this.verbose > 4) console.log(`%c${serialized}`, LOG_CSS.CRYPTO_CODEX);
212
212
  try { // 1, 1, 1, 8, 4, 32, X, 1, X, 64
213
213
  const { marker, dataCode, neighLength, timestamp, dataLength, pubkey } = this.readBufferHeader(serialized, false);
214
214
  const type = UNICAST.MARKERS_BYTES[marker];
@@ -89,6 +89,7 @@ export class NodeServices {
89
89
  this.stunServer.send(this.#buildSTUNResponse(msg, rinfo), rinfo.port, rinfo.address);
90
90
  });
91
91
  this.stunServer.bind(port, host);
92
+ if (this.verbose > 2) console.log(`%cSTUN server listening on ${host}:${port}`, LOG_CSS.SERVICE);
92
93
  }
93
94
  #isValidSTUNRequest(msg) {
94
95
  if (msg.length < 20) return false;
@@ -144,9 +144,18 @@ export class Topologist {
144
144
  }
145
145
  /** Get overlap information for multiple peers @param {string[]} peerIds */
146
146
  #getOverlaps(peerIds = []) { return peerIds.map(id => ({ id, ...this.#getOverlap(id) })); }
147
+ #getFullWsUrl(url) {
148
+ // Auto-detect protocol: use wss:// if in browser + HTTPS
149
+ const isBrowser = typeof window !== 'undefined';
150
+ const isSecure = isBrowser && window.location.protocol === 'https:';
151
+ const protocol = isSecure ? 'wss://' : 'ws://';
152
+
153
+ // Build full URL if not already prefixed
154
+ return url.startsWith('ws') ? url : `${protocol}${url}`;
155
+ }
147
156
  #connectToPublicNode(publicUrl = 'localhost:8080') {
148
157
  let remoteId = null;
149
- const ws = new TRANSPORTS.WS_CLIENT(publicUrl); ws.binaryType = 'arraybuffer';
158
+ const ws = new TRANSPORTS.WS_CLIENT(this.#getFullWsUrl(publicUrl)); ws.binaryType = 'arraybuffer';
150
159
  ws.onerror = (error) => console.error(`WebSocket error:`, error.stack);
151
160
  ws.onopen = () => {
152
161
  this.bootstrapsConnectionState.set(publicUrl, true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hive-p2p/server",
3
- "version": "1.0.24",
3
+ "version": "1.0.25",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },