Changeset 179

Show
Ignore:
Timestamp:
01/10/08 17:39:22 (1 year ago)
Author:
jfp
Message:

Fix retry errors

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/jsmtpd/src/org/jsmtpd/core/common/smtpExtension/IProtocolHandler.java

    r175 r179  
    3939 
    4040    public void setSock(Socket sock) throws IOException; 
    41  
     41     
     42    public int getErrorCount(); 
     43     
    4244    public boolean isSecured(); 
    4345 
  • trunk/jsmtpd/src/org/jsmtpd/core/receive/ProtocolHandler.java

    r176 r179  
    157157    private int maxRcpt =ReadConfig.getInstance().getIntegerProperty("maxRcpt"); 
    158158     
    159     public void init(Socket sock,boolean secured) { 
     159    private int errorCount=0; 
     160     
     161    public int getErrorCount() { 
     162                return errorCount; 
     163        } 
     164 
     165        public void init(Socket sock,boolean secured) { 
    160166        commandHistory=new LinkedList<String>(); 
    161167        remote = ((InetSocketAddress) sock.getRemoteSocketAddress()).getAddress().getHostAddress(); // get client hostname 
     
    189195        // Count errors, if it exceeds a threshold, the connection is droped because someone 
    190196        // is probably trying to do something not allowed 
    191         int errors = 0; 
     197        errorCount = 0; 
    192198        // The last command issued 
    193199        int lastCommand = -1; 
     
    209215            while ((commandString = csp.readLine()) != null) 
    210216            { 
     217                if (errorCount > 10) { 
     218                        log.error("Max err count reached, ciao"); 
     219                    return; 
     220                } 
    211221                command = getCommand(commandString); 
    212222                log.debug("Command: " + commandString); 
     
    288298                                send(MSG_INVALID_CMD); 
    289299                                log.error("Invalid command: " + commandString + " from " + remote); 
    290                                 errors++; 
    291                                 if (errors > 10) 
    292                                     return; 
     300                                errorCount++; 
    293301                                break; 
    294302                            } 
     
    297305                        } catch (SmtpExtensionException e) { 
    298306                            log.error("Error executing SMTP Extensions"); 
    299                             errors++; 
     307                            errorCount++; 
    300308                        }  
    301309                } 
  • trunk/jsmtpd/src/org/jsmtpd/plugins/smtpExtension/SmtpAuthenticator.java

    r136 r179  
    123123            if (login == null) { 
    124124                log.info("LOGIN Remote host issued a null login"); 
    125                 throttle(); 
     125                throttle(protocol); 
    126126                send(wr, MSG_INVALID_CMD); 
    127127                throw new SmtpExtensionException(); 
     
    132132            if (pass == null) { 
    133133                log.info("LOGIN Remote host issued a null password"); 
    134                 throttle(); 
     134                throttle(protocol); 
    135135                send(wr, MSG_INVALID_CMD); 
    136136                throw new SmtpExtensionException(); 
     
    146146            } else { 
    147147                log.info("Remote host authentication failed"); 
    148                 throttle(); 
     148                throttle(protocol); 
    149149                send(wr, MSG_AUTH_FAILED); 
    150150                throw new SmtpExtensionException(); 
     
    187187    } 
    188188 
    189     private void throttle() { 
    190         log.info("Waiting 5 secs before retry"); 
     189    private void throttle(IProtocolHandler handler) { 
     190        long waitTime =  Math.round(Math.exp(handler.getErrorCount())); 
     191        log.info("Waiting "+waitTime+" secs before retry"); 
    191192        Object o = new Object(); 
    192193        synchronized (o) { 
    193194            try { 
    194  
    195                 o.wait(5000); 
     195                o.wait(waitTime*1000); 
    196196            } catch (InterruptedException e) { 
    197197            }