Changeset 636

Show
Ignore:
Timestamp:
24/07/08 00:52:07 (4 months ago)
Author:
markdoliner
Message:

Added a maximum stanza limit to c2s. This can be used to set an
upper limit on the number of individual requests that can be made
in a given window of time.

Location:
trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/c2s/c2s.c

    r629 r636  
    225225            sess->c2s->packet_count++; 
    226226 
     227            /* check rate limits */ 
     228            if(sess->stanza_rate != NULL) { 
     229                if(rate_check(sess->stanza_rate) == 0) { 
     230 
     231                    /* inform the app if we haven't already */ 
     232                    if(!sess->stanza_rate_log) { 
     233                        if(s->state >= state_STREAM && sess->resources != NULL) 
     234                            log_write(sess->c2s->log, LOG_NOTICE, "[%d] [%s] is being stanza rate limited", sess->fd->fd, jid_user(sess->resources->jid)); 
     235                        else 
     236                            log_write(sess->c2s->log, LOG_NOTICE, "[%d] [%s, port=%d] is being stanza rate limited", sess->fd->fd, sess->ip, sess->port); 
     237 
     238                        sess->stanza_rate_log = 1; 
     239                    } 
     240 
     241                    log_write(sess->c2s->log, LOG_NOTICE, "%d is throttled, disconnecting", sess->fd->fd); 
     242 
     243                    /* Disconnect the user.  Ideally we would just stop 
     244                       reading from their socket and delay processing of this 
     245                       stanza until the throttle time expires.  But that's 
     246                       difficult. */ 
     247                    sx_kill(s); 
     248                    return -1; 
     249                } 
     250 
     251                /* update rate limits */ 
     252                rate_add(sess->stanza_rate, 1); 
     253            } 
     254 
    227255            nad = (nad_t) data; 
    228256 
     
    577605            if(c2s->byte_rate_total != 0) 
    578606                sess->rate = rate_new(c2s->byte_rate_total, c2s->byte_rate_seconds, c2s->byte_rate_wait); 
     607 
     608            if(c2s->stanza_rate_total != 0) 
     609                sess->stanza_rate = rate_new(c2s->stanza_rate_total, c2s->stanza_rate_seconds, c2s->stanza_rate_wait); 
    579610 
    580611            /* find out which port this is */ 
  • trunk/c2s/c2s.h

    r629 r636  
    8686    int                 rate_log; 
    8787 
     88    rate_t              stanza_rate; 
     89    int                 stanza_rate_log; 
     90 
    8891    time_t              last_activity; 
    8992    unsigned int        packet_count; 
     
    233236    int                 byte_rate_seconds; 
    234237    int                 byte_rate_wait; 
     238 
     239    /** stanza rates */ 
     240    int                 stanza_rate_total; 
     241    int                 stanza_rate_seconds; 
     242    int                 stanza_rate_wait; 
    235243 
    236244    /** maximum stanza size */ 
  • trunk/c2s/main.c

    r629 r636  
    157157    } 
    158158 
     159    elem = config_get(c2s->config, "io.limits.stanzas"); 
     160    if(elem != NULL) 
     161    { 
     162        c2s->stanza_rate_total = j_atoi(elem->values[0], 0); 
     163        if(c2s->stanza_rate_total != 0) 
     164        { 
     165            c2s->stanza_rate_seconds = j_atoi(j_attr((const char **) elem->attrs[0], "seconds"), 1); 
     166            c2s->stanza_rate_wait = j_atoi(j_attr((const char **) elem->attrs[0], "throttle"), 5); 
     167        } 
     168    } 
     169 
    159170    elem = config_get(c2s->config, "io.limits.connects"); 
    160171    if(elem != NULL) 
  • trunk/ChangeLog

    r635 r636  
    112008-07-23 Mark Doliner <mark@meebo.com> 
    22        * Removed scod module 
     3        * Added a maximum stanza limit to c2s.  This can be used to set an 
     4          upper limit on the number of individual requests that can be made 
     5          in a given window of time. 
    36 
    472008-07-15 Tomasz Sterna <tomek@xiaoka.com> 
  • trunk/etc/c2s.xml.dist.in

    r619 r636  
    205205      <bytes>0</bytes> 
    206206 
     207      <!-- Maximum number of stanzas per second - if more than X stanzas 
     208           are sent in Y seconds, connection is throttled for Z seconds. 
     209           The format is: 
     210 
     211             <stanzas seconds='Y' throttle='Z'>X</bytes> 
     212 
     213           Default Y 1, default Z is 5. Set X to 0 to disable --> 
     214      <stanzas>1000</stanzas> 
     215 
    207216      <!-- Maximum connects per second - if more than X connects are 
    208217           attempted from a single IP in Y seconds, that IP is throttled