Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

Commit

Permalink
After looking at the current use cases, it doesn't make sense to expo…
Browse files Browse the repository at this point in the history
…se a global proto buffer search list. The filter should always first search for an identifier or path first, then do it's own proto searching.
  • Loading branch information
LisoUseInAIKyrios committed Aug 6, 2023
1 parent 0e93358 commit 3e6d4b8
Showing 1 changed file with 2 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,17 +286,6 @@ abstract class Filter {

protected final StringFilterGroupList pathFilterGroups = new StringFilterGroupList();
protected final StringFilterGroupList identifierFilterGroups = new StringFilterGroupList();
/**
* A collection of {@link ByteArrayFilterGroup} that are always searched for (no matter what).
*
* If possible, avoid adding values to this list and instead use a path or identifier filter
* for the item you are looking for. Then inside
* {@link #isFiltered(String, String, byte[], FilterGroupList, FilterGroup, int)},
* the buffer can then be searched using using a different
* {@link ByteArrayFilterGroupList} or a {@link ByteArrayFilterGroup}.
* This way, the expensive buffer searching only occurs if the cheap and fast path/identifier is already found.
*/
protected final ByteArrayFilterGroupList protobufBufferFilterGroups = new ByteArrayFilterGroupList();

/**
* Called after an enabled filter has been matched.
Expand All @@ -318,8 +307,6 @@ boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBuff
LogHelper.printDebug(() -> getClass().getSimpleName() + " Filtered path: " + path);
} else if (identifierFilterGroups == matchedList) {
LogHelper.printDebug(() -> getClass().getSimpleName() + " Filtered identifier: " + identifier);
} else if (protobufBufferFilterGroups == matchedList) {
LogHelper.printDebug(() -> getClass().getSimpleName() + " Filtered from protobuf-buffer");
}
}
return true;
Expand Down Expand Up @@ -393,7 +380,6 @@ private static void findAsciiStrings(StringBuilder builder, byte[] buffer) {

private static final StringTrieSearch pathSearchTree = new StringTrieSearch();
private static final StringTrieSearch identifierSearchTree = new StringTrieSearch();
private static final ByteTrieSearch protoSearchTree = new ByteTrieSearch();

/**
* Because litho filtering is multi-threaded and the buffer is passed in from a different injection point,
Expand All @@ -405,16 +391,13 @@ private static void findAsciiStrings(StringBuilder builder, byte[] buffer) {
for (Filter filter : filters) {
filterGroupLists(pathSearchTree, filter, filter.pathFilterGroups);
filterGroupLists(identifierSearchTree, filter, filter.identifierFilterGroups);
filterGroupLists(protoSearchTree, filter, filter.protobufBufferFilterGroups);
}

LogHelper.printDebug(() -> "Using: "
+ pathSearchTree.numberOfPatterns() + " path filters"
+ " (" + pathSearchTree.getEstimatedMemorySize() + " KB), "
+ identifierSearchTree.numberOfPatterns() + " identifier filters"
+ " (" + identifierSearchTree.getEstimatedMemorySize() + " KB), "
+ protoSearchTree.numberOfPatterns() + " buffer filters"
+ " (" + protoSearchTree.getEstimatedMemorySize() + " KB)");
+ " (" + identifierSearchTree.getEstimatedMemorySize() + " KB)");
}

private static <T> void filterGroupLists(TrieSearch<T> pathSearchTree,
Expand Down Expand Up @@ -454,14 +437,13 @@ public static boolean filter(@Nullable String lithoIdentifier, @NonNull StringBu
LogHelper.printException(() -> "Proto buffer is null"); // Should never happen
return false;
}
LithoFilterParameters parameter = new LithoFilterParameters(pathBuilder, lithoIdentifier, protobufBuffer);
LithoFilterParameters parameter = new LithoFilterParameters(lithoIdentifier, pathBuilder, protobufBuffer);
LogHelper.printDebug(() -> "Searching " + parameter);

if (parameter.identifier != null) {
if (identifierSearchTree.matches(parameter.identifier, parameter)) return true;
}
if (pathSearchTree.matches(parameter.path, parameter)) return true;
if (protoSearchTree.matches(parameter.protoBuffer, parameter)) return true;
} catch (Exception ex) {
LogHelper.printException(() -> "Litho filter failure", ex);
} finally {
Expand Down

0 comments on commit 3e6d4b8

Please sign in to comment.