-
Notifications
You must be signed in to change notification settings - Fork 723
Remove possibility of setFilter and clearFilter shadowing in derived devices.
#2005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Dimi1010
wants to merge
8
commits into
seladb:dev
Choose a base branch
from
Dimi1010:refactor/set-filter-shadowing
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c70e8dd
Updates the `IFilterableDevice` interface to utilize a NVI pattern.
Dimi1010 8f12e7c
Updated PcapNgFileReaderDevice.
Dimi1010 8e97480
Fix inconsistent override warning.
Dimi1010 0afbd9f
Merge branch 'dev' into refactor/set-filter-shadowing
Dimi1010 46f0374
Update `doUpdateFilter` to account for possible valid `""` filter str…
Dimi1010 2b78676
Fix
Dimi1010 e476641
Fix
Dimi1010 ea58bde
Typo.
Dimi1010 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem as presented doesn't apply to
clearFilter()because it only has one overload so nothing is shadowed. Why not keep it abstract?Using
""as an indication to clear the filter seems a bit weird to me. I thinkclearFilter()is more explicitUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplification of the internal interface mostly. Having a single extension point for a certain functionality makes it harder to forget about part of it when overriding. This had happened in a couple of places already.
In the old code
PcapNgFileReaderDeviceandPcapNgFileWriterDeviceonly overrodesetFilterto targetm_BpfWrapper. CallingclearFilterwould have had no effect on the filter, since that still used theIPcapDevice::clearFilterimplementation that worked onm_PcapDescriptor.My reasoning was that both
setFilterandclearFiltercan be conceptualized by the primitive action "update the filter", just with different parameters. This was also a factor when deciding to make the hook asdoUpdateFilterand not for exampledoSetFilter.The single extension point makes the above issue impossible, since to override the filter mechanism you have to update the entire hook. There is nothing to forget to override.
Afterwards
clearFilterwas made non-virtual to remove the possibility of overriding the method, thus potentially bypassing the base implementation, which is undesirable. Under the design derived classes should only modify the hook implementation.For public API, I agree,
clearFilteris more user friendly.However, I primary made the the hook signature to fit the aforementioned design goals. It wasn't designed to be exposed to the public.
The choice of
""for "no filter" was due toPcapHandleand libpcap already treating it asmatch any packet, when passed topcap_compileso I thought it might fit.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that a single abstract method is simpler than two when it comes to overriding and making sure one doesn't accidentally forget to override the other, but when looking at the implementation, in which
""symbolizes clearing a filter, I think thatclearFilteris better. It is an internal API, but it might be used by anyone who wants to extend our packet capture capabilities (including our future selves 🙂 ). UsingdoUpdateFilter("")seems a bit rigid and might limit future functionality (for example - if a""is a valid filter in one of the packet engines).I suggest we keep
clearFilteran abstract method - it doesn't make things much more complex and at the same time provides better flexibility.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. I see the reasoning about potentially
""being valid filter.Tbh, this is one of those times where C++17's
std::optionalwould be really nice. We could havedoUpdateFilter(std::optional<std::string> filter).Maybe we can have a simple struct that mimics it until we upgrade to 17? I would prefer to keep the number of virtual methods to a minimum if we can.
string const*would techinially work too since we don't need to store the value (or we would copy it anyway),nullptrbeing no filter. It would be better from the no copy perspective compared tooptional.If we can't, I guess we can keep the
clearFilterabstract until c++17.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
doUpdateFilterto takestd::string const* filterStras an filter parameter, withnullptrbeing the "no-filter" value. This should allow""to be used in an implementation defined way, while minimising the virtual interface surface area.46f0374