aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_gnunet_service_fs_migration.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-08-03 09:35:48 +0000
committerChristian Grothoff <christian@grothoff.org>2015-08-03 09:35:48 +0000
commitd3e7a5e40dd2d5409009a30e1e41148c4d852673 (patch)
tree21ff19580a99137e9b8aec4393feb67f0f1c7b5a /src/fs/test_gnunet_service_fs_migration.c
parentec69ceabc67a72373a2579d871c5fe85676a73bd (diff)
downloadgnunet-d3e7a5e40dd2d5409009a30e1e41148c4d852673.tar.gz
gnunet-d3e7a5e40dd2d5409009a30e1e41148c4d852673.zip
-use simpler, modern scheduler API
Diffstat (limited to 'src/fs/test_gnunet_service_fs_migration.c')
-rw-r--r--src/fs/test_gnunet_service_fs_migration.c60
1 files changed, 40 insertions, 20 deletions
diff --git a/src/fs/test_gnunet_service_fs_migration.c b/src/fs/test_gnunet_service_fs_migration.c
index 94b6452d6..69fd4619a 100644
--- a/src/fs/test_gnunet_service_fs_migration.c
+++ b/src/fs/test_gnunet_service_fs_migration.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2010, 2012 Christian Grothoff (and other contributing authors) 3 Copyright (C) 2010, 2012, 2015 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -64,13 +64,22 @@ struct DownloadContext
64 64
65 65
66static void 66static void
67do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 67do_stop (void *cls,
68 const struct GNUNET_SCHEDULER_TaskContext *tc)
68{ 69{
69 struct GNUNET_TIME_Relative del; 70 struct GNUNET_TIME_Relative del;
70 char *fancy; 71 char *fancy;
71 72
72 GNUNET_SCHEDULER_shutdown (); 73 GNUNET_SCHEDULER_shutdown ();
73 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) 74 if (0 ==
75 GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time,
76 TIMEOUT)).rel_value_us)
77 {
78 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
79 "Timeout during download, shutting down with error\n");
80 ok = 1;
81 }
82 else
74 { 83 {
75 del = GNUNET_TIME_absolute_get_duration (start_time); 84 del = GNUNET_TIME_absolute_get_duration (start_time);
76 if (del.rel_value_us == 0) 85 if (del.rel_value_us == 0)
@@ -78,16 +87,13 @@ do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
78 fancy = 87 fancy =
79 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * 88 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
80 1000000LL / del.rel_value_us); 89 1000000LL / del.rel_value_us);
81 FPRINTF (stdout, "Download speed was %s/s\n", fancy); 90 FPRINTF (stdout,
91 "Download speed was %s/s\n",
92 fancy);
82 GNUNET_free (fancy); 93 GNUNET_free (fancy);
83 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished download, shutting down\n",
84 (unsigned long long) FILESIZE);
85 }
86 else
87 {
88 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
89 "Timeout during download, shutting down with error\n"); 95 "Finished download, shutting down\n",
90 ok = 1; 96 (unsigned long long) FILESIZE);
91 } 97 }
92} 98}
93 99
@@ -110,34 +116,45 @@ do_download (void *cls,
110 if (NULL != emsg) 116 if (NULL != emsg)
111 { 117 {
112 GNUNET_SCHEDULER_shutdown (); 118 GNUNET_SCHEDULER_shutdown ();
113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to stop source daemon: %s\n", 119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
120 "Failed to stop source daemon: %s\n",
114 emsg); 121 emsg);
115 GNUNET_FS_uri_destroy (uri); 122 GNUNET_FS_uri_destroy (uri);
116 ok = 1; 123 ok = 1;
117 return; 124 return;
118 } 125 }
119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", 126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
127 "Downloading %llu bytes\n",
120 (unsigned long long) FILESIZE); 128 (unsigned long long) FILESIZE);
121 start_time = GNUNET_TIME_absolute_get (); 129 start_time = GNUNET_TIME_absolute_get ();
122 GNUNET_FS_TEST_download (daemons[0], TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop, 130 GNUNET_FS_TEST_download (daemons[0],
131 TIMEOUT,
132 1,
133 SEED,
134 uri,
135 VERBOSE,
136 &do_stop,
123 NULL); 137 NULL);
124 GNUNET_FS_uri_destroy (uri); 138 GNUNET_FS_uri_destroy (uri);
125} 139}
126 140
127 141
128static void 142static void
129stop_source_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 143stop_source_peer (void *cls,
144 const struct GNUNET_SCHEDULER_TaskContext *tc)
130{ 145{
131 struct DownloadContext *dc = cls; 146 struct DownloadContext *dc = cls;
132 147
133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping source peer\n"); 148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
149 "Stopping source peer\n");
134 op = GNUNET_TESTBED_peer_stop (NULL, daemons[1], &do_download, dc); 150 op = GNUNET_TESTBED_peer_stop (NULL, daemons[1], &do_download, dc);
135 GNUNET_assert (NULL != op); 151 GNUNET_assert (NULL != op);
136} 152}
137 153
138 154
139static void 155static void
140do_wait (void *cls, const struct GNUNET_FS_Uri *uri, 156do_wait (void *cls,
157 const struct GNUNET_FS_Uri *uri,
141 const char *fn) 158 const char *fn)
142{ 159{
143 struct DownloadContext *dc; 160 struct DownloadContext *dc;
@@ -150,7 +167,8 @@ do_wait (void *cls, const struct GNUNET_FS_Uri *uri,
150 ok = 1; 167 ok = 1;
151 return; 168 return;
152 } 169 }
153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Waiting to allow content to migrate\n"); 170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
171 "Waiting to allow content to migrate\n");
154 dc = GNUNET_new (struct DownloadContext); 172 dc = GNUNET_new (struct DownloadContext);
155 dc->uri = GNUNET_FS_uri_dup (uri); 173 dc->uri = GNUNET_FS_uri_dup (uri);
156 if (NULL != fn) 174 if (NULL != fn)
@@ -172,7 +190,8 @@ do_publish (void *cls,
172 GNUNET_assert (2 == num_peers); 190 GNUNET_assert (2 == num_peers);
173 for (i=0;i<num_peers;i++) 191 for (i=0;i<num_peers;i++)
174 daemons[i] = peers[i]; 192 daemons[i] = peers[i];
175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", 193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
194 "Publishing %llu bytes\n",
176 (unsigned long long) FILESIZE); 195 (unsigned long long) FILESIZE);
177 GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED, 196 GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED,
178 VERBOSE, &do_wait, NULL); 197 VERBOSE, &do_wait, NULL);
@@ -180,7 +199,8 @@ do_publish (void *cls,
180 199
181 200
182int 201int
183main (int argc, char *argv[]) 202main (int argc,
203 char *argv[])
184{ 204{
185 (void) GNUNET_TESTBED_test_run ("test-gnunet-service-fs-migration", 205 (void) GNUNET_TESTBED_test_run ("test-gnunet-service-fs-migration",
186 "fs_test_lib_data.conf", 206 "fs_test_lib_data.conf",