powered by Jive Software

And/Or filtering with more than two PacketFilters?

Hi,

There are two filters: AndFilter and OrFilter. Both can filter based on two PacketFilters. However, there are situations in which one would like to filter with more than two PacketFilters. Suppose we have the following PacketFilters:

A, B, C and D

We want to filter all PacketFilters with the logical and-operator:

A && B && C && D

To realise this test with the AndFilter the test should be implemented abstractly the following way:

A && B = AB

C && D = CD

AB && CD

In other words. The AndFilter has to be used two times for testing A/B and C/D. Both boolean results have to be tested on ‘‘trueness’’. Surely there are other ways , but it isn’'t possible to do the test using only one AndFilter.

This could be solved by making it possible to use the AndFilter (and also the OrFilter) with an unlimited number of PacketFilters, by providing a method something like:

public void addFilter(PacketFilter filter);

The method adds the PacketFilter to a collection of filters, on which the and-operator will be applied.

Regards,

Jeroen

Jeroen,

AndFilter and OrFilter are both PacketFilter instances. Therefore, it’'s possible to say:

new AndFilter(andFilter, orFilter);

where andFilter and orFilter are instances of AndFilter and OrFilter respectively. Basically, you can do whatever kind of boolean logic you’'d like, including the NOT operation using the NotFilter.

Regards,

Matt

Hi Matt,

I know what you mean, but that way you still have to create more than one filter to do a single and-filtering with more than two PacketFilters, when it could be possible to do an and-filtering at once. I can think of situations in which that would provide a very good solution.

For example a situation that is part of our MyOwnMessenger development in which the OrFilter is important:

A condition is that the incoming packet is a message and is not one of a certain collection of users. Abstractly:

is_msg AND NOT(usr_a OR usr_b OR usr_c OR usr_d OR …)

The OrFilter could then be applied to the whole userlist at once.

Regards,

Jeroen

Message was edited by: jhboosterlaar

I suppose one thing we could do is make it possible to use an arbitrary number of filters in an AndFilter or OrFilter. So, to do an AND operation over three filters:

AndFilter filter1 = new AndFilter();

filter1.addFilter(someFilterA);

filter1.addFilter(someFilterB);

filter1.addFilter(someFilterC);

The existing constructor that takes two arguments would be a shortcut for the longer form of:

AndFilter filter1 = new AndFilter();

filter1.addFilter(someFilterA);

filter1.addFilter(someFilterB);

Would this be what you’'re looking for?

Regards,

Matt

I’'ve been trying something, and changed the source of the OrFilter and the AndFilter. Is this what will suite everybody without taking away the currently available functionality?

OrFilter: http://www.monster-internet.nl/resources/OrFilter.java

AndFilter: http://www.monster-internet.nl/resources/AndFilter.java

Regards,

Mark Monster

Message was edited by: mkamonster

I first tried to add all the code in the message, but that didn’'t work.

Mark,

I’‘ve now given you permission to attach files in the forum, so you should be able to do that in the future. Your changes look similar to how I’‘d implement them, although I’‘d actually use an array instead of an ArrayList. Normally, I’'d never worry about the speed difference of iterating over an ArrayList vs. an Array, but every packet has to go through the filters so they actually are pretty speed critical.

Thanks,

Matt

Hi Matt,

Thanks for the permisson.

Maybe an array would be suitable in this case. I will change this very soon.

Regards,

Mark Monster

Mark,

Thanks for your work on the changes! However, I went ahead and did the array versions myself and checked them into CVS since I was working on some other Smack things today.

Regards,

Matt

Matt,

That’‘s okay, I’'m looking forward to the new Daily builds.

Regards,

Mark Monster

Great reading that the multiple ‘‘and’’ and ‘‘or’’-filtering have been applied. Thanks :).

Regards,

Jeroen

And they are in the current daily builds.

Thanks,

Mark Monster