- Timestamp:
- May 1, 2010, 1:55:20 PM (12 years ago)
- Location:
- branches/1.9x/third-party/dht
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.9x/third-party/dht/CHANGES
r9777 r10597 1 25 March 2010: dht-0.14 2 3 * Fixed ordering of entries in parameter dictionaries. 4 1 5 15 December 2009: dht-0.13 2 6 -
branches/1.9x/third-party/dht/dht.c
r9777 r10597 1 1 /* 2 Copyright (c) 20 09by Juliusz Chroboczek2 Copyright (c) 2010 by Juliusz Chroboczek 3 3 4 4 Permission is hereby granted, free of charge, to any person obtaining a copy … … 263 263 static time_t expire_stuff_time; 264 264 265 #define MAX_ LEAKY_BUCKET_TOKENS 40266 static time_t leaky_bucket_time;267 static int leaky_bucket_tokens;265 #define MAX_TOKEN_BUCKET_TOKENS 40 266 static time_t token_bucket_time; 267 static int token_bucket_tokens; 268 268 269 269 FILE *dht_debug = NULL; … … 989 989 omitting the token when storage tables are full. While 990 990 I don't think this makes a lot of sense -- just sending 991 a positive reply is just as good , let's deal with it. */991 a positive reply is just as good --, let's deal with it. */ 992 992 if(n->token_len == 0) 993 993 n->acked = 1; … … 1593 1593 next_blacklisted = 0; 1594 1594 1595 leaky_bucket_time = now.tv_sec;1596 leaky_bucket_tokens = MAX_LEAKY_BUCKET_TOKENS;1595 token_bucket_time = now.tv_sec; 1596 token_bucket_tokens = MAX_TOKEN_BUCKET_TOKENS; 1597 1597 1598 1598 memset(secret, 0, sizeof(secret)); … … 1656 1656 1657 1657 static int 1658 leaky_bucket(void)1659 { 1660 if( leaky_bucket_tokens == 0) {1661 leaky_bucket_tokens = MIN(MAX_LEAKY_BUCKET_TOKENS,1662 4 * (now.tv_sec - leaky_bucket_time));1663 leaky_bucket_time = now.tv_sec;1664 } 1665 1666 if( leaky_bucket_tokens == 0)1658 token_bucket(void) 1659 { 1660 if(token_bucket_tokens == 0) { 1661 token_bucket_tokens = MIN(MAX_TOKEN_BUCKET_TOKENS, 1662 4 * (now.tv_sec - token_bucket_time)); 1663 token_bucket_time = now.tv_sec; 1664 } 1665 1666 if(token_bucket_tokens == 0) 1667 1667 return 0; 1668 1668 1669 leaky_bucket_tokens--;1669 token_bucket_tokens--; 1670 1670 return 1; 1671 1671 } … … 1870 1870 if(message > REPLY) { 1871 1871 /* Rate limit requests. */ 1872 if(! leaky_bucket()) {1872 if(!token_bucket()) { 1873 1873 debugf("Dropping request due to rate limiting.\n"); 1874 1874 goto dontread; … … 2374 2374 rc = snprintf(buf + i, 2048 - i, "d1:rd2:id20:"); INC(i, rc, 2048); 2375 2375 COPY(buf, i, myid, 20, 2048); 2376 if(nodes_len > 0) { 2377 rc = snprintf(buf + i, 2048 - i, "5:nodes%d:", nodes_len); 2378 INC(i, rc, 2048); 2379 COPY(buf, i, nodes, nodes_len, 2048); 2380 } 2381 if(nodes6_len > 0) { 2382 rc = snprintf(buf + i, 2048 - i, "6:nodes6%d:", nodes6_len); 2383 INC(i, rc, 2048); 2384 COPY(buf, i, nodes6, nodes6_len, 2048); 2385 } 2376 2386 if(token_len > 0) { 2377 2387 rc = snprintf(buf + i, 2048 - i, "5:token%d:", token_len); 2378 2388 INC(i, rc, 2048); 2379 2389 COPY(buf, i, token, token_len, 2048); 2380 }2381 if(nodes_len > 0) {2382 rc = snprintf(buf + i, 2048 - i, "5:nodes%d:", nodes_len);2383 INC(i, rc, 2048);2384 COPY(buf, i, nodes, nodes_len, 2048);2385 }2386 if(nodes6_len > 0) {2387 rc = snprintf(buf + i, 2048 - i, "6:nodes6%d:", nodes6_len);2388 INC(i, rc, 2048);2389 COPY(buf, i, nodes6, nodes6_len, 2048);2390 2390 } 2391 2391
Note: See TracChangeset
for help on using the changeset viewer.