Merge branch 'master' into cleanup-fileaccess
This commit is contained in:
commit
8c5a961011
39 changed files with 1637 additions and 1084 deletions
|
|
@ -61,7 +61,7 @@ public class RouteServer extends Thread implements Comparable<RouteServer>
|
|||
|
||||
private static DateFormat tsFormat = new SimpleDateFormat( "dd.MM.yy HH:mm", new Locale( "en", "US" ) );
|
||||
|
||||
private static String formattedTimestamp()
|
||||
private static String formattedTimeStamp( long t )
|
||||
{
|
||||
synchronized( tsFormat )
|
||||
{
|
||||
|
|
@ -73,15 +73,21 @@ public class RouteServer extends Thread implements Comparable<RouteServer>
|
|||
{
|
||||
BufferedReader br = null;
|
||||
BufferedWriter bw = null;
|
||||
|
||||
// first line
|
||||
String getline = null;
|
||||
String sessionInfo = null;
|
||||
String sIp = null;
|
||||
|
||||
try
|
||||
{
|
||||
br = new BufferedReader( new InputStreamReader( clientSocket.getInputStream() , "UTF-8") );
|
||||
bw = new BufferedWriter( new OutputStreamWriter( clientSocket.getOutputStream(), "UTF-8" ) );
|
||||
|
||||
// first line
|
||||
String getline = null;
|
||||
String agent = null;
|
||||
String encodings = null;
|
||||
String xff = null; // X-Forwarded-For
|
||||
String referer = null;
|
||||
|
||||
// more headers until first empty line
|
||||
for(;;)
|
||||
|
|
@ -102,16 +108,40 @@ public class RouteServer extends Thread implements Comparable<RouteServer>
|
|||
{
|
||||
getline = line;
|
||||
}
|
||||
if ( line.startsWith( "User-Agent: " ) )
|
||||
line = line.toLowerCase();
|
||||
if ( line.startsWith( "user-agent: " ) )
|
||||
{
|
||||
agent = line.substring( "User-Agent: ".length() );
|
||||
agent = line.substring( "user-agent: ".length() );
|
||||
}
|
||||
if ( line.startsWith( "Accept-Encoding: " ) )
|
||||
if ( line.startsWith( "accept-encoding: " ) )
|
||||
{
|
||||
encodings = line.substring( "Accept-Encoding: ".length() );
|
||||
encodings = line.substring( "accept-encoding: ".length() );
|
||||
}
|
||||
if ( line.startsWith( "x-forwarded-for: " ) )
|
||||
{
|
||||
xff = line.substring( "x-forwarded-for: ".length() );
|
||||
}
|
||||
if ( line.startsWith( "Referer: " ) )
|
||||
{
|
||||
referer = line.substring( "Referer: ".length() );
|
||||
}
|
||||
if ( line.startsWith( "Referrer: " ) )
|
||||
{
|
||||
referer = line.substring( "Referrer: ".length() );
|
||||
}
|
||||
}
|
||||
|
||||
InetAddress ip = clientSocket.getInetAddress();
|
||||
sIp = xff == null ? (ip==null ? "null" : ip.toString() ) : xff;
|
||||
boolean newSession = IpAccessMonitor.touchIpAccess( sIp );
|
||||
sessionInfo = " new";
|
||||
if ( !newSession )
|
||||
{
|
||||
int sessionCount = IpAccessMonitor.getSessionCount();
|
||||
sessionInfo = " " + Math.min( sessionCount, 999 );
|
||||
sessionInfo = sessionInfo.substring( sessionInfo.length() - 4 );
|
||||
}
|
||||
|
||||
String excludedAgents = System.getProperty( "excludedAgents" );
|
||||
if ( agent != null && excludedAgents != null )
|
||||
{
|
||||
|
|
@ -128,6 +158,17 @@ public class RouteServer extends Thread implements Comparable<RouteServer>
|
|||
}
|
||||
}
|
||||
|
||||
if ( referer != null && referer.indexOf( "brouter.de/brouter-web" ) >= 0 )
|
||||
{
|
||||
if ( getline.indexOf( "%7C" ) >= 0 && getline.indexOf( "%2C" ) >= 0 )
|
||||
{
|
||||
writeHttpHeader( bw, HTTP_STATUS_FORBIDDEN );
|
||||
bw.write( "Spam? please stop" );
|
||||
bw.flush();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( getline.startsWith("GET /favicon.ico") )
|
||||
{
|
||||
writeHttpHeader( bw, HTTP_STATUS_NOT_FOUND );
|
||||
|
|
@ -143,9 +184,6 @@ public class RouteServer extends Thread implements Comparable<RouteServer>
|
|||
return;
|
||||
}
|
||||
|
||||
InetAddress ip = clientSocket.getInetAddress();
|
||||
System.out.println( formattedTimestamp() + " ip=" + (ip==null ? "null" : ip.toString() ) + " -> " + getline );
|
||||
|
||||
String url = getline.split(" ")[1];
|
||||
HashMap<String,String> params = getUrlParams(url);
|
||||
|
||||
|
|
@ -280,8 +318,12 @@ public class RouteServer extends Thread implements Comparable<RouteServer>
|
|||
{
|
||||
threadPoolSync.notifyAll();
|
||||
}
|
||||
long t = System.currentTimeMillis();
|
||||
long ms = t - starttime;
|
||||
System.out.println( formattedTimeStamp(t) + sessionInfo + " ip=" + sIp + " ms=" + ms + " -> " + getline );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
|
|
@ -355,13 +397,18 @@ public class RouteServer extends Thread implements Comparable<RouteServer>
|
|||
{
|
||||
threadPoolSync.wait( maxWaitTime );
|
||||
}
|
||||
long t = System.currentTimeMillis();
|
||||
System.out.println( formattedTimeStamp(t) + " contention! ms waited " + (t - server.starttime) );
|
||||
}
|
||||
cleanupThreadQueue( threadQueue );
|
||||
if ( threadQueue.size() >= maxthreads )
|
||||
{
|
||||
if ( debug ) System.out.println( "stopping oldest thread..." );
|
||||
// no way... stop the oldest thread
|
||||
threadQueue.poll().stopRouter();
|
||||
RouteServer oldest = threadQueue.poll();
|
||||
oldest.stopRouter();
|
||||
long t = System.currentTimeMillis();
|
||||
System.out.println( formattedTimeStamp(t) + " contention! ms killed " + (t - oldest.starttime) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue