trac-msb 0.1.34 → 0.1.36

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/msb.mjs CHANGED
@@ -4,7 +4,7 @@ const opts = {
4
4
  stores_directory : 'stores/',
5
5
  store_name : typeof process !== "undefined" ? process.argv[2] : Pear.config.args[0],
6
6
  bootstrap: '19a12e9bdaf1cd9ae8169fd87f3d6d63d441c046e37e2ac6c3c36bcb87c59019',
7
- channel: '0000tracnetworkmainsettlementbus',
7
+ channel: '0000tracnetworkmainsettlementbus'
8
8
  };
9
9
 
10
10
  const msb = new MainSettlementBus(opts);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "trac-msb",
3
3
  "main": "msb.mjs",
4
- "version": "0.1.34",
4
+ "version": "0.1.36",
5
5
  "pear": {
6
6
  "name": "trac-msb",
7
7
  "type": "terminal"
@@ -12,7 +12,7 @@
12
12
  "test": "brittle test/*.test.js"
13
13
  },
14
14
  "dependencies": {
15
- "trac-wallet": "^0.0.43",
15
+ "trac-wallet": "0.0.43",
16
16
  "hyperbee": "2.24.2",
17
17
  "hypercore": "11.6.2",
18
18
  "corestore": "7.4.1",
@@ -21,7 +21,7 @@
21
21
  "hyperdht": "6.20.5",
22
22
  "hyperswarm": "4.11.5",
23
23
  "b4a": "1.6.7",
24
- "ready-resource": "^1.0.0",
24
+ "ready-resource": "1.1.2",
25
25
  "bare-readline": "1.0.7",
26
26
  "readline": "npm:bare-node-readline",
27
27
  "bare-tty": "5.0.2",
package/src/index.js CHANGED
@@ -55,6 +55,7 @@ export class MainSettlementBus extends ReadyResource {
55
55
  #signature_whitelist;
56
56
  #readline_instance;
57
57
  #enable_txlogs;
58
+ #disable_rate_limit;
58
59
 
59
60
  constructor(options = {}) {
60
61
  super();
@@ -85,6 +86,7 @@ export class MainSettlementBus extends ReadyResource {
85
86
  this.#enable_txlogs = options.enable_txlogs === true;
86
87
  this.#enable_updater = options.enable_updater !== false;
87
88
  this.#enable_wallet = options.enable_wallet !== false;
89
+ this.#disable_rate_limit = options.disable_rate_limit === true;
88
90
  this.#wallet = new PeerWallet(options);
89
91
  this.#replicate = options.replicate !== false;
90
92
  this.#signature_whitelist = options.signature_whitelist !== undefined && Array.isArray(options.signature_whitelist) ? options.signature_whitelist : [];
@@ -423,7 +425,7 @@ export class MainSettlementBus extends ReadyResource {
423
425
 
424
426
  console.log('');
425
427
  if (this.#replicate) {
426
- this.#swarm = await Network.replicate(this, this.#network, this.#enable_txchannel, this.#base, this.#writingKey, this.#dht_bootstrap, this.#swarm, this.#enable_wallet, this.#store, this.#wallet, this.#channel, this.#isStreaming, this.#handleIncomingEvent.bind(this), this.emit.bind(this));
428
+ this.#swarm = await Network.replicate(this.#disable_rate_limit, this, this.#network, this.#enable_txchannel, this.#base, this.#writingKey, this.#dht_bootstrap, this.#swarm, this.#enable_wallet, this.#store, this.#wallet, this.#channel, this.#isStreaming, this.#handleIncomingEvent.bind(this), this.emit.bind(this));
427
429
  this.#dht_node = this.#swarm.dht;
428
430
  }
429
431
 
package/src/network.js CHANGED
@@ -25,7 +25,7 @@ class Network {
25
25
  }
26
26
 
27
27
 
28
- static async replicate(msb, network, enable_txchannel, base, writingKey, bootstrap, swarm, walletEnabled, store, wallet, channel, isStreaming, handleIncomingEvent, emit) {
28
+ static async replicate(disable_rate_limit, msb, network, enable_txchannel, base, writingKey, bootstrap, swarm, walletEnabled, store, wallet, channel, isStreaming, handleIncomingEvent, emit) {
29
29
  if (!swarm) {
30
30
 
31
31
  let keyPair;
@@ -38,6 +38,9 @@ class Network {
38
38
  };
39
39
  }
40
40
 
41
+ let clean = Date.now();
42
+ let conns = {};
43
+
41
44
  swarm = new Hyperswarm({ keyPair, bootstrap : bootstrap, maxPeers: MAX_PEERS, maxParallel: MAX_PARALLEL, maxServerConnections: MAX_SERVER_CONNECTIONS, maxClientConnections : MAX_CLIENT_CONNECTIONS});
42
45
 
43
46
  console.log(`Channel: ${b4a.toString(channel)}`);
@@ -86,6 +89,33 @@ class Network {
86
89
  else {
87
90
  if (base.isIndexer || !base.writable) return;
88
91
 
92
+ if(true !== disable_rate_limit)
93
+ {
94
+ const peer = b4a.toString(connection.remotePublicKey, 'hex');
95
+ const _now = Date.now();
96
+
97
+ if(_now - clean >= 120_000) {
98
+ clean = _now;
99
+ conns = {};
100
+ }
101
+
102
+ if(conns[peer] === undefined){
103
+ conns[peer] = { prev : _now, now: 0, tx_cnt : 0 }
104
+ }
105
+
106
+ conns[peer].now = _now;
107
+ conns[peer].tx_cnt += 1;
108
+
109
+ if(conns[peer].now - conns[peer].prev >= 60_000){
110
+ delete conns[peer];
111
+ }
112
+
113
+ if(conns[peer] !== undefined && conns[peer].now - conns[peer].prev >= 1000 && conns[peer].tx_cnt >= 50){
114
+ swarm.leavePeer(connection.remotePublicKey);
115
+ connection.end()
116
+ }
117
+ }
118
+
89
119
  if (network.tx_pool.length >= 1000) {
90
120
  console.log('pool full');
91
121
  return
@@ -143,13 +173,13 @@ class Network {
143
173
  const length = this.tx_pool.length;
144
174
  const batch = [];
145
175
  for (let i = 0; i < length; i++) {
146
- if (i >= 100) break;
176
+ if (i >= 10) break;
147
177
  batch.push({ type: OperationType.TX, key: this.tx_pool[i].tx, value: this.tx_pool[i].append_tx });
148
178
  }
149
179
  await base.append(batch);
150
180
  this.tx_pool.splice(0, batch.length);
151
181
  }
152
- await sleep(10);
182
+ await sleep(5);
153
183
  }
154
184
  }
155
185
  }