@hive-p2p/server 1.0.32 → 1.0.34

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
@@ -1,4 +1,5 @@
1
- import { CLOCK, NODE, GOSSIP, UNICAST, LOG_CSS } from './config.mjs';
1
+ import { CLOCK } from '../services/clock.mjs';
2
+ import { GOSSIP, UNICAST, LOG_CSS } from './config.mjs';
2
3
 
3
4
  // TRUST_BALANCE = seconds of ban if negative - never exceed MAX_TRUST if positive
4
5
  // Growing each second by 1000ms until 0
package/core/config.mjs CHANGED
@@ -1,14 +1,10 @@
1
1
  const isNode = (typeof window === 'undefined');
2
2
  if (!isNode) (await import('../libs/simplepeer-9.11.1.min.js')).default;
3
- import { Clock } from '../services/clock.mjs';
4
3
 
5
4
  // HOLD: GLOBAL CONFIG FOR THE LIBRARY
6
5
  // AVOID: CIRCULAR DEPENDENCIES AND TOO MANY FUNCTION/CONSTRUCTOR CONFIG
7
6
  // SIMPLIFY: IMPORTS, SIMULATOR AND BROWSER SUPPORT
8
7
 
9
- /** Synchronized clock that can be used outside the library */
10
- export const CLOCK = Clock.instance;
11
-
12
8
  export const SIMULATION = {
13
9
  /** Specify setInterval() avoidance for faster simulation (true = avoid intervals) | Default: true */
14
10
  AVOID_INTERVALS: false,
@@ -223,6 +219,4 @@ export const LOG_CSS = {
223
219
  PUNISHER: { BAN: 'color: red; font-weight: bold;', KICK: 'color: darkorange; font-weight: bold;' },
224
220
  }
225
221
 
226
- export default {
227
- CLOCK, SIMULATION, NODE, TRANSPORTS, DISCOVERY, IDENTITY, UNICAST, GOSSIP, LOG_CSS
228
- };
222
+ export default { SIMULATION, NODE, TRANSPORTS, DISCOVERY, IDENTITY, UNICAST, GOSSIP, LOG_CSS };
@@ -1,4 +1,5 @@
1
- import { CLOCK, SIMULATION, NODE, IDENTITY, GOSSIP, UNICAST, LOG_CSS } from './config.mjs';
1
+ import { CLOCK } from '../services/clock.mjs';
2
+ import { SIMULATION, NODE, IDENTITY, GOSSIP, UNICAST, LOG_CSS } from './config.mjs';
2
3
  import { GossipMessage } from './gossip.mjs';
3
4
  import { DirectMessage, ReroutedDirectMessage } from './unicast.mjs';
4
5
  import { Converter } from '../services/converter.mjs';
package/core/gossip.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import { CLOCK, GOSSIP, DISCOVERY } from './config.mjs';
1
+ import { CLOCK } from '../services/clock.mjs';
2
+ import { GOSSIP } from './config.mjs';
2
3
  import { xxHash32 } from '../libs/xxhash32.mjs';
3
4
 
4
5
  export class GossipMessage { // TYPE DEFINITION
@@ -1,4 +1,5 @@
1
- import { CLOCK, NODE, TRANSPORTS, LOG_CSS } from './config.mjs';
1
+ import { CLOCK } from '../services/clock.mjs';
2
+ import { NODE, TRANSPORTS, LOG_CSS } from './config.mjs';
2
3
  import { xxHash32 } from '../libs/xxhash32.mjs';
3
4
  async function getWrtc() {
4
5
  if (typeof globalThis.RTCPeerConnection !== 'undefined') return undefined;
package/core/node.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import { CLOCK, SIMULATION, NODE, SERVICE, DISCOVERY } from './config.mjs';
1
+ import { CLOCK } from '../services/clock.mjs';
2
+ import { SIMULATION, NODE, SERVICE, DISCOVERY } from './config.mjs';
2
3
  import { Arbiter } from './arbiter.mjs';
3
4
  import { OfferManager } from './ice-offer-manager.mjs';
4
5
  import { PeerStore } from './peer-store.mjs';
@@ -139,6 +140,7 @@ export class Node {
139
140
  }
140
141
 
141
142
  // PUBLIC API
143
+ /** @returns {string | undefined} */
142
144
  get publicUrl() { return this.services?.publicUrl; }
143
145
 
144
146
  onMessageData(callback) { this.messager.on('message', callback); }
@@ -1,4 +1,5 @@
1
- import { CLOCK, SIMULATION, NODE, DISCOVERY, LOG_CSS } from './config.mjs';
1
+ import { CLOCK } from '../services/clock.mjs';
2
+ import { SIMULATION, NODE, DISCOVERY, LOG_CSS } from './config.mjs';
2
3
  const { SANDBOX, ICE_CANDIDATE_EMITTER, TEST_WS_EVENT_MANAGER } = SIMULATION.ENABLED ? await import('../simulation/test-transports.mjs') : {};
3
4
 
4
5
  export class KnownPeer { // known peer, not necessarily connected
@@ -1,4 +1,5 @@
1
- import { CLOCK, SIMULATION, TRANSPORTS, NODE, DISCOVERY, GOSSIP } from './config.mjs';
1
+ import { CLOCK } from '../services/clock.mjs';
2
+ import { SIMULATION, TRANSPORTS, NODE, DISCOVERY, GOSSIP } from './config.mjs';
2
3
  import { PeerConnection } from './peer-store.mjs';
3
4
  const { SANDBOX, ICE_CANDIDATE_EMITTER, TEST_WS_EVENT_MANAGER } = SIMULATION.ENABLED ? await import('../simulation/test-transports.mjs') : {};
4
5
 
package/index.mjs CHANGED
@@ -1,7 +1,19 @@
1
1
  import { Node, createNode, createPublicNode } from "./core/node.mjs";
2
2
  import { CryptoCodex } from "./core/crypto-codex.mjs";
3
+ import { CLOCK } from "./services/clock.mjs';
3
4
  import CONFIG from "./core/config.mjs";
4
5
 
5
- const HiveP2P = { Node, createNode, createPublicNode, CryptoCodex, CONFIG };
6
- export { Node, createNode, createPublicNode, CryptoCodex, CONFIG };
6
+ /**
7
+ * @typedef {Object} HiveP2PNamespace
8
+ * @property {typeof CLOCK} CLOCK
9
+ * @property {typeof CONFIG} CONFIG
10
+ * @property {typeof Node} Node
11
+ * @property {typeof createNode} createNode
12
+ * @property {typeof CryptoCodex} CryptoCodex
13
+ * @property {typeof createPublicNode} createPublicNode
14
+ */
15
+
16
+ /** @type {HiveP2PNamespace} */
17
+ const HiveP2P = { CLOCK, CONFIG, Node, createNode, createPublicNode, CryptoCodex };
18
+ export { CLOCK, CONFIG, Node, createNode, createPublicNode, CryptoCodex };
7
19
  export default HiveP2P;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hive-p2p/server",
3
- "version": "1.0.32",
3
+ "version": "1.0.34",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -126,7 +126,7 @@ export class Clock {
126
126
  } catch (error) { if (this.verbose) console.warn('[Clock] Background refine failed:', error); }
127
127
  }
128
128
  }
129
-
129
+ export const CLOCK = Clock.instance; // Singleton instance
130
130
 
131
131
  export async function CLOCK_TEST() { // DEBUG TEST WHILE RUNNING AS STANDALONE
132
132
  const startTime = Date.now();