Skip to content

Commit 22e446b

Browse files
committed
Make banning of HTTP seeds download specific
1 parent 29cf37f commit 22e446b

File tree

11 files changed

+218
-80
lines changed

11 files changed

+218
-80
lines changed

core/src/com/biglybt/core/dht/transport/udp/impl/DHTTransportUDPImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,7 @@
17441744
}
17451745

17461746
if ( ip_filter.isInRange(
1747-
contact.getTransportAddress().getAddress(), "DHT", null,
1747+
contact.getTransportAddress().getAddress(), "DHT", null, false,
17481748
logger.isEnabled( DHTLogger.LT_IP_FILTER ))){
17491749

17501750
// don't let an attacker deliberately fill up our filter so we start

core/src/com/biglybt/core/ipfilter/BadIps.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828
BadIps
2929
{
3030
public int
31-
addWarningForIp(String ip);
32-
33-
public int
34-
getNbWarningForIp(String ip);
31+
addWarningForIp(String ip, byte[] specific_hash );
3532

3633
public int
3734
getNbBadIps();

core/src/com/biglybt/core/ipfilter/IpFilter.java

+14
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@
6161
String ipAddress,
6262
String torrent_name,
6363
byte[] torrent_hash,
64+
boolean is_specific,
6465
boolean loggable );
6566

6667
public boolean
6768
isInRange(
6869
InetAddress ipAddress,
6970
String torrent_name,
7071
byte[] torrent_hash,
72+
boolean is_specific,
7173
boolean loggable );
7274

7375
public IpRange
@@ -104,13 +106,25 @@
104106
String torrent_name,
105107
boolean manual );
106108

109+
public boolean
110+
ban(
111+
String ipAddress,
112+
String torrent_name,
113+
byte[] specific_hash,
114+
boolean manual );
115+
107116
public boolean
108117
ban(
109118
String ipAddress,
110119
String torrent_name,
111120
boolean manual,
112121
int ban_for_mins );
113122

123+
public boolean
124+
isBanned(
125+
String ipAddress,
126+
byte[] specific_hash );
127+
114128
public boolean
115129
unban(String ipAddress);
116130

core/src/com/biglybt/core/ipfilter/impl/BadIpsImpl.java

+8-26
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.biglybt.core.ipfilter.BadIp;
2626
import com.biglybt.core.ipfilter.BadIps;
2727
import com.biglybt.core.util.AEMonitor;
28+
import com.biglybt.core.util.ByteFormatter;
2829

2930
/**
3031
* @author Olivier
@@ -65,8 +66,14 @@ public BadIpsImpl()
6566
@Override
6667
public int
6768
addWarningForIp(
68-
String ip )
69+
String ip,
70+
byte[] specific_hash )
6971
{
72+
if ( specific_hash != null ){
73+
74+
ip += " [" + ByteFormatter.encodeString( specific_hash ) + "]";
75+
}
76+
7077
try{
7178
bad_ip_map_mon.enter();
7279

@@ -87,31 +94,6 @@ public BadIpsImpl()
8794
}
8895
}
8996

90-
91-
@Override
92-
public int
93-
getNbWarningForIp(
94-
String ip)
95-
{
96-
try{
97-
bad_ip_map_mon.enter();
98-
99-
BadIpImpl bad_ip = bad_ip_map.get(ip);
100-
101-
if ( bad_ip == null ){
102-
103-
return 0;
104-
105-
}else{
106-
107-
return bad_ip.getNumberOfWarnings();
108-
}
109-
}finally{
110-
111-
bad_ip_map_mon.exit();
112-
}
113-
}
114-
11597
@Override
11698
public BadIp[]
11799
getBadIps()

core/src/com/biglybt/core/ipfilter/impl/IPBannerImpl.java

+26-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.biglybt.core.logging.Logger;
3636
import com.biglybt.core.tracker.protocol.PRHelpers;
3737
import com.biglybt.core.util.AEMonitor;
38+
import com.biglybt.core.util.ByteFormatter;
3839
import com.biglybt.core.util.Debug;
3940
import com.biglybt.core.util.FileUtil;
4041
import com.biglybt.core.util.HostNameToIPResolver;
@@ -213,8 +214,14 @@ public class
213214

214215
protected boolean
215216
isBanned(
216-
InetAddress ipAddress)
217+
InetAddress ipAddress,
218+
byte[] specific_hash )
217219
{
220+
if ( specific_hash != null ){
221+
222+
Debug.out( "Specific hash not supported" );
223+
}
224+
218225
Object oa = decodeAddress( ipAddress );
219226

220227
try{
@@ -237,8 +244,14 @@ public class
237244

238245
protected boolean
239246
isBanned(
240-
String ipAddress)
247+
String ipAddress,
248+
byte[] specific_hash )
241249
{
250+
if ( specific_hash != null ){
251+
252+
ipAddress += " [" + ByteFormatter.encodeString( specific_hash ) + "]";
253+
}
254+
242255
Object oa = decodeAddress( ipAddress );
243256

244257
try{
@@ -266,9 +279,10 @@ public class
266279
ban(
267280
String ipAddress,
268281
String torrent_name,
282+
byte[] specific_hash,
269283
boolean manual,
270284
int for_mins )
271-
{
285+
{
272286
// always allow manual bans through
273287

274288
if ( !manual ){
@@ -294,6 +308,10 @@ public class
294308

295309
boolean temporary = for_mins > 0;
296310

311+
if ( specific_hash != null ){
312+
ipAddress += " [" + ByteFormatter.encodeString( specific_hash ) + "]";
313+
}
314+
297315
Object oa = decodeAddress( ipAddress );
298316

299317
try{
@@ -729,6 +747,11 @@ public class
729747
String address )
730748
{
731749
try{
750+
if ( address.endsWith( "]" )){ // specific hash
751+
752+
return( address );
753+
}
754+
732755
if ( HostNameToIPResolver.isNonDNSName( address )){
733756

734757
return( address );

core/src/com/biglybt/core/ipfilter/impl/IpFilterImpl.java

+51-21
Original file line numberDiff line numberDiff line change
@@ -386,26 +386,27 @@ public static IpFilter getInstance() {
386386
public boolean
387387
isInRange(
388388
String ipAddress,
389-
String torrent_name,
389+
String name,
390390
byte[] torrent_hash )
391391
{
392-
return( isInRange( ipAddress, torrent_name, torrent_hash, true ));
392+
return( isInRange( ipAddress, name, torrent_hash, false, true ));
393393
}
394394

395395
@Override
396396
public boolean
397397
isInRange(
398398
String ipAddress,
399-
String torrent_name,
399+
String name,
400400
byte[] torrent_hash,
401+
boolean is_specific,
401402
boolean loggable )
402403
{
403-
//In all cases, block banned ip addresses
404-
405-
if( ipBanner.isBanned(ipAddress)){
404+
//In all cases, block banned ip addresses
405+
406+
if ( ipBanner.isBanned(ipAddress, is_specific?torrent_hash:null )){
406407

407-
return true;
408-
}
408+
return true;
409+
}
409410

410411

411412
if ( !isEnabled()){
@@ -488,7 +489,7 @@ public static IpFilter getInstance() {
488489
return( false );
489490
}
490491

491-
if ( addBlockedIP( new BlockedIpImpl( ipAddress, match, torrent_name, loggable), torrent_hash, loggable )){
492+
if ( addBlockedIP( new BlockedIpImpl( ipAddress, match, name, loggable), torrent_hash, loggable )){
492493

493494
if (Logger.isEnabled())
494495
Logger.log(new LogEvent(LOGID_NWMAN, "Ip Blocked : "
@@ -517,7 +518,7 @@ public static IpFilter getInstance() {
517518
return( false );
518519
}
519520

520-
if ( addBlockedIP( new BlockedIpImpl(ipAddress,null, torrent_name, loggable), torrent_hash, loggable )){
521+
if ( addBlockedIP( new BlockedIpImpl(ipAddress,null, name, loggable), torrent_hash, loggable )){
521522

522523
if (Logger.isEnabled())
523524
Logger.log(new LogEvent(LOGID_NWMAN, "Ip Blocked : "
@@ -543,13 +544,14 @@ public static IpFilter getInstance() {
543544
public boolean
544545
isInRange(
545546
InetAddress ipAddress,
546-
String torrent_name,
547+
String name,
547548
byte[] torrent_hash,
549+
boolean is_specific,
548550
boolean loggable )
549551
{
550552
//In all cases, block banned ip addresses
551553

552-
if( ipBanner.isBanned(ipAddress)){
554+
if( ipBanner.isBanned(ipAddress,is_specific?torrent_hash:null)){
553555

554556
return true;
555557
}
@@ -617,7 +619,7 @@ public static IpFilter getInstance() {
617619

618620
if(!allow) {
619621

620-
if ( addBlockedIP( new BlockedIpImpl(ipAddress.getHostAddress(),match, torrent_name, loggable), torrent_hash, loggable )){
622+
if ( addBlockedIP( new BlockedIpImpl(ipAddress.getHostAddress(),match, name, loggable), torrent_hash, loggable )){
621623

622624
if (Logger.isEnabled())
623625
Logger.log(new LogEvent(LOGID_NWMAN, "Ip Blocked : "
@@ -642,7 +644,7 @@ public static IpFilter getInstance() {
642644

643645
if( allow ){
644646

645-
if ( addBlockedIP( new BlockedIpImpl(ipAddress.getHostAddress(),null, torrent_name, loggable), torrent_hash, loggable )){
647+
if ( addBlockedIP( new BlockedIpImpl(ipAddress.getHostAddress(),null, name, loggable), torrent_hash, loggable )){
646648

647649
if (Logger.isEnabled())
648650
Logger.log(new LogEvent(LOGID_NWMAN, "Ip Blocked : "
@@ -934,15 +936,32 @@ public static IpFilter getInstance() {
934936
public boolean
935937
ban(
936938
String ipAddress,
937-
String torrent_name,
939+
String name,
938940
boolean manual )
939941
{
940-
return( ban( ipAddress, torrent_name, manual, 0 ));
942+
return( ban( ipAddress, name, null, manual ));
943+
}
944+
945+
@Override
946+
public boolean
947+
ban(
948+
String ipAddress,
949+
String name,
950+
byte[] specific_hash,
951+
boolean manual )
952+
{
953+
return( ban( ipAddress, name, specific_hash, manual, 0 ));
941954
}
942955

943-
944-
945-
956+
@Override
957+
public boolean
958+
isBanned(
959+
String ipAddress,
960+
byte[] specific_hash)
961+
{
962+
return( ipBanner.isBanned( ipAddress, specific_hash ));
963+
}
964+
946965
@Override
947966
public BlockedIp[]
948967
getBlockedIps()
@@ -1127,11 +1146,22 @@ public static IpFilter getInstance() {
11271146
public boolean
11281147
ban(
11291148
String ipAddress,
1130-
String torrent_name,
1149+
String name,
1150+
boolean manual,
1151+
int for_mins )
1152+
{
1153+
return( ban( ipAddress, name, null, manual, for_mins ));
1154+
}
1155+
1156+
private boolean
1157+
ban(
1158+
String ipAddress,
1159+
String name,
1160+
byte[] specific_hash,
11311161
boolean manual,
11321162
int for_mins )
11331163
{
1134-
return( ipBanner.ban( ipAddress, torrent_name, manual, for_mins ));
1164+
return( ipBanner.ban( ipAddress, name, specific_hash, manual, for_mins ));
11351165
}
11361166

11371167
@Override

0 commit comments

Comments
 (0)