trac-msb 0.0.85 → 0.0.87

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.
@@ -11,4 +11,11 @@ b1226d4a4d9e44226a69c9109769c2437dfa3f7ee551bfd3e79226dd3c1706e3
11
11
  e74ea17cc6e05f0b09588a70d8573fca63de715a763420ff7e14b68a0c1d1d14
12
12
  9dedf2e9f8f63c2ffbdccba6a3e28ace22c3788fbdbcf71b030b8574eeaa92c1
13
13
  656c9a53cbed98f9e783b6fd53667a2793c4fd74975cd26971582ea3ab9955f1
14
- 1184e8f926a2f76f12685c9e3fa6b3cd542277ab6c7a09fd02a7391240ceeb18
14
+ 1184e8f926a2f76f12685c9e3fa6b3cd542277ab6c7a09fd02a7391240ceeb18
15
+ 744ac7add47923135928bd69a3bf448845338122ece2b9d86b1c53b025028fd1
16
+ 7bc277890f992bd006eb0609c61e2c35529baf65765e3e4310f99aa18205a7c6
17
+ 8888df74fe541631cedfcf27531d309a02a7915b7680bead4301c342082980b8
18
+ e18e2f57285018c8521aee085fdbbb0a69cf2484a9eadd9022cc25913716427a
19
+ b97c37985cc087d2512a97e00c3432542a2c874fb31543ba6a0c23ea7758cf39
20
+ 0ddf2d7b7144873a2027b784529a9f60d48d0aab859f691faf39fce338e123a2
21
+ 73f3dd2bda6d5904570751fad19c251186e04e18acaaf5a893404addcdabd9aa
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "trac-msb",
3
3
  "main": "msb.mjs",
4
- "version": "0.0.85",
4
+ "version": "0.0.87",
5
5
  "pear": {
6
6
  "name": "trac-msb",
7
7
  "type": "terminal"
package/src/index.js CHANGED
@@ -35,6 +35,7 @@ export class MainSettlementBus extends ReadyResource {
35
35
  #swarm;
36
36
  #dht_server;
37
37
  #dht_node;
38
+ #dht_bootstrap;
38
39
  #base;
39
40
  #writingKey;
40
41
  #enable_txchannel;
@@ -66,7 +67,8 @@ export class MainSettlementBus extends ReadyResource {
66
67
  this.#store = new Corestore(this.STORES_DIRECTORY + options.store_name);
67
68
  this.#bee = null;
68
69
  this.#swarm = null;
69
- this.#dht_node = new DHT();
70
+ this.#dht_bootstrap = ['116.202.214.143:10001','116.202.214.149:10001', 'node1.hyperdht.org:49737', 'node2.hyperdht.org:49737', 'node3.hyperdht.org:49737'];
71
+ this.#dht_node = new DHT({ bootstrap: this.#dht_bootstrap });
70
72
  this.#dht_server = null;
71
73
  this.#base = null;
72
74
  this.#writingKey = null;
@@ -353,7 +355,7 @@ export class MainSettlementBus extends ReadyResource {
353
355
  console.log('Writer Key:', this.#writingKey);
354
356
 
355
357
  if (this.#replicate) {
356
- this.#swarm = await Network.replicate(this.#swarm, this.#enable_wallet, this.#store, this.#wallet, this.#channel, this.#isStreaming, this.#handleIncomingEvent.bind(this), this.emit.bind(this));
358
+ this.#swarm = await Network.replicate(this.#dht_bootstrap, this.#swarm, this.#enable_wallet, this.#store, this.#wallet, this.#channel, this.#isStreaming, this.#handleIncomingEvent.bind(this), this.emit.bind(this));
357
359
  }
358
360
 
359
361
  if (this.#enable_txchannel) {
@@ -418,6 +420,7 @@ export class MainSettlementBus extends ReadyResource {
418
420
  const stream = this.#dht_node.connect(b4a.from(adminEntry.tracPublicKey, 'hex'))
419
421
  stream.on('connect', async function () {
420
422
  await stream.send(b4a.from(JSON.stringify({ op : 'add_writer', message : message })));
423
+ await stream.destroy();
421
424
  });
422
425
  stream.on('open', function () { });
423
426
  stream.on('close', () => { });
@@ -721,6 +724,7 @@ export class MainSettlementBus extends ReadyResource {
721
724
  console.log('- /add_admin: register admin entry with bootstrap key.');
722
725
  console.log('- /add_whitelist: add a list of Trac public keys. Nodes that own these public keys can become writers.');
723
726
  console.log('- /add_indexer <trac_public_key>: change a role of the selected writer node to indexer role');
727
+ console.log('- /push_writer_add: try to enforce adding this peer as writer after whitelisting.');
724
728
  console.log('- /remove_indexer <trac_public_key>: change a role of the selected indexer node to default role');
725
729
  console.log('- /get_node_info <trac_public_key>: get information about a node with the given Trac public key');
726
730
  console.log('- /dag: check system properties such as writing key, DAG, etc.');
@@ -734,6 +738,9 @@ export class MainSettlementBus extends ReadyResource {
734
738
  await this.close();
735
739
  typeof process !== "undefined" ? process.exit(0) : Pear.exit(0);
736
740
  break;
741
+ case '/push_writer_add':
742
+ await this.#requestWriterRole(true)
743
+ break;
737
744
  case '/add_admin':
738
745
  await this.#handleAdminOperations();
739
746
  break;
package/src/network.js CHANGED
@@ -24,7 +24,7 @@ class Network {
24
24
  }
25
25
 
26
26
 
27
- static async replicate(swarm, walletEnabled, store, wallet, channel, isStreaming, handleIncomingEvent, emit) {
27
+ static async replicate(bootstrap, swarm, walletEnabled, store, wallet, channel, isStreaming, handleIncomingEvent, emit) {
28
28
  if (!swarm) {
29
29
  let keyPair;
30
30
  if (!walletEnabled) {
@@ -36,7 +36,7 @@ class Network {
36
36
  };
37
37
  }
38
38
 
39
- swarm = new Hyperswarm({ keyPair, maxPeers: MAX_PEERS, maxParallel: MAX_PARALLEL, maxServerConnections: MAX_SERVER_CONNECTIONS });
39
+ swarm = new Hyperswarm({ keyPair, bootstrap, maxPeers: MAX_PEERS, maxParallel: MAX_PARALLEL, maxServerConnections: MAX_SERVER_CONNECTIONS });
40
40
 
41
41
  console.log(`Channel: ${b4a.toString(channel)}`);
42
42
  swarm.on('connection', async (connection) => {
@@ -69,7 +69,9 @@ class Network {
69
69
  msg = JSON.parse(msg);
70
70
  if(msg === 'get_writer_key'){
71
71
  await connection.send(b4a.from(JSON.stringify({op:'writer_key', key : writingKey})));
72
+ await connection.destroy();
72
73
  } else if(msg.op !== undefined && msg.message !== undefined && msg.op === 'add_writer'){
74
+ await connection.destroy();
73
75
  msg = msg.message;
74
76
  const adminEntry = await msb.getSigned(EntryType.ADMIN);
75
77
  if(null === adminEntry || (adminEntry.tracPublicKey !== wallet.publicKey)) return;
@@ -81,6 +83,7 @@ class Network {
81
83
  await base.append(msg);
82
84
  }
83
85
  } else {
86
+ await connection.destroy();
84
87
  if (base.isIndexer || !base.writable) return;
85
88
 
86
89
  // TODO: decide if a tx rejection should be responded with
@@ -118,7 +121,6 @@ class Network {
118
121
  networkInstance.tx_pool.push({ tx: parsedPreTx.tx, append_tx: append_tx });
119
122
  }
120
123
  }
121
- //await connection.destroy();
122
124
  }catch(e){
123
125
  console.log(e);
124
126
  }