trac-peer 0.1.19 → 0.1.20
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/functions.js +2 -2
- package/src/index.js +6 -22
package/package.json
CHANGED
package/src/functions.js
CHANGED
|
@@ -283,14 +283,14 @@ export async function addWriter(input, peer){
|
|
|
283
283
|
msg: msg
|
|
284
284
|
};
|
|
285
285
|
const hash = peer.wallet.sign(JSON.stringify(msg) + nonce);
|
|
286
|
-
peer.
|
|
286
|
+
await peer.base.append({ op : 'append_writer', type: 'addIndexer', key: parsed.key, value: signature, hash: hash, nonce: nonce });
|
|
287
287
|
} else if(splitted[0] === '/add_writer') {
|
|
288
288
|
const msg = { type: 'addWriter', key: ''+parsed.key }
|
|
289
289
|
const signature = {
|
|
290
290
|
msg: msg
|
|
291
291
|
};
|
|
292
292
|
const hash = peer.wallet.sign(JSON.stringify(msg) + nonce);
|
|
293
|
-
peer.
|
|
293
|
+
await peer.base.append({ op : 'append_writer', type: 'addWriter', key: ''+parsed.key, value: signature, hash: hash, nonce : nonce });
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
296
|
|
package/src/index.js
CHANGED
|
@@ -54,7 +54,8 @@ export class Peer extends ReadyResource {
|
|
|
54
54
|
this.connectedPeers = new Set();
|
|
55
55
|
this.options = options;
|
|
56
56
|
this.check = new Check();
|
|
57
|
-
this.
|
|
57
|
+
this.dhtBootstrap = ['116.202.214.143:10001','116.202.214.149:10001', 'node1.hyperdht.org:49737', 'node2.hyperdht.org:49737', 'node3.hyperdht.org:49737'];
|
|
58
|
+
this.dhtNode = new DHT({ bootstrap: this.dhtBootstrap });
|
|
58
59
|
|
|
59
60
|
this.tx_observer();
|
|
60
61
|
this.nodeListener();
|
|
@@ -432,11 +433,11 @@ export class Peer extends ReadyResource {
|
|
|
432
433
|
const stream = this.dhtNode.connect(b4a.from(_msg.wp, 'hex'))
|
|
433
434
|
stream.on('connect', async function () {
|
|
434
435
|
await stream.send(b4a.from(jsonStringify(_msg)));
|
|
436
|
+
await stream.destroy();
|
|
435
437
|
});
|
|
436
438
|
stream.on('open', function () { });
|
|
437
439
|
stream.on('close', () => { });
|
|
438
440
|
stream.on('error', (error) => { });
|
|
439
|
-
//await stream.destroy();
|
|
440
441
|
}
|
|
441
442
|
|
|
442
443
|
async getValidatorWriterKey(address){
|
|
@@ -462,7 +463,7 @@ export class Peer extends ReadyResource {
|
|
|
462
463
|
await this.sleep(5);
|
|
463
464
|
i += 1;
|
|
464
465
|
}
|
|
465
|
-
|
|
466
|
+
await stream.destroy();
|
|
466
467
|
return writer_key;
|
|
467
468
|
}
|
|
468
469
|
|
|
@@ -484,7 +485,7 @@ export class Peer extends ReadyResource {
|
|
|
484
485
|
this.updater();
|
|
485
486
|
const auto_add_writers = await this.base.view.get('auto_add_writers');
|
|
486
487
|
if(!this.base.writable && null !== auto_add_writers && auto_add_writers.value === 'on'){
|
|
487
|
-
this.
|
|
488
|
+
await this.base.append({
|
|
488
489
|
op : 'auto-add-writer',
|
|
489
490
|
type : 'autoAddWriter',
|
|
490
491
|
key : this.writerLocalKey
|
|
@@ -583,7 +584,7 @@ export class Peer extends ReadyResource {
|
|
|
583
584
|
async _replicate() {
|
|
584
585
|
if (!this.swarm) {
|
|
585
586
|
const keyPair = await this.store.createKeyPair('hyperswarm');
|
|
586
|
-
this.swarm = new Hyperswarm({ keyPair });
|
|
587
|
+
this.swarm = new Hyperswarm({ keyPair, bootstrap: this.dhtBootstrap });
|
|
587
588
|
|
|
588
589
|
console.log(`Writer key: ${this.writerLocalKey}`)
|
|
589
590
|
|
|
@@ -601,23 +602,6 @@ export class Peer extends ReadyResource {
|
|
|
601
602
|
|
|
602
603
|
connection.on('error', (error) => { });
|
|
603
604
|
|
|
604
|
-
connection.on('data', async (msg) => {
|
|
605
|
-
try{
|
|
606
|
-
msg = JSON.parse(msg);
|
|
607
|
-
if(msg.op && msg.op === 'append_writer' && this.base.localWriter.isActive &&
|
|
608
|
-
this.writerLocalKey !== msg.key) {
|
|
609
|
-
await this.base.append(msg);
|
|
610
|
-
} else if(msg.op && msg.op === 'auto-add-writer' && this.base.localWriter.isActive &&
|
|
611
|
-
this.writerLocalKey !== msg.key) {
|
|
612
|
-
await this.base.append(msg);
|
|
613
|
-
}
|
|
614
|
-
} catch(e){ }
|
|
615
|
-
});
|
|
616
|
-
|
|
617
|
-
this.on('announce', async function(msg){
|
|
618
|
-
await connection.write(JSON.stringify(msg))
|
|
619
|
-
});
|
|
620
|
-
|
|
621
605
|
if (!this.isStreaming) {
|
|
622
606
|
this.emit('readyNode');
|
|
623
607
|
}
|