Skip to content
Snippets Groups Projects
Commit ea0c43a5 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[fix] Make Duniter services start more quickly

parent 0826538e
No related branches found
No related tags found
No related merge requests found
...@@ -512,14 +512,25 @@ export class WS2PCluster { ...@@ -512,14 +512,25 @@ export class WS2PCluster {
return all return all
} }
async startCrawling() { async startCrawling(waitConnection = false) {
// For blocks // For blocks
if (this.syncBlockInterval) if (this.syncBlockInterval)
clearInterval(this.syncBlockInterval); clearInterval(this.syncBlockInterval);
this.syncBlockInterval = setInterval(() => this.pullBlocks(), 1000 * WS2PConstants.BLOCK_PULLING_INTERVAL) this.syncBlockInterval = setInterval(() => this.pullBlocks(), 1000 * WS2PConstants.BLOCK_PULLING_INTERVAL);
// Pull blocks right on start // Pull blocks right on start
const init = async () => {
try {
await this.connectToWS2Peers() await this.connectToWS2Peers()
await this.pullBlocks() await this.pullBlocks()
} catch (e) {
this.server.logger.error(e)
}
}
if (waitConnection) {
await init()
} else {
init()
}
// For docpool // For docpool
if (this.syncDocpoolInterval) if (this.syncDocpoolInterval)
clearInterval(this.syncDocpoolInterval); clearInterval(this.syncDocpoolInterval);
......
...@@ -115,8 +115,8 @@ describe("WS2P client limitations", function() { ...@@ -115,8 +115,8 @@ describe("WS2P client limitations", function() {
'WS2P 11111111 127.0.0.1 ' + portWS1 'WS2P 11111111 127.0.0.1 ' + portWS1
]) ])
await s2.writePeer(p1) await s2.writePeer(p1)
await (s1._server.ws2pCluster as WS2PCluster).startCrawling() await (s1._server.ws2pCluster as WS2PCluster).startCrawling(true)
await (s2._server.ws2pCluster as WS2PCluster).startCrawling() await (s2._server.ws2pCluster as WS2PCluster).startCrawling(true)
await s1.expect('/network/ws2p/info', (res:any) => { await s1.expect('/network/ws2p/info', (res:any) => {
assert.equal(res.peers.level1, 0) assert.equal(res.peers.level1, 0)
assert.equal(res.peers.level2, 1) assert.equal(res.peers.level2, 1)
......
...@@ -93,7 +93,7 @@ describe("WS2P cluster", function() { ...@@ -93,7 +93,7 @@ describe("WS2P cluster", function() {
]) ])
await s2.writePeer(p1) await s2.writePeer(p1)
WS2PCluster.plugOn(s2._server); WS2PCluster.plugOn(s2._server);
await (s2._server.ws2pCluster as WS2PCluster).startCrawling() await (s2._server.ws2pCluster as WS2PCluster).startCrawling(true)
await s1.expect('/network/ws2p/info', (res:any) => { await s1.expect('/network/ws2p/info', (res:any) => {
assert.equal(res.peers.level1, 0) assert.equal(res.peers.level1, 0)
assert.equal(res.peers.level2, 1) assert.equal(res.peers.level2, 1)
...@@ -105,7 +105,7 @@ describe("WS2P cluster", function() { ...@@ -105,7 +105,7 @@ describe("WS2P cluster", function() {
}) })
it('should not start another connection if peer is already connected', async () => { it('should not start another connection if peer is already connected', async () => {
await (s1._server.ws2pCluster as WS2PCluster).startCrawling() await (s1._server.ws2pCluster as WS2PCluster).startCrawling(true)
await s1.expect('/network/ws2p/info', (res:any) => { await s1.expect('/network/ws2p/info', (res:any) => {
assert.equal(res.peers.level1, 0) // <- Does not increase! assert.equal(res.peers.level1, 0) // <- Does not increase!
assert.equal(res.peers.level2, 1) assert.equal(res.peers.level2, 1)
......
...@@ -70,8 +70,8 @@ describe("WS2P heads propagation", function() { ...@@ -70,8 +70,8 @@ describe("WS2P heads propagation", function() {
'WS2P 11111111 127.0.0.1 ' + portWS1 'WS2P 11111111 127.0.0.1 ' + portWS1
]) ])
await s2.writePeer(p1) await s2.writePeer(p1)
await (s1._server.ws2pCluster as WS2PCluster).startCrawling() await (s1._server.ws2pCluster as WS2PCluster).startCrawling(true)
await (s2._server.ws2pCluster as WS2PCluster).startCrawling() await (s2._server.ws2pCluster as WS2PCluster).startCrawling(true)
await s1.expect('/network/ws2p/info', (res:any) => { await s1.expect('/network/ws2p/info', (res:any) => {
assert.equal(res.peers.level1, 0) assert.equal(res.peers.level1, 0)
assert.equal(res.peers.level2, 1) assert.equal(res.peers.level2, 1)
......
...@@ -84,7 +84,7 @@ describe("WS2P network", function() { ...@@ -84,7 +84,7 @@ describe("WS2P network", function() {
]) ])
await s2.writePeer(p1) await s2.writePeer(p1)
WS2PCluster.plugOn(s2._server); WS2PCluster.plugOn(s2._server);
await (s2._server.ws2pCluster as WS2PCluster).startCrawling() await (s2._server.ws2pCluster as WS2PCluster).startCrawling(true)
// const network = await simpleWS2PNetwork(s1, s2) // const network = await simpleWS2PNetwork(s1, s2)
// wss = network.wss // wss = network.wss
// cluster2 = network.cluster2 // cluster2 = network.cluster2
......
...@@ -118,9 +118,9 @@ describe("WS2P server limitations", function() { ...@@ -118,9 +118,9 @@ describe("WS2P server limitations", function() {
'WS2P 11111111 127.0.0.1 ' + portWS1 'WS2P 11111111 127.0.0.1 ' + portWS1
]) ])
await s2.writePeer(p1) await s2.writePeer(p1)
await (s1._server.ws2pCluster as WS2PCluster).startCrawling() await (s1._server.ws2pCluster as WS2PCluster).startCrawling(true)
await (s2._server.ws2pCluster as WS2PCluster).startCrawling() await (s2._server.ws2pCluster as WS2PCluster).startCrawling(true)
await (s3._server.ws2pCluster as WS2PCluster).startCrawling() await (s3._server.ws2pCluster as WS2PCluster).startCrawling(true)
await s1.expect('/network/ws2p/info', (res:any) => { await s1.expect('/network/ws2p/info', (res:any) => {
assert.equal(res.peers.level1, 0) assert.equal(res.peers.level1, 0)
assert.equal(res.peers.level2, 1) assert.equal(res.peers.level2, 1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment