aboutsummaryrefslogtreecommitdiff
path: root/src/revocation
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-10-06 08:00:39 +0000
committerChristian Grothoff <christian@grothoff.org>2013-10-06 08:00:39 +0000
commit03acdb1b1764cb9ae65d255c3e4f9606e824f80b (patch)
tree81dd140992cbc2e41ad8a6cf1844e3124c41cef6 /src/revocation
parentad989721684818bee9a0a1f81d5fb085241959ab (diff)
downloadgnunet-03acdb1b1764cb9ae65d255c3e4f9606e824f80b.tar.gz
gnunet-03acdb1b1764cb9ae65d255c3e4f9606e824f80b.zip
-handle client revocation queries in service
Diffstat (limited to 'src/revocation')
-rw-r--r--src/revocation/gnunet-service-revocation.c76
-rw-r--r--src/revocation/revocation.h2
2 files changed, 74 insertions, 4 deletions
diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c
index 168f8c6ef..dbf8817f8 100644
--- a/src/revocation/gnunet-service-revocation.c
+++ b/src/revocation/gnunet-service-revocation.c
@@ -36,7 +36,6 @@
36 * - handle p2p revocations 36 * - handle p2p revocations
37 * - handle p2p connect (trigger SET union) 37 * - handle p2p connect (trigger SET union)
38 * - handle client revoke message 38 * - handle client revoke message
39 * - handle client query message
40 */ 39 */
41#include "platform.h" 40#include "platform.h"
42#include <math.h> 41#include <math.h>
@@ -82,6 +81,12 @@ struct PeerEntry
82static struct GNUNET_SET_Handle *revocation_set; 81static struct GNUNET_SET_Handle *revocation_set;
83 82
84/** 83/**
84 * Hash map with all revoked keys, maps the hash of the public key
85 * to the respective `struct RevokeMessage`.
86 */
87static struct GNUNET_CONTAINER_MultiHashMap *revocation_map;
88
89/**
85 * Handle to our current configuration. 90 * Handle to our current configuration.
86 */ 91 */
87static const struct GNUNET_CONFIGURATION_Handle *cfg; 92static const struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -112,6 +117,11 @@ static struct GNUNET_PeerIdentity my_identity;
112static struct GNUNET_SERVER_Handle *srv; 117static struct GNUNET_SERVER_Handle *srv;
113 118
114/** 119/**
120 * Notification context for convenient sending of replies to the clients.
121 */
122static struct GNUNET_SERVER_NotificationContext *nc;
123
124/**
115 * Amount of work required (W-bit collisions) for REVOCATION proofs, in collision-bits. 125 * Amount of work required (W-bit collisions) for REVOCATION proofs, in collision-bits.
116 */ 126 */
117static unsigned long long revocation_work_required; 127static unsigned long long revocation_work_required;
@@ -164,9 +174,29 @@ handle_query_message (void *cls,
164 struct GNUNET_SERVER_Client *client, 174 struct GNUNET_SERVER_Client *client,
165 const struct GNUNET_MessageHeader *message) 175 const struct GNUNET_MessageHeader *message)
166{ 176{
177 const struct QueryMessage *qm = (const struct QueryMessage *) message;
178 struct QueryResponseMessage qrm;
179 struct GNUNET_HashCode hc;
180 int res;
181
182 GNUNET_CRYPTO_hash (&qm->key,
183 sizeof (struct GNUNET_CRYPTO_EccPublicSignKey),
184 &hc);
185 res = GNUNET_CONTAINER_multihashmap_contains (revocation_map, &hc);
167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
168 "Received QUERY message from client\n"); 187 (GNUNET_NO == res)
169 GNUNET_break (0); 188 ? "Received revocation check for valid key `%s' from client\n"
189 : "Received revocation check for revoked key `%s' from client\n",
190 GNUNET_h2s (&hc));
191 qrm.header.size = htons (sizeof (struct RevocationResponseMessage));
192 qrm.header.type = htons (GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE);
193 qrm.is_valid = htons ((GNUNET_YES == res) ? GNUNET_NO : GNUNET_YES);
194 GNUNET_SERVER_notification_context_add (nc,
195 client);
196 GNUNET_SERVER_notification_context_unicast (nc,
197 client,
198 &qrm.header,
199 GNUNET_NO);
170 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 200 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
171} 201}
172 202
@@ -184,6 +214,7 @@ handle_revoke_message (void *cls,
184 const struct GNUNET_MessageHeader *message) 214 const struct GNUNET_MessageHeader *message)
185{ 215{
186 const struct RevokeMessage *rm; 216 const struct RevokeMessage *rm;
217 struct RevocationResponseMessage rrm;
187 218
188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
189 "Received REVOKE message from client\n"); 220 "Received REVOKE message from client\n");
@@ -195,6 +226,16 @@ handle_revoke_message (void *cls,
195 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 226 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
196 } 227 }
197 GNUNET_break (0); // FIXME: TBD 228 GNUNET_break (0); // FIXME: TBD
229
230 rrm.header.size = htons (sizeof (struct RevocationResponseMessage));
231 rrm.header.type = htons (GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE);
232 rrm.is_valid = htons (GNUNET_NO);
233 GNUNET_SERVER_notification_context_add (nc,
234 client);
235 GNUNET_SERVER_notification_context_unicast (nc,
236 client,
237 &rrm.header,
238 GNUNET_NO);
198 GNUNET_SERVER_receive_done (client, GNUNET_OK); 239 GNUNET_SERVER_receive_done (client, GNUNET_OK);
199} 240}
200 241
@@ -308,6 +349,24 @@ handle_core_disconnect (void *cls,
308 349
309 350
310/** 351/**
352 * Free all values in a hash map.
353 *
354 * @param cls NULL
355 * @param key the key
356 * @param value value to free
357 * @return #GNUNET_OK (continue to iterate)
358 */
359static int
360free_entry (void *cls,
361 const struct GNUNET_HashCode *key,
362 void *value)
363{
364 GNUNET_free (value);
365 return GNUNET_OK;
366}
367
368
369/**
311 * Task run during shutdown. 370 * Task run during shutdown.
312 * 371 *
313 * @param cls unused 372 * @param cls unused
@@ -337,6 +396,15 @@ shutdown_task (void *cls,
337 GNUNET_CONTAINER_multipeermap_destroy (peers); 396 GNUNET_CONTAINER_multipeermap_destroy (peers);
338 peers = NULL; 397 peers = NULL;
339 } 398 }
399 if (NULL != nc)
400 {
401 GNUNET_SERVER_notification_context_destroy (nc);
402 nc = NULL;
403 }
404 GNUNET_CONTAINER_multihashmap_iterate (revocation_map,
405 &free_entry,
406 NULL);
407 GNUNET_CONTAINER_multihashmap_destroy (revocation_map);
340} 408}
341 409
342 410
@@ -388,6 +456,8 @@ run (void *cls,
388 456
389 cfg = c; 457 cfg = c;
390 srv = server; 458 srv = server;
459 revocation_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO);
460 nc = GNUNET_SERVER_notification_context_create (server, 1);
391 if (GNUNET_OK != 461 if (GNUNET_OK !=
392 GNUNET_CONFIGURATION_get_value_number (cfg, "REVOCATION", "WORKBITS", 462 GNUNET_CONFIGURATION_get_value_number (cfg, "REVOCATION", "WORKBITS",
393 &revocation_work_required)) 463 &revocation_work_required))
diff --git a/src/revocation/revocation.h b/src/revocation/revocation.h
index 29235aeee..b13d79a37 100644
--- a/src/revocation/revocation.h
+++ b/src/revocation/revocation.h
@@ -120,7 +120,7 @@ struct RevokeMessage
120struct RevocationResponseMessage 120struct RevocationResponseMessage
121{ 121{
122 /** 122 /**
123 * Type: #GNUNET_MESSAGE_TYPE_REVOKE_RESPONSE 123 * Type: #GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE
124 */ 124 */
125 struct GNUNET_MessageHeader header; 125 struct GNUNET_MessageHeader header;
126 126