diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-10-25 12:59:41 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-10-25 12:59:41 +0000 |
commit | 64a061d90ded1dc913e3c8186dba11bfca9aff9e (patch) | |
tree | f55dc91c945f33817fd8649d408ab757dc229cdb /src/namestore/test_namestore_api_lookup_private.c | |
parent | b596994ef30cb2b2b797654108ddcca331245da0 (diff) | |
download | gnunet-64a061d90ded1dc913e3c8186dba11bfca9aff9e.tar.gz gnunet-64a061d90ded1dc913e3c8186dba11bfca9aff9e.zip |
- clean protocol number
- added lookup protocol numbers
- implemented lookup sending
Diffstat (limited to 'src/namestore/test_namestore_api_lookup_private.c')
-rw-r--r-- | src/namestore/test_namestore_api_lookup_private.c | 186 |
1 files changed, 186 insertions, 0 deletions
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 | |||
36 | static struct GNUNET_NAMESTORE_Handle *nsh; | ||
37 | |||
38 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; | ||
39 | |||
40 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | ||
41 | |||
42 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | ||
43 | |||
44 | static int res; | ||
45 | |||
46 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | ||
47 | |||
48 | static const char * name = "dummy.dummy.gnunet"; | ||
49 | |||
50 | static void | ||
51 | cleanup () | ||
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 | */ | ||
73 | static void | ||
74 | endbadly (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 | |||
86 | static void | ||
87 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
88 | { | ||
89 | cleanup (); | ||
90 | res = 0; | ||
91 | } | ||
92 | |||
93 | void 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 | |||
109 | static void | ||
110 | put_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 | |||
132 | static void | ||
133 | run (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 | |||
172 | int | ||
173 | main (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 */ | ||