FS-10165: Removed dependancy and autoconf check for libsodium from libks. Moved DHT, bencode, and related tests into libblade. Still requires refactoring in blade from ks_* to blade_*.

This commit is contained in:
Shane Bryldt committed 2017-03-22 17:47:33 -05:00
1 parent 716f02897a
commit 5cff01b2a8
28 files changed
+48 -59

No files matched your search

+6
View File
@@ -16,15 +16,21 @@ libblade_la_SOURCES += src/blade_datastore.c
libblade_la_SOURCES += src/blade_identity.c src/blade_module.c src/blade_connection.c
libblade_la_SOURCES += src/blade_session.c src/blade_protocol.c src/blade_space.c src/blade_method.c
libblade_la_SOURCES += src/blade_module_wss.c src/blade_module_chat.c
libblade_la_SOURCES += src/dht/ks_dht.c src/dht/ks_dht_datagram.c src/dht/ks_dht_endpoint.c src/dht/ks_dht_message.c src/dht/ks_dht_transaction.c
libblade_la_SOURCES += src/dht/ks_dht_job.c src/dht/ks_dht_search.c src/dht/ks_dht_publish.c src/dht/ks_dht_distribute.c src/dht/ks_dht_storageitem.c
libblade_la_SOURCES += src/dht/ks_dht_bucket.c src/ks_bencode.c
libblade_la_CFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS)
libblade_la_LDFLAGS = -version-info 0:1:0 -lncurses -lpthread -lm -lconfig $(AM_LDFLAGS)
libblade_la_LIBADD = libunqlite.la
library_includedir = $(prefix)/include
library_include_HEADERS = src/include/blade.h src/include/blade_types.h src/include/blade_stack.h
library_include_HEADERS += src/include/blade_datastore.h
library_include_HEADERS += src/include/blade_identity.h src/include/blade_module.h src/include/blade_connection.h
library_include_HEADERS += src/include/blade_session.h src/include/blade_protocol.h src/include/blade_space.h src/include/blade_method.h
library_include_HEADERS += src/include/unqlite.h test/tap.h
library_include_HEADERS += src/include/ks_dht.h src/include/ks_bencode.h
tests: libblade.la
$(MAKE) -C test tests
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+2
View File
@@ -48,6 +48,8 @@
#include "blade_datastore.h"
#include "blade_space.h"
#include "blade_method.h"
#include "ks_dht.h"
#include "ks_bencode.h"
KS_BEGIN_EXTERN_C
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -19,7 +19,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
*/
#include <ks.h>
#include <blade.h>
#include <stdlib.h>
#include <stdio.h>
@@ -350,7 +350,7 @@ struct bencode *ben_clone(const struct bencode *b)
return clone_str(ben_str_const_cast(b));
default:
die("Invalid type %c\n", b->type);
}
}
}
struct bencode *ben_shared_clone(const struct bencode *b)
@@ -549,7 +549,7 @@ static int resize_dict(struct bencode_dict *d, size_t newalloc)
assert(x >= newalloc);
newalloc = x;
if (newalloc > DICT_MAX_ALLOC)
return -1;
return -1;
}
/* size must be a power of two */
@@ -619,7 +619,7 @@ long long ben_hash(const struct bencode *b)
return ben_str_hash(b);
default:
die("hash: Invalid type: %d\n", b->type);
}
}
}
static struct bencode *decode_dict(struct ben_decode_ctx *ctx)
@@ -938,7 +938,7 @@ static struct bencode *decode_printed_bool(struct ben_decode_ctx *ctx)
struct bencode *b;
int bval = -1;
if (try_match(ctx, "True")) {
if (try_match(ctx, "True")) {
if (ben_need_bytes(ctx, 4))
return ben_insufficient_ptr(ctx);
} else {
@@ -1868,7 +1868,7 @@ static void dict_unlink(struct bencode_dict *d, size_t bucket, size_t unlinkpos)
}
/* Remove node from the linked list, if found */
static struct bencode *dict_pop(struct bencode_dict *d,
static struct bencode *dict_pop(struct bencode_dict *d,
const struct bencode *key, long long hash)
{
struct bencode *value;
+15
View File
@@ -18,6 +18,21 @@ blades_SOURCES = blades.c tap.c
blades_CFLAGS = $(AM_CFLAGS)
blades_LDADD = $(TEST_LDADD)
check_PROGRAMS += testdht2
testdht2_SOURCES = testdht2.c tap.c
testdht2_CFLAGS = $(AM_CFLAGS)
testdht2_LDADD = $(TEST_LDADD)
check_PROGRAMS += testbuckets
testbuckets_SOURCES = testbuckets.c tap.c
testbuckets_CFLAGS = $(AM_CFLAGS)
testbuckets_LDADD = $(TEST_LDADD)
check_PROGRAMS += nodeidgen
nodeidgen_SOURCES = nodeidgen.c tap.c
nodeidgen_CFLAGS = $(AM_CFLAGS)
nodeidgen_LDADD = $(TEST_LDADD)
TESTS=$(check_PROGRAMS)
File renamed without changes.
File renamed without changes.
File renamed without changes.
+3 -6
View File
@@ -9,13 +9,10 @@ AM_CPPFLAGS = $(AM_CFLAGS)
lib_LTLIBRARIES = libks.la
libks_la_SOURCES = src/ks.c src/ks_string.c src/ks_json.c src/cJSON.c src/cJSON_Utils.c src/ks_thread.c src/ks_thread_pool.c src/ks_mutex.c src/ks_config.c
libks_la_SOURCES += src/ks_log.c src/ks_socket.c src/ks_buffer.c src/ks_pool.c src/simclist.c
libks_la_SOURCES += src/ks_time.c src/ks_printf.c src/ks_hash.c src/ks_q.c src/ks_dso.c # src/ks_dht.c
libks_la_SOURCES += src/ks_time.c src/ks_printf.c src/ks_hash.c src/ks_q.c src/ks_dso.c
libks_la_SOURCES += src/ks_ssl.c src/kws.c src/ks_rng.c src/ks_base64.c
libks_la_SOURCES += src/utp/utp_api.cpp src/utp/utp_callbacks.cpp src/utp/utp_hash.cpp src/utp/utp_internal.cpp
libks_la_SOURCES += src/utp/utp_packedsockaddr.cpp src/utp/utp_utils.cpp src/ks_bencode.c
libks_la_SOURCES += src/dht/ks_dht.c src/dht/ks_dht_datagram.c src/dht/ks_dht_endpoint.c src/dht/ks_dht_message.c src/dht/ks_dht_transaction.c
libks_la_SOURCES += src/dht/ks_dht_job.c src/dht/ks_dht_search.c src/dht/ks_dht_publish.c src/dht/ks_dht_distribute.c src/dht/ks_dht_storageitem.c
libks_la_SOURCES += src/dht/ks_dht_bucket.c
libks_la_SOURCES += src/utp/utp_packedsockaddr.cpp src/utp/utp_utils.cpp
libks_la_SOURCES += crypt/aeskey.c crypt/aestab.c crypt/sha2.c crypt/twofish.c crypt/aes_modes.c crypt/aescrypt.c crypt/twofish_cfb.c
#aes.h aescpp.h brg_endian.h aesopt.h aestab.h brg_types.h sha2.h twofish.h
libks_la_SOURCES += src/ks_acl.c
@@ -28,7 +25,7 @@ library_includedir = $(prefix)/include
library_include_HEADERS = src/include/ks_config.h src/include/ks.h src/include/ks_threadmutex.h src/include/ks_json.h src/include/ks_buffer.h
library_include_HEADERS += src/include/ks_thread_pool.h src/include/ks_cJSON.h src/include/ks_cJSON_Utils.h
library_include_HEADERS += src/include/ks_pool.h src/include/simclist.h src/include/ks_time.h src/include/ks_q.h src/include/ks_socket.h
library_include_HEADERS += src/include/ks_dso.h src/include/ks_platform.h src/include/ks_types.h # src/include/ks_rng.h src/include/ks_dht.h
library_include_HEADERS += src/include/ks_dso.h src/include/ks_platform.h src/include/ks_types.h src/include/ks_rng.h
library_include_HEADERS += src/include/ks_printf.h src/include/ks_hash.h src/include/ks_ssl.h src/include/kws.h
library_include_HEADERS += src/include/ks_base64.h
library_include_HEADERS += src/utp/utp_internal.h src/utp/utp.h src/utp/utp_types.h src/utp/utp_callbacks.h src/utp/utp_templates.h
-1
View File
@@ -242,7 +242,6 @@ if test "${enable_address_sanitizer}" = "yes"; then
AM_LDFLAGS="${AM_LDFLAGS} -fsanitize=address"
fi
PKG_CHECK_MODULES([SODIUM], [libsodium >= 1.0.0],[AC_MSG_RESULT([yes])],[AC_MSG_ERROR([libsodium is required])])
PKG_CHECK_MODULES([UUID], [uuid >= 1.0.0],[AC_MSG_RESULT([yes])],[AC_MSG_ERROR([libuuid is required])])
AM_CFLAGS="${AM_CFLAGS} -Werror ${SODIUM_CFLAGS} ${UUID_CFLAGS}"
-2
View File
@@ -131,12 +131,10 @@ KS_DECLARE(void) ks_random_string(char *buf, uint16_t len, char *set);
#include "ks_time.h"
#include "ks_socket.h"
#include "ks_dso.h"
//#include "ks_dht.h"
#include "ks_utp.h"
#include "simclist.h"
#include "ks_ssl.h"
#include "kws.h"
#include "ks_bencode.h"
#include "ks_rng.h"
#include "ks_acl.h"
#include "ks_base64.h"
+3 -18
View File
@@ -18,7 +18,6 @@
*/
#include "ks.h"
#include "sodium.h"
#include <aes.h>
#include <sha2.h>
@@ -40,7 +39,7 @@ int fd = -1;
* memset(buf, val, len), but the use of a volatile pointer
* guarantees that the compiler will not optimise the call away.
*/
//static void * (*volatile memset_volatile)(void *, int, size_t) = memset;
static void * (*volatile memset_volatile)(void *, int, size_t) = memset;
KS_DECLARE(uuid_t *) ks_uuid(uuid_t *uuid)
{
@@ -71,16 +70,12 @@ KS_DECLARE(char *) ks_uuid_str(ks_pool_t *pool, uuid_t *uuid)
KS_DECLARE(ks_status_t) ks_rng_init(void)
{
if (!initialized) {
if (sodium_init() == -1) {
abort();
}
randombytes_random();
ks_aes_init();
ks_mutex_create(&rng_mutex, KS_MUTEX_FLAG_DEFAULT, ks_global_pool());
#ifdef __WINDOWS__
if (!crypt_provider) {
if (!crypt_provider) {
if (CryptAcquireContext(&crypt_provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT) == TRUE) {
initialized = KS_TRUE;
} else {
@@ -174,14 +169,6 @@ KS_DECLARE(size_t) ks_rng_add_entropy(const uint8_t *buffer, size_t length)
return length;
}
KS_DECLARE(size_t) ks_rng_get_data(uint8_t* buffer, size_t length) {
randombytes_buf(buffer, length);
return length;
}
#if 0
KS_DECLARE(size_t) ks_rng_get_data(uint8_t* buffer, size_t length) {
aes_encrypt_ctx cx[1];
@@ -237,8 +224,6 @@ KS_DECLARE(size_t) ks_rng_get_data(uint8_t* buffer, size_t length) {
return generated;
}
#endif
/* For Emacs:
* Local Variables:
* mode:c
-15
View File
@@ -4,11 +4,6 @@ check_PROGRAMS =
EXTRA_DIST = tap.h
check_PROGRAMS += testbuckets
testbuckets_SOURCES = testbuckets.c tap.c
testbuckets_CFLAGS = $(AM_CFLAGS)
testbuckets_LDADD = $(TEST_LDADD)
check_PROGRAMS += testpools
testpools_SOURCES = testpools.c tap.c
testpools_CFLAGS = $(AM_CFLAGS)
@@ -64,16 +59,6 @@ testwebsock_LDADD = $(TEST_LDADD)
#testdht_CFLAGS = $(AM_CFLAGS)
#testdht_LDADD = $(TEST_LDADD)
check_PROGRAMS += testdht2
testdht2_SOURCES = testdht2.c tap.c
testdht2_CFLAGS = $(AM_CFLAGS)
testdht2_LDADD = $(TEST_LDADD)
check_PROGRAMS += nodeidgen
nodeidgen_SOURCES = nodeidgen.c tap.c
nodeidgen_CFLAGS = $(AM_CFLAGS)
nodeidgen_LDADD = $(TEST_LDADD)
#check_PROGRAMS += testdht_net
#testdht_net_SOURCES = testdht-net.c tap.c
#testdht_net_CFLAGS = $(AM_CFLAGS)
+13 -11
View File
@@ -18,7 +18,7 @@ int test1(void)
}
ks_hash_iterator_t *itt;
ks_hash_write_lock(hash);
@@ -53,9 +53,9 @@ static void *test2_thread(ks_thread_t *thread, void *data)
for (itt = ks_hash_first(hash, KS_READLOCKED); itt; itt = ks_hash_next(&itt)) {
const void *key;
void *val;
ks_hash_this(itt, &key, NULL, &val);
printf("%p ITT %s=%s\n", (void *)(intptr_t)ks_thread_self(), (char *)key, (char *)val);
}
ks_sleep(100000);
@@ -81,7 +81,7 @@ int test2(void)
for (i = 0; i < ttl; i++) {
ks_thread_create(&threads[i], test2_thread, hash, pool);
}
for(i = 0; i < runs; i++) {
int x = rand() % 5;
int j;
@@ -93,21 +93,21 @@ int test2(void)
}
ks_sleep(x * 1000000);
ks_hash_write_lock(hash);
for (itt = ks_hash_first(hash, KS_UNLOCKED); itt; itt = ks_hash_next(&itt)) {
const void *key;
void *val;
ks_hash_this(itt, &key, NULL, &val);
printf("DEL %s=%s\n", (char *)key, (char *)val);
ks_hash_remove(hash, (char *)key);
}
ks_hash_write_unlock(hash);
}
for (i = 0; i < ttl; i++) {
threads[i]->running = 0;
ks_thread_join(threads[i]);
@@ -135,8 +135,10 @@ int test3(void)
ks_hash_create(&hash, KS_HASH_MODE_ARBITRARY, KS_HASH_FLAG_NOLOCK, pool);
ks_hash_set_keysize(hash, TEST3_SIZE);
randombytes_buf(data, sizeof(data));
randombytes_buf(data2, sizeof(data2));
ks_rng_get_data(data, sizeof(data));
ks_rng_get_data(data2, sizeof(data));
//randombytes_buf(data, sizeof(data));
//randombytes_buf(data2, sizeof(data2));
ks_hash_insert(hash, data, "FOO");
ks_hash_insert(hash, data2, "BAR");
@@ -155,7 +157,7 @@ int test3(void)
ks_pool_close(&pool);
return !strcmp(A, "FOO") && !strcmp(B, "BAR") && !strcmp(C, "BAZ");
}