refactor(pcap): share passive metadata counter updates (#16881)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-05 09:08:10 +08:00
1 parent 5a706a2a30
commit 7ecdf9e138
1 file changed
+11 -18
+11 -18
View File
@@ -485,13 +485,7 @@ const recordPacketEndpoints = (
scratch.add(addr1);
scratch.add(address);
}
const prev = state.endpoints.get(address);
if (prev === undefined) {
chargeRetainedString(state, address);
state.endpoints.set(address, 1);
} else {
state.endpoints.set(address, prev + 1);
}
countValue(state.endpoints, address, state);
}
};
visit(field("ip.src"));
@@ -626,15 +620,7 @@ const processPacketNonDns = (
for (let i = 0; i < snis.length; i += 1) {
if (snis[i] !== "") addChargedString(state, state.sni, snis[i]!);
}
if (protocol !== "") {
const prev = state.protocols.get(protocol);
if (prev === undefined) {
chargeRetainedString(state, protocol);
state.protocols.set(protocol, 1);
} else {
state.protocols.set(protocol, prev + 1);
}
}
if (protocol !== "") countValue(state.protocols, protocol, state);
recordPacketHttpUris(state, field);
return (
layers.dns !== undefined ||
@@ -646,8 +632,15 @@ const processPacketNonDns = (
);
};
const countValue = (counts: Map<string, number>, value: string): void => {
counts.set(value, (counts.get(value) ?? 0) + 1);
const countValue = (
counts: Map<string, number>,
value: string,
retained?: NonDnsAccumulator,
): void => {
const previous = counts.get(value);
if (previous === undefined && retained !== undefined)
chargeRetainedString(retained, value);
counts.set(value, (previous ?? 0) + 1);
};
const consumeCount = (counts: Map<string, number>, value: string): boolean => {