trac-msb 0.0.72 → 0.0.73

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "trac-msb",
3
3
  "main": "msb.mjs",
4
- "version": "0.0.72",
4
+ "version": "0.0.73",
5
5
  "pear": {
6
6
  "name": "trac-msb",
7
7
  "type": "terminal"
package/src/index.js CHANGED
@@ -34,6 +34,7 @@ export class MainSettlementBus extends ReadyResource {
34
34
  #bee;
35
35
  #swarm;
36
36
  #dht_server;
37
+ #dht_node;
37
38
  #base;
38
39
  #writingKey;
39
40
  #enable_txchannel;
@@ -65,7 +66,8 @@ export class MainSettlementBus extends ReadyResource {
65
66
  this.#store = new Corestore(this.STORES_DIRECTORY + options.store_name);
66
67
  this.#bee = null;
67
68
  this.#swarm = null;
68
- this.#dht_server = null;
69
+ this.#dht_node = new DHT();
70
+ this.#dht_server = this.#dht_node.createServer();
69
71
  this.#base = null;
70
72
  this.#writingKey = null;
71
73
  this.#enable_txchannel = options.enable_txchannel !== false;
@@ -356,7 +358,7 @@ export class MainSettlementBus extends ReadyResource {
356
358
  }
357
359
 
358
360
  if (this.#enable_txchannel) {
359
- this.#dht_server = await Network.dhtServer(this.#base, this.#wallet, this.#writingKey, this.#network);
361
+ await Network.dhtServer(this.#dht_server, this.#base, this.#wallet, this.#writingKey, this.#network);
360
362
  }
361
363
 
362
364
  const adminEntry = await this.getSigned(EntryType.ADMIN);
@@ -387,12 +389,16 @@ export class MainSettlementBus extends ReadyResource {
387
389
  }
388
390
  if (this.#dht_server) {
389
391
  try{
390
- await this.#dht_server.server.close();
391
- await this.#dht_server.node.destroy();
392
+ await this.#dht_server.close();
392
393
  } catch(e){
393
394
  console.log(e.message);
394
395
  }
395
396
  }
397
+ try{
398
+ this.#dht_node.destroy();
399
+ } catch(e){
400
+ console.log(e.message);
401
+ }
396
402
  await this.#base.close();
397
403
  }
398
404
 
package/src/network.js CHANGED
@@ -52,17 +52,17 @@ class Network {
52
52
  return swarm;
53
53
  }
54
54
 
55
- static async dhtServer(base, wallet, writingKey, networkInstance){
55
+ static async dhtServer(dhtServer, base, wallet, writingKey, networkInstance){
56
56
  try{
57
- const _this = this;
58
- const node = new DHT()
59
- const server = node.createServer()
60
57
  server.on('connection', function (connection) {
61
58
  connection.on('message', async (msg) => {
62
59
  const cmd = b4a.toString(msg, 'utf-8');
63
60
  if(cmd === 'get_writer_key'){
64
61
  await connection.send(b4a.from(JSON.stringify({op:'writer_key', key : writingKey})));
65
62
  } else {
63
+
64
+ console.log(msg);
65
+
66
66
  if (base.isIndexer || !base.writable) return;
67
67
 
68
68
  // TODO: decide if a tx rejection should be responded with
@@ -103,12 +103,12 @@ class Network {
103
103
  networkInstance.tx_pool.push({ tx: parsedPreTx.tx, append_tx: append_tx });
104
104
  }
105
105
  } catch (e) {
106
- //console.log(e)
106
+ console.log(e)
107
107
  }
108
108
  }
109
109
  await connection.destroy();
110
110
  });
111
- connection.on('close', () => { console.log('remote closing'); });
111
+ connection.on('close', () => { });
112
112
  connection.on('error', (error) => { });
113
113
  })
114
114
  const keyPair = {
@@ -117,7 +117,6 @@ class Network {
117
117
  };
118
118
  await server.listen(keyPair)
119
119
  console.log('DHT node is listening on public key', wallet.publicKey);
120
- return { server, node }
121
120
  } catch(e) { }
122
121
  }
123
122