aboutsummaryrefslogtreecommitdiff
path: root/src/dht/test_dht_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/test_dht_api.c')
-rw-r--r--src/dht/test_dht_api.c184
1 files changed, 92 insertions, 92 deletions
diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c
index 7ec6758b7..f4a337ea8 100644
--- a/src/dht/test_dht_api.c
+++ b/src/dht/test_dht_api.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file dht/test_dht_api.c 21 * @file dht/test_dht_api.c
22 * @brief base test case for dht api 22 * @brief base test case for dht api
@@ -34,7 +34,7 @@
34/** 34/**
35 * How long until we really give up on a particular testcase portion? 35 * How long until we really give up on a particular testcase portion?
36 */ 36 */
37#define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) 37#define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60)
38 38
39static struct GNUNET_DHT_Handle *dht_handle; 39static struct GNUNET_DHT_Handle *dht_handle;
40 40
@@ -48,55 +48,55 @@ static struct GNUNET_SCHEDULER_Task *die_task;
48 48
49 49
50static void 50static void
51do_shutdown (void *cls) 51do_shutdown(void *cls)
52{ 52{
53 if (NULL != die_task) 53 if (NULL != die_task)
54 { 54 {
55 GNUNET_SCHEDULER_cancel (die_task); 55 GNUNET_SCHEDULER_cancel(die_task);
56 die_task = NULL; 56 die_task = NULL;
57 } 57 }
58 if (NULL != put_handle) 58 if (NULL != put_handle)
59 { 59 {
60 GNUNET_DHT_put_cancel (put_handle); 60 GNUNET_DHT_put_cancel(put_handle);
61 put_handle = NULL; 61 put_handle = NULL;
62 } 62 }
63 if (NULL != get_handle) 63 if (NULL != get_handle)
64 { 64 {
65 GNUNET_DHT_get_stop (get_handle); 65 GNUNET_DHT_get_stop(get_handle);
66 get_handle = NULL; 66 get_handle = NULL;
67 } 67 }
68 GNUNET_DHT_disconnect (dht_handle); 68 GNUNET_DHT_disconnect(dht_handle);
69 dht_handle = NULL; 69 dht_handle = NULL;
70} 70}
71 71
72 72
73static void 73static void
74end_badly (void *cls) 74end_badly(void *cls)
75{ 75{
76 die_task = NULL; 76 die_task = NULL;
77 fprintf (stderr, 77 fprintf(stderr,
78 "%s", 78 "%s",
79 "Ending on an unhappy note.\n"); 79 "Ending on an unhappy note.\n");
80 GNUNET_SCHEDULER_shutdown (); 80 GNUNET_SCHEDULER_shutdown();
81 ok = 1; 81 ok = 1;
82} 82}
83 83
84 84
85static void 85static void
86test_get_iterator (void *cls, 86test_get_iterator(void *cls,
87 struct GNUNET_TIME_Absolute exp, 87 struct GNUNET_TIME_Absolute exp,
88 const struct GNUNET_HashCode *key, 88 const struct GNUNET_HashCode *key,
89 const struct GNUNET_PeerIdentity *get_path, 89 const struct GNUNET_PeerIdentity *get_path,
90 unsigned int get_path_length, 90 unsigned int get_path_length,
91 const struct GNUNET_PeerIdentity *put_path, 91 const struct GNUNET_PeerIdentity *put_path,
92 unsigned int put_path_length, 92 unsigned int put_path_length,
93 enum GNUNET_BLOCK_Type type, 93 enum GNUNET_BLOCK_Type type,
94 size_t size, 94 size_t size,
95 const void *data) 95 const void *data)
96{ 96{
97 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 97 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
98 "test_get_iterator called (we got a result), stopping get request!\n"); 98 "test_get_iterator called (we got a result), stopping get request!\n");
99 GNUNET_SCHEDULER_shutdown (); 99 GNUNET_SCHEDULER_shutdown();
100 ok = 0; 100 ok = 0;
101} 101}
102 102
@@ -107,83 +107,83 @@ test_get_iterator (void *cls,
107 * @param cls closure 107 * @param cls closure
108 */ 108 */
109static void 109static void
110test_get (void *cls) 110test_get(void *cls)
111{ 111{
112 struct GNUNET_HashCode hash; 112 struct GNUNET_HashCode hash;
113 113
114 put_handle = NULL; 114 put_handle = NULL;
115 memset (&hash, 115 memset(&hash,
116 42, 116 42,
117 sizeof (struct GNUNET_HashCode)); 117 sizeof(struct GNUNET_HashCode));
118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 118 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
119 "Called test_get!\n"); 119 "Called test_get!\n");
120 GNUNET_assert (dht_handle != NULL); 120 GNUNET_assert(dht_handle != NULL);
121 get_handle = GNUNET_DHT_get_start (dht_handle, 121 get_handle = GNUNET_DHT_get_start(dht_handle,
122 GNUNET_BLOCK_TYPE_TEST, 122 GNUNET_BLOCK_TYPE_TEST,
123 &hash, 123 &hash,
124 1, 124 1,
125 GNUNET_DHT_RO_NONE, 125 GNUNET_DHT_RO_NONE,
126 NULL, 126 NULL,
127 0, 127 0,
128 &test_get_iterator, 128 &test_get_iterator,
129 NULL); 129 NULL);
130 130
131 if (NULL == get_handle) 131 if (NULL == get_handle)
132 { 132 {
133 GNUNET_break (0); 133 GNUNET_break(0);
134 ok = 1; 134 ok = 1;
135 GNUNET_SCHEDULER_shutdown (); 135 GNUNET_SCHEDULER_shutdown();
136 return; 136 return;
137 } 137 }
138} 138}
139 139
140 140
141static void 141static void
142run (void *cls, 142run(void *cls,
143 const struct GNUNET_CONFIGURATION_Handle *cfg, 143 const struct GNUNET_CONFIGURATION_Handle *cfg,
144 struct GNUNET_TESTING_Peer *peer) 144 struct GNUNET_TESTING_Peer *peer)
145{ 145{
146 struct GNUNET_HashCode hash; 146 struct GNUNET_HashCode hash;
147 char *data; 147 char *data;
148 size_t data_size = 42; 148 size_t data_size = 42;
149 149
150 GNUNET_assert (ok == 1); 150 GNUNET_assert(ok == 1);
151 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 151 GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
152 NULL); 152 NULL);
153 die_task = GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT, 153 die_task = GNUNET_SCHEDULER_add_delayed(TOTAL_TIMEOUT,
154 &end_badly, 154 &end_badly,
155 NULL); 155 NULL);
156 memset (&hash, 156 memset(&hash,
157 42, 157 42,
158 sizeof (struct GNUNET_HashCode)); 158 sizeof(struct GNUNET_HashCode));
159 data = GNUNET_malloc (data_size); 159 data = GNUNET_malloc(data_size);
160 memset (data, 43, data_size); 160 memset(data, 43, data_size);
161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 161 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
162 "Called test_put!\n"); 162 "Called test_put!\n");
163 dht_handle = GNUNET_DHT_connect (cfg, 163 dht_handle = GNUNET_DHT_connect(cfg,
164 100); 164 100);
165 GNUNET_assert (NULL != dht_handle); 165 GNUNET_assert(NULL != dht_handle);
166 put_handle = GNUNET_DHT_put (dht_handle, 166 put_handle = GNUNET_DHT_put(dht_handle,
167 &hash, 167 &hash,
168 1, 168 1,
169 GNUNET_DHT_RO_NONE, 169 GNUNET_DHT_RO_NONE,
170 GNUNET_BLOCK_TYPE_TEST, 170 GNUNET_BLOCK_TYPE_TEST,
171 data_size, 171 data_size,
172 data, 172 data,
173 GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT), 173 GNUNET_TIME_relative_to_absolute(TOTAL_TIMEOUT),
174 &test_get, 174 &test_get,
175 NULL); 175 NULL);
176 GNUNET_free (data); 176 GNUNET_free(data);
177} 177}
178 178
179 179
180int 180int
181main (int argc, 181main(int argc,
182 char *argv[]) 182 char *argv[])
183{ 183{
184 if (0 != GNUNET_TESTING_peer_run ("test-dht-api", 184 if (0 != GNUNET_TESTING_peer_run("test-dht-api",
185 "test_dht_api_data.conf", 185 "test_dht_api_data.conf",
186 &run, NULL)) 186 &run, NULL))
187 return 1; 187 return 1;
188 return ok; 188 return ok;
189} 189}