Skip to content

Commit

Permalink
feat: upgrade to latest ipfs-api and aegir
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Oct 6, 2016
1 parent 4d82ca5 commit b2e61d8
Show file tree
Hide file tree
Showing 16 changed files with 162 additions and 48 deletions.
35 changes: 34 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,35 @@
**/node_modules/
**/*.log
test/repo-tests*

# Logs
logs
*.log

coverage

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

build

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
npm-debug.log

lib
dist
34 changes: 34 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
**/node_modules/
**/*.log
test/repo-tests*

# Logs
logs
*.log

coverage

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

build

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

test
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
sudo: false
language: node_js
node_js:
- 4
- 5
- stable

# Make sure we have new NPM.
before_install:
- npm install -g npm

script:
- npm run lint
- npm test
- npm run coverage


before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start

after_success:
- npm run coverage-publish

env:
- CXX=g++-4.8

addons:
firefox: 'latest'
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
[![Dependency Status](https://david-dm.org/ipfs/ipfs-geoip.svg?style=flat-square)](https://david-dm.org/ipfs/ipfs-geoip)
[![Travis CI](https://img.shields.io/travis/ipfs/ipfs-geoip/master.svg?style=flat-square)](https://travis-ci.org/ipfs/ipfs-geoip)
[![Circle CI](https://circleci.com/gh/ipfs/ipfs-geoip.svg?style=svg)](https://circleci.com/gh/ipfs/ipfs-geoip)
[![Coverage Status](https://coveralls.io/repos/github/ipfs/ipfs-geoip/badge.svg?branch=master)](https://coveralls.io/github/ipfs/ipfs-geoip?branch=master)

> geoip lookup over ipfs
Expand Down
2 changes: 1 addition & 1 deletion bin/generate
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict'

const Gauge = require('gauge')
const gen = require('../generate')
const gen = require('../src/generate')
const API = require('ipfs-api')

function handleNoApi () {
Expand Down
12 changes: 12 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
machine:
node:
version: stable

dependencies:
pre:
- google-chrome --version
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
- sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
- sudo apt-get update
- sudo apt-get --only-upgrade install google-chrome-stable
- google-chrome --version
9 changes: 0 additions & 9 deletions index.js

This file was deleted.

44 changes: 25 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,41 @@
"name": "ipfs-geoip",
"version": "2.0.0",
"description": "Library for ipfs geoip lookups",
"main": "index.js",
"main": "lib/index.js",
"jsnext:main": "src/index.js",
"scripts": {
"lint": "aegir-lint",
"build": "aegir-build",
"test": "aegir-test --env node",
"release": "aegir-release --evn node",
"release-minor": "aegir-release --type minor --env node",
"release-major": "aegir-release --type major --env node",
"coverage": "aegir-coverage",
"coverage-publish": "aegir-coverage publish",
"generate": "bin/generate"
},
"dependencies": {
"inet_ipv4": "^1.0.0",
"memoizee": "^0.3.8"
"memoizee": "^0.4.1",
"multihashes": "^0.2.2"
},
"repository": {
"type": "git",
"url": "https://github.com/ipfs/ipfs-geoip"
},
"devDependencies": {
"aegir": "^8.1.2",
"bl": "^1.1.2",
"bluebird": "^3.3.1",
"bluebird": "^3.4.6",
"chai": "^3.5.0",
"chai-as-promised": "^5.2.0",
"csv": "^0.4.2",
"eslint-plugin-react": "^3.5.1",
"gauge": "^1.2.5",
"iconv-lite": "^0.4.8",
"ipfs-api": "^2.13.0",
"ipfsd-ctl": "^0.8.1",
"lodash": "^4.5.0",
"mocha": "^2.4.5",
"pre-commit": "^1.0.6",
"standard": "^6.0.5"
"chai-as-promised": "^6.0.0",
"csv": "^1.1.0",
"gauge": "^2.6.0",
"iconv-lite": "^0.4.13",
"ipfs-api": "^9.0.0",
"ipfsd-ctl": "^0.16.0",
"lodash": "^4.16.4",
"pre-commit": "^1.1.3"
},
"keywords": [
"ipfs",
Expand All @@ -40,11 +51,6 @@
"directories": {
"example": "example"
},
"scripts": {
"test": "mocha",
"lint": "node_modules/.bin/standard",
"generate": "bin/generate"
},
"pre-commit": [
"lint"
],
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions generate/index.js → src/generate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ function parseBlocks (blocks, locations) {
comment: '#'
})
.then((parsed) => {
var last_end = 0
var lastEnd = 0

return _.reduce(parsed, (acc, row) => {
var start = row.startIpNum
var end = row.endIpNum
var locid = row.locId

// unmapped range?
if ((start - last_end) > 1) {
if ((start - lastEnd) > 1) {
acc.push({
min: last_end + 1,
min: lastEnd + 1,
data: 0
})
}
Expand All @@ -105,7 +105,7 @@ function parseBlocks (blocks, locations) {
data: locations[locid]
})

last_end = end
lastEnd = end

return acc
}, [])
Expand Down
9 changes: 9 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict'

const lookup = require('./lookup')
const lookupPretty = require('./pretty')

module.exports = {
lookup: lookup,
lookupPretty: lookupPretty
}
17 changes: 9 additions & 8 deletions lib/lookup.js → src/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

const memoize = require('memoizee')
const inet = require('inet_ipv4')
const mh = require('multihashes')

const formatData = require('./format')

const GEOIP_ROOT = 'QmRn43NNNBEibc6m7zVNcS6UusB1u3qTTfyoLmkugbeeGJ'
const GEOIP_ROOT = mh.fromB58String('QmRn43NNNBEibc6m7zVNcS6UusB1u3qTTfyoLmkugbeeGJ')

let memoized_lookup
let memoizedLookup

function _lookup (ipfs, hash, lookfor, cb) {
ipfs.object.get(hash, (err, res) => {
if (err) return cb(err)

let obj
try {
obj = JSON.parse(res.Data)
obj = JSON.parse(res.data)
} catch (err) {
return cb(err)
}
Expand All @@ -27,13 +28,13 @@ function _lookup (ipfs, hash, lookfor, cb) {
child++
}

const next = res.Links[child - 1]
const next = res.links[child - 1]

if (!next || !next.Hash) {
if (!next || !next.hash) {
return cb(new Error('Failed to lookup node'))
}

return memoized_lookup(ipfs, next.Hash, lookfor, cb)
return memoizedLookup(ipfs, next.hash, lookfor, cb)
} else if (obj.type === 'Leaf') {
while (obj.data[child] && obj.data[child].min <= lookfor) {
child++
Expand All @@ -54,8 +55,8 @@ function _lookup (ipfs, hash, lookfor, cb) {
})
}

memoized_lookup = memoize(_lookup, {async: true})
memoizedLookup = memoize(_lookup, {async: true})

module.exports = function lookup (ipfs, ip, cb) {
memoized_lookup(ipfs, GEOIP_ROOT, inet.aton(ip), cb)
memoizedLookup(ipfs, GEOIP_ROOT, inet.aton(ip), cb)
}
2 changes: 1 addition & 1 deletion lib/pretty.js → src/pretty.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function isLocal (address) {
if (split[0] === '10') return true
if (split[0] === '127') return true
if (split[0] === '192' && split[1] === '168') return true
if (split[0] === '172' && +split[1] >= 16 && +split[1] <= 31) return true
if (split[0] === '172' && Number(split[1]) >= 16 && Number(split[1]) <= 31) return true
return false
}

Expand Down
2 changes: 1 addition & 1 deletion test/format.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const expect = require('chai').expect

const format = require('../lib/format.js')
const format = require('../src/format')

describe('format', () => {
it('formats with all details present', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/generate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const asPromised = require('chai-as-promised')
chai.use(asPromised)
const expect = chai.expect

const gen = require('../generate/index.js')
const gen = require('../src/generate/')

const countries = new Buffer(`
name,alpha2,countryCallingCodes,alpha3,ioc,currencies,languages,ccTLD,status
Expand Down
6 changes: 3 additions & 3 deletions test/lookup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const expect = require('chai').expect

const geoip = require('../')
const geoip = require('../src')
const IPFS = require('ipfs-api')
const ctl = require('ipfsd-ctl')

Expand Down Expand Up @@ -32,7 +32,7 @@ describe('lookup', function () {

it('looks up 8.8.8.8', (done) => {
geoip.lookup(ipfs, '8.8.8.8', function (err, result) {
expect(err).to.not.exist
if (err) throw err
expect(
result
).to.be.eql({
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('lookup', function () {

it('looks up 8.8.8.8', (done) => {
geoip.lookupPretty(ipfs, '/ip4/8.8.8.8', function (err, result) {
expect(err).to.not.exist
if (err) throw err
expect(
result.formatted
).to.be.eql('Mountain View, CA, United States, Earth')
Expand Down

0 comments on commit b2e61d8

Please sign in to comment.