hive-p2p 1.0.33 → 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';
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hive-p2p",
3
- "version": "1.0.33",
3
+ "version": "1.0.34",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -1,5 +1,6 @@
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
6
  async function runSimulation() {
@@ -9,6 +10,7 @@ async function runSimulation() {
9
10
 
10
11
  /**
11
12
  * @typedef {Object} HiveP2PNamespace
13
+ * @property {typeof CLOCK} CLOCK
12
14
  * @property {typeof CONFIG} CONFIG
13
15
  * @property {typeof CryptoCodex} CryptoCodex
14
16
  * @property {typeof Node} Node
@@ -18,6 +20,6 @@ async function runSimulation() {
18
20
  */
19
21
 
20
22
  /** @type {HiveP2PNamespace} */
21
- const HiveP2P = { CONFIG, CryptoCodex, Node, createNode, createPublicNode, runSimulation };
22
- export { CONFIG, CryptoCodex, Node, createNode, createPublicNode, runSimulation };
23
+ const HiveP2P = { CLOCK, CONFIG, CryptoCodex, Node, createNode, createPublicNode, runSimulation };
24
+ export { CLOCK, CONFIG, CryptoCodex, Node, createNode, createPublicNode, runSimulation };
23
25
  export default HiveP2P;
@@ -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();
@@ -5,7 +5,8 @@ import { readFileSync } from 'fs';
5
5
  import { fileURLToPath } from 'url';
6
6
  import { WebSocketServer } from 'ws';
7
7
  import { io } from 'socket.io-client'; // used for twitch events only
8
- import { CLOCK, SIMULATION, NODE, TRANSPORTS, IDENTITY, DISCOVERY, LOG_CSS } from '../core/config.mjs';
8
+ import { CLOCK } from '../services/clock.mjs';
9
+ import { SIMULATION, NODE, TRANSPORTS, IDENTITY, DISCOVERY, LOG_CSS } from '../core/config.mjs';
9
10
  import { TestWsServer, TestWsConnection, TestTransport,
10
11
  ICE_CANDIDATE_EMITTER, TEST_WS_EVENT_MANAGER, SANDBOX } from '../simulation/test-transports.mjs';
11
12