diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
commit | 502af2167f7c218366666ca4944bd7cc54b5b19a (patch) | |
tree | a91fec5cc9769d260640bd91c6633cb9cf395524 /src/fs/test_gnunet_service_fs_p2p.c | |
parent | 03af5a603b7cc53432249d5854cd412aa90dde0d (diff) | |
download | gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip |
indentation
Diffstat (limited to 'src/fs/test_gnunet_service_fs_p2p.c')
-rw-r--r-- | src/fs/test_gnunet_service_fs_p2p.c | 128 |
1 files changed, 54 insertions, 74 deletions
diff --git a/src/fs/test_gnunet_service_fs_p2p.c b/src/fs/test_gnunet_service_fs_p2p.c index d21e700e5..c48f98666 100644 --- a/src/fs/test_gnunet_service_fs_p2p.c +++ b/src/fs/test_gnunet_service_fs_p2p.c | |||
@@ -49,120 +49,100 @@ static int ok; | |||
49 | static struct GNUNET_TIME_Absolute start_time; | 49 | static struct GNUNET_TIME_Absolute start_time; |
50 | 50 | ||
51 | static void | 51 | static void |
52 | do_stop (void *cls, | 52 | do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
53 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
54 | { | 53 | { |
55 | struct GNUNET_TIME_Relative del; | 54 | struct GNUNET_TIME_Relative del; |
56 | char *fancy; | 55 | char *fancy; |
57 | 56 | ||
58 | GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, | 57 | GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons); |
59 | daemons); | ||
60 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) | 58 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) |
61 | { | 59 | { |
62 | del = GNUNET_TIME_absolute_get_duration (start_time); | 60 | del = GNUNET_TIME_absolute_get_duration (start_time); |
63 | if (del.rel_value == 0) | 61 | if (del.rel_value == 0) |
64 | del.rel_value = 1; | 62 | del.rel_value = 1; |
65 | fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long)FILESIZE) * 1000LL / del.rel_value); | 63 | fancy = |
66 | fprintf (stdout, | 64 | GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * |
67 | "Download speed was %s/s\n", | 65 | 1000LL / del.rel_value); |
68 | fancy); | 66 | fprintf (stdout, "Download speed was %s/s\n", fancy); |
69 | GNUNET_free (fancy); | 67 | GNUNET_free (fancy); |
70 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 68 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
71 | "Finished download, shutting down\n", | 69 | "Finished download, shutting down\n", |
72 | (unsigned long long) FILESIZE); | 70 | (unsigned long long) FILESIZE); |
73 | } | 71 | } |
74 | else | 72 | else |
75 | { | 73 | { |
76 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 74 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
77 | "Timeout during download, shutting down with error\n"); | 75 | "Timeout during download, shutting down with error\n"); |
78 | ok = 1; | 76 | ok = 1; |
79 | } | 77 | } |
80 | } | 78 | } |
81 | 79 | ||
82 | 80 | ||
83 | static void | 81 | static void |
84 | do_download (void *cls, | 82 | do_download (void *cls, const struct GNUNET_FS_Uri *uri) |
85 | const struct GNUNET_FS_Uri *uri) | ||
86 | { | 83 | { |
87 | if (NULL == uri) | 84 | if (NULL == uri) |
88 | { | 85 | { |
89 | GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, | 86 | GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons); |
90 | daemons); | 87 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
91 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 88 | "Timeout during upload attempt, shutting down with error\n"); |
92 | "Timeout during upload attempt, shutting down with error\n"); | 89 | ok = 1; |
93 | ok = 1; | 90 | return; |
94 | return; | 91 | } |
95 | } | ||
96 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 92 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
97 | "Downloading %llu bytes\n", | 93 | "Downloading %llu bytes\n", (unsigned long long) FILESIZE); |
98 | (unsigned long long) FILESIZE); | ||
99 | start_time = GNUNET_TIME_absolute_get (); | 94 | start_time = GNUNET_TIME_absolute_get (); |
100 | GNUNET_FS_TEST_download (daemons[0], | 95 | GNUNET_FS_TEST_download (daemons[0], |
101 | TIMEOUT, | 96 | TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop, NULL); |
102 | 1, SEED, uri, | ||
103 | VERBOSE, | ||
104 | &do_stop, NULL); | ||
105 | } | 97 | } |
106 | 98 | ||
107 | 99 | ||
108 | static void | 100 | static void |
109 | do_publish (void *cls, | 101 | do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
110 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
111 | { | 102 | { |
112 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) | 103 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) |
113 | { | 104 | { |
114 | GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, | 105 | GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons); |
115 | daemons); | 106 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 107 | "Timeout during connect attempt, shutting down with error\n"); |
117 | "Timeout during connect attempt, shutting down with error\n"); | 108 | ok = 1; |
118 | ok = 1; | 109 | return; |
119 | return; | 110 | } |
120 | } | ||
121 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 111 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
122 | "Publishing %llu bytes\n", | 112 | "Publishing %llu bytes\n", (unsigned long long) FILESIZE); |
123 | (unsigned long long) FILESIZE); | ||
124 | GNUNET_FS_TEST_publish (daemons[1], | 113 | GNUNET_FS_TEST_publish (daemons[1], |
125 | TIMEOUT, | 114 | TIMEOUT, |
126 | 1, GNUNET_NO, FILESIZE, SEED, | 115 | 1, GNUNET_NO, FILESIZE, SEED, |
127 | VERBOSE, | 116 | VERBOSE, &do_download, NULL); |
128 | &do_download, NULL); | ||
129 | } | 117 | } |
130 | 118 | ||
131 | 119 | ||
132 | static void | 120 | static void |
133 | do_connect (void *cls, | 121 | do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
134 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
135 | { | 122 | { |
136 | GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)); | 123 | GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)); |
137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
138 | "Daemons started, will now try to connect them\n"); | 125 | "Daemons started, will now try to connect them\n"); |
139 | GNUNET_FS_TEST_daemons_connect (daemons[0], | 126 | GNUNET_FS_TEST_daemons_connect (daemons[0], |
140 | daemons[1], | 127 | daemons[1], TIMEOUT, &do_publish, NULL); |
141 | TIMEOUT, | ||
142 | &do_publish, | ||
143 | NULL); | ||
144 | } | 128 | } |
145 | 129 | ||
146 | 130 | ||
147 | static void | 131 | static void |
148 | run (void *cls, | 132 | run (void *cls, |
149 | char *const *args, | 133 | char *const *args, |
150 | const char *cfgfile, | 134 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
151 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
152 | { | 135 | { |
153 | GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", | 136 | GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", |
154 | TIMEOUT, | 137 | TIMEOUT, |
155 | NUM_DAEMONS, | 138 | NUM_DAEMONS, daemons, &do_connect, NULL); |
156 | daemons, | ||
157 | &do_connect, | ||
158 | NULL); | ||
159 | } | 139 | } |
160 | 140 | ||
161 | 141 | ||
162 | int | 142 | int |
163 | main (int argc, char *argv[]) | 143 | main (int argc, char *argv[]) |
164 | { | 144 | { |
165 | char *const argvx[] = { | 145 | char *const argvx[] = { |
166 | "test-gnunet-service-fs-p2p", | 146 | "test-gnunet-service-fs-p2p", |
167 | "-c", | 147 | "-c", |
168 | "fs_test_lib_data.conf", | 148 | "fs_test_lib_data.conf", |
@@ -176,16 +156,16 @@ main (int argc, char *argv[]) | |||
176 | }; | 156 | }; |
177 | 157 | ||
178 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); | 158 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); |
179 | GNUNET_log_setup ("test_gnunet_service_fs_p2p", | 159 | GNUNET_log_setup ("test_gnunet_service_fs_p2p", |
180 | #if VERBOSE | 160 | #if VERBOSE |
181 | "DEBUG", | 161 | "DEBUG", |
182 | #else | 162 | #else |
183 | "WARNING", | 163 | "WARNING", |
184 | #endif | 164 | #endif |
185 | NULL); | 165 | NULL); |
186 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, | 166 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, |
187 | argvx, "test-gnunet-service-fs-p2p", | 167 | argvx, "test-gnunet-service-fs-p2p", |
188 | "nohelp", options, &run, NULL); | 168 | "nohelp", options, &run, NULL); |
189 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); | 169 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); |
190 | return ok; | 170 | return ok; |
191 | } | 171 | } |