@@ -17,8 +17,8 @@ exports.register = async function () {
17
17
18
18
this . load_asn_ini ( )
19
19
20
- await this . test_and_register_dns_providers ( )
21
20
await this . test_and_register_geoip ( )
21
+ await this . test_and_register_dns_providers ( )
22
22
23
23
if ( this . cfg . header . asn ) {
24
24
this . register_hook ( 'data_post' , 'add_header_asn' )
@@ -133,41 +133,40 @@ exports.get_result = function (zone, first) {
133
133
exports . lookup_via_dns = function ( next , connection ) {
134
134
if ( connection . remote . is_private ) return next ( )
135
135
136
+ if ( connection . results . get ( this ) ?. asn ) return next ( ) // already set, skip
137
+
136
138
const promises = [ ]
137
139
138
140
for ( const zone of providers ) {
139
141
promises . push (
140
142
new Promise ( ( resolve ) => {
141
- // connection.logdebug (plugin, `zone: ${zone}`);
143
+ // connection.loginfo (plugin, `zone: ${zone}`);
142
144
143
145
try {
144
146
this . get_dns_results ( zone , connection . remote . ip ) . then ( ( r ) => {
145
147
if ( ! r ) return resolve ( )
146
148
147
- const results = { emit : true }
148
-
149
149
// store asn & net from any source
150
- if ( r . asn ) results . asn = r . asn
151
- if ( r . net ) results . net = r . net
150
+ if ( r . asn ) connection . results . add ( this , { asn : r . asn } )
151
+ if ( r . net ) connection . results . add ( this , { net : r . net } )
152
152
153
153
// store provider specific results
154
154
switch ( zone ) {
155
155
case 'origin.asn.cymru.com' :
156
- results . cymru = r
156
+ connection . results . add ( this , { cymru : r } )
157
157
break
158
158
case 'asn.routeviews.org' :
159
- results . routeviews = r
159
+ connection . results . add ( this , { routeviews : r } )
160
160
break
161
161
case 'origin.asn.spameatingmonkey.net' :
162
- results . monkey = r
162
+ connection . results . add ( this , { monkey : r } )
163
163
break
164
164
case 'asn.rspamd.com' :
165
- results . rspamd = r
165
+ connection . results . add ( this , { rspamd : r } )
166
166
break
167
167
}
168
168
169
- connection . results . add ( this , results )
170
- resolve ( results )
169
+ resolve ( )
171
170
} )
172
171
} catch ( err ) {
173
172
connection . results . add ( this , { err } )
@@ -177,7 +176,11 @@ exports.lookup_via_dns = function (next, connection) {
177
176
)
178
177
}
179
178
180
- Promise . all ( promises ) . then ( next )
179
+ Promise . all ( promises )
180
+ . then ( ( ) => {
181
+ connection . results . add ( this , { emit : true } )
182
+ next ( )
183
+ } )
181
184
}
182
185
183
186
exports . parse_routeviews = function ( thing ) {
@@ -300,7 +303,7 @@ exports.test_and_register_geoip = async function () {
300
303
try {
301
304
this . maxmind = require ( 'maxmind' )
302
305
if ( await this . load_dbs ( ) ) {
303
- this . register_hook ( 'connect ' , 'lookup_via_maxmind' )
306
+ this . register_hook ( 'lookup_rdns ' , 'lookup_via_maxmind' )
304
307
}
305
308
} catch ( e ) {
306
309
this . logerror ( e )
@@ -340,17 +343,17 @@ exports.load_dbs = async function () {
340
343
exports . lookup_via_maxmind = function ( next , connection ) {
341
344
if ( ! this . maxmind || ! this . dbsLoaded ) return next ( )
342
345
346
+ if ( connection . results . get ( this ) ?. asn ) return next ( ) // already set, skip
347
+
343
348
const asn = this . lookup . get ( connection . remote . ip )
344
- if ( asn ?. autonomous_system_number || asn ?. autonomous_system_organization ) {
345
- connection . results . add ( this , {
346
- ...( asn . autonomous_system_number
347
- ? { asn : asn . autonomous_system_number }
348
- : { } ) ,
349
- ...( asn . autonomous_system_organization
350
- ? { org : asn . autonomous_system_organization }
351
- : { } ) ,
352
- } )
349
+
350
+ if ( asn ?. autonomous_system_number ) {
351
+ connection . results . add ( this , { asn : asn . autonomous_system_number } )
352
+ }
353
+ if ( asn ?. autonomous_system_organization ) {
354
+ connection . results . add ( this , { org : asn . autonomous_system_organization } )
353
355
}
356
+ connection . results . add ( this , { emit : true } )
354
357
355
358
next ( )
356
359
}
0 commit comments