@hive-p2p/server 1.0.30 → 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.
- package/core/node-services.mjs +8 -3
- package/core/node.mjs +9 -3
- package/package.json +1 -1
package/core/node-services.mjs
CHANGED
|
@@ -123,9 +123,14 @@ export class NodeServices {
|
|
|
123
123
|
const stunUrls = [];
|
|
124
124
|
for (const b of bootstraps) {
|
|
125
125
|
if (!b.includes(':')) continue;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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:');
|
|
131
|
+
url.replace('wss://', 'stun:');
|
|
132
|
+
if (!url.includes('stun:')) continue;
|
|
133
|
+
stunUrls.push({ urls: url });
|
|
129
134
|
}
|
|
130
135
|
if (!TRANSPORTS.CENTRALIZED_STUN_SERVERS) return stunUrls;
|
|
131
136
|
|
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
|
-
|
|
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
|