Skip to content
Snippets Groups Projects
Commit 3fce8a17 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

fix(sync): don't lose nodes on single download err - cherry-pick of commit...

fix(sync): don't lose nodes on single download err - cherry-pick of commit 7a59f46f from branch `dev`
parent 85e63ece
No related branches found
No related tags found
No related merge requests found
...@@ -155,21 +155,17 @@ export class RemoteSynchronizer extends AbstractSynchronizer { ...@@ -155,21 +155,17 @@ export class RemoteSynchronizer extends AbstractSynchronizer {
// If we know this is a WS2P connection, don't try BMA // If we know this is a WS2P connection, don't try BMA
if (access.isWS2P !== true) { if (access.isWS2P !== true) {
try { try {
endpoint =
[port == 443 ? "BMAS" : "BASIC_MERKLED_API", host, port].join(" ") +
(path ? (" " + path) : "");
const contacter = await connect( const contacter = await connect(
PeerDTO.fromJSONObject({ PeerDTO.fromJSONObject({
endpoints: [ endpoints: [endpoint],
[port == 443 ? "BMAS" : "BASIC_MERKLED_API", host, port].join(
" "
) + (path ? " " + path : ""),
],
}), }),
3000 3000
); );
peering = await contacter.getPeer(); peering = await contacter.getPeer();
api = new BMARemoteContacter(contacter); api = new BMARemoteContacter(contacter);
endpoint =
[port == 443 ? "BMAS" : "BASIC_MERKLED_API", host, port].join(" ") +
(path ? " " + path : "");
} catch (e) {} } catch (e) {}
} }
......
...@@ -90,21 +90,30 @@ export class P2pCandidate { ...@@ -90,21 +90,30 @@ export class P2pCandidate {
this.dlPromise = querablep( this.dlPromise = querablep(
(async () => { (async () => {
// We try to download the blocks // We try to download the blocks
let blocks: BlockDTO[] | null; let blocks: BlockDTO[] = [];
let tries = 5;
while (tries > 0) {
try { try {
blocks = await (this.api as IRemoteContacter).getBlocks(count, from); blocks = await (this.api as IRemoteContacter).getBlocks(
count,
from
);
} catch (e) { } catch (e) {
// Unfortunately this can fail // Unfortunately this can fail
blocks = null; blocks = [];
error = e; this.logger.error(e);
}
if (blocks.length != count) {
this.logger.error("Wrong number of blocks from %s", this.hostName);
tries--;
} else {
break;
}
} }
this.responseTimes.push(Date.now() - start); this.responseTimes.push(Date.now() - start);
// Only keep a flow of 5 ttas for the node // Only keep a flow of 5 ttas for the node
if (this.responseTimes.length > 5) this.responseTimes.shift(); if (this.responseTimes.length > 5) this.responseTimes.shift();
this.nbSuccess++; this.nbSuccess++;
if (error) {
throw error;
}
return blocks; return blocks;
})() })()
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment