012af788feca927f03fdcbc979c507f4f0919713
[oweals/gnunet.git] / src / fs / test_gnunet_service_fs_p2p.c
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/test_gnunet_service_fs_p2p.c
23  * @brief test P2P routing using simple publish + download operation
24  * @author Christian Grothoff
25  */
26 #include "platform.h"
27 #include "test_fs_lib.h"
28
29 #define VERBOSE GNUNET_NO
30
31 /**
32  * File-size we use for testing.
33  */
34 #define FILESIZE (1024 * 1024 * 2)
35
36 /**
37  * How long until we give up on transmitting the message?
38  */
39 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
40
41 #define NUM_DAEMONS 2
42
43 #define SEED 42
44
45 static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS];
46
47 static struct GNUNET_SCHEDULER_Handle *sched;
48
49
50 static void
51 do_stop (void *cls,
52          const struct GNUNET_SCHEDULER_TaskContext *tc)
53 {
54   GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
55   GNUNET_FS_TEST_daemons_stop (sched,
56                                NUM_DAEMONS,
57                                daemons);
58 }
59
60
61 static void
62 do_download (void *cls,
63              const struct GNUNET_FS_Uri *uri)
64 {
65   GNUNET_assert (NULL != uri);
66   GNUNET_FS_TEST_download (sched,
67                            daemons[1],
68                            TIMEOUT,
69                            1, SEED, uri, 
70                            VERBOSE, 
71                            &do_stop, NULL);
72 }
73
74
75 static void
76 do_publish (void *cls,
77             const struct GNUNET_SCHEDULER_TaskContext *tc)
78 {
79   GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
80   GNUNET_FS_TEST_publish (sched,
81                           daemons[1],
82                           TIMEOUT,
83                           1, GNUNET_NO, FILESIZE, SEED, 
84                           VERBOSE, 
85                           &do_download, NULL);
86 }
87
88
89 static void
90 do_connect (void *cls,
91             const struct GNUNET_SCHEDULER_TaskContext *tc)
92 {
93   GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
94   GNUNET_FS_TEST_daemons_connect (sched,
95                                   daemons[0],
96                                   daemons[1],
97                                   TIMEOUT,
98                                   &do_publish,
99                                   NULL);  
100 }
101
102
103 static void
104 run (void *cls,
105      struct GNUNET_SCHEDULER_Handle *s,
106      char *const *args,
107      const char *cfgfile,
108      const struct GNUNET_CONFIGURATION_Handle *cfg)
109 {
110   sched = s;
111   GNUNET_FS_TEST_daemons_start (sched,
112                                 TIMEOUT,
113                                 NUM_DAEMONS,
114                                 daemons,
115                                 &do_connect,
116                                 NULL);
117 }
118
119
120 int
121 main (int argc, char *argv[])
122 {
123   char *const argvx[] = { 
124     "test-gnunet-service-fs-p2p",
125     "-c",
126     "test_fs_lib_data.conf",
127 #if VERBOSE
128     "-L", "DEBUG",
129 #endif
130     NULL
131   };
132   struct GNUNET_GETOPT_CommandLineOption options[] = {
133     GNUNET_GETOPT_OPTION_END
134   };
135
136   GNUNET_log_setup ("test_gnunet_service_fs_p2p", 
137 #if VERBOSE
138                     "DEBUG",
139 #else
140                     "WARNING",
141 #endif
142                     NULL);
143   GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
144                       argvx, "test-gnunet-service-fs-p2p",
145                       "nohelp", options, &run, NULL);
146   return 0;
147 }
148
149 /* end of test_gnunet_service_fs_p2p.c */