Skip to content

Commit

Permalink
Merge pull request #7 from ipfs/fix
Browse files Browse the repository at this point in the history
Fix everything
  • Loading branch information
dignifiedquire committed Feb 23, 2016
2 parents 42da848 + c814009 commit 139288c
Show file tree
Hide file tree
Showing 17 changed files with 671 additions and 556 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
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# IPFS GeoIP

> *Proof of concept:* Geoip lookup over ipfs
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![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)

> Geoip lookup over ipfs
## API

Expand Down Expand Up @@ -33,10 +38,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 +67,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 139288c

Please sign in to comment.