aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_validation.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-12 10:00:39 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-12 10:00:39 +0000
commit180f2e637029d045e3c72dc3e13fddb1f9f30141 (patch)
tree91356b1fe1c93c8ff69f6136d454d5d12e5978a2 /src/transport/gnunet-service-transport_validation.c
parentf76896d09afabb721219d3217037cc7a7f26d570 (diff)
downloadgnunet-180f2e637029d045e3c72dc3e13fddb1f9f30141.tar.gz
gnunet-180f2e637029d045e3c72dc3e13fddb1f9f30141.zip
moving API around to make ATS implementable and separable
Diffstat (limited to 'src/transport/gnunet-service-transport_validation.c')
-rw-r--r--src/transport/gnunet-service-transport_validation.c162
1 files changed, 52 insertions, 110 deletions
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index 13d48bce2..1a619a901 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -27,6 +27,7 @@
27#include "gnunet-service-transport_validation.h" 27#include "gnunet-service-transport_validation.h"
28#include "gnunet-service-transport_plugins.h" 28#include "gnunet-service-transport_plugins.h"
29#include "gnunet-service-transport_hello.h" 29#include "gnunet-service-transport_hello.h"
30#include "gnunet-service-transport_ats-new.h"
30#include "gnunet-service-transport.h" 31#include "gnunet-service-transport.h"
31#include "gnunet_hello_lib.h" 32#include "gnunet_hello_lib.h"
32#include "gnunet_peerinfo_service.h" 33#include "gnunet_peerinfo_service.h"
@@ -249,28 +250,6 @@ struct CheckHelloValidatedContext
249 250
250 251
251/** 252/**
252 * Opaque handle to stop incremental validation address callbacks.
253 */
254struct GST_ValidationIteratorContext
255{
256 /**
257 * Function to call on each address.
258 */
259 GST_ValidationAddressCallback cb;
260
261 /**
262 * Closure for 'cb'.
263 */
264 void *cb_cls;
265
266 /**
267 * Which peer are we monitoring?
268 */
269 struct GNUNET_PeerIdentity target;
270};
271
272
273/**
274 * Head of linked list of HELLOs awaiting validation. 253 * Head of linked list of HELLOs awaiting validation.
275 */ 254 */
276static struct CheckHelloValidatedContext *chvc_head; 255static struct CheckHelloValidatedContext *chvc_head;
@@ -288,11 +267,6 @@ static struct CheckHelloValidatedContext *chvc_tail;
288static struct GNUNET_CONTAINER_MultiHashMap *validation_map; 267static struct GNUNET_CONTAINER_MultiHashMap *validation_map;
289 268
290/** 269/**
291 * Map of PeerIdentities to 'struct GST_ValidationIteratorContext's.
292 */
293static struct GNUNET_CONTAINER_MultiHashMap *notify_map;
294
295/**
296 * Context for peerinfo iteration. 270 * Context for peerinfo iteration.
297 */ 271 */
298static struct GNUNET_PEERINFO_NotifyContext *pnc; 272static struct GNUNET_PEERINFO_NotifyContext *pnc;
@@ -409,34 +383,6 @@ find_validation_entry (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pub
409 383
410 384
411/** 385/**
412 * Notify validation watcher that an entry is now valid
413 *
414 * @param cls 'struct ValidationEntry' that is now valid
415 * @param key peer identity (unused)
416 * @param value a 'GST_ValidationIteratorContext' to notify
417 * @return GNUNET_YES (continue to iterate)
418 */
419static int
420notify_valid (void *cls,
421 const GNUNET_HashCode *key,
422 void *value)
423{
424 struct ValidationEntry *ve = cls;
425 struct GST_ValidationIteratorContext *vic = value;
426
427 vic->cb (vic->cb_cls,
428 &ve->public_key,
429 &vic->target,
430 ve->valid_until,
431 ve->validation_block,
432 ve->transport_name,
433 ve->addr,
434 ve->addrlen);
435 return GNUNET_OK;
436}
437
438
439/**
440 * Iterator which adds the given address to the set of validated 386 * Iterator which adds the given address to the set of validated
441 * addresses. 387 * addresses.
442 * 388 *
@@ -472,10 +418,14 @@ add_valid_address (void *cls,
472 ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen); 418 ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen);
473 ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, 419 ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until,
474 expiration); 420 expiration);
475 GNUNET_CONTAINER_multihashmap_get_multiple (notify_map, 421 GST_ats_address_update (GST_ats,
476 &pid.hashPubKey, 422 &public_key,
477 &notify_valid, 423 &pid,
478 ve); 424 tname,
425 NULL,
426 addr,
427 addrlen,
428 NULL, 0);
479 return GNUNET_OK; 429 return GNUNET_OK;
480} 430}
481 431
@@ -512,7 +462,6 @@ void
512GST_validation_start () 462GST_validation_start ()
513{ 463{
514 validation_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE); 464 validation_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE);
515 notify_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE);
516 pnc = GNUNET_PEERINFO_notify (GST_cfg, 465 pnc = GNUNET_PEERINFO_notify (GST_cfg,
517 &process_peerinfo_hello, 466 &process_peerinfo_hello,
518 NULL); 467 NULL);
@@ -558,9 +507,6 @@ GST_validation_stop ()
558 NULL); 507 NULL);
559 GNUNET_CONTAINER_multihashmap_destroy (validation_map); 508 GNUNET_CONTAINER_multihashmap_destroy (validation_map);
560 validation_map = NULL; 509 validation_map = NULL;
561 GNUNET_assert (GNUNET_CONTAINER_multihashmap_size (notify_map) == 0);
562 GNUNET_CONTAINER_multihashmap_destroy (notify_map);
563 notify_map = NULL;
564 while (NULL != (chvc = chvc_head)) 510 while (NULL != (chvc = chvc_head))
565 { 511 {
566 GNUNET_CONTAINER_DLL_remove (chvc_head, 512 GNUNET_CONTAINER_DLL_remove (chvc_head,
@@ -801,10 +747,9 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
801 gettext_noop ("# PONGs multicast to all available addresses"), 747 gettext_noop ("# PONGs multicast to all available addresses"),
802 1, 748 1,
803 GNUNET_NO); 749 GNUNET_NO);
804 (void) GST_validation_get_addresses (sender, 750 GST_validation_get_addresses (sender,
805 GNUNET_YES, 751 &multicast_pong,
806 &multicast_pong, 752 pong);
807 pong);
808 GNUNET_free (pong); 753 GNUNET_free (pong);
809} 754}
810 755
@@ -1092,6 +1037,14 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1092 1037
1093 /* validity achieved, remember it! */ 1038 /* validity achieved, remember it! */
1094 ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION); 1039 ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
1040 GST_ats_address_update (GST_ats,
1041 &ve->public_key,
1042 &ve->pid,
1043 ve->transport_name,
1044 NULL,
1045 ve->addr,
1046 ve->addrlen,
1047 NULL, 0); /* FIXME: compute and add latency here... */
1095 1048
1096 /* build HELLO to store in PEERINFO */ 1049 /* build HELLO to store in PEERINFO */
1097 hello = GNUNET_HELLO_create (&ve->public_key, 1050 hello = GNUNET_HELLO_create (&ve->public_key,
@@ -1146,6 +1099,24 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
1146 1099
1147 1100
1148/** 1101/**
1102 * Closure for 'iterate_addresses'
1103 */
1104struct IteratorContext
1105{
1106 /**
1107 * Function to call on each address.
1108 */
1109 GST_ValidationAddressCallback cb;
1110
1111 /**
1112 * Closure for 'cb'.
1113 */
1114 void *cb_cls;
1115
1116};
1117
1118
1119/**
1149 * Call the callback in the closure for each validation entry. 1120 * Call the callback in the closure for each validation entry.
1150 * 1121 *
1151 * @param cls the 'struct GST_ValidationIteratorContext' 1122 * @param cls the 'struct GST_ValidationIteratorContext'
@@ -1158,17 +1129,17 @@ iterate_addresses (void *cls,
1158 const GNUNET_HashCode *key, 1129 const GNUNET_HashCode *key,
1159 void *value) 1130 void *value)
1160{ 1131{
1161 struct GST_ValidationIteratorContext *vic = cls; 1132 struct IteratorContext *ic = cls;
1162 struct ValidationEntry *ve = value; 1133 struct ValidationEntry *ve = value;
1163 1134
1164 vic->cb (vic->cb_cls, 1135 ic->cb (ic->cb_cls,
1165 &ve->public_key, 1136 &ve->public_key,
1166 &ve->pid, 1137 &ve->pid,
1167 ve->valid_until, 1138 ve->valid_until,
1168 ve->validation_block, 1139 ve->validation_block,
1169 ve->transport_name, 1140 ve->transport_name,
1170 ve->addr, 1141 ve->addr,
1171 ve->addrlen); 1142 ve->addrlen);
1172 return GNUNET_OK; 1143 return GNUNET_OK;
1173} 1144}
1174 1145
@@ -1185,48 +1156,19 @@ iterate_addresses (void *cls,
1185 * @param cb_cls closure for 'cb' 1156 * @param cb_cls closure for 'cb'
1186 * @return context to cancel, NULL if 'snapshot_only' is GNUNET_YES 1157 * @return context to cancel, NULL if 'snapshot_only' is GNUNET_YES
1187 */ 1158 */
1188struct GST_ValidationIteratorContext * 1159void
1189GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target, 1160GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
1190 int snapshot_only,
1191 GST_ValidationAddressCallback cb, 1161 GST_ValidationAddressCallback cb,
1192 void *cb_cls) 1162 void *cb_cls)
1193{ 1163{
1194 struct GST_ValidationIteratorContext *vic; 1164 struct IteratorContext ic;
1195 1165
1196 vic = GNUNET_malloc (sizeof (struct GST_ValidationIteratorContext)); 1166 ic.cb = cb;
1197 vic->cb = cb; 1167 ic.cb_cls = cb_cls;
1198 vic->cb_cls = cb_cls;
1199 vic->target = *target;
1200 GNUNET_CONTAINER_multihashmap_get_multiple (validation_map, 1168 GNUNET_CONTAINER_multihashmap_get_multiple (validation_map,
1201 &target->hashPubKey, 1169 &target->hashPubKey,
1202 &iterate_addresses, 1170 &iterate_addresses,
1203 vic); 1171 &ic);
1204 if (GNUNET_YES == snapshot_only)
1205 {
1206 GNUNET_free (vic);
1207 return NULL;
1208 }
1209 GNUNET_CONTAINER_multihashmap_put (notify_map,
1210 &target->hashPubKey,
1211 vic,
1212 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1213 return vic;
1214}
1215
1216
1217/**
1218 * Cancel an active validation address iteration.
1219 *
1220 * @param ctx the context of the operation that is cancelled
1221 */
1222void
1223GST_validation_get_addresses_cancel (struct GST_ValidationIteratorContext *ctx)
1224{
1225 GNUNET_assert (GNUNET_OK ==
1226 GNUNET_CONTAINER_multihashmap_remove (notify_map,
1227 &ctx->target.hashPubKey,
1228 ctx));
1229 GNUNET_free (ctx);
1230} 1172}
1231 1173
1232 1174