@hive-p2p/server 1.0.31 → 1.0.32

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.
@@ -121,11 +121,13 @@ export class NodeServices {
121
121
  static deriveSTUNServers(bootstraps) {
122
122
  /** @type {Array<{urls: string}>} */
123
123
  const stunUrls = [];
124
- for (const b of bootstraps) { // {urls: 'stun:42312:NaN'}
124
+ for (const b of bootstraps) {
125
125
  if (!b.includes(':')) continue;
126
- const url = b.replace('/ws', '/signal'); // in case someone put domain/ws
127
- url.replace('/wss', '/signal'); // in case someone put domain/wss
128
- url.replace('ws://', 'stun:');
126
+ if (b.endsWith('/ws') || b.endsWith('/wss')) continue; // ugly hardcode
127
+ // useless ? => proxy can't serve as stun server
128
+ //const url = b.replace('/ws', '/signal'); // in case someone put domain/ws
129
+ //url.replace('/wss', '/signal'); // in case someone put domain/wss
130
+ const url = b.replace('ws://', 'stun:');
129
131
  url.replace('wss://', 'stun:');
130
132
  if (!url.includes('stun:')) continue;
131
133
  stunUrls.push({ urls: url });
package/core/node.mjs CHANGED
@@ -17,12 +17,13 @@ import { NodeServices } from './node-services.mjs';
17
17
  * @param {number} [options.port] If provided, the node will listen on this port (default: SERVICE.PORT)
18
18
  * @param {number} [options.verbose] Verbosity level for logging (default: NODE.DEFAULT_VERBOSE) */
19
19
  export async function createPublicNode(options) {
20
- await CLOCK.sync(this.verbose);
21
20
  const verbose = options.verbose !== undefined ? options.verbose : NODE.DEFAULT_VERBOSE;
22
21
  const domain = options.domain || undefined;
23
22
  const codex = options.cryptoCodex || new CryptoCodex(undefined, verbose);
23
+ const clockSync = CLOCK.sync(verbose);
24
24
  if (!codex.publicKey) await codex.generate(domain ? true : false);
25
25
 
26
+ await clockSync;
26
27
  const node = new Node(codex, options.bootstraps || [], verbose);
27
28
  if (domain) {
28
29
  node.services = new NodeServices(codex, node.peerStore, undefined, verbose);
@@ -42,8 +43,10 @@ export async function createPublicNode(options) {
42
43
  export async function createNode(options = {}) {
43
44
  const verbose = options.verbose !== undefined ? options.verbose : NODE.DEFAULT_VERBOSE;
44
45
  const codex = options.cryptoCodex || new CryptoCodex(undefined, verbose);
46
+ const clockSync = CLOCK.sync(verbose);
45
47
  if (!codex.publicKey) await codex.generate(false);
46
48
 
49
+ await clockSync;
47
50
  const node = new Node(codex, options.bootstraps || [], verbose);
48
51
  if (options.autoStart !== false) await node.start();
49
52
  return node;
@@ -145,10 +148,13 @@ export class Node {
145
148
  await CLOCK.sync(this.verbose);
146
149
  this.started = true;
147
150
  if (SIMULATION.AVOID_INTERVALS) return true; // SIMULATOR CASE
148
- this.topologist.tryConnectNextBootstrap(); // first shot ASAP
151
+
149
152
  this.arbiterInterval = setInterval(() => this.arbiter.tick(), 1000);
150
- this.enhancerInterval = setInterval(() => this.topologist.tick(), DISCOVERY.LOOP_DELAY);
151
153
  this.peerStoreInterval = setInterval(() => { this.peerStore.cleanupExpired(); this.peerStore.offerManager.tick(); }, 2500);
154
+ if (this.publicUrl) return true;
155
+
156
+ this.enhancerInterval = setInterval(() => this.topologist.tick(), DISCOVERY.LOOP_DELAY);
157
+ this.topologist.tryConnectNextBootstrap(); // first shot ASAP
152
158
  return true;
153
159
  }
154
160
  /** Broadcast a message to all connected peers or to a specified peer
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hive-p2p/server",
3
- "version": "1.0.31",
3
+ "version": "1.0.32",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },