@hive-p2p/server 1.0.103 → 1.0.105

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
@@ -5,11 +5,8 @@ import { NODE, GOSSIP, UNICAST, LOG_CSS } from './config.mjs';
5
5
  // Growing each second by 1000ms until 0
6
6
  // Lowered each second by 100ms until 0 (avoid attacker growing balances on multiple disconnected peers)
7
7
 
8
- const BYTES_COUNT_PERIOD = 10_000; // 10 seconds
9
- const MAX_UNICAST_BYTES_PER_PERIOD = 1_000_000; // 1MB per period
10
- const MAX_GOSSIP_BYTES_PER_PERIOD = 100_000; // 100KB per period
11
-
12
- const MAX_TRUST = 3_600_000; // +3600 seconds = 1 hour of good behavior
8
+ const BYTES_COUNT_PERIOD = 10_000; // 10 seconds
9
+ const MAX_TRUST = 3_600_000; // +3600 seconds = 1 hour of good behavior
13
10
  export const TRUST_VALUES = {
14
11
  // POSITIVE IDENTITY
15
12
  VALID_SIGNATURE: +10_000, // +10 seconds
@@ -90,8 +87,8 @@ export class Arbiter {
90
87
  if (!this.bytesCounters[type][peerId]) this.bytesCounters[type][peerId] = 0;
91
88
  this.bytesCounters[type][peerId] += byteLength;
92
89
  const [maxByte, penality] = type === 'gossip'
93
- ? [MAX_GOSSIP_BYTES_PER_PERIOD, TRUST_VALUES.GOSSIP_FLOOD]
94
- : [MAX_UNICAST_BYTES_PER_PERIOD, TRUST_VALUES.UNICAST_FLOOD];
90
+ ? [GOSSIP.MAX_BYTES_PER_PERIOD, TRUST_VALUES.GOSSIP_FLOOD]
91
+ : [UNICAST.MAX_BYTES_PER_PERIOD, TRUST_VALUES.UNICAST_FLOOD];
95
92
  // If under the limit, return true -> else apply penality and return undefined
96
93
  if (this.bytesCounters[type][peerId] < maxByte) return true;
97
94
  return this.adjustTrust(peerId, penality, `Message ${type} flood detected`);
package/core/config.mjs CHANGED
@@ -145,6 +145,8 @@ export const DISCOVERY = {
145
145
  }
146
146
 
147
147
  export const UNICAST = { // MARKERS RANGE: 0-127
148
+ /** Maximum number of bytes per period | Default: 2_000_000 (2MB per period of 10 seconds) */
149
+ MAX_BYTES_PER_PERIOD: 2_000_000,
148
150
  /** Maximum number of hops(relaying) for direct message | Default: 8
149
151
  * - Default: 8, light: 6, super-light: 4, direct-only: 2 */
150
152
  MAX_HOPS: 8,
@@ -172,6 +174,8 @@ export const UNICAST = { // MARKERS RANGE: 0-127
172
174
  }
173
175
 
174
176
  export const GOSSIP = { // MARKERS RANGE: 128-255
177
+ /** Maximum number of bytes per period | Default: 5_000_000 (5MB per period of 10 seconds) */
178
+ MAX_BYTES_PER_PERIOD: 5_000_000,
175
179
  /** Time to consider a message as valid | Default: 10_000 (10 seconds) */
176
180
  EXPIRATION: 10_000,
177
181
  /** Time to keep messages in cache to avoid reprocessing | Default: 20_000 (20 seconds) */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hive-p2p/server",
3
- "version": "1.0.103",
3
+ "version": "1.0.105",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -3,10 +3,10 @@ const IS_BROWSER = typeof self !== 'undefined';
3
3
 
4
4
  // ED25519 EXPOSURE NODEJS/BROWSER COMPATIBLE ---------------------------------
5
5
  const { ed25519, x25519 } = await import('@noble/curves/ed25519.js');
6
- const { chacha20poly1305 } = await import('@noble/ciphers/chacha.js');
6
+ const { chacha20poly1305, xchacha20poly1305 } = await import('@noble/ciphers/chacha.js');
7
7
  const { randomBytes } = await import('@noble/ciphers/utils.js');
8
8
 
9
- export { ed25519, x25519, chacha20poly1305, randomBytes };
9
+ export { ed25519, x25519, chacha20poly1305, xchacha20poly1305, randomBytes };
10
10
 
11
11
  //-----------------------------------------------------------------------------
12
12