@@ -12,7 +12,9 @@ const { WrkApi } = require('bfx-wrk-api')
1212const geoIp = require ( 'geoip-lite' )
1313const fs = require ( 'fs' )
1414
15- const newDb = path . join ( __dirname , '..' , 'mmdb' , 'GeoLite2-ASN.mmdb' )
15+ const asnMMDB = path . join ( __dirname , '..' , 'mmdb' , 'GeoLite2-ASN.mmdb' )
16+ const ispMMDB = path . join ( __dirname , '..' , 'mmdb' , 'GeoIP2-ISP.mmdb' )
17+ const connectionTypeMMDB = path . join ( __dirname , '..' , 'mmdb' , 'GeoIP2-Connection-Type.mmdb' )
1618
1719class WrkUtilNetApi extends WrkApi {
1820 constructor ( conf , ctx ) {
@@ -35,8 +37,10 @@ class WrkUtilNetApi extends WrkApi {
3537 switch ( type ) {
3638 case 'api_bfx' :
3739 ctx . lru_0 = this . lru_0
38- ctx . asn_db = this . asnDb
40+ ctx . asnDb = this . asnDb
3941 ctx . geoIp = this . geoIp
42+ ctx . ispDb = this . ispDb
43+ ctx . connectionTypeDb = this . connectionTypeDb
4044 break
4145 }
4246
@@ -62,14 +66,30 @@ class WrkUtilNetApi extends WrkApi {
6266
6367 this . geoIp = geoIp
6468
65- this . asnDb = await maxmind . open ( newDb , {
69+ this . asnDb = await maxmind . open ( asnMMDB , {
6670 watchForUpdates : true ,
6771 watchForUpdatesNonPersistent : true ,
6872 watchForUpdatesHook : ( ) => {
6973 process . stdout . write ( 'ASN database has been reloaded\n' )
7074 }
7175 } )
7276
77+ this . ispDb = await maxmind . open ( ispMMDB , {
78+ watchForUpdates : true ,
79+ watchForUpdatesNonPersistent : true ,
80+ watchForUpdatesHook : ( ) => {
81+ process . stdout . write ( 'ISP database has been reloaded\n' )
82+ }
83+ } )
84+
85+ this . connectionTypeDb = await maxmind . open ( connectionTypeMMDB , {
86+ watchForUpdates : true ,
87+ watchForUpdatesNonPersistent : true ,
88+ watchForUpdatesHook : ( ) => {
89+ process . stdout . write ( 'Connection type database has been reloaded\n' )
90+ }
91+ } )
92+
7393 this . geoIp . startWatchingDataUpdate ( ( err ) => {
7494 if ( err instanceof Error ) {
7595 process . stderr . write ( `ERR: ${ err . message } \n` )
@@ -92,9 +112,17 @@ class WrkUtilNetApi extends WrkApi {
92112 }
93113
94114 testIfDbExists ( ) {
95- if ( ! fs . existsSync ( newDb ) ) {
115+ if ( ! fs . existsSync ( asnMMDB ) ) {
96116 throw new Error ( 'GEO_DB_NOT_INSTALLED - run `npm run update-asn-data`' )
97117 }
118+
119+ if ( ! fs . existsSync ( ispMMDB ) ) {
120+ throw new Error ( 'ISP_DB_NOT_INSTALLED - run `npm run update-isp-data`' )
121+ }
122+
123+ if ( ! fs . existsSync ( connectionTypeMMDB ) ) {
124+ throw new Error ( 'CONNECTION_TYPE_DB_NOT_INSTALLED - run `npm run update-connection-type-data`' )
125+ }
98126 }
99127}
100128
0 commit comments