Skip to content

Commit ab44a6b

Browse files
committed
Added Peer Set execute-on-assign option to ban peers
1 parent bf9e63e commit ab44a6b

File tree

5 files changed

+117
-38
lines changed

5 files changed

+117
-38
lines changed

core/src/com/biglybt/core/speedmanager/SpeedLimitHandler.java

+85-17
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.io.File;
2424
import java.net.InetAddress;
2525
import java.net.NetworkInterface;
26-
import java.nio.file.FileSystem;
2726
import java.util.*;
2827
import java.util.function.Predicate;
2928
import java.util.regex.Pattern;
@@ -38,6 +37,8 @@
3837
import com.biglybt.core.global.GlobalManager;
3938
import com.biglybt.core.global.GlobalManagerStats;
4039
import com.biglybt.core.internat.MessageText;
40+
import com.biglybt.core.ipfilter.IpFilter;
41+
import com.biglybt.core.ipfilter.IpFilterManagerFactory;
4142
import com.biglybt.core.networkmanager.LimitedRateGroup;
4243
import com.biglybt.core.networkmanager.Transport;
4344
import com.biglybt.core.peer.PEPeer;
@@ -88,6 +89,8 @@
8889
private static final Object PEER_LT_WAIT_START_KEY = new Object();
8990
private static final Object PEER_ASN_WAIT_START_KEY = new Object();
9091

92+
private static final IpFilter ip_filter = IpFilterManagerFactory.getSingleton().getIPFilter();
93+
9194
public static SpeedLimitHandler
9295
getSingleton(
9396
Core core )
@@ -6460,9 +6463,15 @@ public void run()
64606463

64616464
int actions = COConfigurationManager.getIntParameter( "speed.limit.handler.ipset_n." + tag_id + ".eos", -1 );
64626465

6463-
if ( actions == TagFeatureExecOnAssign.ACTION_DESTROY ){
6466+
if ( actions != -1 ){
64646467

6465-
super.setActionEnabled( actions, true );
6468+
for ( int action: new int[]{TagFeatureExecOnAssign.ACTION_DESTROY, TagFeatureExecOnAssign.ACTION_BAN }){
6469+
6470+
if (( actions & action ) != 0 ){
6471+
6472+
super.setActionEnabled( action, true );
6473+
}
6474+
}
64666475
}
64676476

64686477
int[] colour = COConfigurationManager.getRGBParameter( "speed.limit.handler.ipset_n." + getTagID() + ".color" );
@@ -6484,7 +6493,7 @@ public void run()
64846493
public int
64856494
getSupportedActions()
64866495
{
6487-
return( TagFeatureExecOnAssign.ACTION_DESTROY );
6496+
return( TagFeatureExecOnAssign.ACTION_DESTROY | TagFeatureExecOnAssign.ACTION_BAN );
64886497
}
64896498

64906499
@Override
@@ -6495,9 +6504,36 @@ public void run()
64956504
{
64966505
super.setActionEnabled( action, enabled );
64976506

6498-
if ( action == TagFeatureExecOnAssign.ACTION_DESTROY ){
6507+
if ( action == TagFeatureExecOnAssign.ACTION_DESTROY || action == TagFeatureExecOnAssign.ACTION_BAN ){
64996508

6500-
COConfigurationManager.setParameter( "speed.limit.handler.ipset_n." + getTagID() + ".eos", enabled?TagFeatureExecOnAssign.ACTION_DESTROY:-1);
6509+
int tag_id = getTagID();
6510+
6511+
int actions = COConfigurationManager.getIntParameter( "speed.limit.handler.ipset_n." + tag_id + ".eos", -1 );
6512+
6513+
if ( enabled ){
6514+
6515+
if ( actions == -1 ){
6516+
6517+
actions = action;
6518+
6519+
}else{
6520+
6521+
actions |= action;
6522+
}
6523+
}else{
6524+
6525+
if ( actions != -1 ){
6526+
6527+
actions &= ~action;
6528+
}
6529+
6530+
if ( actions == 0 ){
6531+
6532+
actions = -1; // bad default, keep it I guess
6533+
}
6534+
}
6535+
6536+
COConfigurationManager.setParameter( "speed.limit.handler.ipset_n." + tag_id + ".eos", actions );
65016537
}
65026538
}
65036539

@@ -6618,13 +6654,24 @@ public void run()
66186654

66196655
if ( to_delete != null ){
66206656

6657+
boolean do_ban = isActionEnabled( TagFeatureExecOnAssign.ACTION_BAN );
6658+
66216659
for ( PEPeer peer: to_delete ){
66226660

6623-
PEPeerManager pm = peer.getManager();
6661+
PEPeerManager peer_manager = peer.getManager();
66246662

6625-
if ( pm != null ){
6663+
if ( peer_manager != null ){
66266664

6627-
pm.removePeer( peer, "PeerSet removal action", Transport.CR_IP_BLOCKED );
6665+
if ( do_ban ){
6666+
6667+
ip_filter.ban( peer.getIp(), MessageText.getString( "tag.type.ipset" ) + ": " + getTagName( true ), false );
6668+
6669+
peer_manager.removePeer( peer, "PeerSet ban action", Transport.CR_IP_BLOCKED );
6670+
6671+
}else{
6672+
6673+
peer_manager.removePeer( peer, "PeerSet removal action", Transport.CR_IP_BLOCKED );
6674+
}
66286675
}
66296676
}
66306677
}
@@ -6809,7 +6856,7 @@ public void run()
68096856

68106857
if ( result ){
68116858

6812-
if ( isActionEnabled( TagFeatureExecOnAssign.ACTION_DESTROY )){
6859+
if ( isActionEnabled( TagFeatureExecOnAssign.ACTION_DESTROY ) || isActionEnabled( TagFeatureExecOnAssign.ACTION_BAN )){
68136860

68146861
return( 3 );
68156862
}
@@ -6866,7 +6913,7 @@ public void run()
68666913

68676914
if ( result ){
68686915

6869-
if ( isActionEnabled( TagFeatureExecOnAssign.ACTION_DESTROY )){
6916+
if ( isActionEnabled( TagFeatureExecOnAssign.ACTION_DESTROY ) || isActionEnabled( TagFeatureExecOnAssign.ACTION_BAN )){
68706917

68716918
return( 3 );
68726919
}
@@ -6934,7 +6981,7 @@ public void run()
69346981

69356982
if ( result ){
69366983

6937-
if ( isActionEnabled( TagFeatureExecOnAssign.ACTION_DESTROY )){
6984+
if ( isActionEnabled( TagFeatureExecOnAssign.ACTION_DESTROY ) || isActionEnabled( TagFeatureExecOnAssign.ACTION_BAN )){
69386985

69396986
return( 3 );
69406987
}
@@ -6950,11 +6997,23 @@ public void run()
69506997
{
69516998
PEPeer peer = PluginCoreUtils.unwrap( _peer );
69526999

6953-
if ( isActionEnabled( TagFeatureExecOnAssign.ACTION_DESTROY ) && !deferEOS()){
6954-
6955-
peer_manager.removePeer( _peer, "PeerSet removal action", Transport.CR_IP_BLOCKED );
7000+
if ( !deferEOS()){
7001+
7002+
if ( isActionEnabled( TagFeatureExecOnAssign.ACTION_BAN )){
7003+
7004+
ip_filter.ban( peer.getIp(), MessageText.getString( "tag.type.ipset" ) + ": " + getTagName( true ), false );
7005+
7006+
peer_manager.removePeer( _peer, "PeerSet ban action", Transport.CR_IP_BLOCKED );
7007+
7008+
return;
7009+
}
7010+
7011+
if ( isActionEnabled( TagFeatureExecOnAssign.ACTION_DESTROY )){
69567012

6957-
return;
7013+
peer_manager.removePeer( _peer, "PeerSet removal action", Transport.CR_IP_BLOCKED );
7014+
7015+
return;
7016+
}
69587017
}
69597018

69607019
synchronized( this ){
@@ -6980,7 +7039,16 @@ public void run()
69807039

69817040
// immediate remove
69827041

6983-
peer_manager.removePeer( _peer, "PeerSet removal action", Transport.CR_IP_BLOCKED );
7042+
if ( isActionEnabled( TagFeatureExecOnAssign.ACTION_BAN )){
7043+
7044+
ip_filter.ban( peer.getIp(), MessageText.getString( "tag.type.ipset" ) + ": " + getTagName( true ), false );
7045+
7046+
peer_manager.removePeer( _peer, "PeerSet ban action", Transport.CR_IP_BLOCKED );
7047+
7048+
}else{
7049+
7050+
peer_manager.removePeer( _peer, "PeerSet removal action", Transport.CR_IP_BLOCKED );
7051+
}
69847052

69857053
return;
69867054

core/src/com/biglybt/core/tag/TagFeatureExecOnAssign.java

+19-17
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,24 @@
3131
TagFeatureExecOnAssign
3232
extends TagFeature
3333
{
34-
public static final int ACTION_NONE = 0x0000;
35-
public static final int ACTION_DESTROY = 0x0001;
36-
public static final int ACTION_START = 0x0002;
37-
public static final int ACTION_STOP = 0x0004;
38-
public static final int ACTION_FORCE_START = 0x0008;
39-
public static final int ACTION_NOT_FORCE_START = 0x0010;
40-
public static final int ACTION_SCRIPT = 0x0020;
41-
public static final int ACTION_PAUSE = 0x0040;
42-
public static final int ACTION_RESUME = 0x0080;
43-
public static final int ACTION_APPLY_OPTIONS_TEMPLATE = 0x0100;
44-
public static final int ACTION_POST_MAGNET_URI = 0x0200;
45-
public static final int ACTION_MOVE_INIT_SAVE_LOC = 0x0400;
46-
public static final int ACTION_ASSIGN_TAGS = 0x0800;
47-
public static final int ACTION_HOST = 0x1000;
48-
public static final int ACTION_PUBLISH = 0x2000;
49-
public static final int ACTION_REMOVE_TAGS = 0x4000;
50-
public static final int ACTION_QUEUE = 0x8000;
34+
public static final int ACTION_NONE = 0x00000;
35+
public static final int ACTION_DESTROY = 0x00001;
36+
public static final int ACTION_START = 0x00002;
37+
public static final int ACTION_STOP = 0x00004;
38+
public static final int ACTION_FORCE_START = 0x00008;
39+
public static final int ACTION_NOT_FORCE_START = 0x00010;
40+
public static final int ACTION_SCRIPT = 0x00020;
41+
public static final int ACTION_PAUSE = 0x00040;
42+
public static final int ACTION_RESUME = 0x00080;
43+
public static final int ACTION_APPLY_OPTIONS_TEMPLATE = 0x00100;
44+
public static final int ACTION_POST_MAGNET_URI = 0x00200;
45+
public static final int ACTION_MOVE_INIT_SAVE_LOC = 0x00400;
46+
public static final int ACTION_ASSIGN_TAGS = 0x00800;
47+
public static final int ACTION_HOST = 0x01000;
48+
public static final int ACTION_PUBLISH = 0x02000;
49+
public static final int ACTION_REMOVE_TAGS = 0x04000;
50+
public static final int ACTION_QUEUE = 0x08000;
51+
public static final int ACTION_BAN = 0x10000;
5152

5253
public static final int[] ACTIONS = {
5354
ACTION_DESTROY,
@@ -66,6 +67,7 @@
6667
ACTION_PUBLISH,
6768
ACTION_REMOVE_TAGS,
6869
ACTION_QUEUE,
70+
ACTION_BAN,
6971
};
7072

7173
public int

core/src/com/biglybt/core/tag/impl/TagBase.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -2177,7 +2177,9 @@ public void removeListener(ParameterChangeListener listener){
21772177
TagFeatureExecOnAssign.ACTION_ASSIGN_TAGS,
21782178
TagFeatureExecOnAssign.ACTION_REMOVE_TAGS,
21792179
TagFeatureExecOnAssign.ACTION_HOST,
2180-
TagFeatureExecOnAssign.ACTION_PUBLISH };
2180+
TagFeatureExecOnAssign.ACTION_PUBLISH,
2181+
TagFeatureExecOnAssign.ACTION_BAN
2182+
};
21812183

21822184
String[] action_keys =
21832185
{ "label.apply.options.template",
@@ -2195,7 +2197,9 @@ public void removeListener(ParameterChangeListener listener){
21952197
"label.assign.tags",
21962198
"label.remove.tags",
21972199
"menu.host.on.tracker",
2198-
"menu.publish.on.tracker"};
2200+
"menu.publish.on.tracker",
2201+
"label.ban"
2202+
};
21992203

22002204
for ( int i=0; i<action_ids.length;i++ ){
22012205

core/src/com/biglybt/internat/MessagesBundle.properties

+1
Original file line numberDiff line numberDiff line change
@@ -5237,6 +5237,7 @@ diskops.view.infobar.text2=This view shows major disk operations such as downloa
52375237
tag.type.ds.mov={ManagerItem.moving}
52385238
tag.type.ds.chk={ManagerItem.checking}
52395239
label.allow.both=Allow Both
5240+
label.ban=Ban
52405241
label.ban.ipv4=Ban IPv4
52415242
label.ban.ipv6=Ban IPv6
52425243
ConfigView.label.dual.con.behaviour=When a peer connects via both IPv4 and IPv6:

uis/src/com/biglybt/ui/swt/views/utils/TagUIUtils.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,9 @@ public void menuHidden(MenuEvent e){
716716
TagFeatureExecOnAssign.ACTION_ASSIGN_TAGS,
717717
TagFeatureExecOnAssign.ACTION_REMOVE_TAGS,
718718
TagFeatureExecOnAssign.ACTION_HOST,
719-
TagFeatureExecOnAssign.ACTION_PUBLISH };
719+
TagFeatureExecOnAssign.ACTION_PUBLISH,
720+
TagFeatureExecOnAssign.ACTION_BAN,
721+
};
720722

721723
String[] action_keys =
722724
{ "label.apply.options.template",
@@ -734,7 +736,9 @@ public void menuHidden(MenuEvent e){
734736
"label.assign.tags",
735737
"label.remove.tags",
736738
"menu.host.on.tracker",
737-
"menu.publish.on.tracker"};
739+
"menu.publish.on.tracker",
740+
"label.ban",
741+
};
738742

739743
for ( int i=0;i<action_ids.length;i++ ){
740744

0 commit comments

Comments
 (0)