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

Make geoip requests over ipfs #44

Merged
merged 2 commits into from
May 5, 2015
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
14 changes: 9 additions & 5 deletions js/getlocation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

var $ = require('jquery')
var geoip = require('ipfs-geoip')

function isLocal (address) {
var split = address.split('.')
Expand All @@ -11,14 +11,18 @@ function isLocal (address) {
return false
}

var getLocation = module.exports = function (multiaddrs, cb) {
var getLocation = module.exports = function (ipfs, multiaddrs, cb) {
if (multiaddrs.length === 0) return cb(null, null)
var address = multiaddrs[0].split('/')[2]
if (isLocal(address)) return getLocation(multiaddrs.slice(1), cb)
if (isLocal(address)) return getLocation(ipfs, multiaddrs.slice(1), cb)

geoip.lookup(ipfs, address, function (err, res) {
if (err) {
throw err
}

$.get('http://freegeoip.net/json/' + address, function (res) {
if (!res.country_name && multiaddrs.length > 1) {
return getLocation(multiaddrs.slice(1), cb)
return getLocation(ipfs, multiaddrs.slice(1), cb)
}

var location = 'Earth'
Expand Down
2 changes: 1 addition & 1 deletion js/pages/connections.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var Connections = React.createClass({
t.props.ipfs.id(peer.ID, function (err, id) {
if (err) return console.error(err)

getLocation(id.Addresses, function (err, res) {
getLocation(t.props.ipfs, id.Addresses, function (err, res) {
if (err) return console.error(err)
// If we've unmounted, abort
if (!t.isMounted()) return
Expand Down
2 changes: 1 addition & 1 deletion js/pages/home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var Home = React.createClass({
}
})

getLocation(peer.Addresses, function (err, location) {
getLocation(t.props.ipfs, peer.Addresses, function (err, location) {
if (err || !location) return console.error(err)
t.setState({
node: {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"font-awesome": "^4.3.0",
"font-awesome-webpack": "0.0.3",
"ipfs-api": "^1.2.0",
"ipfs-geoip": "^1.4.0",
"jquery": "^2.1.3",
"lodash": "^3.6.0",
"react": "^0.13.1",
Expand Down