aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-02-28 09:49:44 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-02-28 09:49:44 +0000
commitf47172b3668a738228d7e5171d64fd01567a4a08 (patch)
treea3c2960a38575d971dc0a68d6bec24e50a76388e /src
parent2627e749b6e1d0acc2a43f33e66a3d2a1be65fac (diff)
downloadgnunet-f47172b3668a738228d7e5171d64fd01567a4a08.tar.gz
gnunet-f47172b3668a738228d7e5171d64fd01567a4a08.zip
- more zone iteration code
Diffstat (limited to 'src')
-rw-r--r--src/namestore/Makefile.am8
-rw-r--r--src/namestore/gnunet-service-namestore.c92
-rw-r--r--src/namestore/namestore.h7
-rw-r--r--src/namestore/namestore_api.c6
-rw-r--r--src/namestore/test_namestore_api.conf2
-rw-r--r--src/namestore/test_namestore_api_zone_iteration.c194
6 files changed, 291 insertions, 18 deletions
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index f3211d6a0..f6ea6d051 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -26,7 +26,7 @@ check_PROGRAMS = \
26 $(SQLITE_TESTS) 26 $(SQLITE_TESTS)
27 27
28if HAVE_EXPERIMENTAL 28if HAVE_EXPERIMENTAL
29check_PROGRAMS += test_namestore_api 29check_PROGRAMS += test_namestore_api test_namestore_api_zone_iteration
30endif 30endif
31 31
32lib_LTLIBRARIES = \ 32lib_LTLIBRARIES = \
@@ -73,6 +73,12 @@ test_namestore_api_SOURCES = \
73test_namestore_api_LDADD = \ 73test_namestore_api_LDADD = \
74 $(top_builddir)/src/util/libgnunetutil.la \ 74 $(top_builddir)/src/util/libgnunetutil.la \
75 $(top_builddir)/src/namestore/libgnunetnamestore.la 75 $(top_builddir)/src/namestore/libgnunetnamestore.la
76
77test_namestore_api_zone_iteration_SOURCES = \
78 test_namestore_api_zone_iteration.c
79test_namestore_api_zone_iteration_LDADD = \
80 $(top_builddir)/src/util/libgnunetutil.la \
81 $(top_builddir)/src/namestore/libgnunetnamestore.la
76 82
77EXTRADIST = \ 83EXTRADIST = \
78 test_namestore_api.conf \ 84 test_namestore_api.conf \
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index 7d9eb4801..e796fe530 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -35,14 +35,16 @@
35/** 35/**
36 * A namestore operation. 36 * A namestore operation.
37 */ 37 */
38struct GNUNET_NAMESTORE_Operation 38struct GNUNET_NAMESTORE_ZoneIteration
39{ 39{
40 struct GNUNET_NAMESTORE_Operation *next; 40 struct GNUNET_NAMESTORE_ZoneIteration *next;
41 struct GNUNET_NAMESTORE_Operation *prev; 41 struct GNUNET_NAMESTORE_ZoneIteration *prev;
42
43 struct GNUNET_NAMESTORE_Client * client;
42 44
43 uint64_t op_id; 45 uint64_t op_id;
46 uint32_t offset;
44 47
45 char *data; /*stub data pointer*/
46}; 48};
47 49
48 50
@@ -56,8 +58,8 @@ struct GNUNET_NAMESTORE_Client
56 58
57 struct GNUNET_SERVER_Client * client; 59 struct GNUNET_SERVER_Client * client;
58 60
59 struct GNUNET_NAMESTORE_Operation *op_head; 61 struct GNUNET_NAMESTORE_ZoneIteration *op_head;
60 struct GNUNET_NAMESTORE_Operation *op_tail; 62 struct GNUNET_NAMESTORE_ZoneIteration *op_tail;
61}; 63};
62 64
63 65
@@ -91,8 +93,8 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
91{ 93{
92 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n"); 94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n");
93 95
94 struct GNUNET_NAMESTORE_Operation * no; 96 struct GNUNET_NAMESTORE_ZoneIteration * no;
95 struct GNUNET_NAMESTORE_Operation * tmp; 97 struct GNUNET_NAMESTORE_ZoneIteration * tmp;
96 struct GNUNET_NAMESTORE_Client * nc; 98 struct GNUNET_NAMESTORE_Client * nc;
97 struct GNUNET_NAMESTORE_Client * next; 99 struct GNUNET_NAMESTORE_Client * next;
98 100
@@ -144,7 +146,7 @@ client_lookup (struct GNUNET_SERVER_Client *client)
144static void 146static void
145client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client) 147client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
146{ 148{
147 struct GNUNET_NAMESTORE_Operation * no; 149 struct GNUNET_NAMESTORE_ZoneIteration * no;
148 struct GNUNET_NAMESTORE_Client * nc; 150 struct GNUNET_NAMESTORE_Client * nc;
149 if (NULL == client) 151 if (NULL == client)
150 return; 152 return;
@@ -374,7 +376,7 @@ static void handle_record_put (void *cls,
374 return; 376 return;
375 } 377 }
376 378
377 nc = client_lookup(client); 379 nc = client_lookup (client);
378 if (nc == NULL) 380 if (nc == NULL)
379 { 381 {
380 GNUNET_break_op (0); 382 GNUNET_break_op (0);
@@ -575,6 +577,70 @@ static void handle_record_remove (void *cls,
575} 577}
576 578
577 579
580void zone_iteration_proc (void *cls,
581 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
582 struct GNUNET_TIME_Absolute expire,
583 const char *name,
584 unsigned int rd_count,
585 const struct GNUNET_NAMESTORE_RecordData *rd,
586 const struct GNUNET_CRYPTO_RsaSignature *signature)
587{
588 struct ZoneIterationResponseMessage zir_msg;
589 struct GNUNET_NAMESTORE_ZoneIteration * zi = cls;
590
591 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "ZONE_ITERATION_RESPONSE");
592 zir_msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE);
593 zir_msg.op_id = htonl(zi->op_id);
594 zir_msg.header.size = htons (sizeof (struct ZoneIterationResponseMessage));
595
596
597 GNUNET_SERVER_notification_context_unicast (snc, zi->client->client, (const struct GNUNET_MessageHeader *) &zir_msg, GNUNET_NO);
598}
599
600static void handle_iteration_start (void *cls,
601 struct GNUNET_SERVER_Client * client,
602 const struct GNUNET_MessageHeader * message)
603{
604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_START");
605
606 struct ZoneIterationStartMessage * zis_msg = (struct ZoneIterationStartMessage *) message;
607 struct GNUNET_NAMESTORE_Client *nc;
608 struct GNUNET_NAMESTORE_ZoneIteration *zi;
609
610 nc = client_lookup(client);
611 if (nc == NULL)
612 {
613 GNUNET_break_op (0);
614 GNUNET_SERVER_receive_done (client, GNUNET_OK);
615 return;
616 }
617
618 zi = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_ZoneIteration));
619 zi->op_id = ntohl (zis_msg->op_id);
620 zi->offset = 0;
621 zi->client = nc;
622
623 GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi);
624
625 GSN_database->iterate_records (GSN_database->cls, &zis_msg->zone, NULL, zi->offset , &zone_iteration_proc, zi);
626 GNUNET_SERVER_receive_done (client, GNUNET_OK);
627}
628
629static void handle_iteration_stop (void *cls,
630 struct GNUNET_SERVER_Client * client,
631 const struct GNUNET_MessageHeader * message)
632{
633 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_STOP");
634}
635
636static void handle_iteration_next (void *cls,
637 struct GNUNET_SERVER_Client * client,
638 const struct GNUNET_MessageHeader * message)
639{
640 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_NEXT");
641}
642
643
578 644
579/** 645/**
580 * Process template requests. 646 * Process template requests.
@@ -602,6 +668,12 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
602 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE, 0}, 668 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE, 0},
603 {&handle_record_remove, NULL, 669 {&handle_record_remove, NULL,
604 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE, 0}, 670 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE, 0},
671 {&handle_iteration_start, NULL,
672 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, sizeof (struct ZoneIterationStartMessage)},
673 {&handle_iteration_stop, NULL,
674 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP, 0},
675 {&handle_iteration_next, NULL,
676 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT, 0},
605 {NULL, NULL, 0, 0} 677 {NULL, NULL, 0, 0}
606 }; 678 };
607 679
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h
index d2c026e7a..04eaa61fc 100644
--- a/src/namestore/namestore.h
+++ b/src/namestore/namestore.h
@@ -39,9 +39,10 @@
39#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE 438 39#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE 438
40 40
41#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START 439 41#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START 439
42#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT 439 42#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE 440
43#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP 439 43#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT 441
44#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE 439 44#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP 442
45
45 46
46GNUNET_NETWORK_STRUCT_BEGIN 47GNUNET_NETWORK_STRUCT_BEGIN
47/** 48/**
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index dc6a0aa8f..17c638050 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -1132,14 +1132,14 @@ GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it)
1132 struct GNUNET_NAMESTORE_Handle *h = it->h; 1132 struct GNUNET_NAMESTORE_Handle *h = it->h;
1133 1133
1134 /* set msg_size*/ 1134 /* set msg_size*/
1135 msg_size = sizeof (struct ZoneIterationNextMessage); 1135 msg_size = sizeof (struct ZoneIterationStopMessage);
1136 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); 1136 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
1137 1137
1138 /* create msg here */ 1138 /* create msg here */
1139 struct LookupNameMessage * msg; 1139 struct ZoneIterationStopMessage * msg;
1140 pe->size = msg_size; 1140 pe->size = msg_size;
1141 pe->is_init = GNUNET_NO; 1141 pe->is_init = GNUNET_NO;
1142 msg = (struct LookupNameMessage *) &pe[1]; 1142 msg = (struct ZoneIterationStopMessage *) &pe[1];
1143 msg->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP); 1143 msg->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP);
1144 msg->header.size = htons (msg_size); 1144 msg->header.size = htons (msg_size);
1145 msg->op_id = htonl (it->op_id); 1145 msg->op_id = htonl (it->op_id);
diff --git a/src/namestore/test_namestore_api.conf b/src/namestore/test_namestore_api.conf
index 1b83e8f13..1683d13cf 100644
--- a/src/namestore/test_namestore_api.conf
+++ b/src/namestore/test_namestore_api.conf
@@ -4,7 +4,7 @@ DEFAULTSERVICES = namestore
4UNIXPATH = /tmp/gnunet-p1-service-arm.sock 4UNIXPATH = /tmp/gnunet-p1-service-arm.sock
5 5
6[namestore] 6[namestore]
7#PREFIX = valgrind --leak-check=full 7PREFIX = valgrind --leak-check=full
8AUTOSTART = YES 8AUTOSTART = YES
9UNIXPATH = /tmp/gnunet-service-namestore.sock 9UNIXPATH = /tmp/gnunet-service-namestore.sock
10UNIX_MATCH_UID = YES 10UNIX_MATCH_UID = YES
diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c
new file mode 100644
index 000000000..a53a2febc
--- /dev/null
+++ b/src/namestore/test_namestore_api_zone_iteration.c
@@ -0,0 +1,194 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009 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_zone_iteration.c
22 * @brief testcase for namestore_api.c zone iteration functionality
23 */
24#include "platform.h"
25#include "gnunet_common.h"
26#include "gnunet_namestore_service.h"
27
28#define VERBOSE GNUNET_NO
29
30#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
31
32static struct GNUNET_NAMESTORE_Handle * nsh;
33
34static GNUNET_SCHEDULER_TaskIdentifier endbadly_task;
35static struct GNUNET_OS_Process *arm;
36
37static struct GNUNET_CRYPTO_RsaPrivateKey * privkey;
38static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey;
39static GNUNET_HashCode zone;
40
41static struct GNUNET_NAMESTORE_ZoneIterator *zi;
42static int res;
43
44static void
45start_arm (const char *cfgname)
46{
47 arm = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
48 "gnunet-service-arm", "-c", cfgname,
49#if VERBOSE_PEERS
50 "-L", "DEBUG",
51#else
52 "-L", "ERROR",
53#endif
54 NULL);
55}
56
57static void
58stop_arm ()
59{
60 if (NULL != arm)
61 {
62 if (0 != GNUNET_OS_process_kill (arm, SIGTERM))
63 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
64 GNUNET_OS_process_wait (arm);
65 GNUNET_OS_process_close (arm);
66 arm = NULL;
67 }
68}
69
70/**
71 * Re-establish the connection to the service.
72 *
73 * @param cls handle to use to re-connect.
74 * @param tc scheduler context
75 */
76static void
77endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
78{
79 if (nsh != NULL)
80 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
81 nsh = NULL;
82
83 if (privkey != NULL)
84 GNUNET_CRYPTO_rsa_key_free (privkey);
85 privkey = NULL;
86
87 if (NULL != arm)
88 stop_arm();
89
90 res = 1;
91}
92
93
94static void
95end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
96{
97 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
98 {
99 GNUNET_SCHEDULER_cancel (endbadly_task);
100 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
101 }
102
103 if (privkey != NULL)
104 GNUNET_CRYPTO_rsa_key_free (privkey);
105 privkey = NULL;
106
107 if (nsh != NULL)
108 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
109 nsh = NULL;
110
111
112 if (NULL != arm)
113 stop_arm();
114
115 res = 0;
116}
117
118
119void zone_proc (void *cls,
120 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
121 struct GNUNET_TIME_Absolute expire,
122 const char *name,
123 unsigned int rd_count,
124 const struct GNUNET_NAMESTORE_RecordData *rd,
125 const struct GNUNET_CRYPTO_RsaSignature *signature)
126{
127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for zone `%s'\n", GNUNET_h2s (&zone));
128 endbadly_task = GNUNET_SCHEDULER_add_now (&end, NULL);
129}
130
131static void
132run (void *cls, char *const *args, const char *cfgfile,
133 const struct GNUNET_CONFIGURATION_Handle *cfg)
134{
135 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,&endbadly, NULL);
136
137 privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey");
138 GNUNET_assert (privkey != NULL);
139 GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
140
141 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &zone);
142
143 start_arm (cfgfile);
144 GNUNET_assert (arm != NULL);
145
146 nsh = GNUNET_NAMESTORE_connect (cfg);
147 GNUNET_break (NULL != nsh);
148
149 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
150 &zone,
151 GNUNET_NAMESTORE_RF_NONE,
152 GNUNET_NAMESTORE_RF_NONE,
153 zone_proc,
154 &zone);
155 if (zi == NULL)
156 {
157 GNUNET_break (0);
158 GNUNET_SCHEDULER_cancel (endbadly_task);
159 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
160 }
161}
162
163static int
164check ()
165{
166 static char *const argv[] = { "test_namestore_api_zone_iteration",
167 "-c",
168 "test_namestore_api.conf",
169#if VERBOSE
170 "-L", "DEBUG",
171#endif
172 NULL
173 };
174 static struct GNUNET_GETOPT_CommandLineOption options[] = {
175 GNUNET_GETOPT_OPTION_END
176 };
177
178 res = 1;
179 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test_namestore_api_zone_iteration",
180 "nohelp", options, &run, &res);
181 return res;
182}
183
184int
185main (int argc, char *argv[])
186{
187 int ret;
188
189 ret = check ();
190
191 return ret;
192}
193
194/* end of test_namestore_api_zone_iteration.c */