Comparing version 0.0.2 to 0.0.3
@@ -127,4 +127,15 @@ var bouncy = require('bouncy') | ||
Bouncer.prototype.checkLocalIp = function(addresses) { | ||
var self = this | ||
var haveIp = false | ||
addresses.forEach(function(address) { | ||
if (self.ips.indexOf(address) > -1) { | ||
haveIp = true | ||
} | ||
}) | ||
return haveIp | ||
} | ||
Bouncer.prototype.serviceUp = function(service) { | ||
if (!service.txtRecord || !service.txtRecord.service) return | ||
@@ -134,4 +145,4 @@ | ||
if (this.localOnly) { | ||
if (this.localOnly && !this.checkLocalIp(service.addresses)) { | ||
return | ||
} | ||
@@ -141,2 +152,3 @@ | ||
// we can get multiple hosts by the same name on different addresses | ||
this.connectedByName[service.name] = service | ||
@@ -153,5 +165,5 @@ | ||
Bouncer.prototype.serviceDown = function(service) { | ||
Bouncer.prototype.serviceDown = function(toRemove) { | ||
// retrieve the original record to ease finding | ||
service = this.connectedByName[service.name] | ||
var service = this.connectedByName[toRemove.name] | ||
@@ -163,3 +175,5 @@ if (!service) return | ||
if (!this.services[serviceName]) { | ||
var serverObj = this.services[serviceName] | ||
if (!serverObj) { | ||
console.log("found a service that we never added", service) | ||
@@ -169,12 +183,9 @@ return | ||
if (this.services[serviceName].hosts.length > 1) { | ||
var i = this.services[serviceName].hosts.indexOf(service) | ||
if (serverObj.hosts.length > 0) { | ||
if (i === -1) { | ||
console.log("found a service that we never added", service) | ||
return | ||
} | ||
serverObj.hosts = this.removeByHostName(serverObj.hosts, service.name) | ||
this.services[serviceName].hosts.splice(i, 1) | ||
} | ||
this.services[serviceName] = serverObj | ||
delete this.connectedByName[serviceName] | ||
} | ||
@@ -185,2 +196,10 @@ this.onServiceDown(service) | ||
Bouncer.prototype.removeByHostName = function(hosts, hostName) { | ||
hosts = hosts.filter(function(host) { | ||
return hostName !== host.name | ||
}) | ||
return hosts | ||
} | ||
module.exports = Bouncer |
@@ -5,3 +5,3 @@ { | ||
"description": "A service router that uses MDNS and bouncy to do magic!", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
Sorry, the diff of this file is not supported yet
6826
179