From 1b06877863cfb3bbed0c7fc977329a4e7939796c Mon Sep 17 00:00:00 2001
From: cgeek <cem.moreau@gmail.com>
Date: Sat, 28 Oct 2017 11:04:01 +0200
Subject: [PATCH] [fix] #1135 Regularly try to reconnect to the WS2P network

---
 app/modules/ws2p/lib/WS2PCluster.ts | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts
index bf56d75e9..7f015e75e 100644
--- a/app/modules/ws2p/lib/WS2PCluster.ts
+++ b/app/modules/ws2p/lib/WS2PCluster.ts
@@ -77,6 +77,9 @@ export class WS2PCluster {
   // The triggerer of a buffer of heads' sending
   private headsTimeout:NodeJS.Timer|null = null
 
+  // A timer to regularly reconnect to the network in case we are below the minimum connections' count
+  private reconnectionInteval:NodeJS.Timer|null = null
+
   private constructor(private server:Server) {
     this.messageHandler = new WS2PServerMessageHandler(this.server, this)
     // Conf: max private connections
@@ -622,6 +625,8 @@ export class WS2PCluster {
   }
 
   async startCrawling(waitConnection = false) {
+    // For connectivity
+    this.reconnectionInteval = setInterval(() => this.server.push({ ws2p: 'disconnected' }), 1000 * 60 * 10)
     // For blocks
     if (this.syncBlockInterval)
       clearInterval(this.syncBlockInterval);
@@ -650,6 +655,9 @@ export class WS2PCluster {
   }
 
   async stopCrawling() {
+    if (this.reconnectionInteval) {
+      clearInterval(this.reconnectionInteval)
+    }
     if (this.syncBlockInterval) {
       clearInterval(this.syncBlockInterval)
     }
-- 
GitLab