cleaner stats
[oweals/gnunet.git] / src / fs / fs_test_lib.h
1 /*
2      This file is part of GNUnet.
3      (C) 2010 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 /**
22  * @file fs/fs_test_lib.h
23  * @brief library routines for testing FS publishing and downloading
24  *        with multiple peers; this code is limited to flat files
25  *        and no keywords (those functions can be tested with
26  *        single-peer setups; this is for testing routing).
27  * @author Christian Grothoff
28  */
29 #ifndef FS_TEST_LIB_H
30 #define FS_TEST_LIB_H
31
32 #include "gnunet_util_lib.h"
33 #include "gnunet_fs_service.h"
34
35 /**
36  * Handle for a daemon started for testing FS.
37  */
38 struct GNUNET_FS_TestDaemon;
39
40
41 /**
42  * Start daemons for testing.
43  *
44  * @param sched scheduler to use
45  * @param template_cfg_file configuration template to use
46  * @param timeout if this operation cannot be completed within the
47  *                given period, call the continuation with an error code
48  * @param total number of daemons to start
49  * @param daemons array of 'total' entries to be initialized
50  *                (array must already be allocated, will be filled)
51  * @param cont function to call when done; note that if 'cont'
52  *             is called with reason "TIMEOUT", then starting the
53  *             daemons has failed and the client MUST NOT call
54  *             'GNUNET_FS_TEST_daemons_stop'!
55  * @param cont_cls closure for cont
56  */
57 void
58 GNUNET_FS_TEST_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
59                               const char *template_cfg_file,
60                               struct GNUNET_TIME_Relative timeout,
61                               unsigned int total,
62                               struct GNUNET_FS_TestDaemon **daemons,
63                               GNUNET_SCHEDULER_Task cont,
64                               void *cont_cls);
65
66
67 /**
68  * Connect two daemons for testing.
69  *
70  * @param sched scheduler to use
71  * @param daemon1 first daemon to connect
72  * @param daemon2 second first daemon to connect
73  * @param timeout if this operation cannot be completed within the
74  *                given period, call the continuation with an error code
75  * @param cont function to call when done
76  * @param cont_cls closure for cont
77  */
78 void
79 GNUNET_FS_TEST_daemons_connect (struct GNUNET_SCHEDULER_Handle *sched,
80                                 struct GNUNET_FS_TestDaemon *daemon1,
81                                 struct GNUNET_FS_TestDaemon *daemon2,
82                                 struct GNUNET_TIME_Relative timeout,
83                                 GNUNET_SCHEDULER_Task cont,
84                                 void *cont_cls);
85
86
87 /**
88  * Obtain peer group used for testing.
89  *
90  * @param daemons array with the daemons (must contain at least one)
91  * @return peer group
92  */
93 struct GNUNET_TESTING_PeerGroup *
94 GNUNET_FS_TEST_get_group (struct GNUNET_FS_TestDaemon **daemons);
95
96
97
98 /**
99  * Obtain peer configuration used for testing.
100  *
101  * @param daemons array with the daemons
102  * @param off which configuration to get
103  * @return peer configuration
104  */
105 const struct GNUNET_CONFIGURATION_Handle *
106 GNUNET_FS_TEST_get_configuration (struct GNUNET_FS_TestDaemon **daemons,
107                                   unsigned int off);
108
109 /**
110  * Stop daemons used for testing.
111  *
112  * @param sched scheduler to use
113  * @param total number of daemons to stop
114  * @param daemons array with the daemons (values will be clobbered)
115  */
116 void
117 GNUNET_FS_TEST_daemons_stop (struct GNUNET_SCHEDULER_Handle *sched,
118                              unsigned int total,
119                              struct GNUNET_FS_TestDaemon **daemons);
120
121
122 /**
123  * Function signature.
124  *
125  * @param cls closure (user defined)
126  * @param uri a URI, NULL for errors
127  */
128 typedef void 
129 (*GNUNET_FS_TEST_UriContinuation)(void *cls,
130                                   const struct GNUNET_FS_Uri *uri);
131
132
133 /**
134  * Publish a file at the given daemon.
135  *
136  * @param sched scheduler to use
137  * @param daemon where to publish
138  * @param timeout if this operation cannot be completed within the
139  *                given period, call the continuation with an error code
140  * @param anonymity option for publication
141  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
142  *                GNUNET_SYSERR for simulation
143  * @param size size of the file to publish
144  * @param seed seed to use for file generation
145  * @param verbose how verbose to be in reporting
146  * @param cont function to call when done
147  * @param cont_cls closure for cont
148  */
149 void
150 GNUNET_FS_TEST_publish (struct GNUNET_SCHEDULER_Handle *sched,
151                         struct GNUNET_FS_TestDaemon *daemon,
152                         struct GNUNET_TIME_Relative timeout,
153                         uint32_t anonymity,
154                         int do_index,
155                         uint64_t size,
156                         uint32_t seed,
157                         unsigned int verbose,
158                         GNUNET_FS_TEST_UriContinuation cont,
159                         void *cont_cls);
160
161
162 /**
163  * Perform test download.
164  *
165  * @param sched scheduler to use
166  * @param daemon which peer to download from
167  * @param timeout if this operation cannot be completed within the
168  *                given period, call the continuation with an error code
169  * @param anonymity option for download
170  * @param seed used for file validation
171  * @param uri URI of file to download (CHK/LOC only)
172  * @param verbose how verbose to be in reporting
173  * @param cont function to call when done
174  * @param cont_cls closure for cont
175  */
176 void
177 GNUNET_FS_TEST_download (struct GNUNET_SCHEDULER_Handle *sched,
178                          struct GNUNET_FS_TestDaemon *daemon,
179                          struct GNUNET_TIME_Relative timeout,
180                          uint32_t anonymity,
181                          uint32_t seed,
182                          const struct GNUNET_FS_Uri *uri,
183                          unsigned int verbose,
184                          GNUNET_SCHEDULER_Task cont,
185                          void *cont_cls);
186
187
188
189 #endif