davide-scola / bfx-util-net-js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

bfx-util-net

Setup

The project inherits code from a base repository.

The base / root project is: https://github.com/bitfinexcom/bfx-util-js

Setup

Set upstream

git remote add upstream https://github.com/bitfinexcom/bfx-util-js

Changes should go through the base project and merged from upstream, if applicable.

Configuration

bash setup-config.sh

Grapes

Run two Grapes:

grape --dp 20001 --aph 30001 --bn '127.0.0.1:20002'
grape --dp 20002 --aph 40001 --bn '127.0.0.1:20001'

Update Geo/ASN data

First, export your license key, for staging/prod we have a comercial license. For dev, you can get a free key key optained through https://dev.maxmind.com/geoip/geolite2-free-geolocation-data?lang=en

export MAXMIND_LICENSE='your secret license'

npm run update-geo-data
npm run update-asn-data

Periodic Updates for Geo/ASN data

Update geo-data at midnight every three days with cron. Update geo-data at 23:00 every three days with cron.

Let's assume the path to the deployed service is /opt/var/bfx-util-net.

0 0 */3 * * cd /opt/var/bfx-util-net && /usr/bin/npm run update-geo-data
0 23 */3 * * cd /opt/var/bfx-util-net && /usr/bin/npm run update-asn-data

The IP databases are watching the database files for changes and will load the updated data into the RAM as soon as the data changes.

Boot worker

node worker.js --env=development --wtype=wrk-util-net-api --apiPort 8721

SSL / ACL

To turn on ACL and SSL set up, copy sec-test to sec:

cp -R sec-test sec

Set access rules in sec/acl.json

Access is logged to sec/acl.log.

To use SSL in example.js, uncomment everything related to SSL: https://github.com/bitfinexcom/bfx-util-net-js/blob/8d07c144f3a4135db0d4c7bc51297ffc06e358f9/example.js#L16.L24

Grenache API

action: 'getIpInfo'

  • args: <Array>
    • 0: <String> IP to lookup

Response:

  • <Array>
    • 0 <String> Ip that was looked up
    • 1 <Object> Result: geo, dns

Example Response:

[
  "8.8.8.8",
  {
    "geo": {
      "range": [
        134744064,
        134744319
      ],
      "country": "US",
      "region": "CA",
      "city": "Mountain View",
      "ll": [
        37.386,
        -122.0838
      ],
      "metro": 807,
      "zip": 94035
    },
    "dns": [
      "google-public-dns-a.google.com"
    ],
    "asn": {
      "autonomous_system_number": 15169,
      "autonomous_system_organization": "Google Inc."
    }
  }
]

action: 'getIpAsn'

  • args: <Array>
    • 0: <String> IP to lookup

Response:

  • <Array>
    • 0 <String> Ip that was looked up
    • 1 <Object> ASN information

Example Response:

[ '8.8.8.8',
  { autonomous_system_number: 15169,
    autonomous_system_organization: 'Google Inc.' } ]

action: 'getReverseDns'

  • args: <Array>
    • 0: <String> IP to lookup

Response:

  • <Array>
    • 0 <String> Ip that was looked up
    • 1 <Array> hostnames

Example Response:

[ '8.8.8.8', [ 'google-public-dns-a.google.com' ] ]

action: 'getIpGeo'

  • args: <Array>
    • 0: <String> IP to lookup

Response:

  • <Array>
    • 0 <String> Ip that was looked up
    • 1 <Object> Result: range, country, region, city, ll, metro, zip

Example Response:

[ '53.1.34.21',
  { range: [ 889192448, 897238054 ],
    country: 'DE',
    region: '',
    city: '',
    ll: [ 51.2993, 9.491 ],
    metro: 0,
    zip: 0 } ]

action: 'getIpGeoBatch'

  • args: <Array>
    • 0: <Array> IPs to lookup

Response:

  • <Array>
    • 0 <String> Ip that was looked up
    • 1 <Array> Result array

Example Response:

[ '53.1.34.21',
  { range: [ 889192448, 897238054 ],
    country: 'DE',
    region: '',
    city: '',
    ll: [ 51.2993, 9.491 ],
    metro: 0,
    zip: 0 } ]

Example

  const query = {
    action: 'geoIp',
    'args': [ '53.1.34.21' ]
  }

  peer.request('rest:net:util', query, { timeout: 10000 }, (err, data) => {
    if (err) {
      console.error(err)
      process.exit(1)
    }

    console.log(data)
  })

About

License:Apache License 2.0


Languages

Language:JavaScript 95.6%Language:Shell 4.4%