/
crawler.ts
723 lines (680 loc) · 23.5 KB
/
crawler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
// Source file from duniter: Crypto-currency software to manage libre currency such as Ğ1
// Copyright (C) 2018 Cedric Moreau <cem.moreau@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
import * as stream from "stream";
import { Server } from "../../../../server";
import { ConfDTO } from "../../../lib/dto/ConfDTO";
import { DuniterService } from "../../../../index";
import { PeerDTO } from "../../../lib/dto/PeerDTO";
import { AbstractDAO } from "./pulling";
import { BlockDTO } from "../../../lib/dto/BlockDTO";
import { DBBlock } from "../../../lib/db/DBBlock";
import { tx_cleaner } from "./tx_cleaner";
import { connect } from "./connect";
import { CrawlerConstants } from "./constants";
import { pullSandboxToLocalServer } from "./sandbox";
import { cleanLongDownPeers } from "./garbager";
import { Underscore } from "../../../lib/common-libs/underscore";
import { BMARemoteContacter } from "./sync/BMARemoteContacter";
const async = require("async");
/**
* Service which triggers the server's peering generation (actualization of the Peer document).
* @constructor
*/
export class Crawler extends stream.Transform implements DuniterService {
peerCrawler: PeerCrawler;
peerTester: PeerTester;
blockCrawler: BlockCrawler;
sandboxCrawler: SandboxCrawler;
constructor(
private server: Server,
private conf: ConfDTO,
private logger: any
) {
super({ objectMode: true });
this.peerCrawler = new PeerCrawler(server, conf, logger);
this.peerTester = new PeerTester(server, conf, logger);
this.blockCrawler = new BlockCrawler(server, logger);
this.sandboxCrawler = new SandboxCrawler(server, conf, logger);
}
pullBlocks(server: Server, pubkey = "") {
return this.blockCrawler.pullBlocks(server, pubkey);
}
sandboxPull(server: Server) {
return this.sandboxCrawler.sandboxPull(server);
}
startService() {
if (this.conf.nobma || !this.conf.bmaWithCrawler) {
return Promise.resolve();
}
return Promise.all([
this.peerCrawler.startService(),
this.peerTester.startService(),
this.blockCrawler.startService(),
this.sandboxCrawler.startService(),
]);
}
stopService() {
if (this.conf.nobma || !this.conf.bmaWithCrawler) {
return Promise.resolve();
}
return Promise.all([
this.peerCrawler.stopService(),
this.peerTester.stopService(),
this.blockCrawler.stopService(),
this.sandboxCrawler.stopService(),
]);
}
// Unused
_write(str: string, enc: any, done: any) {
done && done();
}
}
export class PeerCrawler implements DuniterService {
private DONT_IF_MORE_THAN_FOUR_PEERS = true;
private crawlPeersInterval: NodeJS.Timer;
private crawlPeersFifo = async.queue(
(task: any, callback: any) => task(callback),
1
);
constructor(
private server: Server,
private conf: ConfDTO,
private logger: any
) {}
async startService() {
if (this.crawlPeersInterval) clearInterval(this.crawlPeersInterval);
this.crawlPeersInterval = setInterval(
() =>
this.crawlPeersFifo.push((cb: any) =>
this.crawlPeers(this.server, this.conf).then(cb).catch(cb)
),
1000 * this.conf.avgGenTime * CrawlerConstants.SYNC_PEERS_INTERVAL
);
await this.crawlPeers(
this.server,
this.conf,
this.DONT_IF_MORE_THAN_FOUR_PEERS
);
}
async stopService() {
this.crawlPeersFifo.kill();
clearInterval(this.crawlPeersInterval);
}
private async crawlPeers(
server: Server,
conf: ConfDTO,
dontCrawlIfEnoughPeers = false
) {
this.logger.info("Crawling the network...");
const peers = await server.dal.listAllPeersWithStatusNewUPWithtout(
conf.pair.pub
);
if (
peers.length > CrawlerConstants.COUNT_FOR_ENOUGH_PEERS &&
dontCrawlIfEnoughPeers == this.DONT_IF_MORE_THAN_FOUR_PEERS
) {
return;
}
let peersToTest = peers.slice().map((p) => PeerDTO.fromJSONObject(p));
let tested: string[] = [];
const found = [];
while (peersToTest.length > 0) {
const results = await Promise.all(
peersToTest.map((p: PeerDTO) => this.crawlPeer(server, p))
);
tested = tested.concat(peersToTest.map((p: PeerDTO) => p.pubkey));
// End loop condition
peersToTest.splice(0);
// Eventually continue the loop
for (let i = 0, len = results.length; i < len; i++) {
const res: any = results[i];
for (let j = 0, len2 = res.length; j < len2; j++) {
try {
const subpeer = res[j].leaf.value;
if (subpeer.currency && tested.indexOf(subpeer.pubkey) === -1) {
const p = PeerDTO.fromJSONObject(subpeer);
peersToTest.push(p);
found.push(p);
}
} catch (e) {
this.logger.warn("Invalid peer %s", res[j]);
}
}
}
// Make unique list
peersToTest = Underscore.uniq(
peersToTest,
false,
(p: PeerDTO) => p.pubkey
);
}
this.logger.info("Crawling done.");
for (let i = 0, len = found.length; i < len; i++) {
let p = found[i];
try {
// Try to write it
await server.writePeer(p);
} catch (e) {
// Silent error
}
}
await cleanLongDownPeers(server, Date.now());
}
private async crawlPeer(server: Server, aPeer: PeerDTO) {
let subpeers: any[] = [];
try {
this.logger.debug(
"Crawling peers of %s %s",
aPeer.pubkey.substr(0, 6),
aPeer.getNamedURL()
);
const node = await connect(aPeer);
await checkPeerValidity(server, aPeer, node);
const json = await node.getPeers.bind(node)({ leaves: true });
for (let i = 0, len = json.leaves.length; i < len; i++) {
let leaf = json.leaves[i];
let subpeer = await node.getPeers.bind(node)({ leaf: leaf });
subpeers.push(subpeer);
}
return subpeers;
} catch (e) {
return subpeers;
}
}
}
export class SandboxCrawler implements DuniterService {
private pullInterval: NodeJS.Timer;
private pullFifo = async.queue(
(task: any, callback: any) => task(callback),
1
);
constructor(
private server: Server,
private conf: ConfDTO,
private logger: any
) {}
async startService() {
if (this.pullInterval) clearInterval(this.pullInterval);
this.pullInterval = setInterval(
() =>
this.pullFifo.push((cb: any) =>
this.sandboxPull(this.server).then(cb).catch(cb)
),
1000 * this.conf.avgGenTime * CrawlerConstants.SANDBOX_CHECK_INTERVAL
);
setTimeout(() => {
this.pullFifo.push((cb: any) =>
this.sandboxPull(this.server).then(cb).catch(cb)
);
}, CrawlerConstants.SANDBOX_FIRST_PULL_DELAY);
}
async stopService() {
this.pullFifo.kill();
clearInterval(this.pullInterval);
}
async sandboxPull(server: Server) {
this.logger && this.logger.info("Sandbox pulling started...");
const peers = await server.dal.getRandomlyUPsWithout([this.conf.pair.pub]);
const randoms = chooseXin(
peers.map((p) => PeerDTO.fromDBPeer(p)),
CrawlerConstants.SANDBOX_PEERS_COUNT
);
let peersToTest = randoms.slice().map((p) => PeerDTO.fromJSONObject(p));
for (const peer of peersToTest) {
const fromHost = await connect(peer);
const api = new BMARemoteContacter(fromHost);
await pullSandboxToLocalServer(
server.conf.currency,
api,
server,
this.logger
);
}
this.logger && this.logger.info("Sandbox pulling done.");
}
}
export class PeerTester implements DuniterService {
private FIRST_CALL = true;
private testPeerFifo = async.queue(
(task: any, callback: any) => task(callback),
1
);
private testPeerFifoInterval: NodeJS.Timer;
constructor(
private server: Server,
private conf: ConfDTO,
private logger: any
) {}
async startService() {
if (this.testPeerFifoInterval) clearInterval(this.testPeerFifoInterval);
this.testPeerFifoInterval = setInterval(
() =>
this.testPeerFifo.push((cb: any) =>
this.testPeers
.bind(this, this.server, this.conf, !this.FIRST_CALL)()
.then(cb)
.catch(cb)
),
1000 * CrawlerConstants.TEST_PEERS_INTERVAL
);
await this.testPeers(this.server, this.conf, this.FIRST_CALL);
}
async stopService() {
clearInterval(this.testPeerFifoInterval);
this.testPeerFifo.kill();
}
private async testPeers(
server: Server,
conf: ConfDTO,
displayDelays: boolean
) {
let peers = await server.dal.listAllPeers();
let now = new Date().getTime();
peers = Underscore.filter(peers, (p: any) => p.pubkey != conf.pair.pub);
await Promise.all(
peers.map(async (thePeer: any) => {
let p = PeerDTO.fromJSONObject(thePeer);
if (thePeer.status == "DOWN") {
let shouldDisplayDelays = displayDelays;
let downAt = thePeer.first_down || now;
let waitRemaining = this.getWaitRemaining(
now,
downAt,
thePeer.last_try
);
let nextWaitRemaining = this.getWaitRemaining(now, downAt, now);
let testIt = waitRemaining <= 0;
if (testIt) {
// We try to reconnect only with peers marked as DOWN
try {
this.logger.trace(
"Checking if node %s is UP... (%s:%s) ",
p.pubkey.substr(0, 6),
p.getHostPreferDNS(),
p.getPort()
);
// We register the try anyway
await server.dal.setPeerDown(p.pubkey);
// Now we test
let node = await connect(p);
let peering = await node.getPeer();
await checkPeerValidity(server, p, node);
// The node answered, it is no more DOWN!
this.logger.info(
"Node %s (%s:%s) is UP!",
p.pubkey.substr(0, 6),
p.getHostPreferDNS(),
p.getPort()
);
await server.dal.setPeerUP(p.pubkey);
// We try to forward its peering entry
let sp1 = peering.block.split("-");
let currentBlockNumber = sp1[0];
let currentBlockHash = sp1[1];
let sp2 = peering.block.split("-");
let blockNumber = sp2[0];
let blockHash = sp2[1];
if (
!(
currentBlockNumber == blockNumber &&
currentBlockHash == blockHash
)
) {
// The peering changed
await server.PeeringService.submitP(peering);
}
// Do not need to display when next check will occur: the node is now UP
shouldDisplayDelays = false;
} catch (err) {
if (!err) {
err = "NO_REASON";
}
// Error: we set the peer as DOWN
this.logger.trace(
"Peer %s is DOWN (%s)",
p.pubkey,
(err.httpCode && "HTTP " + err.httpCode) ||
err.code ||
err.message ||
err
);
await server.dal.setPeerDown(p.pubkey);
shouldDisplayDelays = true;
}
}
if (shouldDisplayDelays) {
this.logger.debug(
"Will check that node %s (%s:%s) is UP in %s min...",
p.pubkey.substr(0, 6),
p.getHostPreferDNS(),
p.getPort(),
(nextWaitRemaining / 60).toFixed(0)
);
}
}
})
);
}
private getWaitRemaining(now: number, downAt: number, last_try: number) {
let downDelay = Math.floor((now - downAt) / 1000);
let waitedSinceLastTest = Math.floor((now - (last_try || now)) / 1000);
let waitRemaining = 1;
if (downDelay <= CrawlerConstants.DURATIONS.A_MINUTE) {
waitRemaining =
CrawlerConstants.DURATIONS.TEN_SECONDS - waitedSinceLastTest;
} else if (downDelay <= CrawlerConstants.DURATIONS.TEN_MINUTES) {
waitRemaining = CrawlerConstants.DURATIONS.A_MINUTE - waitedSinceLastTest;
} else if (downDelay <= CrawlerConstants.DURATIONS.AN_HOUR) {
waitRemaining =
CrawlerConstants.DURATIONS.TEN_MINUTES - waitedSinceLastTest;
} else if (downDelay <= CrawlerConstants.DURATIONS.A_DAY) {
waitRemaining = CrawlerConstants.DURATIONS.AN_HOUR - waitedSinceLastTest;
} else if (downDelay <= CrawlerConstants.DURATIONS.A_WEEK) {
waitRemaining = CrawlerConstants.DURATIONS.A_DAY - waitedSinceLastTest;
} else if (downDelay <= CrawlerConstants.DURATIONS.A_MONTH) {
waitRemaining = CrawlerConstants.DURATIONS.A_WEEK - waitedSinceLastTest;
}
// Else do not check it, DOWN for too long
return waitRemaining;
}
}
export class BlockCrawler {
private CONST_BLOCKS_CHUNK = CrawlerConstants.CRAWL_BLOCK_CHUNK;
private pullingActualIntervalDuration =
CrawlerConstants.PULLING_MINIMAL_DELAY;
private programStart = Date.now();
private syncBlockFifo = async.queue(
(task: any, callback: any) => task(callback),
1
);
private syncBlockInterval: NodeJS.Timer;
constructor(private server: Server, private logger: any) {}
async startService() {
if (this.syncBlockInterval) clearInterval(this.syncBlockInterval);
this.syncBlockInterval = setInterval(
() =>
this.syncBlockFifo.push((cb: any) =>
this.syncBlock(this.server).then(cb).catch(cb)
),
1000 * this.pullingActualIntervalDuration
);
this.syncBlock(this.server);
}
async stopService() {
clearInterval(this.syncBlockInterval);
this.syncBlockFifo.kill();
}
pullBlocks(server: Server, pubkey = "") {
return this.syncBlock(server, pubkey);
}
private async syncBlock(server: Server, pubkey: string = "") {
// Eventually change the interval duration
const minutesElapsed = Math.ceil(
(Date.now() - this.programStart) / (60 * 1000)
);
const FACTOR = Math.sin(
(minutesElapsed / CrawlerConstants.PULLING_INTERVAL_TARGET) *
(Math.PI / 2)
);
// Make the interval always higher than before
const pullingTheoreticalIntervalNow = Math.max(
Math.max(
FACTOR * CrawlerConstants.PULLING_INTERVAL_TARGET,
CrawlerConstants.PULLING_MINIMAL_DELAY
),
this.pullingActualIntervalDuration
);
if (pullingTheoreticalIntervalNow !== this.pullingActualIntervalDuration) {
this.pullingActualIntervalDuration = pullingTheoreticalIntervalNow;
// Change the interval
if (this.syncBlockInterval) clearInterval(this.syncBlockInterval);
this.syncBlockInterval = setInterval(
() =>
this.syncBlockFifo.push((cb: any) =>
this.syncBlock(server).then(cb).catch(cb)
),
1000 * this.pullingActualIntervalDuration
);
}
try {
let current: DBBlock | null = await server.dal.getCurrentBlockOrNull();
if (current) {
this.pullingEvent(server, "start", current.number);
this.logger && this.logger.info("Pulling blocks from the network...");
let peers = await server.dal.findAllPeersBut([server.conf.pair.pub]);
peers = Underscore.shuffle(peers);
if (pubkey) {
peers = Underscore.filter(peers, (p: any) => p.pubkey == pubkey);
}
// Shuffle the peers
peers = Underscore.shuffle(peers);
// Only take at max X of them
peers = peers.slice(
0,
CrawlerConstants.MAX_NUMBER_OF_PEERS_FOR_PULLING
);
await Promise.all(
peers.map(async (thePeer: any, i: number) => {
let p = PeerDTO.fromJSONObject(thePeer);
this.pullingEvent(
server,
"peer",
Underscore.extend({ number: i, length: peers.length }, p)
);
this.logger &&
this.logger.trace(
"Try with %s %s",
p.getURL(),
p.pubkey.substr(0, 6)
);
try {
let node: any = await connect(p);
let nodeCurrent: BlockDTO | null = null;
node.pubkey = p.pubkey;
await checkPeerValidity(server, p, node);
let dao = new (class extends AbstractDAO {
private lastDownloaded: BlockDTO | null;
constructor(private crawler: BlockCrawler) {
super();
}
async localCurrent(): Promise<DBBlock | null> {
return server.dal.getCurrentBlockOrNull();
}
async remoteCurrent(source?: any): Promise<BlockDTO | null> {
nodeCurrent = await source.getCurrent();
return nodeCurrent;
}
async remotePeers(source?: any): Promise<PeerDTO[]> {
return Promise.resolve([node]);
}
async getLocalBlock(number: number): Promise<DBBlock> {
return server.dal.getBlockWeHaveItForSure(number);
}
async getRemoteBlock(
thePeer: any,
number: number
): Promise<BlockDTO> {
let block = null;
try {
block = await thePeer.getBlock(number);
tx_cleaner(block.transactions);
} catch (e) {
if (e.httpCode != 404) {
throw e;
}
}
return block;
}
async applyMainBranch(block: BlockDTO): Promise<boolean> {
const existing = await server.dal.getAbsoluteBlockByNumberAndHash(
block.number,
block.hash
);
if (!existing) {
let addedBlock = await server.writeBlock(
block,
false,
true
);
if (!this.lastDownloaded) {
this.lastDownloaded = await dao.remoteCurrent(node);
}
this.crawler.pullingEvent(server, "applying", {
number: block.number,
last: this.lastDownloaded && this.lastDownloaded.number,
});
if (addedBlock) {
current = DBBlock.fromBlockDTO(addedBlock);
// Emit block events (for sharing with the network) only in forkWindowSize
if (
nodeCurrent &&
nodeCurrent.number - addedBlock.number <
server.conf.forksize
) {
server.streamPush(addedBlock);
}
}
}
return true;
}
async removeForks(): Promise<boolean> {
return true;
}
async isMemberPeer(thePeer: PeerDTO): Promise<boolean> {
return true;
}
async downloadBlocks(
thePeer: any,
fromNumber: number,
count?: number | undefined
): Promise<BlockDTO[]> {
if (!count) {
count = this.crawler.CONST_BLOCKS_CHUNK;
}
let blocks = await thePeer.getBlocks(count, fromNumber);
// Fix for #734
for (const block of blocks) {
for (const tx of block.transactions) {
tx.version = CrawlerConstants.TRANSACTION_VERSION;
}
}
return blocks;
}
})(this);
await dao.pull(server.conf, server.logger);
} catch (e) {
if (this.isConnectionError(e)) {
this.logger &&
this.logger.info(
"Peer %s unreachable: now considered as DOWN.",
p.pubkey
);
await server.dal.setPeerDown(p.pubkey);
} else if (e.httpCode == 404) {
this.logger &&
this.logger.trace(
"No new block from %s %s",
p.pubkey.substr(0, 6),
p.getURL()
);
} else {
this.logger && this.logger.warn(e);
}
}
})
);
await this.server.BlockchainService.pushFIFO(
"crawlerResolution",
async () => {
await server.BlockchainService.blockResolution();
await server.BlockchainService.forkResolution();
}
);
this.pullingEvent(server, "end", current.number);
}
this.logger &&
this.logger.info(
"Will pull blocks from the network in %s min %s sec",
Math.floor(this.pullingActualIntervalDuration / 60),
Math.floor(this.pullingActualIntervalDuration % 60)
);
} catch (err) {
this.pullingEvent(server, "error");
this.logger &&
this.logger.warn(err.code || err.stack || err.message || err);
}
}
private pullingEvent(server: Server, type: string, number: any = null) {
server.pullingEvent(type, number);
}
private isConnectionError(err: any) {
return (
err &&
(err.code == "E_DUNITER_PEER_CHANGED" ||
err.code == "EINVAL" ||
err.code == "ECONNREFUSED" ||
err.code == "ETIMEDOUT" ||
(err.httpCode !== undefined && err.httpCode !== 404))
);
}
}
function chooseXin(peers: PeerDTO[], max: number) {
const chosen = [];
const nbPeers = peers.length;
for (let i = 0; i < Math.min(nbPeers, max); i++) {
const randIndex = Math.max(
Math.floor(Math.random() * 10) - (10 - nbPeers) - i,
0
);
chosen.push(peers[randIndex]);
peers.splice(randIndex, 1);
}
return chosen;
}
const checkPeerValidity = async (server: Server, p: PeerDTO, node: any) => {
try {
let document = await node.getPeer();
let thePeer = PeerDTO.fromJSONObject(document);
let goodSignature = server.PeeringService.checkPeerSignature(thePeer);
if (!goodSignature) {
throw "Signature from a peer must match";
}
if (p.currency !== thePeer.currency) {
throw (
"Currency has changed from " + p.currency + " to " + thePeer.currency
);
}
if (p.pubkey !== thePeer.pubkey) {
throw (
"Public key of the peer has changed from " +
p.pubkey +
" to " +
thePeer.pubkey
);
}
let sp1 = p.block.split("-");
let sp2 = thePeer.block.split("-");
let blockNumber1 = parseInt(sp1[0]);
let blockNumber2 = parseInt(sp2[0]);
if (blockNumber2 < blockNumber1) {
throw (
"Signature date has changed from block " +
blockNumber1 +
" to older block " +
blockNumber2
);
}
} catch (e) {
throw { code: "E_DUNITER_PEER_CHANGED" };
}
};