BiglySoftware / BiglyBT

Feature-filled Bittorrent client based on the Azureus open source project
https://www.biglybt.com
GNU General Public License v2.0
1.52k stars 153 forks source link

What different about IPFilter#ban and IPFilter#block ? #3313

Closed Ghost-chu closed 2 weeks ago

Ghost-chu commented 2 weeks ago

Hello! I'm building a BiglyBT plugin and I'd like to dynamically add and remove IP filtering rules to block (and break) all estabilshed connections to addresses with specific IPs.

However, I see ban and block methods available, and even more confusingly I see both IPBanned[] and IPBlocked[]... This definitely threw me for a loop, because after looking at the source code, they seem to have the same content, but stored in different places.

image

Okay, I was hoping someone could clarify which method I should use if I need to dynamically block an IP address (and immediately cut off all its established connections)? And which collection should I use to view the record I've added and remove it from?

(I'm using translator, so it may looks weird.)

parg commented 2 weeks ago

Block is the same as Ban, I would imagine that the name, couldn't easily be changed at some point as in use by plugins.

    @Override
    public void
    block(
        String IPAddress)
    {
        filter.ban( IPAddress, "<plugin>", false );
    }

    @Override
    public void
    ban(
        String IPAddress,
        String text)
    {
        filter.ban( IPAddress, text, false );
    }

If you want to expliclty block an address persistently then use ban/block.

parg commented 2 weeks ago

Well, they're persistent if you have

Options->IP Filters: Save blocked IP details across restarts

enabled

Ghost-chu commented 2 weeks ago

Can I assume that I can use any of them and they will behave and act exactly the same?

Block === Ban, but use ban can provide a custom reason

parg commented 2 weeks ago

Yes.

Ghost-chu commented 2 weeks ago

Thank you for your time, answered all my doubts perfectly, have a good day :) ❤

parg commented 2 weeks ago

Hope I'm right :)