From 2a91d7a296a03a55f5b707344c81c626f1bb9d16 Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Mon, 27 Feb 2012 18:33:49 +0000 Subject: [PATCH] -cleanup, fixes --- src/gns/gnunet-service-gns.c | 71 +++++++---------------------------- src/gns/test_gns_twopeer.c | 31 +++++++++++---- src/gns/test_gns_twopeer.conf | 1 + 3 files changed, 39 insertions(+), 64 deletions(-) diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 0e287f6ac..6f3cb9900 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c @@ -817,9 +817,9 @@ char* pop_tld(char* name) } if (len == 0) - return NULL; //Error + return NULL; - name[len] = '\0'; //terminate string + name[len] = '\0'; return (name+len+1); } @@ -839,7 +839,7 @@ resolve_name(struct GNUNET_GNS_ResolverHandle *rh) { if (is_canonical(rh->name)) { - //We only need to check this zone's ns + /* We only need to check the current zone's ns */ GNUNET_NAMESTORE_lookup_record(namestore_handle, &rh->authority, rh->name, @@ -849,7 +849,7 @@ resolve_name(struct GNUNET_GNS_ResolverHandle *rh) } else { - //We have to resolve the authoritative entity + /* We have to resolve the authoritative entity first */ rh->authority_name = pop_tld(rh->name); GNUNET_NAMESTORE_lookup_record(namestore_handle, &rh->authority, @@ -885,7 +885,6 @@ start_resolution(struct GNUNET_DNS_RequestHandle *request, rh->query = q; rh->authority = zone_hash; - //FIXME do not forget to free!! rh->name = GNUNET_malloc(strlen(q->name) - strlen(gnunet_tld) + 1); memset(rh->name, 0, @@ -895,7 +894,7 @@ start_resolution(struct GNUNET_DNS_RequestHandle *request, rh->request_handle = request; - //Start resolution in our zone + /* Start resolution in our zone */ resolve_name(rh); } @@ -949,7 +948,7 @@ handle_dns_request(void *cls, if (p->num_queries > 1) { - //Note: We could also look for .gnunet + /* Note: We could also look for .gnunet */ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, ">1 queriy in DNS packet... odd. We only process #1\n"); } @@ -983,71 +982,25 @@ void put_some_records(void) { GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Populating namestore\n"); - /* put a few records into namestore */ - char* ipA = "1.2.3.4"; + /* put an A record into namestore FIXME use gnunet.org */ char* ipB = "5.6.7.8"; - //struct GNUNET_CRYPTO_RsaPrivateKey *bob_key = GNUNET_CRYPTO_rsa_key_create (); - //struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *bob; - //bob = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); - - //GNUNET_CRYPTO_rsa_key_get_public (bob_key, bob); - - //GNUNET_HashCode *bob_zone = GNUNET_malloc(sizeof(GNUNET_HashCode)); - - //GNUNET_CRYPTO_hash(bob, GNUNET_CRYPTO_RSA_KEY_LENGTH, bob_zone); - struct in_addr *alice = GNUNET_malloc(sizeof(struct in_addr)); struct in_addr *web = GNUNET_malloc(sizeof(struct in_addr)); - struct GNUNET_NAMESTORE_RecordData rda; - //struct GNUNET_NAMESTORE_RecordData rdb; struct GNUNET_NAMESTORE_RecordData rdb_web; - GNUNET_assert(1 == inet_pton (AF_INET, ipA, alice)); GNUNET_assert(1 == inet_pton (AF_INET, ipB, web)); - rda.data_size = sizeof(struct in_addr); rdb_web.data_size = sizeof(struct in_addr); - //rdb.data_size = sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); - rda.data = alice; - //rdb.data = bob; rdb_web.data = web; - rda.record_type = GNUNET_GNS_RECORD_TYPE_A; rdb_web.record_type = GNUNET_DNSPARSER_TYPE_A; - //rdb.record_type = GNUNET_GNS_RECORD_PKEY; rdb_web.expiration = GNUNET_TIME_absolute_get_forever (); - rda.expiration = GNUNET_TIME_absolute_get_forever (); - //rdb.expiration = GNUNET_TIME_absolute_get_forever (); - //alice.gnunet A IN 1.2.3.4 - /*GNUNET_NAMESTORE_record_create (namestore_handle, - zone_key, - "alice", - &rda, - NULL, - NULL);*/ GNUNET_NAMESTORE_record_create (namestore_handle, zone_key, "www", &rdb_web, NULL, NULL); -/* - //www.bob.gnunet A IN 5.6.7.8 - GNUNET_NAMESTORE_record_create (namestore_handle, - zone_key, - "bob", - &rdb, - NULL, - NULL);*/ - /*GNUNET_NAMESTORE_record_put(namestore_handle, - zone_key, - "www", - GNUNET_TIME_absolute_get_forever (), - 1, - &rdb_web, - NULL, //Signature - NULL, //Cont - NULL); //cls*/ } void @@ -1097,7 +1050,8 @@ put_gns_record(void *cls, int i; uint32_t rd_payload_length; - if (NULL == name) //We're done + /* we're done */ + if (NULL == name) { GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Zone iteration finished\n"); GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter); @@ -1108,7 +1062,8 @@ put_gns_record(void *cls, rd_payload_length = rd_count * sizeof(struct GNSRecordBlock); rd_payload_length += strlen(name) + 1 + sizeof(struct GNSNameRecordBlock); - //Calculate payload size + + /* calculate payload size */ for (i=0; ird_count = htonl(rd_count); - memcpy(&nrb[1], name, strlen(name) + 1); //FIXME is this 0 terminated??-sure hope so for we use strlen + memcpy(&nrb[1], name, strlen(name) + 1); //FIXME is this 0 terminated?? rb = (struct GNSRecordBlock *)((char*)&nrb[1] + strlen(name) + 1); @@ -1273,6 +1228,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, GNUNET_CONFIGURATION_get_value_yesno (c, "gns", "HIJACK_DNS")) { + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "DNS hijacking enabled... connecting to service.\n"); /** * Do gnunet dns init here */ diff --git a/src/gns/test_gns_twopeer.c b/src/gns/test_gns_twopeer.c index e30092cc5..3bd36fb17 100644 --- a/src/gns/test_gns_twopeer.c +++ b/src/gns/test_gns_twopeer.c @@ -187,6 +187,7 @@ gns_started(void *cls, const struct GNUNET_PeerIdentity *id, } if (d == d1) { + /* start gns for bob */ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "GNS started on alice\n"); GNUNET_TESTING_daemon_start_service (d2, "gns", TIMEOUT, &gns_started, NULL); @@ -195,6 +196,7 @@ gns_started(void *cls, const struct GNUNET_PeerIdentity *id, GNUNET_log (GNUNET_ERROR_TYPE_INFO, "GNS started on bob\n"); + /* start the lookup tests */ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), &do_lookup, NULL); @@ -247,6 +249,8 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *first, GNUNET_SCHEDULER_cancel (die_task); die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, "from test lookup"); + + /* start gns for alice */ GNUNET_TESTING_daemon_start_service (d1, "gns", TIMEOUT, &gns_started, NULL); } @@ -266,6 +270,7 @@ static void alice_idle (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { + alice_online = 1; if (!bob_online) { GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply @@ -282,10 +287,10 @@ alice_idle (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void bob_idle (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - + /* he's lazy FIXME forever */ bob_online = 1; bob_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, 2), + (GNUNET_TIME_UNIT_SECONDS, 20), &bob_idle, NULL); } @@ -316,7 +321,6 @@ alice_started (void *cls, const struct GNUNET_PeerIdentity *id, } GNUNET_assert (id != NULL); - alice_online = 1; GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), &alice_idle, NULL); @@ -335,7 +339,6 @@ bob_started (void *cls, const struct GNUNET_PeerIdentity *id, } GNUNET_assert (id != NULL); - alice_online = 1; GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), &bob_idle, NULL); @@ -368,25 +371,39 @@ run (void *cls, char *const *args, const char *cfgfile, die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, "didn't start all daemons in reasonable amount of time!!!"); + alice_online = 0; bob_online = 0; + expected_connections = 1; + + /* Start alice */ d1 = GNUNET_TESTING_daemon_start(cfg, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL, NULL, NULL, &alice_started, NULL); + + /* Somebody care to explain? */ uint16_t port = 6000; - expected_connections = 1; uint32_t upnum = 23; uint32_t fdnum = 42; + + + /** + * Modify some config options for bob + * namely swap keys and disable dns hijacking + */ struct GNUNET_CONFIGURATION_Handle *cfg2 = GNUNET_TESTING_create_cfg(cfg, 23, &port, &upnum, NULL, &fdnum); + GNUNET_CONFIGURATION_set_value_string (cfg2, "paths", "servicehome", - "/tmp/peer2"); + "/tmp/test-gnunetd-gns-peer-2/"); GNUNET_CONFIGURATION_set_value_string (cfg2, "gns", "HIJACK_DNS", "NO"); GNUNET_CONFIGURATION_set_value_string (cfg2, "gns", "ZONEKEY", "/tmp/bobkey"); GNUNET_CONFIGURATION_set_value_string (cfg2, "gns", "TRUSTED", - "alice:/tmp/zonekey"); + "alice:/tmp/alicekey"); + + //Start bob d2 = GNUNET_TESTING_daemon_start(cfg2, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL, NULL, NULL, &bob_started, NULL); diff --git a/src/gns/test_gns_twopeer.conf b/src/gns/test_gns_twopeer.conf index 221aa0031..16d8b3ab7 100644 --- a/src/gns/test_gns_twopeer.conf +++ b/src/gns/test_gns_twopeer.conf @@ -71,6 +71,7 @@ AUTOSTART = YES [gns] AUTOSTART = YES BINARY = gnunet-service-gns +ZONEKEY = /tmp/alicekey [nse] -- 2.25.1