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

Commit 4c5a126

Browse files
crazybustermicahalcorn
authored andcommitted
reconnect to the server if it can't connect. (#343)
* reconnect to the server if it can't connect. * Format
1 parent e5e0edd commit 4c5a126

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/resources/messaging.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,22 @@ class Messaging extends ResourceBase {
205205
this.last_peers = peer_ids
206206
console.log('New peers:', this.last_peers)
207207
}
208+
//let's do a 15 second reconnect policy
209+
if (
210+
this.ipfs.__reconnect_peers &&
211+
Date.now() - this.last_connect_time > 20000 &&
212+
this.last_peers
213+
) {
214+
this.last_connect_time = Date.now()
215+
//every 20 seconds either connect or ping
216+
for (const peer of Object.keys(this.ipfs.__reconnect_peers)) {
217+
if (!this.last_peers.includes(peer)) {
218+
const peer_address = this.ipfs.__reconnect_peers[peer]
219+
console.log('Reconnecting:', peer_address)
220+
this.ipfs.swarm.connect(peer_address)
221+
}
222+
}
223+
}
208224
})
209225
}
210226

@@ -247,6 +263,7 @@ class Messaging extends ResourceBase {
247263
clearInterval(this.refreshIntervalId)
248264
}
249265

266+
this.last_connect_time = Date.now()
250267
this.refreshIntervalId = setInterval(
251268
this.refreshPeerList.bind(this),
252269
5000

0 commit comments

Comments
 (0)