Skip to content

Commit

Permalink
Optimized impress.compareHosts, close #686
Browse files Browse the repository at this point in the history
  • Loading branch information
tshemsedinov committed Feb 3, 2017
1 parent f05ae8b commit fd92d4e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion applications/example/config/hosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Wildcard '*' is allowed for masking random or empty substring

'*', // all
// '127.0.0.1', // localhost or IP
// '127.0.0.1', // localhost or IP
// 'domain.com', // domain name
// '*.domain.com', // masked domain name
]
9 changes: 7 additions & 2 deletions config/servers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
slowTime: '1s',
timeout: '30s',
keepAlive: '5s',
applications: ['example'] // undefined for all
applications: ['example'], // undefined for all
// inspect: 2000 // inspect Chrome developer tools
},

Expand All @@ -32,6 +32,7 @@
transport: 'tcp',
address: '*',
ports: [3000, [1]], // Example: [81, [-1]]
applications: ['example'],
heartbeat: '2s'
},

Expand All @@ -49,6 +50,7 @@
transport: 'ws',
address: '*',
ports: [8000],
applications: ['example'],
slowTime: '1s'
},

Expand All @@ -57,7 +59,8 @@
// transport: 'tcp',
// address: '127.0.0.1',
// ports: [80],
// Nagle algorithm, default true, set to false for latency optimization
// applications: ['example'],
//Nagle algorithm, default true, set to false for latency optimization
// nagle: true,
// slowTime: '1s',
// timeout: '120s' // default 30s
Expand All @@ -67,6 +70,7 @@
// protocol: 'http',
// transport: 'tls',
// address: '127.0.0.1',
// applications: ['example'],
// ports: [443],
// key: 'example.key',
// cert: 'example.cer'
Expand All @@ -76,6 +80,7 @@
// protocol: 'http',
// transport: 'tcp',
// address: '127.0.0.1',
// applications: ['example'],
// ports: [8080],
// slowTime: 1000
//}
Expand Down
9 changes: 5 additions & 4 deletions lib/impress.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,25 +162,25 @@ impress.compareMasks = (m1, m2) => (
);

impress.compareHosts = () => {
let i, j, k, ilen, jlen, klen, appName, config, hosts;
const cmp = [];
let i, j, ilen, jlen, appName, config, hosts, hostFound;
for (appName in impress.applications) {
config = impress.applications[appName].config;
if (!config) continue;
hosts = config.hosts;
if (!hosts) continue;
for (i = 0, ilen = hosts.length; i < ilen; i++) {
hostFound = false;
for (j = 0, jlen = cmp.length; j < jlen; j++) {
hostFound = hostFound || hosts[i] === cmp[j];
if (impress.compareMasks(hosts[i], cmp[j])) {
impress.log.warning(
'Hosts mask overlapping: "' + hosts[i] +
'" and "' + cmp[j] + '"'
);
}
}
}
for (k = 0, klen = hosts.length; k < klen; k++) {
if (!cmp.includes(hosts[k])) cmp.push(hosts[k]);
if (!hostFound) cmp.push(hosts[i]);
}
}
};
Expand Down Expand Up @@ -220,6 +220,7 @@ impress.createApplications = (callback) => {
application.createApplication(cb);
});
}, () => {
if (impress.serverProto === 'http') impress.compareHosts();
impress.linkNamespaces();
callback();
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "impress",
"version": "0.4.5",
"version": "0.4.6",
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>",
"description": "Impress Application Server for Node.js",
"license": "MIT",
Expand Down

0 comments on commit fd92d4e

Please sign in to comment.