Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix everything #7

Merged
merged 3 commits into from
Feb 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we add this script as a bin script to be installed and accessible globally? :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's available as npm run generate as documented which I think is enough, but I'm okay adding it the bin scripts


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