Changeset 636
- Timestamp:
- 24/07/08 00:52:07 (4 months ago)
- Location:
- trunk
- Files:
-
- 5 modified
-
c2s/c2s.c (modified) (2 diffs)
-
c2s/c2s.h (modified) (2 diffs)
-
c2s/main.c (modified) (1 diff)
-
ChangeLog (modified) (1 diff)
-
etc/c2s.xml.dist.in (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/c2s/c2s.c
r629 r636 225 225 sess->c2s->packet_count++; 226 226 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 227 255 nad = (nad_t) data; 228 256 … … 577 605 if(c2s->byte_rate_total != 0) 578 606 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); 579 610 580 611 /* find out which port this is */ -
trunk/c2s/c2s.h
r629 r636 86 86 int rate_log; 87 87 88 rate_t stanza_rate; 89 int stanza_rate_log; 90 88 91 time_t last_activity; 89 92 unsigned int packet_count; … … 233 236 int byte_rate_seconds; 234 237 int byte_rate_wait; 238 239 /** stanza rates */ 240 int stanza_rate_total; 241 int stanza_rate_seconds; 242 int stanza_rate_wait; 235 243 236 244 /** maximum stanza size */ -
trunk/c2s/main.c
r629 r636 157 157 } 158 158 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 159 170 elem = config_get(c2s->config, "io.limits.connects"); 160 171 if(elem != NULL) -
trunk/ChangeLog
r635 r636 1 1 2008-07-23 Mark Doliner <mark@meebo.com> 2 2 * 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. 3 6 4 7 2008-07-15 Tomasz Sterna <tomek@xiaoka.com> -
trunk/etc/c2s.xml.dist.in
r619 r636 205 205 <bytes>0</bytes> 206 206 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 207 216 <!-- Maximum connects per second - if more than X connects are 208 217 attempted from a single IP in Y seconds, that IP is throttled
