summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2020-02-12 22:31:17 +0100
committerSander Vrijders <sander@ouroboros.rocks>2020-02-16 18:19:59 +0100
commit71eeedd1a05d5dd200c77527ea15086bf43e1a26 (patch)
treede384011e90f0048f47c0a1b932f028dbff34bc5 /src
parenta63edb8e9d3ba5eef03c1bbb454522ea7b369087 (diff)
downloadouroboros-71eeedd1a05d5dd200c77527ea15086bf43e1a26.tar.gz
ouroboros-71eeedd1a05d5dd200c77527ea15086bf43e1a26.zip
lib: Move hashtable from lib to unicast
The hashtable is only used for forwarding tables in the unicast IPCP. This moves the generic hashtable out of the library into the unicast IPCP to prepare a more tailored implementation specific to routing tables containing address lists. Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks> Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'src')
-rw-r--r--src/ipcpd/unicast/CMakeLists.txt1
-rw-r--r--src/ipcpd/unicast/pol/alternate_pff.c2
-rw-r--r--src/ipcpd/unicast/pol/hashtable.c (renamed from src/lib/hashtable.c)21
-rw-r--r--src/ipcpd/unicast/pol/hashtable.h55
-rw-r--r--src/ipcpd/unicast/pol/simple_pff.c2
-rw-r--r--src/ipcpd/unicast/pol/tests/CMakeLists.txt1
-rw-r--r--src/ipcpd/unicast/pol/tests/hashtable_test.c (renamed from src/lib/tests/hashtable_test.c)0
-rw-r--r--src/lib/CMakeLists.txt1
-rw-r--r--src/lib/tests/CMakeLists.txt1
9 files changed, 70 insertions, 14 deletions
diff --git a/src/ipcpd/unicast/CMakeLists.txt b/src/ipcpd/unicast/CMakeLists.txt
index c9344f89..192b6592 100644
--- a/src/ipcpd/unicast/CMakeLists.txt
+++ b/src/ipcpd/unicast/CMakeLists.txt
@@ -44,6 +44,7 @@ set(SOURCE_FILES
routing.c
psched.c
# Add policies last
+ pol/hashtable.c
pol/alternate_pff.c
pol/flat.c
pol/link_state.c
diff --git a/src/ipcpd/unicast/pol/alternate_pff.c b/src/ipcpd/unicast/pol/alternate_pff.c
index 131bc2d7..36d8d513 100644
--- a/src/ipcpd/unicast/pol/alternate_pff.c
+++ b/src/ipcpd/unicast/pol/alternate_pff.c
@@ -24,7 +24,6 @@
#include "config.h"
-#include <ouroboros/hashtable.h>
#include <ouroboros/errno.h>
#include <ouroboros/list.h>
@@ -32,6 +31,7 @@
#include <assert.h>
#include <pthread.h>
+#include "hashtable.h"
#include "alternate_pff.h"
struct nhop {
diff --git a/src/lib/hashtable.c b/src/ipcpd/unicast/pol/hashtable.c
index ffff1d73..596219f3 100644
--- a/src/lib/hashtable.c
+++ b/src/ipcpd/unicast/pol/hashtable.c
@@ -1,22 +1,22 @@
/*
* Ouroboros - Copyright (C) 2016 - 2020
*
- * Hash table with separate chaining on collisions
+ * Hash table with integer keys with separate chaining on collisions
*
* Dimitri Staessens <dimitri.staessens@ugent.be>
* Sander Vrijders <sander.vrijders@ugent.be>
*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * version 2.1 as published by the Free Software Foundation.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
*
- * This library is distributed in the hope that it will be useful,
+ * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
* Foundation, Inc., http://www.fsf.org/about/contact/.
*/
@@ -24,11 +24,12 @@
#define _DEFAULT_SOURCE
#endif
-#include <ouroboros/hashtable.h>
#include <ouroboros/list.h>
#include <ouroboros/errno.h>
#include <ouroboros/hash.h>
+#include "hashtable.h"
+
#include <assert.h>
#include <string.h>
diff --git a/src/ipcpd/unicast/pol/hashtable.h b/src/ipcpd/unicast/pol/hashtable.h
new file mode 100644
index 00000000..b6a36180
--- /dev/null
+++ b/src/ipcpd/unicast/pol/hashtable.h
@@ -0,0 +1,55 @@
+/*
+ * Ouroboros - Copyright (C) 2016 - 2020
+ *
+* Hash table with integer keys with separate chaining on collisions
+ *
+ * Dimitri Staessens <dimitri.staessens@ugent.be>
+ * Sander Vrijders <sander.vrijders@ugent.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., http://www.fsf.org/about/contact/.
+ */
+
+#ifndef OUROBOROS_HASHTABLE_H
+#define OUROBOROS_HASHTABLE_H
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdlib.h>
+
+struct htable;
+
+/* Buckets is rounded up to the nearest power of 2 */
+struct htable * htable_create(uint64_t buckets,
+ bool hash_key);
+
+void htable_destroy(struct htable * table);
+
+void htable_flush(struct htable * table);
+
+/* Passes ownership of the block of memory */
+int htable_insert(struct htable * table,
+ uint64_t key,
+ void * val,
+ size_t len);
+
+/* The block of memory returned is no copy */
+int htable_lookup(struct htable * table,
+ uint64_t key,
+ void ** val,
+ size_t * len);
+
+int htable_delete(struct htable * table,
+ uint64_t key);
+
+#endif /* OUROBOROS_HASHTABLE_H */
diff --git a/src/ipcpd/unicast/pol/simple_pff.c b/src/ipcpd/unicast/pol/simple_pff.c
index c34a4fdc..3d294d90 100644
--- a/src/ipcpd/unicast/pol/simple_pff.c
+++ b/src/ipcpd/unicast/pol/simple_pff.c
@@ -24,12 +24,12 @@
#include "config.h"
-#include <ouroboros/hashtable.h>
#include <ouroboros/errno.h>
#include <assert.h>
#include <pthread.h>
+#include "hashtable.h"
#include "simple_pff.h"
struct pff_i {
diff --git a/src/ipcpd/unicast/pol/tests/CMakeLists.txt b/src/ipcpd/unicast/pol/tests/CMakeLists.txt
index d0652533..86c2d948 100644
--- a/src/ipcpd/unicast/pol/tests/CMakeLists.txt
+++ b/src/ipcpd/unicast/pol/tests/CMakeLists.txt
@@ -18,6 +18,7 @@ get_filename_component(PARENT_DIR ${PARENT_PATH} NAME)
create_test_sourcelist(${PARENT_DIR}_tests test_suite.c
# Add new tests here
graph_test.c
+ hashtable_test.c
)
add_executable(${PARENT_DIR}_test EXCLUDE_FROM_ALL ${${PARENT_DIR}_tests})
diff --git a/src/lib/tests/hashtable_test.c b/src/ipcpd/unicast/pol/tests/hashtable_test.c
index f84fee63..f84fee63 100644
--- a/src/lib/tests/hashtable_test.c
+++ b/src/ipcpd/unicast/pol/tests/hashtable_test.c
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 8dbedcff..c5be9946 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -202,7 +202,6 @@ set(SOURCE_FILES_COMMON
btree.c
crc32.c
hash.c
- hashtable.c
list.c
lockfile.c
logs.c
diff --git a/src/lib/tests/CMakeLists.txt b/src/lib/tests/CMakeLists.txt
index c887626a..9e23b0ee 100644
--- a/src/lib/tests/CMakeLists.txt
+++ b/src/lib/tests/CMakeLists.txt
@@ -6,7 +6,6 @@ create_test_sourcelist(${PARENT_DIR}_tests test_suite.c
bitmap_test.c
btree_test.c
crc32_test.c
- hashtable_test.c
md5_test.c
sha3_test.c
shm_rbuff_test.c