aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-02-16 20:38:29 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-02-16 20:38:29 +0000
commit349d176da232e5fdc6afd9c90ae02bf928365ac0 (patch)
tree0b3dd606f9e9f10d1c45d4113eead668648c99ce
parentf49e139a6fbcde654b2130e78665e48712713612 (diff)
downloadgnunet-349d176da232e5fdc6afd9c90ae02bf928365ac0.tar.gz
gnunet-349d176da232e5fdc6afd9c90ae02bf928365ac0.zip
- removed add, other feedback
-rw-r--r--src/gns/Makefile.am11
-rw-r--r--src/gns/gns.h8
-rw-r--r--src/gns/gns_api.c37
-rw-r--r--src/gns/gnunet-gns-add.c200
-rw-r--r--src/gns/gnunet-gns-lookup.c9
-rw-r--r--src/gns/gnunet-service-gns.c10
-rw-r--r--src/include/gnunet_gns_service.h68
7 files changed, 20 insertions, 323 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 1dbce3b66..46ac4eb42 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -22,21 +22,12 @@ bin_PROGRAMS = \
22 gnunet-service-gns 22 gnunet-service-gns
23 23
24noinst_PROGRAMS = \ 24noinst_PROGRAMS = \
25 gnunet-gns-lookup gnunet-gns-add 25 gnunet-gns-lookup
26 26
27#check_SCRIPTS = \ 27#check_SCRIPTS = \
28# test_gnunet_dns.sh 28# test_gnunet_dns.sh
29 29
30 30
31gnunet_gns_add_SOURCES = \
32 gnunet-gns-add.c
33gnunet_gns_add_LDADD = \
34 $(top_builddir)/src/gns/libgnunetgns.la \
35 $(top_builddir)/src/util/libgnunetutil.la \
36 $(GN_LIBINTL)
37gnunet_dns_add_DEPENDENCIES = \
38 libgnunetgns.la
39
40gnunet_gns_lookup_SOURCES = \ 31gnunet_gns_lookup_SOURCES = \
41 gnunet-gns-lookup.c 32 gnunet-gns-lookup.c
42gnunet_gns_lookup_LDADD = \ 33gnunet_gns_lookup_LDADD = \
diff --git a/src/gns/gns.h b/src/gns/gns.h
index b7f0f306a..d6b491db3 100644
--- a/src/gns/gns.h
+++ b/src/gns/gns.h
@@ -53,15 +53,9 @@ struct GNUNET_GNS_ClientLookupMessage
53 /** 53 /**
54 * the type of record to look up 54 * the type of record to look up
55 */ 55 */
56 // FIXME: bad type 56 // FIXME: bad type - should be of GNUNET_GNS_RecordType
57 int type; 57 int type;
58 58
59 /**
60 * Length of name to lookup
61 * // FIXME: redundant
62 */
63 uint32_t namelen;
64
65 /* Followed by the name to look up */ 59 /* Followed by the name to look up */
66}; 60};
67 61
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index 14c1220c9..cb418c0a6 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.c
@@ -435,6 +435,7 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value)
435{ 435{
436 const struct GNUNET_GNS_ClientResultMessage *gns_msg = cls; 436 const struct GNUNET_GNS_ClientResultMessage *gns_msg = cls;
437 struct GNUNET_GNS_LookupHandle *lookup_handle = value; 437 struct GNUNET_GNS_LookupHandle *lookup_handle = value;
438 const char *name = (const char*) &lookup_handle[1];
438 const struct GNUNET_GNS_Record *records; 439 const struct GNUNET_GNS_Record *records;
439 uint32_t num_records; 440 uint32_t num_records;
440 size_t meta_length; 441 size_t meta_length;
@@ -467,7 +468,7 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value)
467 (unsigned int) (msize - meta_length), GNUNET_h2s (key)); 468 (unsigned int) (msize - meta_length), GNUNET_h2s (key));
468#endif 469#endif
469 records = (const struct GNUNET_GNS_Record *) &gns_msg[1]; 470 records = (const struct GNUNET_GNS_Record *) &gns_msg[1];
470 lookup_handle->iter (lookup_handle->iter_cls, key, records, num_records); 471 lookup_handle->iter (lookup_handle->iter_cls, name, records, num_records);
471 return GNUNET_YES; 472 return GNUNET_YES;
472} 473}
473 474
@@ -559,37 +560,10 @@ GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle)
559 560
560 561
561/** 562/**
562 * Add a new record to the GNS.
563 *
564 * @param handle handle to GNS service
565 * @param record the record to store
566 * @param exp desired expiration time for the value
567 * @param timeout how long to wait for transmission of this request
568 */
569void
570GNUNET_GNS_add_record (struct GNUNET_GNS_Handle *handle,
571 const char* name,
572 enum GNUNET_GNS_RecordType type,
573 size_t size, const char *data,
574 struct GNUNET_TIME_Absolute exp,
575 struct GNUNET_TIME_Relative timeout)
576{
577 /**
578 * build add record message
579 */
580 struct GNUNET_GNS_Record *record;
581
582 record = GNUNET_malloc(sizeof (struct GNUNET_GNS_Record));
583 /**
584 * TODO
585 * queue_record_msg(handle, record);
586 **/
587}
588
589
590/**
591 * Perform an asynchronous Lookup operation on the GNS. 563 * Perform an asynchronous Lookup operation on the GNS.
592 * TODO: Still not sure what we query for... "names" it is for now 564 * TODO:
565 * - Still not sure what we query for... "names" it is for now
566 * - Do we need such sophisticated message queueing like dht? simplify?
593 * 567 *
594 * @param handle handle to the GNS service 568 * @param handle handle to the GNS service
595 * @param timeout how long to wait for transmission of this request to the service 569 * @param timeout how long to wait for transmission of this request to the service
@@ -632,7 +606,6 @@ GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle,
632 pending->free_on_send = GNUNET_NO; 606 pending->free_on_send = GNUNET_NO;
633 lookup_msg->header.size = htons (msize); 607 lookup_msg->header.size = htons (msize);
634 lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP); 608 lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP);
635 lookup_msg->namelen = strlen(name);
636 lookup_msg->key = key; 609 lookup_msg->key = key;
637 memcpy(&lookup_msg[1], name, strlen(name)); 610 memcpy(&lookup_msg[1], name, strlen(name));
638 handle->uid_gen++; 611 handle->uid_gen++;
diff --git a/src/gns/gnunet-gns-add.c b/src/gns/gnunet-gns-add.c
deleted file mode 100644
index a1beebca3..000000000
--- a/src/gns/gnunet-gns-add.c
+++ /dev/null
@@ -1,200 +0,0 @@
1/*
2 This file is part of GNUnet.
3 (C) 2001, 2002, 2004, 2005, 2006, 2007, 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 gns/gnunet-gns-add.c
22 * @brief search for data in GNS
23 * @author Martin Schanzenbach
24 */
25#include "platform.h"
26#include "gnunet_gns_service.h"
27
28/**
29 * The type of the record
30 */
31static unsigned int record_type;
32
33/**
34 * The key for the recprd
35 */
36static char *record_key;
37
38/**
39 * User supplied timeout value
40 */
41static unsigned long long timeout_request = 5;
42
43/**
44 * User supplied expiration value
45 */
46static unsigned long long expiration_seconds = 3600;
47
48/**
49 * Desired replication level.
50 */
51static unsigned int replication = 5;
52
53/**
54 * Be verbose
55 */
56static int verbose;
57
58/**
59 * Handle to the GNS
60 */
61static struct GNUNET_GNS_Handle *gns_handle;
62
63
64/**
65 * Global handle of the configuration
66 */
67static const struct GNUNET_CONFIGURATION_Handle *cfg;
68
69/**
70 * Global status value
71 */
72static int ret;
73
74/**
75 * The data to insert into the dht
76 */
77static char *data;
78
79static void
80shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
81{
82 if (gns_handle != NULL)
83 {
84 GNUNET_GNS_disconnect (gns_handle);
85 gns_handle = NULL;
86 }
87}
88
89/**
90 * Signature of the main function of a task.
91 *
92 * @param cls closure
93 * @param tc context information (why was this task triggered now)
94 */
95void
96message_sent_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
97{
98 if (verbose)
99 FPRINTF (stderr, "%s", _("PUT request sent!\n"));
100 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
101}
102
103/**
104 * Main function that will be run by the scheduler.
105 *
106 * @param cls closure
107 * @param args remaining command-line arguments
108 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
109 * @param c configuration
110 */
111static void
112run (void *cls, char *const *args, const char *cfgfile,
113 const struct GNUNET_CONFIGURATION_Handle *c)
114{
115 struct GNUNET_TIME_Relative timeout;
116 struct GNUNET_TIME_Absolute expiration;
117
118 cfg = c;
119
120 if ((record_key == NULL) || (data == NULL))
121 {
122 FPRINTF (stderr, "%s", _("Must provide KEY and DATA for GNS record!\n"));
123 ret = 1;
124 return;
125 }
126
127 gns_handle = GNUNET_GNS_connect (cfg, 1);
128 if (gns_handle == NULL)
129 {
130 FPRINTF (stderr, _("Could not connect to %s service!\n"), "GNS");
131 ret = 1;
132 return;
133 }
134 else if (verbose)
135 FPRINTF (stderr, _("Connected to %s service!\n"), "GNS");
136
137 timeout =
138 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_request);
139 expiration =
140 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
141 (GNUNET_TIME_UNIT_SECONDS,
142 expiration_seconds));
143
144 if (verbose)
145 FPRINTF (stderr, _("Issuing add request for `%s' with data `%s'!\n"),
146 record_key, data);
147 GNUNET_GNS_add_record (gns_handle, record_key,
148 0/*RecordType*/,
149 strlen (data), data, expiration, timeout);
150
151}
152
153
154/**
155 * gnunet-gns-add command line options
156 */
157static struct GNUNET_GETOPT_CommandLineOption options[] = {
158 {'d', "data", "DATA",
159 gettext_noop ("the data to insert under the key"),
160 1, &GNUNET_GETOPT_set_string, &data},
161 {'e', "expiration", "EXPIRATION",
162 gettext_noop ("how long to store this entry in the GNS (in seconds)"),
163 1, &GNUNET_GETOPT_set_ulong, &expiration_seconds},
164 {'k', "key", "KEY",
165 gettext_noop ("the record key"),
166 1, &GNUNET_GETOPT_set_string, &record_key},
167 {'r', "replication", "LEVEL",
168 gettext_noop ("how many replicas to create"),
169 1, &GNUNET_GETOPT_set_uint, &replication},
170 {'t', "type", "TYPE",
171 gettext_noop ("the type to insert record as"),
172 1, &GNUNET_GETOPT_set_uint, &record_type},
173 {'T', "timeout", "TIMEOUT",
174 gettext_noop ("how long to execute this query before giving up?"),
175 1, &GNUNET_GETOPT_set_ulong, &timeout_request},
176 {'V', "verbose", NULL,
177 gettext_noop ("be verbose (print progress information)"),
178 0, &GNUNET_GETOPT_set_one, &verbose},
179 GNUNET_GETOPT_OPTION_END
180};
181
182
183/**
184 * Entry point for gnunet-gns-add
185 *
186 * @param argc number of arguments from the command line
187 * @param argv command line arguments
188 * @return 0 ok, 1 on error
189 */
190int
191main (int argc, char *const *argv)
192{
193 return (GNUNET_OK ==
194 GNUNET_PROGRAM_run (argc, argv, "gnunet-gns-add",
195 gettext_noop
196 ("Issue an add to the GNUnet NS of DATA under KEY."),
197 options, &run, NULL)) ? ret : 1;
198}
199
200/* end of gnunet-gns-put.c */
diff --git a/src/gns/gnunet-gns-lookup.c b/src/gns/gnunet-gns-lookup.c
index f305baf0f..5adb4064e 100644
--- a/src/gns/gnunet-gns-lookup.c
+++ b/src/gns/gnunet-gns-lookup.c
@@ -71,11 +71,6 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
71static struct GNUNET_GNS_LookupHandle *lookup_handle; 71static struct GNUNET_GNS_LookupHandle *lookup_handle;
72 72
73/** 73/**
74 * Count of results found
75 */
76static unsigned int result_count;
77
78/**
79 * Global status value 74 * Global status value
80 */ 75 */
81static int ret; 76static int ret;
@@ -121,11 +116,11 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
121 */ 116 */
122static void 117static void
123lookup_result_iterator (void *cls, 118lookup_result_iterator (void *cls,
124 const GNUNET_HashCode * key, 119 const char * name,
125 const struct GNUNET_GNS_Record *record, 120 const struct GNUNET_GNS_Record *record,
126 unsigned int num_records) 121 unsigned int num_records)
127{ 122{
128 FPRINTF (stdout, "Results %d\n", num_records); 123 FPRINTF (stdout, "%d results for %s\n", num_records, name);
129} 124}
130 125
131 126
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index ca732c78e..ff624c9b3 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -134,14 +134,6 @@ handle_client_record_lookup(void *cls,
134{ 134{
135} 135}
136 136
137/*TODO*/
138static void
139handle_client_record_add(void *cls,
140 struct GNUNET_SERVER_Client *client,
141 const struct GNUNET_MessageHeader *message)
142{
143}
144
145/** 137/**
146 * Process GNS requests. 138 * Process GNS requests.
147 * 139 *
@@ -158,8 +150,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
158 /* callback, cls, type, size */ 150 /* callback, cls, type, size */
159 {&handle_client_record_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP, 151 {&handle_client_record_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP,
160 0}, 152 0},
161 /*{&handle_client_record_add, NULL, GNUNET_MESSAGE_TYPE_GNS_CLIENT_ADD,
162 0},*/
163 {NULL, NULL, 0, 0} 153 {NULL, NULL, 0, 0}
164 }; 154 };
165 155
diff --git a/src/include/gnunet_gns_service.h b/src/include/gnunet_gns_service.h
index 322a1c9bf..748aa9f4b 100644
--- a/src/include/gnunet_gns_service.h
+++ b/src/include/gnunet_gns_service.h
@@ -93,43 +93,7 @@ void
93GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle); 93GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle);
94 94
95 95
96/* *************** Standard API: add and lookup ******************* */ 96/* *************** Standard API: lookup ******************* */
97
98/**
99 * Perform an add operation storing records in the GNS.
100 *
101 * FIXME: Yes, we need this kind of API, but should it not be with the
102 * NameDataStore, rather than the GNS-service?
103 *
104 * @param handle handle to GNS service
105 * @param name the key to store under
106 * // FIXME: need to be precise here what 'name' is. Does it
107 // include '.gnunet'? What happens if we specify 'a.b.c.gnunet'
108 // but 'b.c.gnunet' has been delegated? (error?)
109 * @param desired_replication_level estimate of how many
110 * nearest peers this request should reach
111 * @param options routing options for this message
112 // FIXME: which are? where is the arg?
113 // FIXME: we should probably distinguish between 'private' and 'public'
114 // records;
115 * @param type type of the value
116 * @param size number of bytes in data; must be less than 64k
117 * @param data the data to store
118 // FIXME: what is the exact format of data?
119 * @param exp desired expiration time for the value
120 * @param timeout how long to wait for transmission of this request
121 * @param cont continuation to call when done (transmitting request to service)
122 * @param cont_cls closure for cont
123 * // FIXME: where are the continuations?
124 */
125void
126GNUNET_GNS_add_record (struct GNUNET_GNS_Handle *handle,
127 const char* name,
128 enum GNUNET_GNS_RecordType type,
129 size_t size, const char *data,
130 struct GNUNET_TIME_Absolute exp,
131 struct GNUNET_TIME_Relative timeout);
132
133 97
134/** 98/**
135 * Iterator called on each result obtained for a GNS 99 * Iterator called on each result obtained for a GNS
@@ -137,17 +101,13 @@ GNUNET_GNS_add_record (struct GNUNET_GNS_Handle *handle,
137 * 101 *
138 * 102 *
139 * @param cls closure 103 * @param cls closure
140 * @param exp when will this value expire 104 * @param name "name" of the original lookup
141 * @param key key of the result
142 * // how does the key relate to the name exactly? Why not give the name?
143 * @param record the records in reply 105 * @param record the records in reply
144 * // FIXME: shouldn't this then be an array of pointers? 106 * // FIXME: shouldn't this then be an array of pointers? - not sure as of yet
145 * @param num_records the number of records in reply 107 * @param num_records the number of records in reply
146 * @param type type of the result
147 * // FIXME: not in signature
148 */ 108 */
149typedef void (*GNUNET_GNS_LookupIterator) (void *cls, 109typedef void (*GNUNET_GNS_LookupIterator) (void *cls,
150 const GNUNET_HashCode * key, 110 const char * name,
151 const struct GNUNET_GNS_Record *record, 111 const struct GNUNET_GNS_Record *record,
152 unsigned int num_records); 112 unsigned int num_records);
153 113
@@ -160,14 +120,8 @@ typedef void (*GNUNET_GNS_LookupIterator) (void *cls,
160 * @param timeout how long to wait for transmission of this request to the service 120 * @param timeout how long to wait for transmission of this request to the service
161 * // FIXME: what happens afterwards? 121 * // FIXME: what happens afterwards?
162 * @param type expected type of the response object 122 * @param type expected type of the response object
163 * @param key the key to look up 123 * @param name the name to look up
164 * // FIXME: key, name, what format? 124 * @param type the GNUNET_GNS_RecordType to look for
165 * @param desired_replication_level estimate of how many
166 nearest peers this request should reach
167 * @param options routing options for this message
168 * //FIXME: missmatch between documented and actual options...
169 * @param xquery extended query data (can be NULL, depending on type)
170 * @param xquery_size number of bytes in xquery
171 * @param iter function to call on each result 125 * @param iter function to call on each result
172 * @param iter_cls closure for iter 126 * @param iter_cls closure for iter
173 * 127 *
@@ -175,11 +129,11 @@ typedef void (*GNUNET_GNS_LookupIterator) (void *cls,
175 */ 129 */
176struct GNUNET_GNS_LookupHandle * 130struct GNUNET_GNS_LookupHandle *
177GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle, 131GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle,
178 struct GNUNET_TIME_Relative timeout, 132 struct GNUNET_TIME_Relative timeout,
179 const char * name, 133 const char * name,
180 enum GNUNET_GNS_RecordType type, 134 enum GNUNET_GNS_RecordType type,
181 GNUNET_GNS_LookupIterator iter, 135 GNUNET_GNS_LookupIterator iter,
182 void *iter_cls); 136 void *iter_cls);
183 137
184 138
185/** 139/**