黑名单
🌐 Block lists
端点可以使用 net.BlockList 按源地址过滤传入的数据包。阻止列表会在任何 QUIC 处理之前进行检查,所以被阻止的数据包除了检查本身,不会消耗任何资源。
🌐 Endpoints can filter incoming packets by source address using a
net.BlockList. The block list is checked before any QUIC processing
occurs, so blocked packets consume no resources beyond the check itself.
在拒绝模式下(默认模式),来自列表中地址的数据包会被丢弃:
🌐 In deny mode (the default), packets from addresses in the list are dropped:
import { BlockList } from 'node:net';
import { listen } from 'node:quic';
const blocked = new BlockList();
blocked.addSubnet('192.168.1.0', 24); // Block an entire subnet
blocked.addAddress('10.0.0.5'); // Block a specific address
const endpoint = await listen(onSession, {
endpoint: {
blockList: blocked,
blockListPolicy: 'deny',
},
// ...
}); 在允许模式下,只接受来自列表中地址的数据包:
🌐 In allow mode, only packets from addresses in the list are accepted:
const trusted = new BlockList();
trusted.addSubnet('10.0.0.0', 8);
const endpoint = await listen(onSession, {
endpoint: {
blockList: trusted,
blockListPolicy: 'allow',
},
// ...
}); 阻止列表是实时评估的——在端点创建后添加或移除的规则会立即生效。endpoint.stats.packetsBlocked计数器跟踪被过滤器丢弃的数据包数量。
🌐 The block list is evaluated live — rules added or removed after the endpoint
is created take effect immediately. The endpoint.stats.packetsBlocked
counter tracks how many packets have been dropped by the filter.