mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
* fix duplicate address insertion in SocketAddressBlockList * fix BlockList rule listing order to match apply * add minor bound check in BlockList * improve performance of BlockList apply * eliminating shared_ptr * check fast api path * add clear method to BlockList * general storage improvements to BlockList * use shared locks for BlockList reads * add bulk address adding to BlockList * add BlockList benchmark * add remove range/subnet to BlockList * add cidr notation parsing to BlockList * add additional apis to BlockList * add private subnet presets to BlockList Signed-off-by: James M Snell <jasnell@gmail.com> Assisted-by: OpenCode/Opus PR-URL: https://github.com/nodejs/node/pull/64974 Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
43 lines
1.5 KiB
JavaScript
43 lines
1.5 KiB
JavaScript
// Flags: --allow-natives-syntax --expose-internals --no-warnings
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { BlockList } = require('net');
|
|
const { internalBinding } = require('internal/test/binding');
|
|
|
|
// The fast API is on the native check() method which takes a
|
|
// SocketAddressBase object. The JS BlockList.prototype.check() routes
|
|
// string arguments to checkString() which has no fast API, so we need
|
|
// to use SocketAddress objects to exercise the fast API path.
|
|
const { kHandle: kBlockListHandle } = require('internal/blocklist');
|
|
const {
|
|
SocketAddress,
|
|
kHandle: kSocketAddressHandle,
|
|
} = require('internal/socketaddress');
|
|
|
|
const blockList = new BlockList();
|
|
blockList.addAddress('1.1.1.1');
|
|
blockList.addSubnet('10.0.0.0', 24);
|
|
|
|
const handle = blockList[kBlockListHandle];
|
|
const addr1 = new SocketAddress({ address: '1.1.1.1' })[kSocketAddressHandle];
|
|
const addr2 = new SocketAddress({ address: '2.2.2.2' })[kSocketAddressHandle];
|
|
const addr3 = new SocketAddress({ address: '10.0.0.5' })[kSocketAddressHandle];
|
|
|
|
function testFastCheck() {
|
|
assert.strictEqual(handle.check(addr1), true);
|
|
assert.strictEqual(handle.check(addr2), false);
|
|
assert.strictEqual(handle.check(addr3), true);
|
|
}
|
|
|
|
eval('%PrepareFunctionForOptimization(testFastCheck)');
|
|
testFastCheck();
|
|
eval('%OptimizeFunctionOnNextCall(testFastCheck)');
|
|
testFastCheck();
|
|
|
|
if (common.isDebug) {
|
|
const { getV8FastApiCallCount } = internalBinding('debug');
|
|
assert.strictEqual(getV8FastApiCallCount('blocklist.check'), 3);
|
|
}
|