Skip to content

Commit

Permalink
Add data and rewrite generate script
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Feb 22, 2016
1 parent 42da848 commit bc09c71
Show file tree
Hide file tree
Showing 17 changed files with 666 additions and 557 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sudo: false
language: node_js
node_js:
- stable

script:
- npm run lint
- npm test
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# IPFS GeoIP

> *Proof of concept:* Geoip lookup over ipfs
> Geoip lookup over ipfs
## API

Expand Down Expand Up @@ -33,10 +32,10 @@ a `formatted` property that looks like this: `Mountain View, CA, United States,

The utility geoip-gen reads csv files provided from GeoLite, and turns them into a 32-way branching b-tree, which is stored as ipfs json objects.

There is a generator included, that can be called like this:
There is a generator included, that can be run with

```bash
$ node geoip-gen.js path/GeoLite-Blocks.csv path/GeoLite-Location.csv
$ npm run generate
```

This takes quite a long time to import, but you only need to do it once globally to use the lookup feature.
Expand All @@ -62,6 +61,10 @@ Result: {
Pretty result: Mountain View, CA, United States, Earth
```

## Root hash

The current root hash for lookups is `QmRn43NNNBEibc6m7zVNcS6UusB1u3qTTfyoLmkugbeeGJ`.

## License

[MIT](LICENSE)
51 changes: 51 additions & 0 deletions bin/generate
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env node
'use strict'

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

function handleNoApi () {
console.error('No ipfs daemon running. Please start one')
process.exit(1)
}

// -- CLI interaction

const ipfs = new API()

ipfs.id()
.then((id) => {
if (!id) handleNoApi()
}, handleNoApi)
.then(() => {
const gauge = new Gauge()
let length = 0
let counter = 0

gen.progress.on('progress', (event) => {
if (event.type === 'node') {
length = event.length
}

if (event.type === 'put') {
counter++
gauge.show('Uploading', (counter / (length / 32)))
}

if (event.status === 'start' && event.type !== 'put') {
gauge.show(event.type)
}
})

gauge.show('Starting', 0.0001)
return gen.main(ipfs)
})
.then((hash) => {
console.log('Finished with root hash %s', hash)
process.exit(0)
})
.catch((err) => {
console.error(err.stack)
process.exit(1)
})
260 changes: 0 additions & 260 deletions country_data/countries.csv

This file was deleted.

8 changes: 4 additions & 4 deletions example/lookup.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
'use strict'

var geoip = require('../')
var ipfs = require('ipfs-api')()
const geoip = require('../')
const ipfs = require('ipfs-api')()

if (process.argv.length !== 3) {
console.log('usage: node lookup.js <ip4-adr>')
process.exit(1)
}

geoip.lookup(ipfs, process.argv[2], function (err, result) {
geoip.lookup(ipfs, process.argv[2], (err, result) => {
if (err) {
console.log('Error: ' + err)
} else {
console.log('Result: ' + JSON.stringify(result, null, 2))
}
})

geoip.lookupPretty(ipfs, '/ip4/' + process.argv[2], function (err, result) {
geoip.lookupPretty(ipfs, '/ip4/' + process.argv[2], (err, result) => {
if (err) {
console.log('Error: ' + err)
} else {
Expand Down
Loading

0 comments on commit bc09c71

Please sign in to comment.