Skip to content

Commit 53cd82a

Browse files
author
Daniel Borkan
committed
Only ping servers until they are online
1 parent 7993842 commit 53cd82a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/lib/cloud/social/provider.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export class CloudSocialProvider {
175175
// Map from host to intervalId used for monitoring online presence.
176176
private onlinePresenceMonitorIds_: { [host: string]: NodeJS.Timer } = {};
177177

178-
static PING_INTERVAL = 60000;
178+
private static PING_INTERVAL_ = 60000;
179179

180180
constructor(private dispatchEvent_: (name: string, args: Object) => void) { }
181181

@@ -453,7 +453,9 @@ export class CloudSocialProvider {
453453
return;
454454
}
455455
// Ping server every minute to see if it is online. A server is considered
456-
// online if a connection can be established with the SSH port.
456+
// online if a connection can be established with the SSH port. We stop
457+
// pinging for presence once the host is online, so as to not give away
458+
// that we are pinging uProxy cloud servers with a regular heartbeat.
457459
const ping = () : Promise<boolean> => {
458460
var pinger = new Pinger(host, SSH_SERVER_PORT);
459461
return pinger.pingOnce().then(() => {
@@ -477,14 +479,15 @@ export class CloudSocialProvider {
477479
}
478480
});
479481
}
480-
this.onlinePresenceMonitorIds_[host] = setInterval(ping, CloudSocialProvider.PING_INTERVAL);
482+
this.onlinePresenceMonitorIds_[host] = setInterval(ping, CloudSocialProvider.PING_INTERVAL_);
481483
// Ping server immediately (so we don't have to wait 1 min for 1st result).
482484
ping();
483485
}
484486

485487
private stopMonitoringPresence_ = (host: string) => {
486488
if (!this.onlinePresenceMonitorIds_[host]) {
487-
log.error('unexpected call to stopMonitoringPresence_ for ' + host);
489+
// We may have already stopped monitoring presence, e.g. because the
490+
// host has come online.
488491
return;
489492
}
490493
clearInterval(this.onlinePresenceMonitorIds_[host]);
@@ -497,6 +500,10 @@ export class CloudSocialProvider {
497500

498501
private setOnlineStatus_ = (host: string, isOnline: boolean) => {
499502
this.onlineHosts_[host] = isOnline;
503+
if (isOnline) {
504+
// Stop monitoring presence once the client is online.
505+
this.stopMonitoringPresence_(host);
506+
}
500507
}
501508

502509
// To see how these fields are handled, see

0 commit comments

Comments
 (0)