aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-09-11 10:44:09 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-09-11 10:44:09 +0000
commit06fe1957600739d6b6546a1276c0693d058e6caa (patch)
tree0e573a0949d93cf3dfce9531eb65fb5dba00e8ec /src
parent1cd12d09f18474f7720bd4b33316087b83623bf4 (diff)
downloadgnunet-06fe1957600739d6b6546a1276c0693d058e6caa.tar.gz
gnunet-06fe1957600739d6b6546a1276c0693d058e6caa.zip
new test
Diffstat (limited to 'src')
-rw-r--r--src/namestore/Makefile.am2
-rw-r--r--src/namestore/test_namestore_api_remove_not_existing_record.c218
2 files changed, 106 insertions, 114 deletions
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index 639a4484e..d29cb4766 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -44,12 +44,12 @@ TESTING_TESTS = \
44 test_namestore_api_store \ 44 test_namestore_api_store \
45 test_namestore_api_store_update \ 45 test_namestore_api_store_update \
46 test_namestore_api_remove \ 46 test_namestore_api_remove \
47 test_namestore_api_remove_not_existing_record \
47 test_namestore_api_zone_iteration \ 48 test_namestore_api_zone_iteration \
48 test_namestore_api_zone_iteration_specific_zone \ 49 test_namestore_api_zone_iteration_specific_zone \
49 test_namestore_api_zone_iteration_stop \ 50 test_namestore_api_zone_iteration_stop \
50 test_namestore_api_monitoring \ 51 test_namestore_api_monitoring \
51 test_namestore_api_monitoring_existing 52 test_namestore_api_monitoring_existing
52#test_namestore_api_remove_not_existing_record
53#test_namestore_api_zone_to_name 53#test_namestore_api_zone_to_name
54endif 54endif
55 55
diff --git a/src/namestore/test_namestore_api_remove_not_existing_record.c b/src/namestore/test_namestore_api_remove_not_existing_record.c
index 9e0b22ea5..b09748e69 100644
--- a/src/namestore/test_namestore_api_remove_not_existing_record.c
+++ b/src/namestore/test_namestore_api_remove_not_existing_record.c
@@ -25,10 +25,6 @@
25#include "gnunet_common.h" 25#include "gnunet_common.h"
26#include "gnunet_namestore_service.h" 26#include "gnunet_namestore_service.h"
27#include "gnunet_testing_lib.h" 27#include "gnunet_testing_lib.h"
28#include "namestore.h"
29#include "gnunet_signatures.h"
30
31#define RECORDS 5
32 28
33#define TEST_RECORD_TYPE 1234 29#define TEST_RECORD_TYPE 1234
34 30
@@ -36,32 +32,39 @@
36 32
37#define TEST_RECORD_DATA 'a' 33#define TEST_RECORD_DATA 'a'
38 34
39#define TEST_REMOVE_RECORD_TYPE 4321
40
41#define TEST_REMOVE_RECORD_DATALEN 255
42
43#define TEST_REMOVE_RECORD_DATA 'b'
44
45#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100)
46 36
47 37
48static struct GNUNET_NAMESTORE_Handle * nsh; 38static struct GNUNET_NAMESTORE_Handle *nsh;
49 39
50static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; 40static GNUNET_SCHEDULER_TaskIdentifier endbadly_task;
51 41
52static struct GNUNET_CRYPTO_EccPrivateKey * privkey; 42static struct GNUNET_CRYPTO_EccPrivateKey *privkey;
53 43
54static struct GNUNET_CRYPTO_EccPublicKey pubkey; 44static struct GNUNET_CRYPTO_EccPublicKey pubkey;
55 45
56static struct GNUNET_CRYPTO_EccSignature *s_signature; 46static struct GNUNET_HashCode derived_hash;
57 47
58static struct GNUNET_HashCode s_zone; 48static int res;
59 49
60static struct GNUNET_NAMESTORE_RecordData *s_rd; 50static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
61 51
62static char *s_name;
63 52
64static int res; 53static void
54cleanup ()
55{
56 if (NULL != nsh)
57 {
58 GNUNET_NAMESTORE_disconnect (nsh);
59 nsh = NULL;
60 }
61 if (NULL != privkey)
62 {
63 GNUNET_free (privkey);
64 privkey = NULL;
65 }
66 GNUNET_SCHEDULER_shutdown ();
67}
65 68
66 69
67/** 70/**
@@ -73,13 +76,12 @@ static int res;
73static void 76static void
74endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 77endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
75{ 78{
76 if (nsh != NULL) 79 if (NULL != nsqe)
77 GNUNET_NAMESTORE_disconnect (nsh); 80 {
78 nsh = NULL; 81 GNUNET_NAMESTORE_cancel (nsqe);
79 if (privkey != NULL) 82 nsqe = NULL;
80 GNUNET_free (privkey); 83 }
81 privkey = NULL; 84 cleanup ();
82 GNUNET_free_non_null (s_name);
83 res = 1; 85 res = 1;
84} 86}
85 87
@@ -87,84 +89,90 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
87static void 89static void
88end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 90end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
89{ 91{
90 int c; 92 cleanup ();
93 res = 0;
94}
91 95
92 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
93 {
94 GNUNET_SCHEDULER_cancel (endbadly_task);
95 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
96 }
97 for (c = 0; c < RECORDS; c++)
98 GNUNET_free_non_null((void *) s_rd[c].data);
99 GNUNET_free (s_rd);
100 96
101 if (privkey != NULL) 97static void
102 GNUNET_free (privkey); 98rd_decrypt_cb (void *cls,
103 privkey = NULL; 99 unsigned int rd_count,
104 if (nsh != NULL) 100 const struct GNUNET_NAMESTORE_RecordData *rd)
105 GNUNET_NAMESTORE_disconnect (nsh); 101{
106 nsh = NULL; 102 GNUNET_assert (0 == rd_count);
107 GNUNET_free_non_null (s_name); 103 GNUNET_assert (NULL == rd);
108}
109 104
105 GNUNET_SCHEDULER_add_now (&end, NULL);
106}
110 107
111static void 108static void
112remove_cont (void *cls, int32_t success, const char *emsg) 109name_lookup_proc (void *cls,
110 const struct GNUNET_NAMESTORE_Block *block)
113{ 111{
114 char *name = cls; 112 const char *name = cls;
113 nsqe = NULL;
114
115 GNUNET_assert (NULL != cls);
115 116
116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Remove record for `%s': %s `%s'\n", name, (success == GNUNET_YES) ? "SUCCESS" : "FAIL", emsg); 117 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
117 if (GNUNET_OK == success)
118 { 118 {
119 res = 0; 119 GNUNET_SCHEDULER_cancel (endbadly_task);
120 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
120 } 121 }
121 else 122
123 if (NULL == block)
122 { 124 {
123 res = 1; 125 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
124 GNUNET_break (0); 126 _("Namestore returned no block\n"));
127 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
128 GNUNET_SCHEDULER_cancel (endbadly_task);
129 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
130 return;
125 } 131 }
126 GNUNET_SCHEDULER_add_now(&end, NULL);
127}
128 132
133 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
134 "Namestore returned block, decrypting \n");
135 GNUNET_assert (GNUNET_OK == GNUNET_NAMESTORE_block_decrypt(block,
136 &pubkey, name, &rd_decrypt_cb, (void *) name));
137}
129 138
130static void 139static void
131put_cont (void *cls, int32_t success, const char *emsg) 140put_cont (void *cls, int32_t success, const char *emsg)
132{ 141{
133 char *name = cls; 142 const char *name = cls;
134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name store added record for `%s': %s\n", name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); 143
135 if (success == GNUNET_OK) 144 GNUNET_assert (NULL != cls);
136 { 145 if (GNUNET_SYSERR == success)
137 res = 0;
138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing non existing record for `%s'\n", name);
139 GNUNET_NAMESTORE_record_put_by_authority (nsh, privkey, name,
140 0, NULL,
141 &remove_cont, name);
142 }
143 else
144 { 146 {
145 res = 1; 147 GNUNET_break (0);
146 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to put records for name `%s'\n", name); 148 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
147 GNUNET_SCHEDULER_add_now(&end, NULL); 149 _("Namestore could not store record: `%s'\n"), emsg);
150 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
151 GNUNET_SCHEDULER_cancel (endbadly_task);
152 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
153 return;
148 } 154 }
149}
150 155
156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
157 "Name store added record for `%s': %s\n",
158 name,
159 (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
151 160
152static struct GNUNET_NAMESTORE_RecordData * 161 /* Create derived hash */
153create_record (unsigned int count) 162 GNUNET_NAMESTORE_query_from_private_key (privkey, name, &derived_hash);
154{
155 unsigned int c;
156 struct GNUNET_NAMESTORE_RecordData * rd;
157 163
158 rd = GNUNET_malloc (count * sizeof (struct GNUNET_NAMESTORE_RecordData)); 164 nsqe = GNUNET_NAMESTORE_lookup_block (nsh, &derived_hash,
159 for (c = 0; c < count; c++) 165 &name_lookup_proc, (void *) name);
166 if (NULL == nsqe)
160 { 167 {
161 rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us; 168 GNUNET_break (0);
162 rd[c].record_type = TEST_RECORD_TYPE; 169 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
163 rd[c].data_size = TEST_RECORD_DATALEN; 170 _("Namestore cannot perform lookup\n"));
164 rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN); 171 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
165 memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); 172 GNUNET_SCHEDULER_cancel (endbadly_task);
173 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
174 return;
166 } 175 }
167 return rd;
168} 176}
169 177
170 178
@@ -174,44 +182,29 @@ run (void *cls,
174 struct GNUNET_TESTING_Peer *peer) 182 struct GNUNET_TESTING_Peer *peer)
175{ 183{
176 char *hostkey_file; 184 char *hostkey_file;
177 size_t rd_ser_len; 185 const char * name = "dummy.dummy.gnunet";
178 struct GNUNET_TIME_Absolute et; 186
179 187 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
180 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); 188 &endbadly, NULL);
181 189 GNUNET_asprintf (&hostkey_file,
182 /* load privat key */ 190 "zonefiles%s%s",
183 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, 191 DIR_SEPARATOR_STR,
184 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); 192 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); 193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
186 privkey = GNUNET_CRYPTO_ecc_key_create_from_file(hostkey_file); 194 privkey = GNUNET_CRYPTO_ecc_key_create_from_file (hostkey_file);
187 GNUNET_free (hostkey_file); 195 GNUNET_free (hostkey_file);
188 GNUNET_assert (privkey != NULL); 196 GNUNET_assert (privkey != NULL);
189 /* get public key */ 197 GNUNET_CRYPTO_ecc_key_get_public (privkey, &pubkey);
190 GNUNET_CRYPTO_ecc_key_get_public(privkey, &pubkey);
191 198
192 /* create record */
193 s_name = GNUNET_NAMESTORE_normalize_string ("DUMMY.dummy.gnunet");
194 s_rd = create_record (RECORDS);
195
196 rd_ser_len = GNUNET_NAMESTORE_records_get_size(RECORDS, s_rd);
197 char rd_ser[rd_ser_len];
198 GNUNET_NAMESTORE_records_serialize(RECORDS, s_rd, rd_ser_len, rd_ser);
199
200 /* sign */
201 et.abs_value_us = s_rd[0].expiration_time;
202 s_signature = GNUNET_NAMESTORE_create_signature(privkey, et, s_name, s_rd, RECORDS);
203
204 /* create random zone hash */
205 GNUNET_CRYPTO_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_EccPublicKey), &s_zone);
206
207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name: `%s' Zone: `%s' \n", s_name, GNUNET_h2s_full(&s_zone));
208 nsh = GNUNET_NAMESTORE_connect (cfg); 199 nsh = GNUNET_NAMESTORE_connect (cfg);
209 GNUNET_break (NULL != nsh); 200 GNUNET_break (NULL != nsh);
210 GNUNET_break (s_rd != NULL); 201 nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
211 GNUNET_break (s_name != NULL); 202 0, NULL, &put_cont, (void *) name);
212 GNUNET_NAMESTORE_record_put (nsh, &pubkey, s_name, 203 if (NULL == nsqe)
213 GNUNET_TIME_UNIT_FOREVER_ABS, 204 {
214 RECORDS, s_rd, s_signature, put_cont, s_name); 205 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
206 _("Namestore cannot store no block\n"));
207 }
215} 208}
216 209
217 210
@@ -220,13 +213,12 @@ main (int argc, char *argv[])
220{ 213{
221 res = 1; 214 res = 1;
222 if (0 != 215 if (0 !=
223 GNUNET_TESTING_service_run ("test-namestore-api-remove-not-existing-record", 216 GNUNET_TESTING_service_run ("test-namestore-api",
224 "namestore", 217 "namestore",
225 "test_namestore_api.conf", 218 "test_namestore_api.conf",
226 &run, 219 &run,
227 NULL)) 220 NULL))
228 return 1; 221 return 1;
229 GNUNET_free_non_null (s_signature);
230 return res; 222 return res;
231} 223}
232 224