Skip to content

Commit

Permalink
move from maxmind.openSync to async maxmind.open (#36)
Browse files Browse the repository at this point in the history
* move from maxmind.openSync to async maxmind.open
* version bump\
  • Loading branch information
analogic authored and msimerson committed Jul 17, 2019
1 parent efecfc6 commit 2eea88b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ env:
plugins:
- haraka

parserOptions:
ecmaVersion: 2017

extends:
- eslint:recommended
- plugin:haraka/recommended
Expand Down
3 changes: 3 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.0.10 - 2019-07-16

- move from maxmind.openSync to async maxmind.open, #35

## 1.0.9 - 2019-07-09

Expand Down
13 changes: 6 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ function ucFirst (string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}

exports.register = function () {
exports.register = async function () {
const plugin = this;

plugin.load_geoip_ini();
plugin.require_maxmind();
plugin.load_dbs();
await plugin.load_dbs();

if (plugin.dbsLoaded) {
plugin.register_hook('connect', 'lookup_maxmind');
Expand Down Expand Up @@ -55,28 +55,27 @@ exports.require_maxmind = function () {
plugin.logerror(`unable to load maxmind, try\n\n\t'npm install -g maxmind'\n\n`);
}

exports.load_dbs = function () {
exports.load_dbs = async function () {
const plugin = this;

if (!plugin.maxmind) return;

plugin.dbsLoaded = 0;
const dbdir = plugin.cfg.main.dbdir || '/usr/local/share/GeoIP/';

['city', 'country'].forEach((db) => {

for (const db of ['city', 'country']) {
const dbPath = path.join(dbdir, `GeoLite2-${ucFirst(db)}.mmdb`);
if (!fs.existsSync(dbPath)) return;

plugin[db + 'Lookup'] = plugin.maxmind.openSync(dbPath, {
plugin[db + 'Lookup'] = await plugin.maxmind.open(dbPath, {
watchForUpdates: true,
cache: {
max: 1000, // max items in cache
maxAge: 1000 * 60 * 60 // life time in milliseconds
}
});
plugin.dbsLoaded++;
})
}

plugin.loginfo(`loaded maxmind with ${plugin.dbsLoaded} DBs`);
}
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": "haraka-plugin-geoip",
"version": "1.0.9",
"version": "1.0.10",
"description": "provide geographic information about mail senders.",
"main": "index.js",
"directories": {
Expand Down

0 comments on commit 2eea88b

Please sign in to comment.