diff options
Diffstat (limited to 'src/namecache/plugin_namecache_postgres.c')
-rw-r--r-- | src/namecache/plugin_namecache_postgres.c | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/src/namecache/plugin_namecache_postgres.c b/src/namecache/plugin_namecache_postgres.c index 0e947e9c5..ae0f71a1f 100644 --- a/src/namecache/plugin_namecache_postgres.c +++ b/src/namecache/plugin_namecache_postgres.c | |||
@@ -64,15 +64,13 @@ database_setup (struct Plugin *plugin) | |||
64 | " query BYTEA NOT NULL DEFAULT ''," | 64 | " query BYTEA NOT NULL DEFAULT ''," |
65 | " block BYTEA NOT NULL DEFAULT ''," | 65 | " block BYTEA NOT NULL DEFAULT ''," |
66 | " expiration_time BIGINT NOT NULL DEFAULT 0" | 66 | " expiration_time BIGINT NOT NULL DEFAULT 0" |
67 | ")" | 67 | ")"); |
68 | "WITH OIDS"); | ||
69 | struct GNUNET_PQ_ExecuteStatement es_default = | 68 | struct GNUNET_PQ_ExecuteStatement es_default = |
70 | GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS ns096blocks (" | 69 | GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS ns096blocks (" |
71 | " query BYTEA NOT NULL DEFAULT ''," | 70 | " query BYTEA NOT NULL DEFAULT ''," |
72 | " block BYTEA NOT NULL DEFAULT ''," | 71 | " block BYTEA NOT NULL DEFAULT ''," |
73 | " expiration_time BIGINT NOT NULL DEFAULT 0" | 72 | " expiration_time BIGINT NOT NULL DEFAULT 0" |
74 | ")" | 73 | ")"); |
75 | "WITH OIDS"); | ||
76 | const struct GNUNET_PQ_ExecuteStatement *cr; | 74 | const struct GNUNET_PQ_ExecuteStatement *cr; |
77 | 75 | ||
78 | if (GNUNET_YES == | 76 | if (GNUNET_YES == |
@@ -155,11 +153,11 @@ namecache_postgres_expire_blocks (struct Plugin *plugin) | |||
155 | static void | 153 | static void |
156 | delete_old_block (struct Plugin *plugin, | 154 | delete_old_block (struct Plugin *plugin, |
157 | const struct GNUNET_HashCode *query, | 155 | const struct GNUNET_HashCode *query, |
158 | struct GNUNET_TIME_AbsoluteNBO expiration_time) | 156 | struct GNUNET_TIME_Absolute expiration_time) |
159 | { | 157 | { |
160 | struct GNUNET_PQ_QueryParam params[] = { | 158 | struct GNUNET_PQ_QueryParam params[] = { |
161 | GNUNET_PQ_query_param_auto_from_type (query), | 159 | GNUNET_PQ_query_param_auto_from_type (query), |
162 | GNUNET_PQ_query_param_absolute_time_nbo (&expiration_time), | 160 | GNUNET_PQ_query_param_absolute_time (&expiration_time), |
163 | GNUNET_PQ_query_param_end | 161 | GNUNET_PQ_query_param_end |
164 | }; | 162 | }; |
165 | enum GNUNET_DB_QueryStatus res; | 163 | enum GNUNET_DB_QueryStatus res; |
@@ -184,21 +182,20 @@ namecache_postgres_cache_block (void *cls, | |||
184 | { | 182 | { |
185 | struct Plugin *plugin = cls; | 183 | struct Plugin *plugin = cls; |
186 | struct GNUNET_HashCode query; | 184 | struct GNUNET_HashCode query; |
187 | size_t block_size = ntohl (block->purpose.size) | 185 | size_t block_size = GNUNET_GNSRECORD_block_get_size (block); |
188 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | 186 | struct GNUNET_TIME_Absolute exp; |
189 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature); | 187 | exp = GNUNET_GNSRECORD_block_get_expiration (block); |
190 | struct GNUNET_PQ_QueryParam params[] = { | 188 | struct GNUNET_PQ_QueryParam params[] = { |
191 | GNUNET_PQ_query_param_auto_from_type (&query), | 189 | GNUNET_PQ_query_param_auto_from_type (&query), |
192 | GNUNET_PQ_query_param_fixed_size (block, block_size), | 190 | GNUNET_PQ_query_param_fixed_size (block, block_size), |
193 | GNUNET_PQ_query_param_absolute_time_nbo (&block->expiration_time), | 191 | GNUNET_PQ_query_param_absolute_time (&exp), |
194 | GNUNET_PQ_query_param_end | 192 | GNUNET_PQ_query_param_end |
195 | }; | 193 | }; |
196 | enum GNUNET_DB_QueryStatus res; | 194 | enum GNUNET_DB_QueryStatus res; |
197 | 195 | ||
198 | namecache_postgres_expire_blocks (plugin); | 196 | namecache_postgres_expire_blocks (plugin); |
199 | GNUNET_CRYPTO_hash (&block->derived_key, | 197 | GNUNET_GNSRECORD_query_from_block (block, |
200 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 198 | &query); |
201 | &query); | ||
202 | if (block_size > 64 * 65536) | 199 | if (block_size > 64 * 65536) |
203 | { | 200 | { |
204 | GNUNET_break (0); | 201 | GNUNET_break (0); |
@@ -206,7 +203,7 @@ namecache_postgres_cache_block (void *cls, | |||
206 | } | 203 | } |
207 | delete_old_block (plugin, | 204 | delete_old_block (plugin, |
208 | &query, | 205 | &query, |
209 | block->expiration_time); | 206 | exp); |
210 | 207 | ||
211 | res = GNUNET_PQ_eval_prepared_non_select (plugin->dbh, | 208 | res = GNUNET_PQ_eval_prepared_non_select (plugin->dbh, |
212 | "cache_block", | 209 | "cache_block", |
@@ -265,10 +262,7 @@ namecache_postgres_lookup_block (void *cls, | |||
265 | "Ending iteration (no more results)\n"); | 262 | "Ending iteration (no more results)\n"); |
266 | return GNUNET_NO; | 263 | return GNUNET_NO; |
267 | } | 264 | } |
268 | if ((bsize < sizeof(*block)) || | 265 | if ((bsize < sizeof(*block))) |
269 | (bsize != ntohl (block->purpose.size) | ||
270 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | ||
271 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature))) | ||
272 | { | 266 | { |
273 | GNUNET_break (0); | 267 | GNUNET_break (0); |
274 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 268 | LOG (GNUNET_ERROR_TYPE_DEBUG, |