diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-14 15:07:04 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-14 15:07:04 +0000 |
commit | 274e545b05205c6779b634ca8969ebbee3db0029 (patch) | |
tree | e6b929304ed8bfdda9932243fad345089623211e /src | |
parent | 3cac797cab78c3c3cd874388d775f3fdeb3e31e1 (diff) | |
download | gnunet-274e545b05205c6779b634ca8969ebbee3db0029.tar.gz gnunet-274e545b05205c6779b634ca8969ebbee3db0029.zip |
-resolver bugfix, gnunet-gns command line features
Diffstat (limited to 'src')
-rw-r--r-- | src/gns/gns_api.c | 1 | ||||
-rw-r--r-- | src/gns/gnunet-gns.c | 88 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 11 |
3 files changed, 92 insertions, 8 deletions
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c index d6709a96e..fe1ba3200 100644 --- a/src/gns/gns_api.c +++ b/src/gns/gns_api.c | |||
@@ -591,6 +591,7 @@ GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
591 | void | 591 | void |
592 | GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle) | 592 | GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle) |
593 | { | 593 | { |
594 | GNUNET_CLIENT_disconnect (handle->client, 0); | ||
594 | /* disco from GNS */ | 595 | /* disco from GNS */ |
595 | } | 596 | } |
596 | 597 | ||
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c index 8c087defe..b689cab18 100644 --- a/src/gns/gnunet-gns.c +++ b/src/gns/gnunet-gns.c | |||
@@ -39,7 +39,25 @@ static struct GNUNET_GNS_Handle *gns; | |||
39 | /** | 39 | /** |
40 | * GNS name to shorten. (-s option) | 40 | * GNS name to shorten. (-s option) |
41 | */ | 41 | */ |
42 | static char *name; | 42 | static char *shorten_name; |
43 | |||
44 | /** | ||
45 | * GNS name to lookup. (-u option) | ||
46 | */ | ||
47 | static char *lookup_name; | ||
48 | |||
49 | |||
50 | /** | ||
51 | * record type to look up (-t option) | ||
52 | */ | ||
53 | static char *lookup_type; | ||
54 | |||
55 | /** | ||
56 | * name to look up authority for (-a option) | ||
57 | */ | ||
58 | static char *auth_name; | ||
59 | |||
60 | static enum GNUNET_GNS_RecordType rtype; | ||
43 | 61 | ||
44 | /** | 62 | /** |
45 | * Task run on shutdown. Cleans up everything. | 63 | * Task run on shutdown. Cleans up everything. |
@@ -65,6 +83,43 @@ process_shorten_result(void* cls, const char* nshort) | |||
65 | printf("%s shortened to %s\n", (char*) cls, nshort); | 83 | printf("%s shortened to %s\n", (char*) cls, nshort); |
66 | } | 84 | } |
67 | 85 | ||
86 | static void | ||
87 | process_lookup_result(void* cls, uint32_t rd_count, | ||
88 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
89 | { | ||
90 | int i; | ||
91 | char* addr; | ||
92 | char* name = (char*) cls; | ||
93 | |||
94 | if (rd_count == 0) | ||
95 | printf("No results.\n"); | ||
96 | |||
97 | for (i=0; i<rd_count; i++) | ||
98 | { | ||
99 | if (rd[i].record_type != rtype) | ||
100 | continue; | ||
101 | if (rd[i].record_type == GNUNET_GNS_RECORD_TYPE_A) | ||
102 | { | ||
103 | addr = inet_ntoa(*((struct in_addr*)rd[i].data)); | ||
104 | printf("Got A record for %s: %s\n", name, addr); | ||
105 | } | ||
106 | if (rd[i].record_type == GNUNET_GNS_RECORD_MX) | ||
107 | { | ||
108 | printf("Got MX record for %s: %s\n", name, (char*)rd[i].data); | ||
109 | } | ||
110 | |||
111 | //FIXME others? maybe to string method for records? | ||
112 | } | ||
113 | |||
114 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
115 | } | ||
116 | |||
117 | static void | ||
118 | process_auth_result(void* cls, const char* auth) | ||
119 | { | ||
120 | printf ("%s\n", auth); | ||
121 | } | ||
122 | |||
68 | /** | 123 | /** |
69 | * Main function that will be run. | 124 | * Main function that will be run. |
70 | * | 125 | * |
@@ -78,6 +133,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
78 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 133 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
79 | { | 134 | { |
80 | gns = GNUNET_GNS_connect (cfg); | 135 | gns = GNUNET_GNS_connect (cfg); |
136 | rtype = GNUNET_GNS_RECORD_TYPE_A; | ||
137 | |||
81 | if (NULL == gns) | 138 | if (NULL == gns) |
82 | { | 139 | { |
83 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 140 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -85,14 +142,26 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
85 | return; | 142 | return; |
86 | } | 143 | } |
87 | 144 | ||
88 | if (name != NULL) | 145 | if (shorten_name != NULL) |
89 | { | 146 | { |
90 | /** shorten name */ | 147 | /** shorten name */ |
91 | GNUNET_GNS_shorten(gns, name, &process_shorten_result, name); | 148 | GNUNET_GNS_shorten(gns, shorten_name, &process_shorten_result, |
149 | shorten_name); | ||
150 | } | ||
151 | |||
152 | if (lookup_name != NULL) | ||
153 | { | ||
154 | GNUNET_GNS_lookup(gns, lookup_name, rtype, | ||
155 | &process_lookup_result, lookup_name); | ||
92 | } | 156 | } |
93 | 157 | ||
158 | if (auth_name != NULL) | ||
159 | { | ||
160 | GNUNET_GNS_get_authority(gns, auth_name, &process_auth_result, auth_name); | ||
161 | } | ||
162 | |||
94 | // FIXME: do work here... | 163 | // FIXME: do work here... |
95 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 164 | //GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
96 | } | 165 | } |
97 | 166 | ||
98 | 167 | ||
@@ -109,7 +178,16 @@ main (int argc, char *const *argv) | |||
109 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 178 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
110 | {'s', "shorten", NULL, | 179 | {'s', "shorten", NULL, |
111 | gettext_noop ("try to shorten a given GNS name"), 1, | 180 | gettext_noop ("try to shorten a given GNS name"), 1, |
112 | &GNUNET_GETOPT_set_string, &name}, | 181 | &GNUNET_GETOPT_set_string, &shorten_name}, |
182 | {'u', "lookup", NULL, | ||
183 | gettext_noop ("Lookup a record using GNS (NOT IMPLEMENTED)"), 1, | ||
184 | &GNUNET_GETOPT_set_string, &lookup_name}, | ||
185 | {'a', "authority", NULL, | ||
186 | gettext_noop ("Get the authority of a particular name"), 1, | ||
187 | &GNUNET_GETOPT_set_string, &auth_name}, | ||
188 | {'t', "type", NULL, | ||
189 | gettext_noop ("Specify the type of the record lookup"), 1, | ||
190 | &GNUNET_GETOPT_set_string, &lookup_type}, | ||
113 | GNUNET_GETOPT_OPTION_END | 191 | GNUNET_GETOPT_OPTION_END |
114 | }; | 192 | }; |
115 | 193 | ||
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 53fdcc463..d3e9d8da6 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -651,8 +651,10 @@ handle_record_ns(void* cls, struct ResolverHandle *rh, | |||
651 | rlh = (struct RecordLookupHandle*) cls; | 651 | rlh = (struct RecordLookupHandle*) cls; |
652 | if (rd_count == 0) | 652 | if (rd_count == 0) |
653 | { | 653 | { |
654 | /* ns entry expired. try dht */ | 654 | /* ns entry expired and not ours. try dht */ |
655 | if (rh->status & (EXPIRED | !EXISTS)) | 655 | if (rh->status & (EXPIRED | !EXISTS) && |
656 | GNUNET_CRYPTO_hash_cmp(&rh->authority_chain_head->zone, | ||
657 | &rh->authority_chain_tail->zone)) | ||
656 | { | 658 | { |
657 | rh->proc = &handle_record_dht; | 659 | rh->proc = &handle_record_dht; |
658 | resolve_record_dht(rh); | 660 | resolve_record_dht(rh); |
@@ -842,7 +844,10 @@ handle_delegation_ns(void* cls, struct ResolverHandle *rh, | |||
842 | * we still have some left | 844 | * we still have some left |
843 | * check if ns entry is fresh | 845 | * check if ns entry is fresh |
844 | **/ | 846 | **/ |
845 | if (rh->status & (EXISTS | !EXPIRED)) | 847 | |
848 | if ((rh->status & (EXISTS | !EXPIRED)) || | ||
849 | !GNUNET_CRYPTO_hash_cmp(&rh->authority_chain_head->zone, | ||
850 | &rh->authority_chain_tail->zone)) | ||
846 | { | 851 | { |
847 | if (is_canonical(rh->name)) | 852 | if (is_canonical(rh->name)) |
848 | { | 853 | { |