aboutsummaryrefslogtreecommitdiff
path: root/src/datacache
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-07-07 20:29:24 +0200
committerChristian Grothoff <christian@grothoff.org>2022-07-07 20:29:24 +0200
commit3abeb45550e1cbf4939583c9b6ff48335fe6f1a9 (patch)
treea653991a417cc0a683a95d3b61c67e26fb341486 /src/datacache
parent2906241b6a21d6009a0d195199f3a08e8f4d4e2a (diff)
downloadgnunet-3abeb45550e1cbf4939583c9b6ff48335fe6f1a9.tar.gz
gnunet-3abeb45550e1cbf4939583c9b6ff48335fe6f1a9.zip
implemented new DHT path signing with origin authentication
Diffstat (limited to 'src/datacache')
-rw-r--r--src/datacache/plugin_datacache_heap.c5
-rw-r--r--src/datacache/plugin_datacache_postgres.c30
-rw-r--r--src/datacache/plugin_datacache_sqlite.c17
-rw-r--r--src/datacache/test_datacache.c6
-rw-r--r--src/datacache/test_datacache_quota.c3
5 files changed, 42 insertions, 19 deletions
diff --git a/src/datacache/plugin_datacache_heap.c b/src/datacache/plugin_datacache_heap.c
index a2b60c8da..0dd8e47f8 100644
--- a/src/datacache/plugin_datacache_heap.c
+++ b/src/datacache/plugin_datacache_heap.c
@@ -196,10 +196,13 @@ heap_plugin_put (void *cls,
196 else 196 else
197 val->distance = xor_distance; 197 val->distance = xor_distance;
198 if (0 != block->put_path_length) 198 if (0 != block->put_path_length)
199 val->block.put_path 199 {
200 val->put_path
200 = GNUNET_memdup (block->put_path, 201 = GNUNET_memdup (block->put_path,
201 block->put_path_length 202 block->put_path_length
202 * sizeof (struct GNUNET_DHT_PathElement)); 203 * sizeof (struct GNUNET_DHT_PathElement));
204 val->block.put_path = val->put_path;
205 }
203 (void) GNUNET_CONTAINER_multihashmap_put (plugin->map, 206 (void) GNUNET_CONTAINER_multihashmap_put (plugin->map,
204 &val->block.key, 207 &val->block.key,
205 val, 208 val,
diff --git a/src/datacache/plugin_datacache_postgres.c b/src/datacache/plugin_datacache_postgres.c
index d9e25992b..b1f9a1b8e 100644
--- a/src/datacache/plugin_datacache_postgres.c
+++ b/src/datacache/plugin_datacache_postgres.c
@@ -71,11 +71,12 @@ init_connection (struct Plugin *plugin)
71 "CREATE TEMPORARY SEQUENCE IF NOT EXISTS gn180dc_oid_seq"), 71 "CREATE TEMPORARY SEQUENCE IF NOT EXISTS gn180dc_oid_seq"),
72 GNUNET_PQ_make_execute ("CREATE TEMPORARY TABLE IF NOT EXISTS gn180dc (" 72 GNUNET_PQ_make_execute ("CREATE TEMPORARY TABLE IF NOT EXISTS gn180dc ("
73 " oid OID NOT NULL DEFAULT nextval('gn180dc_oid_seq')," 73 " oid OID NOT NULL DEFAULT nextval('gn180dc_oid_seq'),"
74 " type INTEGER NOT NULL," 74 " type INT4 NOT NULL,"
75 " ro INTEGER NOT NULL," 75 " ro INT4 NOT NULL,"
76 " prox INTEGER NOT NULL," 76 " prox INT4 NOT NULL,"
77 " expiration_time BIGINT NOT NULL," 77 " expiration_time INT8 NOT NULL,"
78 " key BYTEA NOT NULL," 78 " key BYTEA NOT NULL CHECK(LENGTH(key)=64),"
79 " trunc BYTEA NOT NULL CHECK(LENGTH(trunc)=32),"
79 " value BYTEA NOT NULL," 80 " value BYTEA NOT NULL,"
80 " path BYTEA DEFAULT NULL)"), 81 " path BYTEA DEFAULT NULL)"),
81 GNUNET_PQ_make_try_execute ( 82 GNUNET_PQ_make_try_execute (
@@ -93,11 +94,11 @@ init_connection (struct Plugin *plugin)
93 }; 94 };
94 struct GNUNET_PQ_PreparedStatement ps[] = { 95 struct GNUNET_PQ_PreparedStatement ps[] = {
95 GNUNET_PQ_make_prepare ("getkt", 96 GNUNET_PQ_make_prepare ("getkt",
96 "SELECT expiration_time,type,ro,value,path FROM gn180dc " 97 "SELECT expiration_time,type,ro,value,trunc,path FROM gn180dc "
97 "WHERE key=$1 AND type=$2 AND expiration_time >= $3", 98 "WHERE key=$1 AND type=$2 AND expiration_time >= $3",
98 3), 99 3),
99 GNUNET_PQ_make_prepare ("getk", 100 GNUNET_PQ_make_prepare ("getk",
100 "SELECT expiration_time,type,ro,value,path FROM gn180dc " 101 "SELECT expiration_time,type,ro,value,trunc,path FROM gn180dc "
101 "WHERE key=$1 AND expiration_time >= $2", 102 "WHERE key=$1 AND expiration_time >= $2",
102 2), 103 2),
103 GNUNET_PQ_make_prepare ("getex", 104 GNUNET_PQ_make_prepare ("getex",
@@ -110,14 +111,14 @@ init_connection (struct Plugin *plugin)
110 " ORDER BY prox ASC, expiration_time ASC LIMIT 1", 111 " ORDER BY prox ASC, expiration_time ASC LIMIT 1",
111 0), 112 0),
112 GNUNET_PQ_make_prepare ("get_closest", 113 GNUNET_PQ_make_prepare ("get_closest",
113 "(SELECT expiration_time,type,ro,value,path,key FROM gn180dc" 114 "(SELECT expiration_time,type,ro,value,trunc,path,key FROM gn180dc"
114 " WHERE key >= $1" 115 " WHERE key >= $1"
115 " AND expiration_time >= $2" 116 " AND expiration_time >= $2"
116 " AND ( (type = $3) OR ( 0 = $3) )" 117 " AND ( (type = $3) OR ( 0 = $3) )"
117 " ORDER BY key ASC" 118 " ORDER BY key ASC"
118 " LIMIT $4)" 119 " LIMIT $4)"
119 " UNION " 120 " UNION "
120 "(SELECT expiration_time,type,ro,value,path,key FROM gn180dc" 121 "(SELECT expiration_time,type,ro,value,trunc,path,key FROM gn180dc"
121 " WHERE key <= $1" 122 " WHERE key <= $1"
122 " AND expiration_time >= $2" 123 " AND expiration_time >= $2"
123 " AND ( (type = $3) OR ( 0 = $3) )" 124 " AND ( (type = $3) OR ( 0 = $3) )"
@@ -129,9 +130,9 @@ init_connection (struct Plugin *plugin)
129 1), 130 1),
130 GNUNET_PQ_make_prepare ("put", 131 GNUNET_PQ_make_prepare ("put",
131 "INSERT INTO gn180dc" 132 "INSERT INTO gn180dc"
132 " (type, ro, prox, expiration_time, key, value, path) " 133 " (type, ro, prox, expiration_time, key, value, trunc, path) "
133 "VALUES ($1, $2, $3, $4, $5, $6, $7)", 134 "VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
134 7), 135 8),
135 GNUNET_PQ_PREPARED_STATEMENT_END 136 GNUNET_PQ_PREPARED_STATEMENT_END
136 }; 137 };
137 138
@@ -170,6 +171,7 @@ postgres_plugin_put (void *cls,
170 GNUNET_PQ_query_param_auto_from_type (&block->key), 171 GNUNET_PQ_query_param_auto_from_type (&block->key),
171 GNUNET_PQ_query_param_fixed_size (block->data, 172 GNUNET_PQ_query_param_fixed_size (block->data,
172 block->data_size), 173 block->data_size),
174 GNUNET_PQ_query_param_auto_from_type (&block->trunc_peer),
173 GNUNET_PQ_query_param_fixed_size (block->put_path, 175 GNUNET_PQ_query_param_fixed_size (block->put_path,
174 block->put_path_length 176 block->put_path_length
175 * sizeof(struct GNUNET_DHT_PathElement)), 177 * sizeof(struct GNUNET_DHT_PathElement)),
@@ -243,6 +245,8 @@ handle_results (void *cls,
243 GNUNET_PQ_result_spec_variable_size ("value", 245 GNUNET_PQ_result_spec_variable_size ("value",
244 &data, 246 &data,
245 &block.data_size), 247 &block.data_size),
248 GNUNET_PQ_result_spec_auto_from_type ("trunc",
249 &block.trunc_peer),
246 GNUNET_PQ_result_spec_variable_size ("path", 250 GNUNET_PQ_result_spec_variable_size ("path",
247 &path, 251 &path,
248 &path_size), 252 &path_size),
@@ -465,6 +469,8 @@ extract_result_cb (void *cls,
465 GNUNET_PQ_result_spec_variable_size ("value", 469 GNUNET_PQ_result_spec_variable_size ("value",
466 &data, 470 &data,
467 &block.data_size), 471 &block.data_size),
472 GNUNET_PQ_result_spec_auto_from_type ("trunc",
473 &block.trunc_peer),
468 GNUNET_PQ_result_spec_variable_size ("path", 474 GNUNET_PQ_result_spec_variable_size ("path",
469 &path, 475 &path,
470 &path_size), 476 &path_size),
diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c
index 22ae5c0f5..0753d87ce 100644
--- a/src/datacache/plugin_datacache_sqlite.c
+++ b/src/datacache/plugin_datacache_sqlite.c
@@ -207,6 +207,7 @@ sqlite_plugin_put (void *cls,
207 GNUNET_SQ_query_param_fixed_size (block->put_path, 207 GNUNET_SQ_query_param_fixed_size (block->put_path,
208 block->put_path_length 208 block->put_path_length
209 * sizeof(struct GNUNET_DHT_PathElement)), 209 * sizeof(struct GNUNET_DHT_PathElement)),
210 GNUNET_SQ_query_param_auto_from_type (&block->trunc_peer),
210 GNUNET_SQ_query_param_end 211 GNUNET_SQ_query_param_end
211 }; 212 };
212 213
@@ -290,6 +291,7 @@ get_any (void *cls,
290 GNUNET_SQ_result_spec_absolute_time (&block.expiration_time), 291 GNUNET_SQ_result_spec_absolute_time (&block.expiration_time),
291 GNUNET_SQ_result_spec_variable_size (&path, 292 GNUNET_SQ_result_spec_variable_size (&path,
292 &path_size), 293 &path_size),
294 GNUNET_SQ_result_spec_auto_from_type (&block.trunc_peer),
293 GNUNET_SQ_result_spec_uint32 (&btype32), 295 GNUNET_SQ_result_spec_uint32 (&btype32),
294 GNUNET_SQ_result_spec_uint32 (&bro32), 296 GNUNET_SQ_result_spec_uint32 (&bro32),
295 GNUNET_SQ_result_spec_end 297 GNUNET_SQ_result_spec_end
@@ -451,6 +453,7 @@ get_typed (void *cls,
451 GNUNET_SQ_result_spec_absolute_time (&block.expiration_time), 453 GNUNET_SQ_result_spec_absolute_time (&block.expiration_time),
452 GNUNET_SQ_result_spec_variable_size (&path, 454 GNUNET_SQ_result_spec_variable_size (&path,
453 &path_size), 455 &path_size),
456 GNUNET_SQ_result_spec_auto_from_type (&block.trunc_peer),
454 GNUNET_SQ_result_spec_uint32 (&bro32), 457 GNUNET_SQ_result_spec_uint32 (&bro32),
455 GNUNET_SQ_result_spec_end 458 GNUNET_SQ_result_spec_end
456 }; 459 };
@@ -749,6 +752,7 @@ sqlite_plugin_get_closest (void *cls,
749 GNUNET_SQ_result_spec_absolute_time (&block.expiration_time), 752 GNUNET_SQ_result_spec_absolute_time (&block.expiration_time),
750 GNUNET_SQ_result_spec_variable_size (&path, 753 GNUNET_SQ_result_spec_variable_size (&path,
751 &path_size), 754 &path_size),
755 GNUNET_SQ_result_spec_auto_from_type (&block.trunc_peer),
752 GNUNET_SQ_result_spec_uint32 (&rtype32), 756 GNUNET_SQ_result_spec_uint32 (&rtype32),
753 GNUNET_SQ_result_spec_uint32 (&bro32), 757 GNUNET_SQ_result_spec_uint32 (&bro32),
754 GNUNET_SQ_result_spec_auto_from_type (&block.key), 758 GNUNET_SQ_result_spec_auto_from_type (&block.key),
@@ -882,6 +886,7 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
882 " key BLOB NOT NULL DEFAULT ''," 886 " key BLOB NOT NULL DEFAULT '',"
883 " prox INTEGER NOT NULL," 887 " prox INTEGER NOT NULL,"
884 " value BLOB NOT NULL," 888 " value BLOB NOT NULL,"
889 " trunc BLOB NOT NULL,"
885 " path BLOB DEFAULT '')"); 890 " path BLOB DEFAULT '')");
886 SQLITE3_EXEC (dbh, 891 SQLITE3_EXEC (dbh,
887 "CREATE INDEX idx_hashidx" 892 "CREATE INDEX idx_hashidx"
@@ -900,8 +905,8 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
900 if ((SQLITE_OK != 905 if ((SQLITE_OK !=
901 sq_prepare (plugin->dbh, 906 sq_prepare (plugin->dbh,
902 "INSERT INTO ds180" 907 "INSERT INTO ds180"
903 " (type, ro, expire, key, prox, value, path)" 908 " (type, ro, expire, key, prox, value, path, trunc)"
904 " VALUES (?, ?, ?, ?, ?, ?, ?)", 909 " VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
905 &plugin->insert_stmt)) || 910 &plugin->insert_stmt)) ||
906 (SQLITE_OK != 911 (SQLITE_OK !=
907 sq_prepare (plugin->dbh, 912 sq_prepare (plugin->dbh,
@@ -917,7 +922,7 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
917 &plugin->get_count_any_stmt)) || 922 &plugin->get_count_any_stmt)) ||
918 (SQLITE_OK != 923 (SQLITE_OK !=
919 sq_prepare (plugin->dbh, 924 sq_prepare (plugin->dbh,
920 "SELECT value,expire,path,ro" 925 "SELECT value,expire,path,trunc,ro"
921 " FROM ds180" 926 " FROM ds180"
922 " WHERE key=?" 927 " WHERE key=?"
923 " AND type=?" 928 " AND type=?"
@@ -926,7 +931,7 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
926 &plugin->get_stmt)) || 931 &plugin->get_stmt)) ||
927 (SQLITE_OK != 932 (SQLITE_OK !=
928 sq_prepare (plugin->dbh, 933 sq_prepare (plugin->dbh,
929 "SELECT value,expire,path,type,ro" 934 "SELECT value,expire,path,trunc,type,ro"
930 " FROM ds180" 935 " FROM ds180"
931 " WHERE key=?" 936 " WHERE key=?"
932 " AND expire >= ?" 937 " AND expire >= ?"
@@ -950,7 +955,7 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
950 (SQLITE_OK != 955 (SQLITE_OK !=
951 sq_prepare (plugin->dbh, 956 sq_prepare (plugin->dbh,
952 "SELECT * FROM (" 957 "SELECT * FROM ("
953 " SELECT value,expire,path,type,ro,key" 958 " SELECT value,expire,path,trunc,type,ro,key"
954 " FROM ds180 " 959 " FROM ds180 "
955 " WHERE key>=?1 " 960 " WHERE key>=?1 "
956 " AND expire >= ?2" 961 " AND expire >= ?2"
@@ -958,7 +963,7 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
958 " ORDER BY KEY ASC LIMIT ?4)" 963 " ORDER BY KEY ASC LIMIT ?4)"
959 "UNION " 964 "UNION "
960 "SELECT * FROM (" 965 "SELECT * FROM ("
961 " SELECT value,expire,path,type,ro,key" 966 " SELECT value,expire,path,trunc,type,ro,key"
962 " FROM ds180 " 967 " FROM ds180 "
963 " WHERE key<=?1 " 968 " WHERE key<=?1 "
964 " AND expire >= ?2" 969 " AND expire >= ?2"
diff --git a/src/datacache/test_datacache.c b/src/datacache/test_datacache.c
index b5d978995..fd5a5f54c 100644
--- a/src/datacache/test_datacache.c
+++ b/src/datacache/test_datacache.c
@@ -97,6 +97,9 @@ run (void *cls,
97 block.key = k; 97 block.key = k;
98 block.data = &n; 98 block.data = &n;
99 block.data_size = sizeof (n); 99 block.data_size = sizeof (n);
100 memset (&block.trunc_peer,
101 43,
102 sizeof (block.trunc_peer));
100 block.ro = 42; 103 block.ro = 42;
101 block.type = (enum GNUNET_BLOCK_Type) (1 + i % 16); 104 block.type = (enum GNUNET_BLOCK_Type) (1 + i % 16);
102 block.put_path = NULL; 105 block.put_path = NULL;
@@ -134,6 +137,9 @@ run (void *cls,
134 block.data = &n; 137 block.data = &n;
135 block.data_size = sizeof (n); 138 block.data_size = sizeof (n);
136 block.ro = 42; 139 block.ro = 42;
140 memset (&block.trunc_peer,
141 44,
142 sizeof (block.trunc_peer));
137 block.type = (enum GNUNET_BLOCK_Type) 792; 143 block.type = (enum GNUNET_BLOCK_Type) 792;
138 block.put_path = NULL; 144 block.put_path = NULL;
139 block.put_path_length = 0; 145 block.put_path_length = 0;
diff --git a/src/datacache/test_datacache_quota.c b/src/datacache/test_datacache_quota.c
index 0b647ee99..994147a64 100644
--- a/src/datacache/test_datacache_quota.c
+++ b/src/datacache/test_datacache_quota.c
@@ -92,6 +92,9 @@ run (void *cls,
92 block.key = k; 92 block.key = k;
93 block.data = buf; 93 block.data = buf;
94 block.data_size = j; 94 block.data_size = j;
95 memset (&block.trunc_peer,
96 43,
97 sizeof (block.trunc_peer));
95 block.ro = 42; 98 block.ro = 42;
96 block.type = (enum GNUNET_BLOCK_Type) (1 + i); 99 block.type = (enum GNUNET_BLOCK_Type) (1 + i);
97 block.put_path = NULL; 100 block.put_path = NULL;