aboutsummaryrefslogtreecommitdiff
path: root/devel
diff options
context:
space:
mode:
authorMikhail Teterin <mi@FreeBSD.org>2014-05-05 01:48:38 +0000
committerMikhail Teterin <mi@FreeBSD.org>2014-05-05 01:48:38 +0000
commitee6bf5f093b7816b81b7f619e1bba43ac6106e03 (patch)
tree770c5ed33166cbb5393a6d3524081e7cea535048 /devel
parent646c69ebdc757e49a40b75e19e809e3b0cee1eb1 (diff)
downloadports-ee6bf5f093b7816b81b7f619e1bba43ac6106e03.tar.gz
ports-ee6bf5f093b7816b81b7f619e1bba43ac6106e03.zip
This library comes with an example program (dht-example).
Build and install it...
Notes
Notes: svn path=/head/; revision=352975
Diffstat (limited to 'devel')
-rw-r--r--devel/jech-dht/Makefile9
-rw-r--r--devel/jech-dht/files/Makefile.example7
-rw-r--r--devel/jech-dht/files/patch-dht-example118
-rw-r--r--devel/jech-dht/pkg-plist1
4 files changed, 135 insertions, 0 deletions
diff --git a/devel/jech-dht/Makefile b/devel/jech-dht/Makefile
index 5dc9a955d993..951380e9bfb9 100644
--- a/devel/jech-dht/Makefile
+++ b/devel/jech-dht/Makefile
@@ -13,6 +13,15 @@ LICENSE= MIT
MAKEFILE= ${FILESDIR}/BSDmakefile
USE_LDCONFIG= yes
+USES= uidfix
+MAKE_ENV+= STAGEDIR="${STAGEDIR}"
+
+post-build:
+ ${SETENV} ${MAKE_ENV} ${MAKE} -C ${WRKSRC} -f \
+ ${FILESDIR}/Makefile.example
+post-install:
+ ${SETENV} ${MAKE_ENV} ${MAKE} -C ${WRKSRC} -f \
+ ${FILESDIR}/Makefile.example install
pre-su-install:
${MKDIR} ${STAGEDIR}${PREFIX}/include/dht
diff --git a/devel/jech-dht/files/Makefile.example b/devel/jech-dht/files/Makefile.example
new file mode 100644
index 000000000000..13972c4eec7b
--- /dev/null
+++ b/devel/jech-dht/files/Makefile.example
@@ -0,0 +1,7 @@
+PROG= dht-example
+NO_MAN= nope, too much to ask
+
+LDADD= -L. -ldht -lcrypt -lmd
+BINDIR= ${STAGEDIR}${PREFIX}/bin
+
+.include <bsd.prog.mk>
diff --git a/devel/jech-dht/files/patch-dht-example b/devel/jech-dht/files/patch-dht-example
new file mode 100644
index 000000000000..61618ac6add9
--- /dev/null
+++ b/devel/jech-dht/files/patch-dht-example
@@ -0,0 +1,118 @@
+This allow switching the hashing algorithm (between a crypt(3)-based
+one and MD5) at run-time, rather than at compile-time.
+
+ -mi
+
+--- dht-example.c 2014-05-03 14:37:50.000000000 -0400
++++ dht-example.c 2014-05-04 21:34:58.000000000 -0400
+@@ -12,4 +12,5 @@
+ #include <fcntl.h>
+ #include <sys/time.h>
++#include <netinet/in.h>
+ #include <arpa/inet.h>
+ #include <sys/types.h>
+@@ -17,4 +18,7 @@
+ #include <netdb.h>
+ #include <sys/signal.h>
++#include <signal.h>
++#include <unistd.h>
++#include <md5.h>
+
+ #include "dht.h"
+@@ -91,4 +95,11 @@
+ static unsigned char buf[4096];
+
++typedef void (hashing_method)(void *, int,
++ const void *, int,
++ const void *, int,
++ const void *, int);
++
++static hashing_method *hasher, crypt_hash, md5_hash;
++
+ int
+ main(int argc, char **argv)
+@@ -112,9 +123,8 @@
+ memset(&sin6, 0, sizeof(sin6));
+ sin6.sin6_family = AF_INET6;
+-
+-
++ hasher = crypt_hash;
+
+ while(1) {
+- opt = getopt(argc, argv, "q46b:i:");
++ opt = getopt(argc, argv, "q46b:i:m");
+ if(opt < 0)
+ break;
+@@ -143,4 +153,6 @@
+ id_file = optarg;
+ break;
++ case 'm':
++ hasher = md5_hash;
+ default:
+ goto usage;
+@@ -405,6 +417,7 @@
+
+ usage:
+- printf("Usage: dht-example [-q] [-4] [-6] [-i filename] [-b address]...\n"
+- " port [address port]...\n");
++ printf("Usage: dht-example [-q] [-4] [-6] [-i filename] [-b address] [-m]\n"
++ " port [address port]...\n"
++ "(Use -m if you wish to use MD5 digest instead of crypt()-based)");
+ exit(1);
+ }
+@@ -420,25 +433,28 @@
+ /* We need to provide a reasonably strong cryptographic hashing function.
+ Here's how we'd do it if we had RSA's MD5 code. */
+-#if 0
+-void
+-dht_hash(void *hash_return, int hash_size,
++static void
++md5_hash(void *hash_return, int hash_size,
+ const void *v1, int len1,
+ const void *v2, int len2,
+ const void *v3, int len3)
+ {
+- static MD5_CTX ctx;
++ MD5_CTX ctx;
+ MD5Init(&ctx);
+ MD5Update(&ctx, v1, len1);
+ MD5Update(&ctx, v2, len2);
+ MD5Update(&ctx, v3, len3);
+- MD5Final(&ctx);
+- if(hash_size > 16)
+- memset((char*)hash_return + 16, 0, hash_size - 16);
+- memcpy(hash_return, ctx.digest, hash_size > 16 ? 16 : hash_size);
++ if (hash_size >= 16) {
++ MD5Final(hash_return, &ctx);
++ if(hash_size > 16)
++ memset((char*)hash_return + 16, 0, hash_size - 16);
++ } else {
++ unsigned char digest[16];
++ MD5Final(digest, &ctx);
++ memcpy(hash_return, digest, hash_size);
++ }
+ }
+-#else
+ /* But for this example, we might as well use something weaker. */
+-void
+-dht_hash(void *hash_return, int hash_size,
++static void
++crypt_hash(void *hash_return, int hash_size,
+ const void *v1, int len1,
+ const void *v2, int len2,
+@@ -460,5 +476,14 @@
+ strncpy(hash_return, crypt(key, "jc"), hash_size);
+ }
+-#endif
++
++void
++dht_hash(void *hash_return, int hash_size,
++ const void *v1, int len1,
++ const void *v2, int len2,
++ const void *v3, int len3)
++{
++ hasher(hash_return, hash_size, v1, len1,
++ v2, len2, v3, len3);
++}
+
+ int
diff --git a/devel/jech-dht/pkg-plist b/devel/jech-dht/pkg-plist
index 5d87e1c05872..ecdf6081bf92 100644
--- a/devel/jech-dht/pkg-plist
+++ b/devel/jech-dht/pkg-plist
@@ -1,5 +1,6 @@
lib/libdht.so.0
lib/libdht.so
lib/libdht.a
+bin/dht-example
include/dht/dht.h
@dirrm include/dht