trac-msb 0.0.72 → 0.0.74
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 +1 -1
- package/src/index.js +10 -4
- package/src/network.js +16 -12
- package/src/utils/check.js +1 -0
package/package.json
CHANGED
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.#
|
|
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
|
-
|
|
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.
|
|
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,15 @@ 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
|
-
|
|
58
|
-
const node = new DHT()
|
|
59
|
-
const server = node.createServer()
|
|
60
|
-
server.on('connection', function (connection) {
|
|
57
|
+
dhtServer.on('connection', function (connection) {
|
|
61
58
|
connection.on('message', async (msg) => {
|
|
62
|
-
|
|
63
|
-
if(
|
|
59
|
+
msg = b4a.toString(msg, 'utf-8');
|
|
60
|
+
if(msg === 'get_writer_key'){
|
|
64
61
|
await connection.send(b4a.from(JSON.stringify({op:'writer_key', key : writingKey})));
|
|
65
62
|
} else {
|
|
63
|
+
|
|
66
64
|
if (base.isIndexer || !base.writable) return;
|
|
67
65
|
|
|
68
66
|
// TODO: decide if a tx rejection should be responded with
|
|
@@ -77,6 +75,13 @@ class Network {
|
|
|
77
75
|
|
|
78
76
|
const parsedPreTx = JSON.parse(msg);
|
|
79
77
|
|
|
78
|
+
console.log(networkInstance.check.sanitizePreTx(parsedPreTx),
|
|
79
|
+
wallet.verify(b4a.from(parsedPreTx.is, 'hex'), b4a.from(parsedPreTx.tx + parsedPreTx.in), b4a.from(parsedPreTx.ipk, 'hex')),
|
|
80
|
+
parsedPreTx.w === writingKey,
|
|
81
|
+
parsedPreTx.wp === wallet.publicKey,
|
|
82
|
+
null === await base.view.get(parsedPreTx.tx)
|
|
83
|
+
);
|
|
84
|
+
|
|
80
85
|
if (networkInstance.check.sanitizePreTx(parsedPreTx) &&
|
|
81
86
|
wallet.verify(b4a.from(parsedPreTx.is, 'hex'), b4a.from(parsedPreTx.tx + parsedPreTx.in), b4a.from(parsedPreTx.ipk, 'hex')) &&
|
|
82
87
|
parsedPreTx.w === writingKey &&
|
|
@@ -103,21 +108,20 @@ class Network {
|
|
|
103
108
|
networkInstance.tx_pool.push({ tx: parsedPreTx.tx, append_tx: append_tx });
|
|
104
109
|
}
|
|
105
110
|
} catch (e) {
|
|
106
|
-
|
|
111
|
+
console.log(e)
|
|
107
112
|
}
|
|
108
113
|
}
|
|
109
|
-
await connection.destroy();
|
|
114
|
+
//await connection.destroy();
|
|
110
115
|
});
|
|
111
|
-
connection.on('close', () => {
|
|
116
|
+
connection.on('close', () => { });
|
|
112
117
|
connection.on('error', (error) => { });
|
|
113
118
|
})
|
|
114
119
|
const keyPair = {
|
|
115
120
|
publicKey: b4a.from(wallet.publicKey, 'hex'),
|
|
116
121
|
secretKey: b4a.from(wallet.secretKey, 'hex')
|
|
117
122
|
};
|
|
118
|
-
await
|
|
123
|
+
await dhtServer.listen(keyPair)
|
|
119
124
|
console.log('DHT node is listening on public key', wallet.publicKey);
|
|
120
|
-
return { server, node }
|
|
121
125
|
} catch(e) { }
|
|
122
126
|
}
|
|
123
127
|
|
package/src/utils/check.js
CHANGED
|
@@ -108,6 +108,7 @@ class Check {
|
|
|
108
108
|
op: { type: 'string', enum: ['pre-tx'], required: true },
|
|
109
109
|
tx: { type: 'is_hex_string', required: true }, // TODO: if we will use only 256 bit hash then change to length: 64
|
|
110
110
|
is: { type: 'is_hex_string', length: 128, required: true },
|
|
111
|
+
wp: { type: 'is_hex_string', length: 64, required: true },
|
|
111
112
|
w: { type: 'is_hex_string', length: 64, required: true },
|
|
112
113
|
i: { type: 'is_hex_string', length: 64, required: true },
|
|
113
114
|
ipk: { type: 'is_hex_string', length: 64, required: true },
|