Skip to content

Commit 9314e35

Browse files
committed
Fix up ip filter application on some tracker paths
1 parent 16d3def commit 9314e35

8 files changed

+44
-27
lines changed

core/src/com/biglybt/core/tracker/server/impl/TRTrackerServerFactoryImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@
201201
throw( new TRTrackerServerException( "TRTrackerServerFactory: UDP doesn't support SSL"));
202202
}
203203

204-
server = new TRTrackerServerUDP( name, port, start_up_ready, properties );
204+
server = new TRTrackerServerUDP( name, port, apply_ip_filter, start_up_ready, properties );
205205

206206
}else{
207207

208-
server = new TRTrackerServerDHT( name, start_up_ready, properties );
208+
server = new TRTrackerServerDHT( name, apply_ip_filter, start_up_ready, properties );
209209
}
210210

211211
servers.add( server );

core/src/com/biglybt/core/tracker/server/impl/TRTrackerServerImpl.java

+23-5
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@
349349
return( support_experimental_extensions );
350350
}
351351

352-
protected final IpFilter ip_filter = IpFilterManagerFactory.getSingleton().getIPFilter();
352+
private final IpFilter ip_filter = IpFilterManagerFactory.getSingleton().getIPFilter();
353353

354354
private long current_announce_retry_interval;
355355
private long current_scrape_retry_interval;
@@ -361,6 +361,8 @@
361361
private final TRTrackerServerStatsImpl stats = new TRTrackerServerStatsImpl( this );
362362

363363
private final String name;
364+
private final boolean apply_ip_filter;
365+
364366
private final Map<String,Object> properties;
365367

366368
private final boolean reverse_proxy;
@@ -398,12 +400,14 @@
398400
public
399401
TRTrackerServerImpl(
400402
String _name,
403+
boolean _apply_ip_filter,
401404
boolean _start_up_ready,
402405
Map<String,Object> _properties )
403406
{
404-
name = _name==null?DEFAULT_NAME:_name;
405-
is_ready = _start_up_ready;
406-
properties = _properties==null?new HashMap<>():_properties;
407+
name = _name==null?DEFAULT_NAME:_name;
408+
apply_ip_filter = _apply_ip_filter;
409+
is_ready = _start_up_ready;
410+
properties = _properties==null?new HashMap<>():_properties;
407411

408412
Boolean b_rp = (Boolean)properties.get( Tracker.PR_REVERSE_PROXY );
409413

@@ -473,7 +477,7 @@
473477

474478
key_enabled = COConfigurationManager.getBooleanParameter("Tracker Key Enable Server");
475479
}
476-
480+
477481
@Override
478482
public void
479483
setReady()
@@ -515,6 +519,20 @@
515519
return( keep_alive_enabled );
516520
}
517521

522+
protected boolean
523+
isIPFiltered(
524+
String ip )
525+
{
526+
if ( apply_ip_filter && ip_filter.isInRange( ip, "Tracker", null )){
527+
528+
return( true );
529+
530+
}else{
531+
532+
return( false );
533+
}
534+
}
535+
518536
public TRTrackerServerTorrent
519537
addLink(
520538
String link,

core/src/com/biglybt/core/tracker/server/impl/TRTrackerServerProcessor.java

+5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@
9393
throw( new TRTrackerServerException( "Tracker initialising, please wait" ));
9494
}
9595

96+
if ( server.isIPFiltered( real_ip_address )){
97+
98+
throw( new TRTrackerServerException( "Unauthorized" ));
99+
}
100+
96101
start = SystemTime.getHighPrecisionCounter();
97102

98103
boolean ip_override = real_ip_address != original_client_ip_address;

core/src/com/biglybt/core/tracker/server/impl/dht/TRTrackerServerDHT.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@
3737
public
3838
TRTrackerServerDHT(
3939
String name,
40+
boolean apply_ip_filter,
4041
boolean start_up_ready,
4142
Map<String,Object> properties )
4243
{
43-
super( name, start_up_ready, properties );
44+
super( name, apply_ip_filter, start_up_ready, properties );
4445
}
4546

4647
@Override

core/src/com/biglybt/core/tracker/server/impl/tcp/TRTrackerServerTCP.java

+3-11
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
public static final int PROCESSING_POST_MULTIPLIER = Math.max(0, COConfigurationManager.getIntParameter( "Tracker Max POST Time Multiplier" ));
4848

4949
private final boolean ssl;
50-
private int port;
51-
private final boolean apply_ip_filter;
50+
private int port;
5251

5352
private boolean restrict_non_blocking_requests = TRTrackerServerImpl.restrict_non_blocking_requests;
5453

@@ -65,12 +64,11 @@
6564

6665
throws TRTrackerServerException
6766
{
68-
super( _name, _start_up_ready, _properties );
67+
super( _name, _apply_ip_filter, _start_up_ready, _properties );
6968

7069
port = _port;
7170
ssl = _ssl;
72-
apply_ip_filter = _apply_ip_filter;
73-
71+
7472
thread_pool = new ThreadPool( "TrackerServer:TCP:"+port, THREAD_POOL_SIZE );
7573

7674
if ( PROCESSING_GET_LIMIT > 0 ){
@@ -86,12 +84,6 @@
8684
thread_pool.run( processor );
8785
}
8886

89-
protected boolean
90-
isIPFilterEnabled()
91-
{
92-
return( apply_ip_filter );
93-
}
94-
9587
public boolean
9688
getRestrictNonBlocking()
9789
{

core/src/com/biglybt/core/tracker/server/impl/tcp/blocking/TRBlockingServer.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,14 @@
283283

284284
String ip = socket.getInetAddress().getHostAddress();
285285

286-
if ( (!isIPFilterEnabled()) || (!ip_filter.isInRange( ip, "Tracker", null ))){
287-
288-
runProcessor( new TRBlockingServerProcessor( this, socket ));
286+
if ( isIPFiltered(ip)){
289287

288+
socket.close();
289+
290290
}else{
291+
292+
runProcessor( new TRBlockingServerProcessor( this, socket ));
291293

292-
socket.close();
293294
}
294295

295296
}catch( Throwable e ){

core/src/com/biglybt/core/tracker/server/impl/tcp/nonblocking/TRNonBlockingServer.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,7 @@
336336

337337
removeAndCloseConnection( processor );
338338

339-
}else if ( isIPFilterEnabled() &&
340-
ip_filter.isInRange( channel.socket().getInetAddress().getHostAddress(), "Tracker", null )){
339+
}else if ( isIPFiltered( channel.socket().getInetAddress().getHostAddress())){
341340

342341
removeAndCloseConnection( processor );
343342

core/src/com/biglybt/core/tracker/server/impl/udp/TRTrackerServerUDP.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@
6464
TRTrackerServerUDP(
6565
String _name,
6666
int _port,
67+
boolean _apply_ip_filter,
6768
boolean _start_up_ready,
6869
Map<String,Object> _properties )
6970
{
70-
super( _name, _start_up_ready, _properties );
71+
super( _name, _apply_ip_filter, _start_up_ready, _properties );
7172

7273
port = _port;
7374

@@ -156,7 +157,7 @@
156157

157158
String ip = packet.getAddress().getHostAddress();
158159

159-
if ( !ip_filter.isInRange( ip, "Tracker", null )){
160+
if ( !isIPFiltered( ip )){
160161

161162
thread_pool.run( new TRTrackerServerProcessorUDP( this, socket, packet ));
162163
}

0 commit comments

Comments
 (0)