diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-10-02 13:58:05 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-10-02 13:58:05 +0000 |
commit | 7b80cc15aaf3f61fb05635577fdd5258d5b8bb17 (patch) | |
tree | 4eaf19b132776841b8ab4ec2a8a81887c242b836 /src/dht/gnunet-dht-get.c | |
parent | 3953eff33493400e9ef8ba4f9df18cc27bacadc1 (diff) | |
download | gnunet-7b80cc15aaf3f61fb05635577fdd5258d5b8bb17.tar.gz gnunet-7b80cc15aaf3f61fb05635577fdd5258d5b8bb17.zip |
new DHT API, tests do not yet compile
Diffstat (limited to 'src/dht/gnunet-dht-get.c')
-rw-r--r-- | src/dht/gnunet-dht-get.c | 69 |
1 files changed, 33 insertions, 36 deletions
diff --git a/src/dht/gnunet-dht-get.c b/src/dht/gnunet-dht-get.c index 023188f35..fabe4aeb9 100644 --- a/src/dht/gnunet-dht-get.c +++ b/src/dht/gnunet-dht-get.c | |||
@@ -81,23 +81,27 @@ static unsigned int result_count; | |||
81 | */ | 81 | */ |
82 | static int ret; | 82 | static int ret; |
83 | 83 | ||
84 | |||
84 | static void | 85 | static void |
85 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 86 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
86 | { | 87 | { |
87 | |||
88 | if (dht_handle != NULL) | 88 | if (dht_handle != NULL) |
89 | GNUNET_DHT_disconnect (dht_handle); | 89 | { |
90 | 90 | GNUNET_DHT_disconnect (dht_handle); | |
91 | dht_handle = NULL; | 91 | dht_handle = NULL; |
92 | } | ||
92 | } | 93 | } |
93 | 94 | ||
95 | |||
94 | static void | 96 | static void |
95 | cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 97 | cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
96 | { | 98 | { |
97 | if (get_handle != NULL) | 99 | if (get_handle != NULL) |
98 | GNUNET_DHT_get_stop (get_handle, &shutdown_task, NULL); | 100 | { |
99 | else | 101 | GNUNET_DHT_get_stop (get_handle); |
100 | GNUNET_SCHEDULER_add_now (sched, &shutdown_task, NULL); | 102 | get_handle = NULL; |
103 | } | ||
104 | GNUNET_SCHEDULER_add_now (sched, &shutdown_task, NULL); | ||
101 | } | 105 | } |
102 | 106 | ||
103 | 107 | ||
@@ -108,6 +112,10 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
108 | * @param cls closure | 112 | * @param cls closure |
109 | * @param exp when will this value expire | 113 | * @param exp when will this value expire |
110 | * @param key key of the result | 114 | * @param key key of the result |
115 | * @param get_path NULL-terminated array of pointers | ||
116 | * to the peers on reverse GET path (or NULL if not recorded) | ||
117 | * @param put_path NULL-terminated array of pointers | ||
118 | * to the peers on the PUT path (or NULL if not recorded) | ||
111 | * @param type type of the result | 119 | * @param type type of the result |
112 | * @param size number of bytes in data | 120 | * @param size number of bytes in data |
113 | * @param data pointer to the result data | 121 | * @param data pointer to the result data |
@@ -116,39 +124,17 @@ void | |||
116 | get_result_iterator (void *cls, | 124 | get_result_iterator (void *cls, |
117 | struct GNUNET_TIME_Absolute exp, | 125 | struct GNUNET_TIME_Absolute exp, |
118 | const GNUNET_HashCode * key, | 126 | const GNUNET_HashCode * key, |
119 | uint32_t type, uint32_t size, const void *data) | 127 | const struct GNUNET_PeerIdentity * const *get_path, |
128 | const struct GNUNET_PeerIdentity * const *put_path, | ||
129 | enum GNUNET_BLOCK_Type type, | ||
130 | size_t size, | ||
131 | const void *data) | ||
120 | { | 132 | { |
121 | fprintf (stdout, "Result %d, type %d:\n%.*s\n", result_count, type, size, | 133 | fprintf (stdout, "Result %d, type %d:\n%.*s\n", result_count, type, size, |
122 | (char *) data); | 134 | (char *) data); |
123 | result_count++; | 135 | result_count++; |
124 | } | 136 | } |
125 | 137 | ||
126 | /** | ||
127 | * Signature of the main function of a task. | ||
128 | * | ||
129 | * @param cls closure | ||
130 | * @param tc context information (why was this task triggered now) | ||
131 | */ | ||
132 | void | ||
133 | message_sent_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
134 | { | ||
135 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) | ||
136 | { | ||
137 | if (verbose) | ||
138 | fprintf (stderr, | ||
139 | "Failed to send GET request to service, quitting.\n"); | ||
140 | ret = 1; | ||
141 | GNUNET_SCHEDULER_add_now (sched, &shutdown_task, NULL); | ||
142 | } | ||
143 | else | ||
144 | { | ||
145 | if (verbose) | ||
146 | fprintf (stderr, "GET request sent, awaiting results!\n"); | ||
147 | GNUNET_SCHEDULER_add_delayed (sched, | ||
148 | GNUNET_TIME_absolute_get_remaining | ||
149 | (absolute_timeout), &cleanup_task, NULL); | ||
150 | } | ||
151 | } | ||
152 | 138 | ||
153 | /** | 139 | /** |
154 | * Main function that will be run by the scheduler. | 140 | * Main function that will be run by the scheduler. |
@@ -198,8 +184,17 @@ run (void *cls, | |||
198 | 184 | ||
199 | if (verbose) | 185 | if (verbose) |
200 | fprintf (stderr, "Issuing GET request for %s!\n", query_key); | 186 | fprintf (stderr, "Issuing GET request for %s!\n", query_key); |
201 | get_handle = GNUNET_DHT_get_start (dht_handle, timeout, query_type, &key, | 187 | GNUNET_SCHEDULER_add_delayed (sched, |
202 | &get_result_iterator, NULL, &message_sent_cont, NULL); | 188 | GNUNET_TIME_absolute_get_remaining |
189 | (absolute_timeout), &cleanup_task, NULL); | ||
190 | get_handle = GNUNET_DHT_get_start (dht_handle, | ||
191 | timeout, | ||
192 | query_type, | ||
193 | &key, | ||
194 | GNUNET_DHT_RO_NONE, | ||
195 | NULL, 0, | ||
196 | NULL, 0, | ||
197 | &get_result_iterator, NULL); | ||
203 | 198 | ||
204 | } | 199 | } |
205 | 200 | ||
@@ -242,3 +237,5 @@ main (int argc, char *const *argv) | |||
242 | ("Issue a GET request to the GNUnet DHT, prints results."), | 237 | ("Issue a GET request to the GNUnet DHT, prints results."), |
243 | options, &run, NULL)) ? ret : 1; | 238 | options, &run, NULL)) ? ret : 1; |
244 | } | 239 | } |
240 | |||
241 | /* end of gnunet-dht-get.c */ | ||