From 5bfe0a518657495430d7dbef217ed4207b4028bf Mon Sep 17 00:00:00 2001 From: Yu Pan Date: Wed, 15 Aug 2018 19:32:39 -0700 Subject: [PATCH 1/2] reconnect to the server if it can't connect. --- src/resources/messaging.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/resources/messaging.js b/src/resources/messaging.js index a2d08e58..b9dabe2a 100644 --- a/src/resources/messaging.js +++ b/src/resources/messaging.js @@ -205,6 +205,21 @@ class Messaging extends ResourceBase { this.last_peers = peer_ids console.log('New peers:', this.last_peers) } + //let's do a 15 second reconnect policy + if (this.ipfs.__reconnect_peers && Date.now() - this.last_connect_time > 20000 && this.last_peers) + { + this.last_connect_time = Date.now() + //every 20 seconds either connect or ping + for (const peer of Object.keys(this.ipfs.__reconnect_peers)) + { + if (!this.last_peers.includes(peer)) + { + const peer_address = this.ipfs.__reconnect_peers[peer] + console.log('Reconnecting:', peer_address) + this.ipfs.swarm.connect(peer_address) + } + } + } }) } @@ -247,6 +262,7 @@ class Messaging extends ResourceBase { clearInterval(this.refreshIntervalId) } + this.last_connect_time = Date.now() this.refreshIntervalId = setInterval( this.refreshPeerList.bind(this), 5000 From 728f517cb282ddb94dd5dd5c9a8e418594ced5d7 Mon Sep 17 00:00:00 2001 From: Micah Alcorn Date: Wed, 15 Aug 2018 21:13:30 -0700 Subject: [PATCH 2/2] Format --- src/resources/messaging.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/resources/messaging.js b/src/resources/messaging.js index b9dabe2a..21ba9c95 100644 --- a/src/resources/messaging.js +++ b/src/resources/messaging.js @@ -206,14 +206,15 @@ class Messaging extends ResourceBase { console.log('New peers:', this.last_peers) } //let's do a 15 second reconnect policy - if (this.ipfs.__reconnect_peers && Date.now() - this.last_connect_time > 20000 && this.last_peers) - { + if ( + this.ipfs.__reconnect_peers && + Date.now() - this.last_connect_time > 20000 && + this.last_peers + ) { this.last_connect_time = Date.now() //every 20 seconds either connect or ping - for (const peer of Object.keys(this.ipfs.__reconnect_peers)) - { - if (!this.last_peers.includes(peer)) - { + for (const peer of Object.keys(this.ipfs.__reconnect_peers)) { + if (!this.last_peers.includes(peer)) { const peer_address = this.ipfs.__reconnect_peers[peer] console.log('Reconnecting:', peer_address) this.ipfs.swarm.connect(peer_address)