diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/fs/test_gnunet_service_fs_migration.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/fs/test_gnunet_service_fs_migration.c')
-rw-r--r-- | src/fs/test_gnunet_service_fs_migration.c | 209 |
1 files changed, 106 insertions, 103 deletions
diff --git a/src/fs/test_gnunet_service_fs_migration.c b/src/fs/test_gnunet_service_fs_migration.c index c56e89e11..9842f8a83 100644 --- a/src/fs/test_gnunet_service_fs_migration.c +++ b/src/fs/test_gnunet_service_fs_migration.c | |||
@@ -37,12 +37,13 @@ | |||
37 | /** | 37 | /** |
38 | * How long until we give up on transmitting the message? | 38 | * How long until we give up on transmitting the message? |
39 | */ | 39 | */ |
40 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) | 40 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * How long do we give the peers for content migration? | 43 | * How long do we give the peers for content migration? |
44 | */ | 44 | */ |
45 | #define MIGRATION_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90) | 45 | #define MIGRATION_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ |
46 | 90) | ||
46 | 47 | ||
47 | #define SEED 42 | 48 | #define SEED 42 |
48 | 49 | ||
@@ -55,7 +56,8 @@ static struct GNUNET_TIME_Absolute start_time; | |||
55 | static struct GNUNET_TESTBED_Operation *op; | 56 | static struct GNUNET_TESTBED_Operation *op; |
56 | 57 | ||
57 | 58 | ||
58 | struct DownloadContext { | 59 | struct DownloadContext |
60 | { | ||
59 | char *fn; | 61 | char *fn; |
60 | 62 | ||
61 | struct GNUNET_FS_Uri *uri; | 63 | struct GNUNET_FS_Uri *uri; |
@@ -63,154 +65,155 @@ struct DownloadContext { | |||
63 | 65 | ||
64 | 66 | ||
65 | static void | 67 | static void |
66 | do_stop(void *cls) | 68 | do_stop (void *cls) |
67 | { | 69 | { |
68 | struct GNUNET_TIME_Relative del; | 70 | struct GNUNET_TIME_Relative del; |
69 | char *fancy; | 71 | char *fancy; |
70 | 72 | ||
71 | GNUNET_SCHEDULER_shutdown(); | 73 | GNUNET_SCHEDULER_shutdown (); |
72 | if (0 == | 74 | if (0 == |
73 | GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_add(start_time, | 75 | GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time, |
74 | TIMEOUT)).rel_value_us) | 76 | TIMEOUT)). |
75 | { | 77 | rel_value_us) |
76 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 78 | { |
77 | "Timeout during download, shutting down with error\n"); | 79 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
78 | ok = 1; | 80 | "Timeout during download, shutting down with error\n"); |
79 | } | 81 | ok = 1; |
82 | } | ||
80 | else | 83 | else |
81 | { | 84 | { |
82 | del = GNUNET_TIME_absolute_get_duration(start_time); | 85 | del = GNUNET_TIME_absolute_get_duration (start_time); |
83 | if (del.rel_value_us == 0) | 86 | if (del.rel_value_us == 0) |
84 | del.rel_value_us = 1; | 87 | del.rel_value_us = 1; |
85 | fancy = | 88 | fancy = |
86 | GNUNET_STRINGS_byte_size_fancy(((unsigned long long)FILESIZE) * | 89 | GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) |
87 | 1000000LL / del.rel_value_us); | 90 | * 1000000LL / del.rel_value_us); |
88 | fprintf(stdout, | 91 | fprintf (stdout, |
89 | "Download speed was %s/s\n", | 92 | "Download speed was %s/s\n", |
90 | fancy); | 93 | fancy); |
91 | GNUNET_free(fancy); | 94 | GNUNET_free (fancy); |
92 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 95 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
93 | "Finished download, shutting down\n"); | 96 | "Finished download, shutting down\n"); |
94 | } | 97 | } |
95 | } | 98 | } |
96 | 99 | ||
97 | 100 | ||
98 | static void | 101 | static void |
99 | do_download(void *cls, | 102 | do_download (void *cls, |
100 | const char *emsg) | 103 | const char *emsg) |
101 | { | 104 | { |
102 | struct DownloadContext *dc = cls; | 105 | struct DownloadContext *dc = cls; |
103 | struct GNUNET_FS_Uri *uri = dc->uri; | 106 | struct GNUNET_FS_Uri *uri = dc->uri; |
104 | 107 | ||
105 | GNUNET_TESTBED_operation_done(op); | 108 | GNUNET_TESTBED_operation_done (op); |
106 | op = NULL; | 109 | op = NULL; |
107 | if (NULL != dc->fn) | 110 | if (NULL != dc->fn) |
108 | { | 111 | { |
109 | GNUNET_DISK_directory_remove(dc->fn); | 112 | GNUNET_DISK_directory_remove (dc->fn); |
110 | GNUNET_free(dc->fn); | 113 | GNUNET_free (dc->fn); |
111 | } | 114 | } |
112 | GNUNET_free(dc); | 115 | GNUNET_free (dc); |
113 | if (NULL != emsg) | 116 | if (NULL != emsg) |
114 | { | 117 | { |
115 | GNUNET_SCHEDULER_shutdown(); | 118 | GNUNET_SCHEDULER_shutdown (); |
116 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
117 | "Failed to stop source daemon: %s\n", | 120 | "Failed to stop source daemon: %s\n", |
118 | emsg); | 121 | emsg); |
119 | GNUNET_FS_uri_destroy(uri); | 122 | GNUNET_FS_uri_destroy (uri); |
120 | ok = 1; | 123 | ok = 1; |
121 | return; | 124 | return; |
122 | } | 125 | } |
123 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
124 | "Downloading %llu bytes\n", | 127 | "Downloading %llu bytes\n", |
125 | (unsigned long long)FILESIZE); | 128 | (unsigned long long) FILESIZE); |
126 | start_time = GNUNET_TIME_absolute_get(); | 129 | start_time = GNUNET_TIME_absolute_get (); |
127 | GNUNET_FS_TEST_download(daemons[0], | 130 | GNUNET_FS_TEST_download (daemons[0], |
128 | TIMEOUT, | 131 | TIMEOUT, |
129 | 1, | 132 | 1, |
130 | SEED, | 133 | SEED, |
131 | uri, | 134 | uri, |
132 | VERBOSE, | 135 | VERBOSE, |
133 | &do_stop, | 136 | &do_stop, |
134 | NULL); | 137 | NULL); |
135 | GNUNET_FS_uri_destroy(uri); | 138 | GNUNET_FS_uri_destroy (uri); |
136 | } | 139 | } |
137 | 140 | ||
138 | 141 | ||
139 | static void | 142 | static void |
140 | stop_source_peer(void *cls) | 143 | stop_source_peer (void *cls) |
141 | { | 144 | { |
142 | struct DownloadContext *dc = cls; | 145 | struct DownloadContext *dc = cls; |
143 | 146 | ||
144 | /* FIXME: We should not interact with testbed when shutting down */ | 147 | /* FIXME: We should not interact with testbed when shutting down */ |
145 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 148 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
146 | "Stopping source peer\n"); | 149 | "Stopping source peer\n"); |
147 | op = GNUNET_TESTBED_peer_stop(NULL, | 150 | op = GNUNET_TESTBED_peer_stop (NULL, |
148 | daemons[1], | 151 | daemons[1], |
149 | &do_download, dc); | 152 | &do_download, dc); |
150 | GNUNET_assert(NULL != op); | 153 | GNUNET_assert (NULL != op); |
151 | } | 154 | } |
152 | 155 | ||
153 | 156 | ||
154 | static void | 157 | static void |
155 | do_wait(void *cls, | 158 | do_wait (void *cls, |
156 | const struct GNUNET_FS_Uri *uri, | 159 | const struct GNUNET_FS_Uri *uri, |
157 | const char *fn) | 160 | const char *fn) |
158 | { | 161 | { |
159 | struct DownloadContext *dc; | 162 | struct DownloadContext *dc; |
160 | 163 | ||
161 | if (NULL == uri) | 164 | if (NULL == uri) |
162 | { | 165 | { |
163 | GNUNET_SCHEDULER_shutdown(); | 166 | GNUNET_SCHEDULER_shutdown (); |
164 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 167 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
165 | "Timeout during upload attempt, shutting down with error\n"); | 168 | "Timeout during upload attempt, shutting down with error\n"); |
166 | ok = 1; | 169 | ok = 1; |
167 | return; | 170 | return; |
168 | } | 171 | } |
169 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
170 | "Waiting to allow content to migrate\n"); | 173 | "Waiting to allow content to migrate\n"); |
171 | dc = GNUNET_new(struct DownloadContext); | 174 | dc = GNUNET_new (struct DownloadContext); |
172 | dc->uri = GNUNET_FS_uri_dup(uri); | 175 | dc->uri = GNUNET_FS_uri_dup (uri); |
173 | if (NULL != fn) | 176 | if (NULL != fn) |
174 | dc->fn = GNUNET_strdup(fn); | 177 | dc->fn = GNUNET_strdup (fn); |
175 | (void)GNUNET_SCHEDULER_add_delayed(MIGRATION_DELAY, | 178 | (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY, |
176 | &stop_source_peer, | 179 | &stop_source_peer, |
177 | dc); | 180 | dc); |
178 | } | 181 | } |
179 | 182 | ||
180 | 183 | ||
181 | static void | 184 | static void |
182 | do_publish(void *cls, | 185 | do_publish (void *cls, |
183 | struct GNUNET_TESTBED_RunHandle *h, | 186 | struct GNUNET_TESTBED_RunHandle *h, |
184 | unsigned int num_peers, | 187 | unsigned int num_peers, |
185 | struct GNUNET_TESTBED_Peer **peers, | 188 | struct GNUNET_TESTBED_Peer **peers, |
186 | unsigned int links_succeeded, | 189 | unsigned int links_succeeded, |
187 | unsigned int links_failed) | 190 | unsigned int links_failed) |
188 | { | 191 | { |
189 | unsigned int i; | 192 | unsigned int i; |
190 | 193 | ||
191 | GNUNET_assert(2 == num_peers); | 194 | GNUNET_assert (2 == num_peers); |
192 | for (i = 0; i < num_peers; i++) | 195 | for (i = 0; i < num_peers; i++) |
193 | daemons[i] = peers[i]; | 196 | daemons[i] = peers[i]; |
194 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
195 | "Publishing %llu bytes\n", | 198 | "Publishing %llu bytes\n", |
196 | (unsigned long long)FILESIZE); | 199 | (unsigned long long) FILESIZE); |
197 | GNUNET_FS_TEST_publish(daemons[1], TIMEOUT, 1, GNUNET_NO, | 200 | GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, 1, GNUNET_NO, |
198 | FILESIZE, SEED, | 201 | FILESIZE, SEED, |
199 | VERBOSE, &do_wait, NULL); | 202 | VERBOSE, &do_wait, NULL); |
200 | } | 203 | } |
201 | 204 | ||
202 | 205 | ||
203 | int | 206 | int |
204 | main(int argc, | 207 | main (int argc, |
205 | char *argv[]) | 208 | char *argv[]) |
206 | { | 209 | { |
207 | (void)GNUNET_TESTBED_test_run("test-gnunet-service-fs-migration", | 210 | (void) GNUNET_TESTBED_test_run ("test-gnunet-service-fs-migration", |
208 | "fs_test_lib_data.conf", | 211 | "fs_test_lib_data.conf", |
209 | 2, | 212 | 2, |
210 | 0, NULL, NULL, | 213 | 0, NULL, NULL, |
211 | &do_publish, | 214 | &do_publish, |
212 | NULL); | 215 | NULL); |
213 | GNUNET_DISK_directory_remove("/tmp/test-gnunet-service-fs-migration/"); | 216 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/"); |
214 | return ok; | 217 | return ok; |
215 | } | 218 | } |
216 | 219 | ||