aboutsummaryrefslogtreecommitdiff
path: root/src/dht/test_dht_api.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-04-04 11:34:11 +0000
committerNathan S. Evans <evans@in.tum.de>2010-04-04 11:34:11 +0000
commitf5ee95ef07151a06778fa02a6d74689dcbb0bdf5 (patch)
tree725d1f48758206950aeb72f6285dbf40720cf532 /src/dht/test_dht_api.c
parent1687b7a632f45a63fce5bf635a6286a1dad1c1d6 (diff)
downloadgnunet-f5ee95ef07151a06778fa02a6d74689dcbb0bdf5.tar.gz
gnunet-f5ee95ef07151a06778fa02a6d74689dcbb0bdf5.zip
add find peer to api, went a bit continuation crazy but i think it's better this way...
Diffstat (limited to 'src/dht/test_dht_api.c')
-rw-r--r--src/dht/test_dht_api.c62
1 files changed, 49 insertions, 13 deletions
diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c
index dd940a6e4..9dc429148 100644
--- a/src/dht/test_dht_api.c
+++ b/src/dht/test_dht_api.c
@@ -51,8 +51,8 @@ struct PeerContext
51 struct GNUNET_CONFIGURATION_Handle *cfg; 51 struct GNUNET_CONFIGURATION_Handle *cfg;
52 struct GNUNET_DHT_Handle *dht_handle; 52 struct GNUNET_DHT_Handle *dht_handle;
53 struct GNUNET_PeerIdentity id; 53 struct GNUNET_PeerIdentity id;
54 struct GNUNET_DHT_RouteHandle *get_handle; 54 struct GNUNET_DHT_GetHandle *get_handle;
55 struct GNUNET_DHT_RouteHandle *find_peer_handle; 55 struct GNUNET_DHT_FindPeerHandle *find_peer_handle;
56 56
57#if START_ARM 57#if START_ARM
58 pid_t arm_pid; 58 pid_t arm_pid;
@@ -123,6 +123,50 @@ end_badly ()
123 return; 123 return;
124} 124}
125 125
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 */
132void test_find_peer_stop (void *cls,
133 const struct GNUNET_SCHEDULER_TaskContext * tc)
134{
135 struct PeerContext *peer = cls;
136
137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer_stop!\n");
138 if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
139 GNUNET_SCHEDULER_add_now(sched, &end_badly, NULL);
140
141 GNUNET_assert (peer->dht_handle != NULL);
142
143 GNUNET_DHT_find_peer_stop(peer->find_peer_handle, &end, &p1);
144
145 //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &end, &p1);
146
147}
148
149/**
150 * Signature of the main function of a task.
151 *
152 * @param cls closure
153 * @param tc context information (why was this task triggered now)
154 */
155void test_find_peer (void *cls,
156 const struct GNUNET_SCHEDULER_TaskContext * tc)
157{
158 struct PeerContext *peer = cls;
159 GNUNET_HashCode hash;
160 memset(&hash, 42, sizeof(GNUNET_HashCode));
161
162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer!\n");
163 GNUNET_assert (peer->dht_handle != NULL);
164
165 peer->find_peer_handle = GNUNET_DHT_find_peer_start(peer->dht_handle, TIMEOUT, 0, NULL, &hash, NULL, NULL, &test_find_peer_stop, &p1);
166
167 if (peer->find_peer_handle == NULL)
168 GNUNET_SCHEDULER_add_now(sched, &end_badly, &p1);
169}
126 170
127/** 171/**
128 * Signature of the main function of a task. 172 * Signature of the main function of a task.
@@ -143,11 +187,8 @@ void test_put (void *cls,
143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_put!\n"); 187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_put!\n");
144 GNUNET_assert (peer->dht_handle != NULL); 188 GNUNET_assert (peer->dht_handle != NULL);
145 189
146 GNUNET_DHT_put(peer->dht_handle, &hash, 0, data_size, data, GNUNET_TIME_relative_to_absolute(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 360)) ,GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 360), &end, NULL); 190 GNUNET_DHT_put(peer->dht_handle, &hash, 0, data_size, data, GNUNET_TIME_relative_to_absolute(TIMEOUT), TIMEOUT, &test_find_peer, &p1);
147 191
148 //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1);
149
150 //GNUNET_SCHEDULER_add_now(sched, &end, NULL);
151} 192}
152 193
153/** 194/**
@@ -160,8 +201,6 @@ void test_get_stop (void *cls,
160 const struct GNUNET_SCHEDULER_TaskContext * tc) 201 const struct GNUNET_SCHEDULER_TaskContext * tc)
161{ 202{
162 struct PeerContext *peer = cls; 203 struct PeerContext *peer = cls;
163 GNUNET_HashCode hash;
164 memset(&hash, 42, sizeof(GNUNET_HashCode));
165 204
166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get_stop!\n"); 205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get_stop!\n");
167 if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) 206 if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
@@ -169,10 +208,9 @@ void test_get_stop (void *cls,
169 208
170 GNUNET_assert (peer->dht_handle != NULL); 209 GNUNET_assert (peer->dht_handle != NULL);
171 210
172 GNUNET_DHT_get_stop(peer->get_handle); 211 GNUNET_DHT_get_stop(peer->get_handle, &test_put, &p1);
173 212
174 //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1); 213 //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1);
175 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1);
176 214
177} 215}
178 216
@@ -193,12 +231,10 @@ void test_get (void *cls,
193 peer->dht_handle = GNUNET_DHT_connect (sched, peer->cfg, 100); 231 peer->dht_handle = GNUNET_DHT_connect (sched, peer->cfg, 100);
194 GNUNET_assert (peer->dht_handle != NULL); 232 GNUNET_assert (peer->dht_handle != NULL);
195 233
196 peer->get_handle = GNUNET_DHT_get_start(peer->dht_handle, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100), 42, &hash, NULL, NULL, &test_get_stop, &p1); 234 peer->get_handle = GNUNET_DHT_get_start(peer->dht_handle, TIMEOUT, 42, &hash, NULL, NULL, &test_get_stop, &p1);
197 235
198 if (peer->get_handle == NULL) 236 if (peer->get_handle == NULL)
199 GNUNET_SCHEDULER_add_now(sched, &end_badly, &p1); 237 GNUNET_SCHEDULER_add_now(sched, &end_badly, &p1);
200
201 //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_get_stop, &p1);
202} 238}
203 239
204static void 240static void