Fix throttle to 1) Work, 2) Not throttle outbound connections

This commit is contained in:
md_5 2013-08-02 19:31:46 +10:00
parent 4c96880580
commit fb94612315
4 changed files with 13 additions and 10 deletions

View File

@ -18,6 +18,7 @@ import net.md_5.bungee.config.Configuration;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.Calendar;
@ -194,9 +195,9 @@ public class BungeeCord extends ProxyServer
}
}
}
private final Map<SocketAddress, Long> throttle = new HashMap<>();
private final Map<InetAddress, Long> throttle = new HashMap<>();
public void unThrottle(SocketAddress address)
public void unThrottle(InetAddress address)
{
if ( address != null )
{
@ -207,7 +208,7 @@ public class BungeeCord extends ProxyServer
}
}
public boolean throttle(SocketAddress address)
public boolean throttle(InetAddress address)
{
long currentTime = System.currentTimeMillis();
synchronized ( throttle )

View File

@ -153,7 +153,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
+ "\00" + response.getMotd()
+ "\00" + response.getCurrentPlayers()
+ "\00" + response.getMaxPlayers();
BungeeCord.getInstance().unThrottle( getAddress() );
BungeeCord.getInstance().unThrottle( getAddress().getAddress() );
disconnect( kickMessage );
} catch ( Throwable t )
{

View File

@ -6,6 +6,7 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.MessageList;
import io.netty.handler.timeout.ReadTimeoutException;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.logging.Level;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.ProxyServer;
@ -33,12 +34,6 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception
{
if ( BungeeCord.getInstance().throttle( ctx.channel().remoteAddress() ) )
{
ctx.channel().close();
return;
}
if ( handler != null )
{
channel = new ChannelWrapper( ctx );

View File

@ -7,6 +7,7 @@ import io.netty.channel.ChannelOption;
import io.netty.handler.codec.bytes.ByteArrayEncoder;
import io.netty.handler.timeout.ReadTimeoutHandler;
import io.netty.util.AttributeKey;
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.BungeeServerInfo;
@ -28,6 +29,12 @@ public class PipelineUtils
@Override
protected void initChannel(Channel ch) throws Exception
{
if ( BungeeCord.getInstance().throttle( ( (InetSocketAddress) ch.remoteAddress() ).getAddress() ) )
{
ch.close();
return;
}
BASE.initChannel( ch );
ch.pipeline().get( HandlerBoss.class ).setHandler( new InitialHandler( ProxyServer.getInstance(), ch.attr( LISTENER ).get() ) );
}