Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
reconnect to the server if it can't connect. (#343)
Browse files Browse the repository at this point in the history
* reconnect to the server if it can't connect.

* Format
  • Loading branch information
crazybuster authored and micahalcorn committed Aug 16, 2018
1 parent e5e0edd commit 4c5a126
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/resources/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,22 @@ 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)
}
}
}
})
}

Expand Down Expand Up @@ -247,6 +263,7 @@ class Messaging extends ResourceBase {
clearInterval(this.refreshIntervalId)
}

this.last_connect_time = Date.now()
this.refreshIntervalId = setInterval(
this.refreshPeerList.bind(this),
5000
Expand Down

0 comments on commit 4c5a126

Please sign in to comment.