diff options
Diffstat (limited to 'src/gns/gnunet-service-gns.c')
-rw-r--r-- | src/gns/gnunet-service-gns.c | 139 |
1 files changed, 134 insertions, 5 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index ce83af60d..19195d419 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -153,8 +153,8 @@ struct ClientShortenHandle | |||
153 | /* request id */ | 153 | /* request id */ |
154 | uint64_t unique_id; | 154 | uint64_t unique_id; |
155 | 155 | ||
156 | /* request key */ | 156 | /* request type */ |
157 | GNUNET_HashCode key; | 157 | enum GNUNET_GNS_RecordType type; |
158 | 158 | ||
159 | /* name to shorten */ | 159 | /* name to shorten */ |
160 | char* name; | 160 | char* name; |
@@ -172,8 +172,8 @@ struct ClientLookupHandle | |||
172 | /* request id */ | 172 | /* request id */ |
173 | uint64_t unique_id; | 173 | uint64_t unique_id; |
174 | 174 | ||
175 | /* request key */ | 175 | /* request type */ |
176 | GNUNET_HashCode key; | 176 | enum GNUNET_GNS_RecordType type; |
177 | 177 | ||
178 | /* the name to look up */ | 178 | /* the name to look up */ |
179 | char* name; //Needed? | 179 | char* name; //Needed? |
@@ -2229,13 +2229,142 @@ static void handle_shorten(void *cls, | |||
2229 | } | 2229 | } |
2230 | 2230 | ||
2231 | /** | 2231 | /** |
2232 | * TODO | 2232 | * Reply to client with the result from our lookup. |
2233 | * | ||
2234 | * @param cls the closure (our client lookup handle) | ||
2235 | * @param rh the request handle of the lookup | ||
2236 | * @param rd_count the number of records | ||
2237 | * @param rd the record data | ||
2238 | */ | ||
2239 | static void | ||
2240 | reply_to_client(void* cls, struct GNUNET_GNS_ResolverHandle *rh, | ||
2241 | uint32_t rd_count, | ||
2242 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
2243 | { | ||
2244 | struct ClientLookupHandle* clh = (struct ClientLookupHandle*)cls; | ||
2245 | struct GNUNET_GNS_ClientLookupResultMessage *rmsg; | ||
2246 | size_t len; | ||
2247 | |||
2248 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message with %d results\n", | ||
2249 | "LOOKUP_RESULT", rd_count); | ||
2250 | |||
2251 | len = GNUNET_NAMESTORE_records_get_size (rd_count, rd); | ||
2252 | rmsg = GNUNET_malloc(len+sizeof(struct GNUNET_GNS_ClientLookupResultMessage)); | ||
2253 | |||
2254 | rmsg->id = clh->unique_id; | ||
2255 | rmsg->rd_count = htonl(rd_count); | ||
2256 | rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT); | ||
2257 | rmsg->header.size = | ||
2258 | htons(len+sizeof(struct GNUNET_GNS_ClientLookupResultMessage)); | ||
2259 | |||
2260 | GNUNET_NAMESTORE_records_serialize (rd_count, rd, len, (char*)&rmsg[1]); | ||
2261 | |||
2262 | GNUNET_SERVER_notification_context_unicast (nc, clh->client, | ||
2263 | (const struct GNUNET_MessageHeader *) rmsg, | ||
2264 | GNUNET_NO); | ||
2265 | GNUNET_SERVER_receive_done (clh->client, GNUNET_OK); | ||
2266 | GNUNET_free(rmsg); | ||
2267 | GNUNET_free(clh->name); | ||
2268 | GNUNET_free(clh); | ||
2269 | |||
2270 | } | ||
2271 | |||
2272 | /** | ||
2273 | * Lookup a given name | ||
2274 | * | ||
2275 | * @param name the name to looku[ | ||
2276 | * @param clh the client lookup handle | ||
2277 | */ | ||
2278 | static void | ||
2279 | lookup_name(char* name, struct ClientLookupHandle* clh) | ||
2280 | { | ||
2281 | |||
2282 | struct GNUNET_GNS_ResolverHandle *rh; | ||
2283 | struct RecordLookupHandle* rlh; | ||
2284 | |||
2285 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2286 | "Starting resolution for %s (type=%d)!\n", | ||
2287 | name, clh->type); | ||
2288 | |||
2289 | rh = GNUNET_malloc(sizeof (struct GNUNET_GNS_ResolverHandle)); | ||
2290 | rlh = GNUNET_malloc(sizeof(struct RecordLookupHandle)); | ||
2291 | |||
2292 | rh->authority = zone_hash; | ||
2293 | |||
2294 | rlh->record_type = clh->type; | ||
2295 | rlh->name = clh->name; | ||
2296 | rlh->proc = &reply_to_client; | ||
2297 | rlh->proc_cls = clh; | ||
2298 | |||
2299 | rh->proc_cls = rlh; | ||
2300 | |||
2301 | rh->name = GNUNET_malloc(strlen(name) | ||
2302 | - strlen(gnunet_tld) + 1); | ||
2303 | memset(rh->name, 0, | ||
2304 | strlen(name)-strlen(gnunet_tld) + 1); | ||
2305 | memcpy(rh->name, name, | ||
2306 | strlen(name)-strlen(gnunet_tld)); | ||
2307 | |||
2308 | rh->authority_name = GNUNET_malloc(sizeof(char)*MAX_DNS_LABEL_LENGTH); | ||
2309 | |||
2310 | rh->authority_chain_head = GNUNET_malloc(sizeof(struct AuthorityChain)); | ||
2311 | rh->authority_chain_head->prev = NULL; | ||
2312 | rh->authority_chain_head->next = NULL; | ||
2313 | rh->authority_chain_tail = rh->authority_chain_head; | ||
2314 | rh->authority_chain_head->zone = zone_hash; | ||
2315 | |||
2316 | /* Start resolution in our zone */ | ||
2317 | rh->proc = &process_ns_delegation_dns; //FIXME rename | ||
2318 | resolve_delegation_from_ns(rh); | ||
2319 | } | ||
2320 | |||
2321 | |||
2322 | /** | ||
2323 | * Handle lookup requests from client | ||
2324 | * | ||
2325 | * @param cls the closure | ||
2326 | * @param client the client | ||
2327 | * @param message the message | ||
2233 | */ | 2328 | */ |
2234 | static void | 2329 | static void |
2235 | handle_lookup(void *cls, | 2330 | handle_lookup(void *cls, |
2236 | struct GNUNET_SERVER_Client * client, | 2331 | struct GNUNET_SERVER_Client * client, |
2237 | const struct GNUNET_MessageHeader * message) | 2332 | const struct GNUNET_MessageHeader * message) |
2238 | { | 2333 | { |
2334 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "LOOKUP"); | ||
2335 | |||
2336 | size_t msg_size = 0; | ||
2337 | struct ClientLookupHandle *clh; | ||
2338 | |||
2339 | if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage)) | ||
2340 | { | ||
2341 | GNUNET_break_op (0); | ||
2342 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
2343 | return; | ||
2344 | } | ||
2345 | |||
2346 | GNUNET_SERVER_notification_context_add (nc, client); | ||
2347 | |||
2348 | struct GNUNET_GNS_ClientLookupMessage *sh_msg = | ||
2349 | (struct GNUNET_GNS_ClientLookupMessage *) message; | ||
2350 | |||
2351 | msg_size = ntohs(message->size); | ||
2352 | |||
2353 | if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE) | ||
2354 | { | ||
2355 | GNUNET_break_op (0); | ||
2356 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
2357 | return; | ||
2358 | } | ||
2359 | |||
2360 | clh = GNUNET_malloc(sizeof(struct ClientLookupHandle)); | ||
2361 | clh->client = client; | ||
2362 | clh->name = GNUNET_malloc(strlen((char*)&sh_msg[1]) + 1); | ||
2363 | strcpy(clh->name, (char*)&sh_msg[1]); | ||
2364 | clh->unique_id = sh_msg->id; | ||
2365 | clh->type = ntohl(sh_msg->type); | ||
2366 | |||
2367 | lookup_name((char*)&sh_msg[1], clh); | ||
2239 | } | 2368 | } |
2240 | 2369 | ||
2241 | /** | 2370 | /** |