Commit 790a7f92 authored by mi's avatar mi
Browse files

Add implementation of Kademlia Distributed Hash Table (DHT) used

in the Bittorrent network (``mainline'' variant).
parent d22b04c3
......@@ -314,6 +314,7 @@
SUBDIR += devhelp
SUBDIR += devtodo
SUBDIR += dfuife-curses
SUBDIR += jech-dht
SUBDIR += dia2code
SUBDIR += diffuse
SUBDIR += ding-libs
......
# New ports collection makefile for: jech-dht
# Date created: July 28, 2012
# Whom: Mikhail Teterin <mi@aldan.algebra.com>
#
# $FreeBSD$
#
PORTNAME= dht
PORTVERSION= 0.21
CATEGORIES= net devel
MASTER_SITES= http://www.pps.univ-paris-diderot.fr/~jch/software/files/
MAINTAINER= mi@aldan.algebra.com
COMMENT= Mainline variant of Kademlia Distributed Hash Table (DHT)
LICENSE= MIT
MAKEFILE= ${FILESDIR}/BSDmakefile
MAKE_JOBS_SAFE= yes
USE_LDCONFIG= yes
pre-su-install:
${MKDIR} ${PREFIX}/include/dht
.include <bsd.port.mk>
SHA256 (dht-0.21.tar.gz) = edf8fd9bf6225bbced38a74bb40592d46876fdfb74e9ebddecbdc1e805bdf44f
SIZE (dht-0.21.tar.gz) = 27578
LIB= dht
SHLIB_MAJOR= 0
SHLIB_MINOR= 21
SRCS= dht.c
CFLAGS+=-DHAVE_MEMMEM
WARNS= 3
INCS= dht.h
INCLUDEDIR=${PREFIX}/include/dht
LIBDIR= ${PREFIX}/lib
.include <bsd.lib.mk>
--- dht.c 2011-07-25 17:59:36.000000000 -0400
+++ dht.c 2012-07-28 16:21:07.000000000 -0400
@@ -356,5 +356,5 @@
switch(sa->sa_family) {
case AF_INET: {
- struct sockaddr_in *sin = (struct sockaddr_in*)sa;
+ const struct sockaddr_in *sin = (const struct sockaddr_in*)sa;
const unsigned char *address = (const unsigned char*)&sin->sin_addr;
return sin->sin_port == 0 ||
@@ -364,5 +364,5 @@
}
case AF_INET6: {
- struct sockaddr_in6 *sin6 = (struct sockaddr_in6*)sa;
+ const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6*)sa;
const unsigned char *address = (const unsigned char*)&sin6->sin6_addr;
return sin6->sin6_port == 0 ||
@@ -687,5 +687,5 @@
int i;
- if(salen > sizeof(struct sockaddr_storage))
+ if((unsigned)salen > sizeof(struct sockaddr_storage))
abort();
@@ -1281,13 +1281,13 @@
int i, len;
struct storage *st;
- unsigned char *ip;
+ const unsigned char *ip;
if(sa->sa_family == AF_INET) {
- struct sockaddr_in *sin = (struct sockaddr_in*)sa;
- ip = (unsigned char*)&sin->sin_addr;
+ const struct sockaddr_in *sin = (const struct sockaddr_in*)sa;
+ ip = (const unsigned char*)&sin->sin_addr;
len = 4;
} else if(sa->sa_family == AF_INET6) {
- struct sockaddr_in6 *sin6 = (struct sockaddr_in6*)sa;
- ip = (unsigned char*)&sin6->sin6_addr;
+ const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6*)sa;
+ ip = (const unsigned char*)&sin6->sin6_addr;
len = 16;
} else {
@@ -1406,15 +1406,15 @@
make_token(const struct sockaddr *sa, int old, unsigned char *token_return)
{
- void *ip;
+ const void *ip;
int iplen;
unsigned short port;
if(sa->sa_family == AF_INET) {
- struct sockaddr_in *sin = (struct sockaddr_in*)sa;
+ const struct sockaddr_in *sin = (const struct sockaddr_in*)sa;
ip = &sin->sin_addr;
iplen = 4;
port = htons(sin->sin_port);
} else if(sa->sa_family == AF_INET6) {
- struct sockaddr_in6 *sin6 = (struct sockaddr_in6*)sa;
+ const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6*)sa;
ip = &sin6->sin6_addr;
iplen = 16;
@@ -1892,5 +1892,5 @@
}
- if(((char*)buf)[buflen] != '\0') {
+ if(((const char*)buf)[buflen] != '\0') {
debugf("Unterminated message.\n");
errno = EINVAL;
@@ -2743,5 +2743,5 @@
#define CHECK(ptr, len) \
- if(((unsigned char*)ptr) + (len) > (buf) + (buflen)) goto overflow;
+ if(((const unsigned char*)ptr) + (len) > (buf) + (buflen)) goto overflow;
if(tid_return) {
@@ -2750,5 +2750,5 @@
long l;
char *q;
- l = strtol((char*)p + 3, &q, 10);
+ l = strtol((const char*)p + 3, &q, 10);
if(q && *q == ':' && l > 0 && l < *tid_len) {
CHECK(q + 1, l);
@@ -2782,5 +2782,5 @@
long l;
char *q;
- l = strtol((char*)p + 5, &q, 10);
+ l = strtol((const char*)p + 5, &q, 10);
if(q && *q == 'e' && l > 0 && l < 0x10000)
*port_return = l;
@@ -2804,5 +2804,5 @@
long l;
char *q;
- l = strtol((char*)p + 7, &q, 10);
+ l = strtol((const char*)p + 7, &q, 10);
if(q && *q == ':' && l > 0 && l < *token_len) {
CHECK(q + 1, l);
@@ -2820,5 +2820,5 @@
long l;
char *q;
- l = strtol((char*)p + 7, &q, 10);
+ l = strtol((const char*)p + 7, &q, 10);
if(q && *q == ':' && l > 0 && l < *nodes_len) {
CHECK(q + 1, l);
@@ -2836,5 +2836,5 @@
long l;
char *q;
- l = strtol((char*)p + 8, &q, 10);
+ l = strtol((const char*)p + 8, &q, 10);
if(q && *q == ':' && l > 0 && l < *nodes6_len) {
CHECK(q + 1, l);
@@ -2855,8 +2855,8 @@
long l;
char *q;
- l = strtol((char*)buf + i, &q, 10);
+ l = strtol((const char*)buf + i, &q, 10);
if(q && *q == ':' && l > 0) {
CHECK(q + 1, l);
- i = q + 1 + l - (char*)buf;
+ i = q + 1 + l - (const char*)buf;
if(l == 6) {
if(j + l > *values_len)
The files dht.c and dht.h implement the variant of the Kademlia
Distributed Hash Table (DHT) used in the Bittorrent network
(``mainline'' variant).
WWW: http://www.pps.univ-paris-diderot.fr/~jch/software/bittorrent/
WWW: https://github.com/jech/dht
lib/libdht.so.0
lib/libdht.so
lib/libdht.a
include/dht/dht.h
@dirrm include/dht
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment