From 88050a09341dfb3926254cbdcdee44dda62c52b6 Mon Sep 17 00:00:00 2001 From: grothoff Date: Tue, 30 Oct 2012 14:12:44 +0000 Subject: -some gns code cleanup, still a mess git-svn-id: https://gnunet.org/svn/gnunet@24607 140774ce-b5e7-0310-ab8b-a85725594a96 --- src/gns/gnunet-service-gns.c | 4 +- src/gns/gnunet-service-gns_interceptor.c | 2 +- src/gns/gnunet-service-gns_resolver.c | 123 +++++++++---------- src/gns/gnunet-service-gns_resolver.h | 4 +- src/gns/test_gns_dht_delegated_lookup.c | 35 +++--- src/gns/test_gns_dht_three_peers.c | 28 ++--- src/gns/test_gns_max_queries.c | 5 - src/gns/test_gns_pseu_shorten.c | 56 ++++----- src/gns/test_gns_revocation.c | 26 ++-- src/gns/test_gns_simple_delegated_lookup.c | 189 +++++++++++++---------------- src/gns/test_gns_simple_get_authority.c | 20 +-- src/gns/test_gns_simple_mx_lookup.c | 25 ++-- src/gns/test_gns_simple_shorten.c | 19 +-- src/gns/test_gns_simple_srv_lookup.c | 12 -- src/gns/test_gns_simple_zkey_lookup.c | 34 +++--- 15 files changed, 235 insertions(+), 347 deletions(-) (limited to 'src/gns') diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index dc22efdab8..79c453406b 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c @@ -815,7 +815,7 @@ handle_shorten (void *cls, GNUNET_CONTAINER_DLL_insert (csh_head, csh_tail, csh); GNUNET_STRINGS_utf8_tolower (utf_in, &nameptr); GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "SHORTEN: Converted `%s' to `%s'\n", + "SHORTEN: Converted `%s' to `%s'\n", utf_in, nameptr); GNUNET_SERVER_notification_context_add (nc, client); @@ -837,7 +837,7 @@ handle_shorten (void *cls, GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } - if ( (! is_gnunet_tld (name)) && + if ( (! is_gads_tld (name)) && (! is_zkey_tld (name)) ) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, diff --git a/src/gns/gnunet-service-gns_interceptor.c b/src/gns/gnunet-service-gns_interceptor.c index 9c1c3a6666..828efc39e2 100644 --- a/src/gns/gnunet-service-gns_interceptor.c +++ b/src/gns/gnunet-service-gns_interceptor.c @@ -312,7 +312,7 @@ handle_dns_request (void *cls, * Check for .gads/.zkey */ - if ((is_gnunet_tld(p->queries[0].name) == GNUNET_YES) || + if ((is_gads_tld(p->queries[0].name) == GNUNET_YES) || (is_zkey_tld(p->queries[0].name) == GNUNET_YES) || (strcmp(p->queries[0].name, GNUNET_GNS_TLD) == 0)) { diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 40efc8bd80..641e042ba5 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c @@ -953,7 +953,7 @@ dht_lookup_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) char new_name[MAX_DNS_NAME_LENGTH]; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "GNS_PHASE_REC-%llu: dht lookup for query %s (%llus)timed out.\n", + "GNS_PHASE_REC-%llu: dht lookup for query %s (%llus) timed out.\n", rh->id, rh->name, rh->timeout.rel_value); /** * Start resolution in bg @@ -2037,7 +2037,8 @@ dht_authority_lookup_timeout(void *cls, * * @param rh the pending gns query */ -static void resolve_delegation_dht(struct ResolverHandle *rh); +static void +resolve_delegation_dht(struct ResolverHandle *rh); /** @@ -2045,7 +2046,8 @@ static void resolve_delegation_dht(struct ResolverHandle *rh); * * @param rh the resolver handle */ -static void resolve_delegation_ns(struct ResolverHandle *rh); +static void +resolve_delegation_ns(struct ResolverHandle *rh); /** @@ -2192,15 +2194,15 @@ on_namestore_delegation_put_result(void *cls, * @param data the record data */ static void -process_delegation_result_dht(void* cls, - struct GNUNET_TIME_Absolute exp, - const struct GNUNET_HashCode * key, - const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_length, - const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_length, - enum GNUNET_BLOCK_Type type, - size_t size, const void *data) +process_delegation_result_dht (void* cls, + struct GNUNET_TIME_Absolute exp, + const struct GNUNET_HashCode * key, + const struct GNUNET_PeerIdentity *get_path, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *put_path, + unsigned int put_path_length, + enum GNUNET_BLOCK_Type type, + size_t size, const void *data) { struct ResolverHandle *rh = cls; struct GNSNameRecordBlock *nrb; @@ -2478,7 +2480,7 @@ finish_lookup (struct ResolverHandle *rh, unsigned int rd_count, const struct GNUNET_NAMESTORE_RecordData *rd) { - int i; + unsigned int i; char new_rr_data[MAX_DNS_NAME_LENGTH]; char new_mx_data[MAX_MX_LENGTH]; char new_soa_data[MAX_SOA_LENGTH]; @@ -2709,8 +2711,8 @@ handle_record_ns (void* cls, struct ResolverHandle *rh, * @param name the domain * @param dest the destination where the tld will be put */ -void -pop_tld(char* name, char* dest) +static void +pop_tld (char* name, char* dest) { uint32_t len; @@ -2776,10 +2778,8 @@ handle_delegation_dht(void* cls, struct ResolverHandle *rh, unsigned int rd_count, const struct GNUNET_NAMESTORE_RecordData *rd) { - struct RecordLookupHandle* rlh; - rlh = cls; + struct RecordLookupHandle* rlh = cls; - if (0 == strcmp(rh->name, "")) { if (GNUNET_GNS_RECORD_PKEY == rlh->record_type) @@ -3114,25 +3114,24 @@ handle_delegation_ns (void* cls, struct ResolverHandle *rh, */ static void process_delegation_result_ns (void* cls, - const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key, - struct GNUNET_TIME_Absolute expiration, - const char *name, - unsigned int rd_count, - const struct GNUNET_NAMESTORE_RecordData *rd, - const struct GNUNET_CRYPTO_RsaSignature *signature) + const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key, + struct GNUNET_TIME_Absolute expiration, + const char *name, + unsigned int rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd, + const struct GNUNET_CRYPTO_RsaSignature *signature) { - struct ResolverHandle *rh; + struct ResolverHandle *rh = cls; struct GNUNET_TIME_Relative remaining_time; struct GNUNET_CRYPTO_ShortHashCode zone; char new_name[MAX_DNS_NAME_LENGTH]; unsigned int i; struct GNUNET_TIME_Absolute et; - rh = (struct ResolverHandle *)cls; rh->namestore_task = NULL; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "GNS_PHASE_DELEGATE_NS-%llu: Got %d records from authority lookup\n", - rh->id, rd_count); + "GNS_PHASE_DELEGATE_NS-%llu: Got %d records from authority lookup\n", + rh->id, rd_count); GNUNET_CRYPTO_short_hash (key, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), @@ -3305,13 +3304,12 @@ process_delegation_result_ns (void* cls, rh->rd_count = 1; /* Check for key revocation and delegate */ rh->namestore_task = GNUNET_NAMESTORE_lookup_record (namestore_handle, - &rh->authority, - "+", - GNUNET_GNS_RECORD_REV, - &process_pkey_revocation_result_ns, - rh); + &rh->authority, + "+", + GNUNET_GNS_RECORD_REV, + &process_pkey_revocation_result_ns, + rh); return; - } /** @@ -3360,17 +3358,17 @@ process_delegation_result_ns (void* cls, static void resolve_delegation_ns (struct ResolverHandle *rh) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "GNS_PHASE_DELEGATE_NS-%llu: Resolving delegation for %s\n", - rh->id, rh->name); - pop_tld(rh->name, rh->authority_name); - rh->namestore_task = GNUNET_NAMESTORE_lookup_record(namestore_handle, - &rh->authority, - rh->authority_name, - GNUNET_GNS_RECORD_ANY, - &process_delegation_result_ns, - rh); - + pop_tld (rh->name, rh->authority_name); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "GNS_PHASE_DELEGATE_NS-%llu: Resolving delegation for %s by looking up %s\n", + rh->id, rh->name, + rh->authority_name); + rh->namestore_task = GNUNET_NAMESTORE_lookup_record (namestore_handle, + &rh->authority, + rh->authority_name, + GNUNET_GNS_RECORD_ANY, + &process_delegation_result_ns, + rh); } @@ -3409,7 +3407,6 @@ gns_resolver_lookup_record (struct GNUNET_CRYPTO_ShortHashCode zone, "Starting resolution for %s (type=%d)!\n", name, record_type); - if ((is_canonical ((char*)name) == GNUNET_YES) && (strcmp(GNUNET_GNS_TLD, name) != 0)) { @@ -3421,18 +3418,13 @@ gns_resolver_lookup_record (struct GNUNET_CRYPTO_ShortHashCode zone, rlh = GNUNET_malloc (sizeof(struct RecordLookupHandle)); rh = GNUNET_malloc (sizeof (struct ResolverHandle)); - - memset (rh, 0, sizeof (struct ResolverHandle)); rh->authority = zone; rh->id = rid++; rh->proc_cls = rlh; rh->priv_key = key; rh->timeout = timeout; - rh->get_handle = NULL; rh->private_local_zone = pzone; rh->only_cached = only_cached; - rh->namestore_task = NULL; - rh->rd.data = NULL; GNUNET_CONTAINER_DLL_insert (rlh_head, rlh_tail, rh); @@ -3506,17 +3498,16 @@ gns_resolver_lookup_record (struct GNUNET_CRYPTO_ShortHashCode zone, } } - else if (is_gnunet_tld (name) == GNUNET_YES) + else if (is_gads_tld (name) == GNUNET_YES) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "TLD is gnunet\n"); + "TLD is gads\n"); /** - * Presumably GNUNET tld + * Presumably GADS tld */ - memset (rh->name, 0, - strlen(name)-strlen(GNUNET_GNS_TLD)); memcpy (rh->name, name, - strlen(name)-strlen(GNUNET_GNS_TLD) - 1); + strlen (name) - strlen(GNUNET_GNS_TLD) - 1); + rh->name[strlen (name) - strlen(GNUNET_GNS_TLD) - 1] = '\0'; } else { @@ -3536,9 +3527,7 @@ gns_resolver_lookup_record (struct GNUNET_CRYPTO_ShortHashCode zone, /** * Initialize authority chain */ - rh->authority_chain_head = GNUNET_malloc(sizeof(struct AuthorityChain)); - rh->authority_chain_head->prev = NULL; - rh->authority_chain_head->next = NULL; + rh->authority_chain_head = GNUNET_malloc (sizeof(struct AuthorityChain)); rh->authority_chain_tail = rh->authority_chain_head; rh->authority_chain_head->zone = rh->authority; strcpy (rh->authority_chain_head->name, ""); @@ -3614,7 +3603,7 @@ process_zone_to_name_shorten_shorten (void *cls, const struct GNUNET_NAMESTORE_RecordData *rd, const struct GNUNET_CRYPTO_RsaSignature *signature) { - struct ResolverHandle *rh = (struct ResolverHandle *)cls; + struct ResolverHandle *rh = cls; struct NameShortenHandle* nsh = (struct NameShortenHandle*)rh->proc_cls; struct AuthorityChain *next_authority; @@ -3730,7 +3719,7 @@ process_zone_to_name_shorten_private (void *cls, const struct GNUNET_NAMESTORE_RecordData *rd, const struct GNUNET_CRYPTO_RsaSignature *signature) { - struct ResolverHandle *rh = (struct ResolverHandle *)cls; + struct ResolverHandle *rh = cls; struct NameShortenHandle* nsh = (struct NameShortenHandle*)rh->proc_cls; struct AuthorityChain *next_authority; @@ -3845,10 +3834,9 @@ process_zone_to_name_shorten_root (void *cls, const struct GNUNET_NAMESTORE_RecordData *rd, const struct GNUNET_CRYPTO_RsaSignature *signature) { - struct ResolverHandle *rh = (struct ResolverHandle *)cls; + struct ResolverHandle *rh = cls; struct NameShortenHandle* nsh = (struct NameShortenHandle*)rh->proc_cls; struct AuthorityChain *next_authority; - char result[MAX_DNS_NAME_LENGTH]; char tmp_name[MAX_DNS_NAME_LENGTH]; size_t answer_len; @@ -4150,7 +4138,6 @@ gns_resolver_shorten_name (struct GNUNET_CRYPTO_ShortHashCode *zone, char nzkey[MAX_DNS_LABEL_LENGTH]; char* nzkey_ptr = nzkey; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting shorten for %s!\n", name); @@ -4224,7 +4211,7 @@ gns_resolver_shorten_name (struct GNUNET_CRYPTO_ShortHashCode *zone, return; } - else if (is_gnunet_tld (name) == GNUNET_YES) + else if (is_gads_tld (name) == GNUNET_YES) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TLD is gnunet\n"); @@ -4276,6 +4263,7 @@ finish_get_auth (struct ResolverHandle *rh, free_resolver_handle (rh); } + /** * Process result from namestore delegation lookup * for get authority operation @@ -4338,8 +4326,6 @@ handle_delegation_result_ns_get_auth(void* cls, strcpy(nah->result, ""); finish_get_auth (rh, nah); } - - } @@ -4371,7 +4357,6 @@ gns_resolver_get_authority(struct GNUNET_CRYPTO_ShortHashCode zone, rh->authority = zone; rh->id = rid++; rh->private_local_zone = pzone; - rh->namestore_task = NULL; GNUNET_CONTAINER_DLL_insert (nah_head, nah_tail, rh); diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h index e8bb746975..466e931756 100644 --- a/src/gns/gnunet-service-gns_resolver.h +++ b/src/gns/gnunet-service-gns_resolver.h @@ -637,9 +637,9 @@ is_tld (const char* name, /** - * Checks for gnunet/zkey + * Checks for gads/zkey */ -#define is_gnunet_tld(name) is_tld(name, GNUNET_GNS_TLD) +#define is_gads_tld(name) is_tld(name, GNUNET_GNS_TLD) #define is_zkey_tld(name) is_tld(name, GNUNET_GNS_TLD_ZKEY) diff --git a/src/gns/test_gns_dht_delegated_lookup.c b/src/gns/test_gns_dht_delegated_lookup.c index 0fcd723e34..f9531751ad 100644 --- a/src/gns/test_gns_dht_delegated_lookup.c +++ b/src/gns/test_gns_dht_delegated_lookup.c @@ -33,18 +33,12 @@ #include "gnunet_dht_service.h" #include "gnunet_gns_service.h" -/* DEFINES */ -#define VERBOSE GNUNET_YES - /* Timeout for entire testcase */ #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) /* Timeout for entire testcase */ #define DHT_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) -/* If number of peers not in config file, use this number */ -#define DEFAULT_NUM_PEERS 2 - /* test records to resolve */ #define TEST_DOMAIN "www.bob.gads" #define TEST_IP "127.0.0.1" @@ -56,11 +50,9 @@ #define KEYFILE_BOB "../namestore/zonefiles/HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey" -/* Globals */ - /* Task handle to use to schedule test failure */ -GNUNET_SCHEDULER_TaskIdentifier die_task; -GNUNET_SCHEDULER_TaskIdentifier wait_task; +static GNUNET_SCHEDULER_TaskIdentifier die_task; +static GNUNET_SCHEDULER_TaskIdentifier wait_task; /* Global return value (0 for success, anything else for failure) */ static int ok; @@ -71,12 +63,12 @@ static struct GNUNET_GNS_Handle *gns_handle; static struct GNUNET_DHT_Handle *dht_handle; -const struct GNUNET_CONFIGURATION_Handle *cfg; +static const struct GNUNET_CONFIGURATION_Handle *cfg; -struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey; -struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey; -struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; -struct GNUNET_CRYPTO_RsaPrivateKey *bob_key; +static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey; +static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey; +static struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; +static struct GNUNET_CRYPTO_RsaPrivateKey *bob_key; /** @@ -110,6 +102,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) ok = 1; } + static void end_badly_now () { @@ -123,14 +116,17 @@ end_badly_now () die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); } -static void shutdown_task (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) + +static void +shutdown_task (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_GNS_disconnect(gns_handle); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n"); GNUNET_SCHEDULER_shutdown (); } + static void on_lookup_result(void *cls, uint32_t rd_count, const struct GNUNET_NAMESTORE_RecordData *rd) @@ -295,6 +291,7 @@ put_dht(void *cls, int32_t success, const char *emsg) wait_task = GNUNET_SCHEDULER_add_delayed(DHT_DELAY, &commence_testing, NULL); } + static void do_check (void *cls, const struct GNUNET_CONFIGURATION_Handle *ccfg, @@ -364,11 +361,7 @@ main (int argc, char *argv[]) ok = 1; GNUNET_log_setup ("test-gns-dht-delegated-lookup", -#if VERBOSE - "DEBUG", -#else "WARNING", -#endif NULL); GNUNET_TESTING_peer_run ("test-gns-dht-delegated-lookup", "test_gns_simple_lookup.conf", &do_check, NULL); return ok; diff --git a/src/gns/test_gns_dht_three_peers.c b/src/gns/test_gns_dht_three_peers.c index a7bad9bbac..2a109559fa 100644 --- a/src/gns/test_gns_dht_three_peers.c +++ b/src/gns/test_gns_dht_three_peers.c @@ -42,14 +42,9 @@ #define ZONE_PUT_WAIT_TIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) -/* If number of peers not in config file, use this number */ -#define DEFAULT_NUM_PEERS 2 - #define TEST_DOMAIN "www.buddy.bob.gads" #define TEST_IP "1.1.1.1" #define TEST_DAVE_PSEU "hagbard" -#define TEST_NUM_PEERS 3 -#define TEST_NUM_CON 3 /* Timeout for entire testcase */ @@ -59,22 +54,23 @@ static int ok; /* Task handle to use to schedule test failure */ -GNUNET_SCHEDULER_TaskIdentifier die_task; -GNUNET_SCHEDULER_TaskIdentifier wait_task; +static GNUNET_SCHEDULER_TaskIdentifier die_task; + +static GNUNET_SCHEDULER_TaskIdentifier wait_task; -struct GNUNET_CRYPTO_ShortHashCode dave_hash; +static struct GNUNET_CRYPTO_ShortHashCode dave_hash; -struct GNUNET_CRYPTO_ShortHashCode bob_hash; +static struct GNUNET_CRYPTO_ShortHashCode bob_hash; -struct GNUNET_TESTBED_Peer **cpeers; +static struct GNUNET_TESTBED_Peer **cpeers; -struct GNUNET_GNS_Handle *gh; -struct GNUNET_GNS_LookupRequest *lookup_handle; +static struct GNUNET_GNS_Handle *gh; +static struct GNUNET_GNS_LookupRequest *lookup_handle; -struct GNUNET_TESTBED_Operation *get_cfg_ops[3]; -struct GNUNET_TESTBED_Operation *connect_ops[3]; -struct GNUNET_CONFIGURATION_Handle *cfg_handles[3]; -struct GNUNET_NAMESTORE_Handle *nh[3]; +static struct GNUNET_TESTBED_Operation *get_cfg_ops[3]; +static struct GNUNET_TESTBED_Operation *connect_ops[3]; +static struct GNUNET_CONFIGURATION_Handle *cfg_handles[3]; +static struct GNUNET_NAMESTORE_Handle *nh[3]; static int dave_is_setup; static int bob_is_setup; diff --git a/src/gns/test_gns_max_queries.c b/src/gns/test_gns_max_queries.c index d06f4ebed8..fae90bf72d 100644 --- a/src/gns/test_gns_max_queries.c +++ b/src/gns/test_gns_max_queries.c @@ -36,9 +36,6 @@ /* Timeout for entire testcase */ #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) -/* If number of peers not in config file, use this number */ -#define DEFAULT_NUM_PEERS 2 - /* test records to resolve */ #define TEST_DOMAIN "www.gads" #define TEST_DOMAIN_NACK "doesnotexist.bob.gads" @@ -49,8 +46,6 @@ #define KEYFILE_BOB "../namestore/zonefiles/HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey" -/* Globals */ - /* Task handle to use to schedule test failure */ static GNUNET_SCHEDULER_TaskIdentifier die_task; diff --git a/src/gns/test_gns_pseu_shorten.c b/src/gns/test_gns_pseu_shorten.c index 8f279bb554..74f41398d0 100644 --- a/src/gns/test_gns_pseu_shorten.c +++ b/src/gns/test_gns_pseu_shorten.c @@ -33,15 +33,9 @@ #include "gnunet_dht_service.h" #include "gnunet_gns_service.h" -/* DEFINES */ -#define VERBOSE GNUNET_YES - /* Timeout for entire testcase */ #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) -/* If number of peers not in config file, use this number */ -#define DEFAULT_NUM_PEERS 2 - /* test records to resolve */ #define TEST_DOMAIN "www.alicewonderland.bobbuilder.gads" #define TEST_IP "127.0.0.1" @@ -75,23 +69,23 @@ static struct GNUNET_GNS_Handle *gns_handle; static struct GNUNET_DHT_Handle *dht_handle; -const struct GNUNET_CONFIGURATION_Handle *cfg; - -struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey; -struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey; -struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded our_pkey; -struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded priv_pkey; -struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded short_pkey; -struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; -struct GNUNET_CRYPTO_RsaPrivateKey *bob_key; -struct GNUNET_CRYPTO_RsaPrivateKey *our_key; -struct GNUNET_CRYPTO_RsaPrivateKey *priv_key; -struct GNUNET_CRYPTO_RsaPrivateKey *short_key; -struct GNUNET_CRYPTO_ShortHashCode alice_hash; -struct GNUNET_CRYPTO_ShortHashCode bob_hash; -struct GNUNET_CRYPTO_ShortHashCode our_zone; -struct GNUNET_CRYPTO_ShortHashCode priv_zone; -struct GNUNET_CRYPTO_ShortHashCode short_zone; +static const struct GNUNET_CONFIGURATION_Handle *cfg; + +static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey; +static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey; +static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded our_pkey; +static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded priv_pkey; +static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded short_pkey; +static struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; +static struct GNUNET_CRYPTO_RsaPrivateKey *bob_key; +static struct GNUNET_CRYPTO_RsaPrivateKey *our_key; +static struct GNUNET_CRYPTO_RsaPrivateKey *priv_key; +static struct GNUNET_CRYPTO_RsaPrivateKey *short_key; +static struct GNUNET_CRYPTO_ShortHashCode alice_hash; +static struct GNUNET_CRYPTO_ShortHashCode bob_hash; +static struct GNUNET_CRYPTO_ShortHashCode our_zone; +static struct GNUNET_CRYPTO_ShortHashCode priv_zone; +static struct GNUNET_CRYPTO_ShortHashCode short_zone; /** @@ -126,6 +120,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) ok = 1; } + static void end_badly_now () { @@ -133,8 +128,10 @@ end_badly_now () die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); } -static void shutdown_task (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) + +static void +shutdown_task (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_GNS_disconnect(gns_handle); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n"); @@ -346,6 +343,7 @@ put_pseu_dht (void *cls, int success) GNUNET_free (nrb); } + static void put_www_dht(void *cls, int success) { @@ -514,6 +512,7 @@ put_pkey_dht(void *cls, int32_t success, const char *emsg) GNUNET_free (nrb); } + static void fin_init_zone (void *cls, int32_t success, const char *emsg) { @@ -552,6 +551,7 @@ cont_init_zone (void *cls, int32_t success, const char *emsg) NULL); } + static void do_check (void *cls, const struct GNUNET_CONFIGURATION_Handle *ccfg, @@ -646,17 +646,13 @@ do_check (void *cls, NULL); } + int main (int argc, char *argv[]) { ok = 1; - GNUNET_log_setup ("test-gns-pseu-shorten", -#if VERBOSE - "DEBUG", -#else "WARNING", -#endif NULL); GNUNET_TESTING_peer_run ("test-gns-pseu-shorten", "test_gns_simple_lookup.conf", &do_check, NULL); return ok; diff --git a/src/gns/test_gns_revocation.c b/src/gns/test_gns_revocation.c index a538ab3e78..691d8c1240 100644 --- a/src/gns/test_gns_revocation.c +++ b/src/gns/test_gns_revocation.c @@ -32,15 +32,9 @@ #include "gnunet_dnsparser_lib.h" #include "gnunet_gns_service.h" -/* DEFINES */ -#define VERBOSE GNUNET_YES - /* Timeout for entire testcase */ #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) -/* If number of peers not in config file, use this number */ -#define DEFAULT_NUM_PEERS 2 - /* test records to resolve */ #define TEST_DOMAIN "www.bob.gads" #define TEST_IP "127.0.0.1" @@ -50,10 +44,8 @@ #define KEYFILE_BOB "../namestore/zonefiles/HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey" -/* Globals */ - /* Task handle to use to schedule test failure */ -GNUNET_SCHEDULER_TaskIdentifier die_task; +static GNUNET_SCHEDULER_TaskIdentifier die_task; /* Global return value (0 for success, anything else for failure) */ static int ok; @@ -62,7 +54,8 @@ static struct GNUNET_NAMESTORE_Handle *namestore_handle; static struct GNUNET_GNS_Handle *gns_handle; -const struct GNUNET_CONFIGURATION_Handle *cfg; +static const struct GNUNET_CONFIGURATION_Handle *cfg; + /** * Check if the get_handle is being used, if so stop the request. Either @@ -89,6 +82,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) ok = 1; } + static void end_badly_now () { @@ -96,14 +90,17 @@ end_badly_now () die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); } -static void shutdown_task (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) + +static void +shutdown_task (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_GNS_disconnect(gns_handle); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n"); GNUNET_SCHEDULER_shutdown (); } + static void on_lookup_result(void *cls, uint32_t rd_count, const struct GNUNET_NAMESTORE_RecordData *rd) @@ -272,18 +269,13 @@ do_check (void *cls, } - int main (int argc, char *argv[]) { ok = 1; GNUNET_log_setup ("test-gns-revocation", -#if VERBOSE - "DEBUG", -#else "WARNING", -#endif NULL); GNUNET_TESTING_peer_run ("test-gns-revocation", "test_gns_simple_lookup.conf", &do_check, NULL); return ok; diff --git a/src/gns/test_gns_simple_delegated_lookup.c b/src/gns/test_gns_simple_delegated_lookup.c index b456e41120..c01bd8cce0 100644 --- a/src/gns/test_gns_simple_delegated_lookup.c +++ b/src/gns/test_gns_simple_delegated_lookup.c @@ -18,7 +18,7 @@ Boston, MA 02111-1307, USA. */ /** - * @file gns/test_gns_twopeer.c + * @file gns/test_gns_simple_delegated_lookup.c * @brief base testcase for testing DHT service with * two running peers. * @@ -46,15 +46,9 @@ #include "gnunet_dnsparser_lib.h" #include "gnunet_gns_service.h" -/* DEFINES */ -#define VERBOSE GNUNET_YES - /* Timeout for entire testcase */ #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) -/* If number of peers not in config file, use this number */ -#define DEFAULT_NUM_PEERS 2 - /* test records to resolve */ #define TEST_DOMAIN "www.bob.gads" #define TEST_IP "127.0.0.1" @@ -64,10 +58,8 @@ #define KEYFILE_BOB "../namestore/zonefiles/HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey" -/* Globals */ - /* Task handle to use to schedule test failure */ -GNUNET_SCHEDULER_TaskIdentifier die_task; +static GNUNET_SCHEDULER_TaskIdentifier die_task; /* Global return value (0 for success, anything else for failure) */ static int ok; @@ -76,7 +68,8 @@ static struct GNUNET_NAMESTORE_Handle *namestore_handle; static struct GNUNET_GNS_Handle *gns_handle; -const struct GNUNET_CONFIGURATION_Handle *cfg; +static const struct GNUNET_CONFIGURATION_Handle *cfg; + /** * Check if the get_handle is being used, if so stop the request. Either @@ -92,7 +85,6 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_GNS_disconnect(gns_handle); gns_handle = NULL; } - if (NULL != namestore_handle) { GNUNET_NAMESTORE_disconnect (namestore_handle); @@ -103,66 +95,60 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) ok = 1; } -void end_badly_now () -{ - GNUNET_SCHEDULER_cancel (die_task); - die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); -} - -static void shutdown_task (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +static void +shutdown_task (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) { - GNUNET_GNS_disconnect(gns_handle); + GNUNET_GNS_disconnect (gns_handle); + gns_handle = NULL; GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n"); GNUNET_SCHEDULER_shutdown (); } + static void -on_lookup_result(void *cls, uint32_t rd_count, - const struct GNUNET_NAMESTORE_RecordData *rd) +on_lookup_result (void *cls, uint32_t rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd) { + const char *name = cls; + uint32_t i; + const char* addr; struct in_addr a; - int i; - char* addr; - - if (GNUNET_SCHEDULER_NO_TASK != die_task) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = GNUNET_SCHEDULER_NO_TASK; - } GNUNET_NAMESTORE_disconnect (namestore_handle); - if (rd_count == 0) + namestore_handle = NULL; + if (0 == rd_count) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup failed, rp_filtering?\n"); + "Lookup failed!\n"); ok = 2; + GNUNET_SCHEDULER_shutdown (); + return; + } + if (GNUNET_SCHEDULER_NO_TASK != die_task) + { + GNUNET_SCHEDULER_cancel (die_task); + die_task = GNUNET_SCHEDULER_NO_TASK; } - else + ok = 1; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "name: %s\n", + name); + for (i=0; i