From d220651a00e92367387e6f0d881c8115fc9e2973 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 12 Aug 2011 08:46:13 +0000 Subject: validation should notify async callbacks about updates --- .../gnunet-service-transport_validation.c | 77 +++++++++++++++------- 1 file changed, 54 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index 6a300abcb..13522931a 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c @@ -247,6 +247,28 @@ struct CheckHelloValidatedContext }; +/** + * Opaque handle to stop incremental validation address callbacks. + */ +struct GST_ValidationIteratorContext +{ + /** + * Function to call on each address. + */ + GST_ValidationAddressCallback cb; + + /** + * Closure for 'cb'. + */ + void *cb_cls; + + /** + * Which peer are we monitoring? + */ + struct GNUNET_PeerIdentity target; +}; + + /** * Head of linked list of HELLOs awaiting validation. */ @@ -385,6 +407,34 @@ find_validation_entry (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pub } +/** + * Notify validation watcher that an entry is now valid + * + * @param cls 'struct ValidationEntry' that is now valid + * @param key peer identity (unused) + * @param value a 'GST_ValidationIteratorContext' to notify + * @return GNUNET_YES (continue to iterate) + */ +static int +notify_valid (void *cls, + const GNUNET_HashCode *key, + void *value) +{ + struct ValidationEntry *ve = cls; + struct GST_ValidationIteratorContext *vic = value; + + vic->cb (vic->cb_cls, + &ve->public_key, + &vic->target, + ve->valid_until, + ve->validation_block, + ve->transport_name, + ve->addr, + ve->addrlen); + return GNUNET_OK; +} + + /** * Iterator which adds the given address to the set of validated * addresses. @@ -418,10 +468,13 @@ add_valid_address (void *cls, GNUNET_break (0); return GNUNET_OK; /* invalid HELLO !? */ } - ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen); ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, expiration); + GNUNET_CONTAINER_multihashmap_get_multiple (notify_map, + &pid.hashPubKey, + ¬ify_valid, + ve); return GNUNET_OK; } @@ -1091,28 +1144,6 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello) } -/** - * Opaque handle to stop incremental validation address callbacks. - */ -struct GST_ValidationIteratorContext -{ - /** - * Function to call on each address. - */ - GST_ValidationAddressCallback cb; - - /** - * Closure for 'cb'. - */ - void *cb_cls; - - /** - * Which peer are we monitoring? - */ - struct GNUNET_PeerIdentity target; -}; - - /** * Call the callback in the closure for each validation entry. * -- cgit v1.2.3