aboutsummaryrefslogtreecommitdiff
path: root/src/dht/test_dht_api.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-03-17 17:19:30 +0000
committerNathan S. Evans <evans@in.tum.de>2010-03-17 17:19:30 +0000
commita48e8f508403c9d8641a0c9eb47d88f98cb47f28 (patch)
tree4f4f5f09a6aa89c60ba1798d507e1cb0cab0a6b9 /src/dht/test_dht_api.c
parentb571e5a4ed7fb2ef6f203c540e82675cf38bfcf8 (diff)
downloadgnunet-a48e8f508403c9d8641a0c9eb47d88f98cb47f28.tar.gz
gnunet-a48e8f508403c9d8641a0c9eb47d88f98cb47f28.zip
beginning of changes
Diffstat (limited to 'src/dht/test_dht_api.c')
-rw-r--r--src/dht/test_dht_api.c60
1 files changed, 57 insertions, 3 deletions
diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c
index 9c9fcb4d0..8092d7b2e 100644
--- a/src/dht/test_dht_api.c
+++ b/src/dht/test_dht_api.c
@@ -51,6 +51,9 @@ 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_GetHandle *get_handle;
55 struct GNUNET_DHT_GetHandle *find_peer_handle;
56
54#if START_ARM 57#if START_ARM
55 pid_t arm_pid; 58 pid_t arm_pid;
56#endif 59#endif
@@ -110,6 +113,54 @@ end_badly ()
110 return; 113 return;
111} 114}
112 115
116
117/**
118 * Signature of the main function of a task.
119 *
120 * @param cls closure
121 * @param tc context information (why was this task triggered now)
122 */
123void test_put (void *cls,
124 const struct GNUNET_SCHEDULER_TaskContext * tc)
125{
126 struct PeerContext *peer = cls;
127 GNUNET_HashCode hash;
128 char *data;
129 size_t data_size = 42;
130 memset(&hash, 42, sizeof(GNUNET_HashCode));
131 data = GNUNET_malloc(data_size);
132 memset(data, 43, data_size);
133
134 GNUNET_assert (peer->dht_handle != NULL);
135
136 GNUNET_DHT_put(peer->dht_handle, &hash, 0, data_size, data, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 360), NULL, NULL);
137
138 //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1);
139
140 GNUNET_SCHEDULER_add_now(sched, &end, NULL);
141}
142
143/**
144 * Signature of the main function of a task.
145 *
146 * @param cls closure
147 * @param tc context information (why was this task triggered now)
148 */
149void test_get_stop (void *cls,
150 const struct GNUNET_SCHEDULER_TaskContext * tc)
151{
152 struct PeerContext *peer = cls;
153 GNUNET_HashCode hash;
154 memset(&hash, 42, sizeof(GNUNET_HashCode));
155
156 GNUNET_assert (peer->dht_handle != NULL);
157
158 GNUNET_DHT_get_stop(peer->dht_handle, peer->get_handle);
159
160 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1);
161
162}
163
113/** 164/**
114 * Signature of the main function of a task. 165 * Signature of the main function of a task.
115 * 166 *
@@ -126,9 +177,12 @@ void test_get (void *cls,
126 peer->dht_handle = GNUNET_DHT_connect (sched, peer->cfg); 177 peer->dht_handle = GNUNET_DHT_connect (sched, peer->cfg);
127 GNUNET_assert (peer->dht_handle != NULL); 178 GNUNET_assert (peer->dht_handle != NULL);
128 179
129 GNUNET_DHT_get_start(peer->dht_handle, 42, &hash, NULL, NULL); 180 peer->get_handle = GNUNET_DHT_get_start(peer->dht_handle, 42, &hash, NULL, NULL);
181
182 if (peer->get_handle == NULL)
183 GNUNET_SCHEDULER_add_now(sched, &end_badly, &p1);
130 184
131 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), &end, &p1); 185 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_get_stop, &p1);
132} 186}
133 187
134static void 188static void
@@ -162,7 +216,7 @@ run (void *cls,
162 216
163 setup_peer (&p1, "test_dht_api_peer1.conf"); 217 setup_peer (&p1, "test_dht_api_peer1.conf");
164 218
165 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &test_get, &p1); 219 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_get, &p1);
166} 220}
167 221
168static int 222static int