Include dht-0.19.

This fixes a bug with parsing of announce messages, noticed by cjdelisle.
This commit is contained in:
Juliusz Chroboczek 2011-04-30 23:03:25 +00:00
parent 0cff181c09
commit 09c67f749a
2 changed files with 10 additions and 7 deletions

View File

@ -1,3 +1,8 @@
30 April 2011: dht-0.19
* Fix incorrect parsing of announces. Thanks to cjdelisle.
* Relax rate limiting slightly.
20 January 2011: dht-0.18
* Fix a bug that could cause parse_message to enter an infinite loop

12
third-party/dht/dht.c vendored
View File

@ -310,7 +310,7 @@ static struct timeval now;
static time_t mybucket_grow_time, mybucket6_grow_time;
static time_t expire_stuff_time;
#define MAX_TOKEN_BUCKET_TOKENS 40
#define MAX_TOKEN_BUCKET_TOKENS 400
static time_t token_bucket_time;
static int token_bucket_tokens;
@ -1221,23 +1221,21 @@ find_storage(const unsigned char *id)
}
static int
storage_store(const unsigned char *id, const struct sockaddr *sa)
storage_store(const unsigned char *id,
const struct sockaddr *sa, unsigned short port)
{
int i, len;
struct storage *st;
unsigned char *ip;
unsigned short port;
if(sa->sa_family == AF_INET) {
struct sockaddr_in *sin = (struct sockaddr_in*)sa;
ip = (unsigned char*)&sin->sin_addr;
len = 4;
port = ntohs(sin->sin_port);
} else if(sa->sa_family == AF_INET6) {
struct sockaddr_in6 *sin6 = (struct sockaddr_in6*)sa;
ip = (unsigned char*)&sin6->sin6_addr;
len = 16;
port = ntohs(sin6->sin6_port);
} else {
return -1;
}
@ -1714,7 +1712,7 @@ token_bucket(void)
{
if(token_bucket_tokens == 0) {
token_bucket_tokens = MIN(MAX_TOKEN_BUCKET_TOKENS,
4 * (now.tv_sec - token_bucket_time));
100 * (now.tv_sec - token_bucket_time));
token_bucket_time = now.tv_sec;
}
@ -2089,7 +2087,7 @@ dht_periodic(const void *buf, size_t buflen,
203, "Announce_peer with forbidden port number");
break;
}
storage_store(info_hash, from);
storage_store(info_hash, from, port);
/* Note that if storage_store failed, we lie to the requestor.
This is to prevent them from backtracking, and hence
polluting the DHT. */