aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-10-25 12:59:41 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-10-25 12:59:41 +0000
commit64a061d90ded1dc913e3c8186dba11bfca9aff9e (patch)
treef55dc91c945f33817fd8649d408ab757dc229cdb /src/namestore
parentb596994ef30cb2b2b797654108ddcca331245da0 (diff)
downloadgnunet-64a061d90ded1dc913e3c8186dba11bfca9aff9e.tar.gz
gnunet-64a061d90ded1dc913e3c8186dba11bfca9aff9e.zip
- clean protocol number
- added lookup protocol numbers - implemented lookup sending
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/Makefile.am10
-rw-r--r--src/namestore/gnunet-service-namestore.c45
-rw-r--r--src/namestore/namestore.h10
-rw-r--r--src/namestore/namestore_api.c3
-rw-r--r--src/namestore/test_namestore_api_lookup_private.c186
5 files changed, 248 insertions, 6 deletions
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index c80fd3ef3..bd0754fc3 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -40,6 +40,7 @@ TESTING_TESTS = \
40 test_namestore_api_store \ 40 test_namestore_api_store \
41 test_namestore_api_store_update \ 41 test_namestore_api_store_update \
42 test_namestore_api_lookup_public \ 42 test_namestore_api_lookup_public \
43 test_namestore_api_lookup_private \
43 test_namestore_api_remove \ 44 test_namestore_api_remove \
44 test_namestore_api_remove_not_existing_record \ 45 test_namestore_api_remove_not_existing_record \
45 test_namestore_api_zone_iteration \ 46 test_namestore_api_zone_iteration \
@@ -196,6 +197,15 @@ test_namestore_api_lookup_public_LDADD = \
196 $(top_builddir)/src/namecache/libgnunetnamecache.la \ 197 $(top_builddir)/src/namecache/libgnunetnamecache.la \
197 $(top_builddir)/src/namestore/libgnunetnamestore.la 198 $(top_builddir)/src/namestore/libgnunetnamestore.la
198 199
200test_namestore_api_lookup_private_SOURCES = \
201 test_namestore_api_lookup_private.c
202test_namestore_api_lookup_private_LDADD = \
203 $(top_builddir)/src/testing/libgnunettesting.la \
204 $(top_builddir)/src/util/libgnunetutil.la \
205 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
206 $(top_builddir)/src/namecache/libgnunetnamecache.la \
207 $(top_builddir)/src/namestore/libgnunetnamestore.la
208
199test_namestore_api_put_SOURCES = \ 209test_namestore_api_put_SOURCES = \
200 test_namestore_api_put.c 210 test_namestore_api_put.c
201test_namestore_api_put_LDADD = \ 211test_namestore_api_put_LDADD = \
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index 58f214e43..79e154cc2 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -561,6 +561,49 @@ refresh_block (struct GNUNET_SERVER_Client *client,
561 GNUNET_free (block); 561 GNUNET_free (block);
562} 562}
563 563
564/**
565 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP message
566 *
567 * @param cls unused
568 * @param client client sending the message
569 * @param message message of type 'struct RecordCreateMessage'
570 */
571static void
572handle_record_lookup (void *cls,
573 struct GNUNET_SERVER_Client *client,
574 const struct GNUNET_MessageHeader *message)
575{
576 const struct LabelLookupMessage * ll_msg;
577 const char *name_tmp;
578 uint32_t rid;
579 uint32_t name_len;
580 size_t msg_size;
581
582 if (ntohs (message->size) < sizeof (struct LabelLookupMessage))
583 {
584 GNUNET_break (0);
585 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
586 return;
587 }
588
589 ll_msg = (const struct LabelLookupMessage *) message;
590 rid = ntohl (ll_msg->gns_header.r_id);
591 name_len = ntohs (ll_msg->label_len);
592 msg_size = ntohs (message->size);
593
594 if (name_len != msg_size - sizeof (struct LabelLookupMessage))
595 {
596 GNUNET_break (0);
597 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
598 return;
599 }
600 name_tmp = &ll_msg[1];
601
602 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
603 "Received `%s' message for name `%s'\n",
604 "NAMESTORE_RECORD_LOOKUP", name_tmp);
605}
606
564 607
565/** 608/**
566 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE message 609 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE message
@@ -1292,6 +1335,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1292 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 1335 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
1293 {&handle_record_store, NULL, 1336 {&handle_record_store, NULL,
1294 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE, 0}, 1337 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE, 0},
1338 {&handle_record_lookup, NULL,
1339 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP, 0},
1295 {&handle_zone_to_name, NULL, 1340 {&handle_zone_to_name, NULL,
1296 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME, sizeof (struct ZoneToNameMessage) }, 1341 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME, sizeof (struct ZoneToNameMessage) },
1297 {&handle_iteration_start, NULL, 1342 {&handle_iteration_start, NULL,
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h
index bd0cf82cc..d633f7393 100644
--- a/src/namestore/namestore.h
+++ b/src/namestore/namestore.h
@@ -215,19 +215,19 @@ struct RecordStoreResponseMessage
215struct LabelLookupMessage 215struct LabelLookupMessage
216{ 216{
217 /** 217 /**
218 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_LABEL_LOOKUP 218 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP
219 */ 219 */
220 struct GNUNET_NAMESTORE_Header gns_header; 220 struct GNUNET_NAMESTORE_Header gns_header;
221 221
222 /** 222 /**
223 * The private key of the zone to look up in 223 * Length of the name
224 */ 224 */
225 struct GNUNET_CRYPTO_EcdsaPrivateKey zone; 225 uint32_t label_len GNUNET_PACKED;
226 226
227 /** 227 /**
228 * Length of the name 228 * The private key of the zone to look up in
229 */ 229 */
230 uint16_t label_len GNUNET_PACKED; 230 struct GNUNET_CRYPTO_EcdsaPrivateKey zone;
231 231
232 /* followed by: 232 /* followed by:
233 * name with length name_len 233 * name with length name_len
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index 8d3ea16dd..9d290fca2 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -1022,11 +1022,12 @@ GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
1022 pe = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size); 1022 pe = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size);
1023 pe->size = msg_size; 1023 pe->size = msg_size;
1024 msg = (struct LabelLookupMessage *) &pe[1]; 1024 msg = (struct LabelLookupMessage *) &pe[1];
1025 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LABEL_LOOKUP); 1025 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP);
1026 msg->gns_header.header.size = htons (msg_size); 1026 msg->gns_header.header.size = htons (msg_size);
1027 msg->gns_header.r_id = htonl (qe->op_id); 1027 msg->gns_header.r_id = htonl (qe->op_id);
1028 msg->zone = *pkey; 1028 msg->zone = *pkey;
1029 msg->label_len = htons(label_len); 1029 msg->label_len = htons(label_len);
1030 memcpy (&msg[1], label, label_len);
1030 1031
1031 /* transmit message */ 1032 /* transmit message */
1032 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); 1033 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
diff --git a/src/namestore/test_namestore_api_lookup_private.c b/src/namestore/test_namestore_api_lookup_private.c
new file mode 100644
index 000000000..1678ba970
--- /dev/null
+++ b/src/namestore/test_namestore_api_lookup_private.c
@@ -0,0 +1,186 @@
1/*
2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file namestore/test_namestore_api_store.c
22 * @brief testcase for namestore_api.c: store a record
23 */
24#include "platform.h"
25#include "gnunet_namestore_service.h"
26#include "gnunet_testing_lib.h"
27
28#define TEST_RECORD_TYPE 1234
29
30#define TEST_RECORD_DATALEN 123
31
32#define TEST_RECORD_DATA 'a'
33
34#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
35
36static struct GNUNET_NAMESTORE_Handle *nsh;
37
38static GNUNET_SCHEDULER_TaskIdentifier endbadly_task;
39
40static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
41
42static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
43
44static int res;
45
46static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
47
48static const char * name = "dummy.dummy.gnunet";
49
50static void
51cleanup ()
52{
53 if (NULL != nsh)
54 {
55 GNUNET_NAMESTORE_disconnect (nsh);
56 nsh = NULL;
57 }
58 if (NULL != privkey)
59 {
60 GNUNET_free (privkey);
61 privkey = NULL;
62 }
63 GNUNET_SCHEDULER_shutdown ();
64}
65
66
67/**
68 * Re-establish the connection to the service.
69 *
70 * @param cls handle to use to re-connect.
71 * @param tc scheduler context
72 */
73static void
74endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
75{
76 if (NULL != nsqe)
77 {
78 GNUNET_NAMESTORE_cancel (nsqe);
79 nsqe = NULL;
80 }
81 cleanup ();
82 res = 1;
83}
84
85
86static void
87end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
88{
89 cleanup ();
90 res = 0;
91}
92
93void lookup_it (void *cls,
94 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
95 const char *label,
96 unsigned int rd_count,
97 const struct GNUNET_GNSRECORD_Data *rd)
98{
99 /* Check here */
100
101
102 /* Done */
103 GNUNET_SCHEDULER_cancel (endbadly_task);
104 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
105 GNUNET_SCHEDULER_add_now (&end, NULL);
106}
107
108
109static void
110put_cont (void *cls, int32_t success, const char *emsg)
111{
112 const char *name = cls;
113
114 nsqe = NULL;
115 GNUNET_assert (NULL != cls);
116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
117 "Name store added record for `%s': %s\n",
118 name,
119 (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
120
121 if (GNUNET_OK != success)
122 {
123 GNUNET_SCHEDULER_cancel (endbadly_task);
124 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
125 return;
126 }
127 /* Lookup */
128 nsqe = GNUNET_NAMESTORE_records_lookup (nsh, privkey, name, lookup_it, NULL);
129}
130
131
132static void
133run (void *cls,
134 const struct GNUNET_CONFIGURATION_Handle *cfg,
135 struct GNUNET_TESTING_Peer *peer)
136{
137 struct GNUNET_GNSRECORD_Data rd;
138 char *hostkey_file;
139
140 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
141 &endbadly, NULL);
142 GNUNET_asprintf (&hostkey_file,
143 "zonefiles%s%s",
144 DIR_SEPARATOR_STR,
145 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
147 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
148 GNUNET_free (hostkey_file);
149 GNUNET_assert (privkey != NULL);
150 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
151
152 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us;
153 rd.record_type = TEST_RECORD_TYPE;
154 rd.data_size = TEST_RECORD_DATALEN;
155 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
156 memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN);
157
158 nsh = GNUNET_NAMESTORE_connect (cfg);
159 GNUNET_break (NULL != nsh);
160 nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
161 1, &rd, &put_cont, (void *) name);
162 if (NULL == nsqe)
163 {
164 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
165 _("Namestore cannot store no block\n"));
166 }
167
168 GNUNET_free ((void *)rd.data);
169}
170
171
172int
173main (int argc, char *argv[])
174{
175 res = 1;
176 if (0 !=
177 GNUNET_TESTING_peer_run ("test-namestore-api",
178 "test_namestore_api.conf",
179 &run,
180 NULL))
181 return 1;
182 return res;
183}
184
185
186/* end of test_namestore_api_store.c */