fixing common off-by-one error with respect to maximum message size
[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 2, 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
52  * @param cont_cls closure for cont
53  */
54 void
55 GNUNET_FS_TEST_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
56                               const char *template_cfg_file,
57                               struct GNUNET_TIME_Relative timeout,
58                               unsigned int total,
59                               struct GNUNET_FS_TestDaemon **daemons,
60                               GNUNET_SCHEDULER_Task cont,
61                               void *cont_cls);
62
63
64 /**
65  * Connect two daemons for testing.
66  *
67  * @param sched scheduler to use
68  * @param daemon1 first daemon to connect
69  * @param daemon2 second first daemon to connect
70  * @param timeout if this operation cannot be completed within the
71  *                given period, call the continuation with an error code
72  * @param cont function to call when done
73  * @param cont_cls closure for cont
74  */
75 void
76 GNUNET_FS_TEST_daemons_connect (struct GNUNET_SCHEDULER_Handle *sched,
77                                 struct GNUNET_FS_TestDaemon *daemon1,
78                                 struct GNUNET_FS_TestDaemon *daemon2,
79                                 struct GNUNET_TIME_Relative timeout,
80                                 GNUNET_SCHEDULER_Task cont,
81                                 void *cont_cls);
82
83
84 /**
85  * Obtain peer group used for testing.
86  *
87  * @param daemons array with the daemons (must contain at least one)
88  * @return peer group
89  */
90 struct GNUNET_TESTING_PeerGroup *
91 GNUNET_FS_TEST_get_group (struct GNUNET_FS_TestDaemon **daemons);
92
93
94
95 /**
96  * Stop daemons used for testing.
97  *
98  * @param sched scheduler to use
99  * @param total number of daemons to stop
100  * @param daemons array with the daemons (values will be clobbered)
101  */
102 void
103 GNUNET_FS_TEST_daemons_stop (struct GNUNET_SCHEDULER_Handle *sched,
104                              unsigned int total,
105                              struct GNUNET_FS_TestDaemon **daemons);
106
107
108 /**
109  * Function signature.
110  *
111  * @param cls closure (user defined)
112  * @param uri a URI, NULL for errors
113  */
114 typedef void 
115 (*GNUNET_FS_TEST_UriContinuation)(void *cls,
116                                   const struct GNUNET_FS_Uri *uri);
117
118
119 /**
120  * Publish a file at the given daemon.
121  *
122  * @param sched scheduler to use
123  * @param daemon where to publish
124  * @param timeout if this operation cannot be completed within the
125  *                given period, call the continuation with an error code
126  * @param anonymity option for publication
127  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
128  *                GNUNET_SYSERR for simulation
129  * @param size size of the file to publish
130  * @param seed seed to use for file generation
131  * @param verbose how verbose to be in reporting
132  * @param cont function to call when done
133  * @param cont_cls closure for cont
134  */
135 void
136 GNUNET_FS_TEST_publish (struct GNUNET_SCHEDULER_Handle *sched,
137                         struct GNUNET_FS_TestDaemon *daemon,
138                         struct GNUNET_TIME_Relative timeout,
139                         uint32_t anonymity,
140                         int do_index,
141                         uint64_t size,
142                         uint32_t seed,
143                         unsigned int verbose,
144                         GNUNET_FS_TEST_UriContinuation cont,
145                         void *cont_cls);
146
147
148 /**
149  * Perform test download.
150  *
151  * @param sched scheduler to use
152  * @param daemon which peer to download from
153  * @param timeout if this operation cannot be completed within the
154  *                given period, call the continuation with an error code
155  * @param anonymity option for download
156  * @param seed used for file validation
157  * @param uri URI of file to download (CHK/LOC only)
158  * @param verbose how verbose to be in reporting
159  * @param cont function to call when done
160  * @param cont_cls closure for cont
161  */
162 void
163 GNUNET_FS_TEST_download (struct GNUNET_SCHEDULER_Handle *sched,
164                          struct GNUNET_FS_TestDaemon *daemon,
165                          struct GNUNET_TIME_Relative timeout,
166                          uint32_t anonymity,
167                          uint32_t seed,
168                          const struct GNUNET_FS_Uri *uri,
169                          unsigned int verbose,
170                          GNUNET_SCHEDULER_Task cont,
171                          void *cont_cls);
172
173
174
175 #endif