diff options
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/test_testing.c | 32 | ||||
-rw-r--r-- | src/testing/test_testing_connect.c | 47 | ||||
-rw-r--r-- | src/testing/test_testing_group.c | 73 | ||||
-rw-r--r-- | src/testing/test_testing_group_remote.c | 188 | ||||
-rw-r--r-- | src/testing/test_testing_large_topology.c | 826 | ||||
-rw-r--r-- | src/testing/test_testing_peergroup.c | 55 | ||||
-rw-r--r-- | src/testing/test_testing_reconnect.c | 70 | ||||
-rw-r--r-- | src/testing/test_testing_topology.c | 853 | ||||
-rw-r--r-- | src/testing/test_testing_topology_blacklist.c | 357 | ||||
-rw-r--r-- | src/testing/test_testing_topology_churn.c | 114 | ||||
-rw-r--r-- | src/testing/testing.c | 2691 | ||||
-rw-r--r-- | src/testing/testing_group.c | 5809 | ||||
-rw-r--r-- | src/testing/testing_peergroup.c | 849 |
13 files changed, 6007 insertions, 5957 deletions
diff --git a/src/testing/test_testing.c b/src/testing/test_testing.c index 7045ee6b1..88861a156 100644 --- a/src/testing/test_testing.c +++ b/src/testing/test_testing.c | |||
@@ -34,28 +34,27 @@ static void | |||
34 | end_cb (void *cls, const char *emsg) | 34 | end_cb (void *cls, const char *emsg) |
35 | { | 35 | { |
36 | if (emsg != NULL) | 36 | if (emsg != NULL) |
37 | { | 37 | { |
38 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ending with error: %s\n", emsg); | 38 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ending with error: %s\n", emsg); |
39 | ok = 1; | 39 | ok = 1; |
40 | } | 40 | } |
41 | else | 41 | else |
42 | { | 42 | { |
43 | #if VERBOSE | 43 | #if VERBOSE |
44 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 44 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Daemon terminated, will now exit.\n"); |
45 | "Daemon terminated, will now exit.\n"); | ||
46 | #endif | 45 | #endif |
47 | ok = 0; | 46 | ok = 0; |
48 | } | 47 | } |
49 | } | 48 | } |
50 | 49 | ||
51 | 50 | ||
52 | 51 | ||
53 | void do_shutdown (void *cls, | 52 | void |
54 | const struct GNUNET_SCHEDULER_TaskContext * tc) | 53 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
55 | { | 54 | { |
56 | struct GNUNET_TESTING_Daemon *d = cls; | 55 | struct GNUNET_TESTING_Daemon *d = cls; |
57 | GNUNET_TESTING_daemon_stop (d, TIMEOUT, &end_cb, NULL, GNUNET_YES, | 56 | |
58 | GNUNET_NO); | 57 | GNUNET_TESTING_daemon_stop (d, TIMEOUT, &end_cb, NULL, GNUNET_YES, GNUNET_NO); |
59 | } | 58 | } |
60 | 59 | ||
61 | 60 | ||
@@ -70,7 +69,7 @@ my_cb (void *cls, | |||
70 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 69 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
71 | "Daemon `%s' started, will now stop it.\n", GNUNET_i2s (id)); | 70 | "Daemon `%s' started, will now stop it.\n", GNUNET_i2s (id)); |
72 | #endif | 71 | #endif |
73 | GNUNET_SCHEDULER_add_now(&do_shutdown, d); | 72 | GNUNET_SCHEDULER_add_now (&do_shutdown, d); |
74 | } | 73 | } |
75 | 74 | ||
76 | 75 | ||
@@ -85,9 +84,8 @@ run (void *cls, | |||
85 | #if VERBOSE | 84 | #if VERBOSE |
86 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n"); | 85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n"); |
87 | #endif | 86 | #endif |
88 | d = | 87 | d = GNUNET_TESTING_daemon_start (cfg, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL, |
89 | GNUNET_TESTING_daemon_start (cfg, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL, NULL, NULL, | 88 | NULL, NULL, &my_cb, NULL); |
90 | &my_cb, NULL); | ||
91 | GNUNET_assert (d != NULL); | 89 | GNUNET_assert (d != NULL); |
92 | } | 90 | } |
93 | 91 | ||
diff --git a/src/testing/test_testing_connect.c b/src/testing/test_testing_connect.c index 631b224f5..19e3bb1c0 100644 --- a/src/testing/test_testing_connect.c +++ b/src/testing/test_testing_connect.c | |||
@@ -48,33 +48,33 @@ end2_cb (void *cls, const char *emsg) | |||
48 | { | 48 | { |
49 | 49 | ||
50 | if (emsg != NULL) | 50 | if (emsg != NULL) |
51 | { | 51 | { |
52 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ending with error: %s\n", emsg); | 52 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ending with error: %s\n", emsg); |
53 | ok = 1; | 53 | ok = 1; |
54 | } | 54 | } |
55 | else | 55 | else |
56 | { | 56 | { |
57 | #if VERBOSE | 57 | #if VERBOSE |
58 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 58 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
59 | "Both daemons terminated, will now exit.\n"); | 59 | "Both daemons terminated, will now exit.\n"); |
60 | #endif | 60 | #endif |
61 | ok = 0; | 61 | ok = 0; |
62 | } | 62 | } |
63 | } | 63 | } |
64 | 64 | ||
65 | static void | 65 | static void |
66 | end1_cb (void *cls, const char *emsg) | 66 | end1_cb (void *cls, const char *emsg) |
67 | { | 67 | { |
68 | if (emsg != NULL) | 68 | if (emsg != NULL) |
69 | { | 69 | { |
70 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Stopping daemon 1 gave: %s\n", | 70 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Stopping daemon 1 gave: %s\n", |
71 | emsg); | 71 | emsg); |
72 | ok = 1; | 72 | ok = 1; |
73 | } | 73 | } |
74 | else | 74 | else |
75 | { | 75 | { |
76 | ok = 0; | 76 | ok = 0; |
77 | } | 77 | } |
78 | 78 | ||
79 | GNUNET_TESTING_daemon_stop (d2, TIMEOUT, &end2_cb, NULL, GNUNET_YES, | 79 | GNUNET_TESTING_daemon_stop (d2, TIMEOUT, &end2_cb, NULL, GNUNET_YES, |
80 | GNUNET_NO); | 80 | GNUNET_NO); |
@@ -117,8 +117,7 @@ my_cb2 (void *cls, | |||
117 | #endif | 117 | #endif |
118 | GNUNET_TESTING_daemons_connect (d1, d2, | 118 | GNUNET_TESTING_daemons_connect (d1, d2, |
119 | TIMEOUT, CONNECT_ATTEMPTS, | 119 | TIMEOUT, CONNECT_ATTEMPTS, |
120 | GNUNET_YES, | 120 | GNUNET_YES, &my_connect_complete, NULL); |
121 | &my_connect_complete, NULL); | ||
122 | } | 121 | } |
123 | 122 | ||
124 | 123 | ||
@@ -133,9 +132,8 @@ my_cb1 (void *cls, | |||
133 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
134 | "Daemon `%s' started.\n", GNUNET_i2s (id)); | 133 | "Daemon `%s' started.\n", GNUNET_i2s (id)); |
135 | #endif | 134 | #endif |
136 | d2 = | 135 | d2 = GNUNET_TESTING_daemon_start (c2, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL, |
137 | GNUNET_TESTING_daemon_start (c2, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL, NULL, NULL, | 136 | NULL, NULL, &my_cb2, NULL); |
138 | &my_cb2, NULL); | ||
139 | GNUNET_assert (d2 != NULL); | 137 | GNUNET_assert (d2 != NULL); |
140 | 138 | ||
141 | } | 139 | } |
@@ -154,9 +152,8 @@ run (void *cls, | |||
154 | GNUNET_CONFIGURATION_parse (c1, "test_testing_connect_peer1.conf"); | 152 | GNUNET_CONFIGURATION_parse (c1, "test_testing_connect_peer1.conf"); |
155 | c2 = GNUNET_CONFIGURATION_create (); | 153 | c2 = GNUNET_CONFIGURATION_create (); |
156 | GNUNET_CONFIGURATION_parse (c2, "test_testing_connect_peer2.conf"); | 154 | GNUNET_CONFIGURATION_parse (c2, "test_testing_connect_peer2.conf"); |
157 | d1 = | 155 | d1 = GNUNET_TESTING_daemon_start (c1, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL, |
158 | GNUNET_TESTING_daemon_start (c1, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL, NULL, NULL, | 156 | NULL, NULL, &my_cb1, NULL); |
159 | &my_cb1, NULL); | ||
160 | GNUNET_assert (d1 != NULL); | 157 | GNUNET_assert (d1 != NULL); |
161 | } | 158 | } |
162 | 159 | ||
diff --git a/src/testing/test_testing_group.c b/src/testing/test_testing_group.c index 0056588bc..88893f45d 100644 --- a/src/testing/test_testing_group.c +++ b/src/testing/test_testing_group.c | |||
@@ -48,20 +48,19 @@ void | |||
48 | shutdown_callback (void *cls, const char *emsg) | 48 | shutdown_callback (void *cls, const char *emsg) |
49 | { | 49 | { |
50 | if (emsg != NULL) | 50 | if (emsg != NULL) |
51 | { | 51 | { |
52 | #if VERBOSE | 52 | #if VERBOSE |
53 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n"); | 53 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n"); |
54 | #endif | 54 | #endif |
55 | if (ok == 0) | 55 | if (ok == 0) |
56 | ok = 666; | 56 | ok = 666; |
57 | } | 57 | } |
58 | else | 58 | else |
59 | { | 59 | { |
60 | #if VERBOSE | 60 | #if VERBOSE |
61 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 61 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n"); |
62 | "All peers successfully shut down!\n"); | ||
63 | #endif | 62 | #endif |
64 | } | 63 | } |
65 | } | 64 | } |
66 | 65 | ||
67 | 66 | ||
@@ -72,36 +71,36 @@ my_cb (void *cls, | |||
72 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 71 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
73 | { | 72 | { |
74 | if (id == NULL) | 73 | if (id == NULL) |
74 | { | ||
75 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
76 | "Start callback called with error (too long starting peers), aborting test!\n"); | ||
77 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n"); | ||
78 | failed_peers++; | ||
79 | if (failed_peers == peers_left) | ||
75 | { | 80 | { |
76 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 81 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
77 | "Start callback called with error (too long starting peers), aborting test!\n"); | 82 | "Too many peers failed, ending test!\n"); |
78 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n"); | 83 | ok = 1; |
79 | failed_peers++; | 84 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
80 | if (failed_peers == peers_left) | ||
81 | { | ||
82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
83 | "Too many peers failed, ending test!\n"); | ||
84 | ok = 1; | ||
85 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | ||
86 | } | ||
87 | return; | ||
88 | } | 85 | } |
86 | return; | ||
87 | } | ||
89 | 88 | ||
90 | peers_left--; | 89 | peers_left--; |
91 | if (peers_left == 0) | 90 | if (peers_left == 0) |
92 | { | 91 | { |
93 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 92 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
94 | "All peers started successfully, ending test!\n"); | 93 | "All peers started successfully, ending test!\n"); |
95 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 94 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
96 | ok = 0; | 95 | ok = 0; |
97 | } | 96 | } |
98 | else if (failed_peers == peers_left) | 97 | else if (failed_peers == peers_left) |
99 | { | 98 | { |
100 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 99 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
101 | "Too many peers failed, ending test!\n"); | 100 | "Too many peers failed, ending test!\n"); |
102 | ok = 1; | 101 | ok = 1; |
103 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 102 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
104 | } | 103 | } |
105 | } | 104 | } |
106 | 105 | ||
107 | 106 | ||
@@ -115,10 +114,9 @@ run (void *cls, | |||
115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); | 114 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); |
116 | #endif | 115 | #endif |
117 | peers_left = NUM_PEERS; | 116 | peers_left = NUM_PEERS; |
118 | pg = GNUNET_TESTING_daemons_start (cfg, | 117 | pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of peers */ |
119 | peers_left, /* Total number of peers */ | 118 | peers_left, /* Number of outstanding connections */ |
120 | peers_left, /* Number of outstanding connections */ | 119 | peers_left, /* Number of parallel ssh connections, or peers being started at once */ |
121 | peers_left, /* Number of parallel ssh connections, or peers being started at once */ | ||
122 | TIMEOUT, | 120 | TIMEOUT, |
123 | NULL, NULL, | 121 | NULL, NULL, |
124 | &my_cb, NULL, NULL, NULL, NULL); | 122 | &my_cb, NULL, NULL, NULL, NULL); |
@@ -140,8 +138,7 @@ check () | |||
140 | GNUNET_GETOPT_OPTION_END | 138 | GNUNET_GETOPT_OPTION_END |
141 | }; | 139 | }; |
142 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 140 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
143 | argv, "test-testing-group", "nohelp", | 141 | argv, "test-testing-group", "nohelp", options, &run, &ok); |
144 | options, &run, &ok); | ||
145 | return ok; | 142 | return ok; |
146 | } | 143 | } |
147 | 144 | ||
diff --git a/src/testing/test_testing_group_remote.c b/src/testing/test_testing_group_remote.c index 58f3c4143..d43e7ed57 100644 --- a/src/testing/test_testing_group_remote.c +++ b/src/testing/test_testing_group_remote.c | |||
@@ -54,20 +54,20 @@ void | |||
54 | shutdown_callback (void *cls, const char *emsg) | 54 | shutdown_callback (void *cls, const char *emsg) |
55 | { | 55 | { |
56 | if (emsg != NULL) | 56 | if (emsg != NULL) |
57 | { | 57 | { |
58 | #if VERBOSE | 58 | #if VERBOSE |
59 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed (error %s)!\n", emsg); | 59 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
60 | "Shutdown of peers failed (error %s)!\n", emsg); | ||
60 | #endif | 61 | #endif |
61 | if (ok == 0) | 62 | if (ok == 0) |
62 | ok = 666; | 63 | ok = 666; |
63 | } | 64 | } |
64 | else | 65 | else |
65 | { | 66 | { |
66 | #if VERBOSE | 67 | #if VERBOSE |
67 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 68 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n"); |
68 | "All peers successfully shut down!\n"); | ||
69 | #endif | 69 | #endif |
70 | } | 70 | } |
71 | } | 71 | } |
72 | 72 | ||
73 | 73 | ||
@@ -78,22 +78,22 @@ my_cb (void *cls, | |||
78 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 78 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
79 | { | 79 | { |
80 | if (emsg != NULL) | 80 | if (emsg != NULL) |
81 | { | 81 | { |
82 | peers_failed++; | 82 | peers_failed++; |
83 | } | 83 | } |
84 | 84 | ||
85 | peers_left--; | 85 | peers_left--; |
86 | if (peers_left == 0) | 86 | if (peers_left == 0) |
87 | { | 87 | { |
88 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 88 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
89 | ok = 0; | 89 | ok = 0; |
90 | } | 90 | } |
91 | else if (peers_failed == peers_left) | 91 | else if (peers_failed == peers_left) |
92 | { | 92 | { |
93 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 93 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
94 | "Too many peers failed, ending test!\n"); | 94 | "Too many peers failed, ending test!\n"); |
95 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 95 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
96 | } | 96 | } |
97 | } | 97 | } |
98 | 98 | ||
99 | 99 | ||
@@ -111,6 +111,7 @@ run (void *cls, | |||
111 | char *data; | 111 | char *data; |
112 | int count; | 112 | int count; |
113 | int ret; | 113 | int ret; |
114 | |||
114 | ok = 1; | 115 | ok = 1; |
115 | #if VERBOSE | 116 | #if VERBOSE |
116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); | 117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); |
@@ -130,93 +131,89 @@ run (void *cls, | |||
130 | hosts = NULL; | 131 | hosts = NULL; |
131 | data = NULL; | 132 | data = NULL; |
132 | if (hostfile != NULL) | 133 | if (hostfile != NULL) |
134 | { | ||
135 | if (GNUNET_OK != GNUNET_DISK_file_test (hostfile)) | ||
136 | GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ | ||
137 | | GNUNET_DISK_PERM_USER_WRITE); | ||
138 | if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0)) | ||
133 | { | 139 | { |
134 | if (GNUNET_OK != GNUNET_DISK_file_test (hostfile)) | 140 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
135 | GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ | 141 | "Could not open file specified for host list, ending test!"); |
136 | | GNUNET_DISK_PERM_USER_WRITE); | 142 | ok = 1119; |
137 | if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0)) | 143 | GNUNET_free (hostfile); |
138 | { | 144 | return; |
139 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 145 | } |
140 | "Could not open file specified for host list, ending test!"); | ||
141 | ok = 1119; | ||
142 | GNUNET_free (hostfile); | ||
143 | return; | ||
144 | } | ||
145 | 146 | ||
146 | data = GNUNET_malloc_large (frstat.st_size); | 147 | data = GNUNET_malloc_large (frstat.st_size); |
147 | GNUNET_assert (data != NULL); | 148 | GNUNET_assert (data != NULL); |
148 | if (frstat.st_size != | 149 | if (frstat.st_size != GNUNET_DISK_fn_read (hostfile, data, frstat.st_size)) |
149 | GNUNET_DISK_fn_read (hostfile, data, frstat.st_size)) | 150 | { |
150 | { | 151 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
151 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 152 | "Could not read file %s specified for host list, ending test!", |
152 | "Could not read file %s specified for host list, ending test!", | 153 | hostfile); |
153 | hostfile); | 154 | GNUNET_free (hostfile); |
154 | GNUNET_free (hostfile); | 155 | GNUNET_free (data); |
155 | GNUNET_free (data); | 156 | return; |
156 | return; | 157 | } |
157 | } | ||
158 | 158 | ||
159 | GNUNET_free_non_null (hostfile); | 159 | GNUNET_free_non_null (hostfile); |
160 | 160 | ||
161 | buf = data; | 161 | buf = data; |
162 | count = 0; | 162 | count = 0; |
163 | while (count < frstat.st_size) | 163 | while (count < frstat.st_size) |
164 | { | ||
165 | count++; | ||
166 | if (count >= frstat.st_size) | ||
167 | break; | ||
168 | |||
169 | /* if (((data[count] == '\n') || (data[count] == '\0')) && (buf != &data[count])) */ | ||
170 | if (((data[count] == '\n')) && (buf != &data[count])) | ||
171 | { | ||
172 | data[count] = '\0'; | ||
173 | temphost = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Host)); | ||
174 | ret = | ||
175 | sscanf (buf, "%a[a-zA-Z0-9]@%a[a-zA-Z0-9.]:%hd", | ||
176 | &temphost->username, &temphost->hostname, &temphost->port); | ||
177 | if (3 == ret) | ||
178 | { | ||
179 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
180 | "Successfully read host %s, port %d and user %s from file\n", | ||
181 | temphost->hostname, temphost->port, temphost->username); | ||
182 | } | ||
183 | else | ||
164 | { | 184 | { |
165 | count++; | 185 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
166 | if (count >= frstat.st_size) | 186 | "Error reading line `%s' in hostfile\n", buf); |
167 | break; | 187 | GNUNET_free (temphost); |
168 | 188 | buf = &data[count + 1]; | |
169 | /* if (((data[count] == '\n') || (data[count] == '\0')) && (buf != &data[count])) */ | 189 | continue; |
170 | if (((data[count] == '\n')) && (buf != &data[count])) | ||
171 | { | ||
172 | data[count] = '\0'; | ||
173 | temphost = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Host)); | ||
174 | ret = | ||
175 | sscanf (buf, "%a[a-zA-Z0-9]@%a[a-zA-Z0-9.]:%hd", | ||
176 | &temphost->username, &temphost->hostname, | ||
177 | &temphost->port); | ||
178 | if (3 == ret) | ||
179 | { | ||
180 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
181 | "Successfully read host %s, port %d and user %s from file\n", | ||
182 | temphost->hostname, temphost->port, | ||
183 | temphost->username); | ||
184 | } | ||
185 | else | ||
186 | { | ||
187 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
188 | "Error reading line `%s' in hostfile\n", buf); | ||
189 | GNUNET_free (temphost); | ||
190 | buf = &data[count + 1]; | ||
191 | continue; | ||
192 | } | ||
193 | /* temphost->hostname = buf; */ | ||
194 | temphost->next = hosts; | ||
195 | hosts = temphost; | ||
196 | buf = &data[count + 1]; | ||
197 | } | ||
198 | else if ((data[count] == '\n') || (data[count] == '\0')) | ||
199 | buf = &data[count + 1]; | ||
200 | } | 190 | } |
191 | /* temphost->hostname = buf; */ | ||
192 | temphost->next = hosts; | ||
193 | hosts = temphost; | ||
194 | buf = &data[count + 1]; | ||
195 | } | ||
196 | else if ((data[count] == '\n') || (data[count] == '\0')) | ||
197 | buf = &data[count + 1]; | ||
201 | } | 198 | } |
199 | } | ||
202 | 200 | ||
203 | peers_left = num_peers; | 201 | peers_left = num_peers; |
204 | pg = GNUNET_TESTING_daemons_start (cfg, | 202 | pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of peers */ |
205 | peers_left, /* Total number of peers */ | 203 | peers_left, /* Number of outstanding connections */ |
206 | peers_left, /* Number of outstanding connections */ | 204 | peers_left, /* Number of parallel ssh connections, or peers being started at once */ |
207 | peers_left, /* Number of parallel ssh connections, or peers being started at once */ | ||
208 | TIMEOUT, | 205 | TIMEOUT, |
209 | NULL, | 206 | NULL, |
210 | NULL, &my_cb, NULL, NULL, NULL, hosts); | 207 | NULL, &my_cb, NULL, NULL, NULL, hosts); |
211 | hostpos = hosts; | 208 | hostpos = hosts; |
212 | while (hostpos != NULL) | 209 | while (hostpos != NULL) |
213 | { | 210 | { |
214 | temphost = hostpos->next; | 211 | temphost = hostpos->next; |
215 | GNUNET_free (hostpos->hostname); | 212 | GNUNET_free (hostpos->hostname); |
216 | GNUNET_free (hostpos->username); | 213 | GNUNET_free (hostpos->username); |
217 | GNUNET_free (hostpos); | 214 | GNUNET_free (hostpos); |
218 | hostpos = temphost; | 215 | hostpos = temphost; |
219 | } | 216 | } |
220 | GNUNET_free_non_null (data); | 217 | GNUNET_free_non_null (data); |
221 | GNUNET_assert (pg != NULL); | 218 | GNUNET_assert (pg != NULL); |
222 | 219 | ||
@@ -237,8 +234,7 @@ check () | |||
237 | GNUNET_GETOPT_OPTION_END | 234 | GNUNET_GETOPT_OPTION_END |
238 | }; | 235 | }; |
239 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 236 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
240 | argv, "test-testing-group", "nohelp", | 237 | argv, "test-testing-group", "nohelp", options, &run, &ok); |
241 | options, &run, &ok); | ||
242 | return ok; | 238 | return ok; |
243 | } | 239 | } |
244 | 240 | ||
diff --git a/src/testing/test_testing_large_topology.c b/src/testing/test_testing_large_topology.c index f9f4ff6fd..62922e9e8 100644 --- a/src/testing/test_testing_large_topology.c +++ b/src/testing/test_testing_large_topology.c | |||
@@ -99,7 +99,7 @@ static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY | |||
99 | static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */ | 99 | static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */ |
100 | 100 | ||
101 | static enum GNUNET_TESTING_TopologyOption connect_topology_option = | 101 | static enum GNUNET_TESTING_TopologyOption connect_topology_option = |
102 | GNUNET_TESTING_TOPOLOGY_OPTION_ALL; | 102 | GNUNET_TESTING_TOPOLOGY_OPTION_ALL; |
103 | 103 | ||
104 | static double connect_topology_option_modifier = 0.0; | 104 | static double connect_topology_option_modifier = 0.0; |
105 | 105 | ||
@@ -160,20 +160,19 @@ void | |||
160 | shutdown_callback (void *cls, const char *emsg) | 160 | shutdown_callback (void *cls, const char *emsg) |
161 | { | 161 | { |
162 | if (emsg != NULL) | 162 | if (emsg != NULL) |
163 | { | 163 | { |
164 | #if VERBOSE | 164 | #if VERBOSE |
165 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n"); | 165 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n"); |
166 | #endif | 166 | #endif |
167 | if (ok == 0) | 167 | if (ok == 0) |
168 | ok = 666; | 168 | ok = 666; |
169 | } | 169 | } |
170 | else | 170 | else |
171 | { | 171 | { |
172 | #if VERBOSE | 172 | #if VERBOSE |
173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n"); |
174 | "All peers successfully shut down!\n"); | ||
175 | #endif | 174 | #endif |
176 | } | 175 | } |
177 | } | 176 | } |
178 | 177 | ||
179 | #if DELAY_FOR_LOGGING | 178 | #if DELAY_FOR_LOGGING |
@@ -183,6 +182,7 @@ gather_log_data () | |||
183 | char *peer_number; | 182 | char *peer_number; |
184 | char *connect_number; | 183 | char *connect_number; |
185 | struct GNUNET_OS_Process *mem_process; | 184 | struct GNUNET_OS_Process *mem_process; |
185 | |||
186 | GNUNET_asprintf (&peer_number, "%llu", num_peers); | 186 | GNUNET_asprintf (&peer_number, "%llu", num_peers); |
187 | GNUNET_asprintf (&connect_number, "%llu", expected_connections); | 187 | GNUNET_asprintf (&connect_number, "%llu", expected_connections); |
188 | mem_process = GNUNET_OS_start_process (NULL, NULL, "./memsize.pl", | 188 | mem_process = GNUNET_OS_start_process (NULL, NULL, "./memsize.pl", |
@@ -201,6 +201,7 @@ finish_testing () | |||
201 | GNUNET_assert (pg != NULL); | 201 | GNUNET_assert (pg != NULL); |
202 | struct TestMessageContext *pos; | 202 | struct TestMessageContext *pos; |
203 | struct TestMessageContext *free_pos; | 203 | struct TestMessageContext *free_pos; |
204 | |||
204 | #if VERBOSE | 205 | #if VERBOSE |
205 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
206 | "Called finish testing, stopping daemons.\n"); | 207 | "Called finish testing, stopping daemons.\n"); |
@@ -208,25 +209,25 @@ finish_testing () | |||
208 | 209 | ||
209 | pos = test_messages; | 210 | pos = test_messages; |
210 | while (pos != NULL) | 211 | while (pos != NULL) |
212 | { | ||
213 | if (pos->peer1handle != NULL) | ||
214 | { | ||
215 | GNUNET_CORE_disconnect (pos->peer1handle); | ||
216 | pos->peer1handle = NULL; | ||
217 | } | ||
218 | if (pos->peer2handle != NULL) | ||
211 | { | 219 | { |
212 | if (pos->peer1handle != NULL) | 220 | GNUNET_CORE_disconnect (pos->peer2handle); |
213 | { | 221 | pos->peer2handle = NULL; |
214 | GNUNET_CORE_disconnect (pos->peer1handle); | ||
215 | pos->peer1handle = NULL; | ||
216 | } | ||
217 | if (pos->peer2handle != NULL) | ||
218 | { | ||
219 | GNUNET_CORE_disconnect (pos->peer2handle); | ||
220 | pos->peer2handle = NULL; | ||
221 | } | ||
222 | free_pos = pos; | ||
223 | pos = pos->next; | ||
224 | if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK) | ||
225 | { | ||
226 | GNUNET_SCHEDULER_cancel (free_pos->disconnect_task); | ||
227 | } | ||
228 | GNUNET_free (free_pos); | ||
229 | } | 222 | } |
223 | free_pos = pos; | ||
224 | pos = pos->next; | ||
225 | if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK) | ||
226 | { | ||
227 | GNUNET_SCHEDULER_cancel (free_pos->disconnect_task); | ||
228 | } | ||
229 | GNUNET_free (free_pos); | ||
230 | } | ||
230 | #if VERBOSE | 231 | #if VERBOSE |
231 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
232 | "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", | 233 | "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", |
@@ -240,10 +241,10 @@ finish_testing () | |||
240 | GNUNET_TESTING_daemons_stop (pg, timeout, &shutdown_callback, NULL); | 241 | GNUNET_TESTING_daemons_stop (pg, timeout, &shutdown_callback, NULL); |
241 | 242 | ||
242 | if (dotOutFile != NULL) | 243 | if (dotOutFile != NULL) |
243 | { | 244 | { |
244 | fprintf (dotOutFile, "}"); | 245 | fprintf (dotOutFile, "}"); |
245 | fclose (dotOutFile); | 246 | fclose (dotOutFile); |
246 | } | 247 | } |
247 | 248 | ||
248 | ok = 0; | 249 | ok = 0; |
249 | } | 250 | } |
@@ -284,27 +285,28 @@ topology_cb (void *cls, | |||
284 | const struct GNUNET_PeerIdentity *second, const char *emsg) | 285 | const struct GNUNET_PeerIdentity *second, const char *emsg) |
285 | { | 286 | { |
286 | FILE *outfile = cls; | 287 | FILE *outfile = cls; |
288 | |||
287 | if (first != NULL) | 289 | if (first != NULL) |
290 | { | ||
291 | if (outfile != NULL) | ||
288 | { | 292 | { |
289 | if (outfile != NULL) | 293 | fprintf (outfile, "\t\"%s\" -- ", GNUNET_i2s (first)); |
290 | { | 294 | fprintf (outfile, "\"%s\";\n", GNUNET_i2s (second)); |
291 | fprintf (outfile, "\t\"%s\" -- ", GNUNET_i2s (first)); | ||
292 | fprintf (outfile, "\"%s\";\n", GNUNET_i2s (second)); | ||
293 | } | ||
294 | topology_connections++; | ||
295 | } | 295 | } |
296 | topology_connections++; | ||
297 | } | ||
296 | else | 298 | else |
299 | { | ||
300 | fprintf (stderr, | ||
301 | "Finished iterating over topology, %d total connections!\n", | ||
302 | topology_connections); | ||
303 | if (outfile != NULL) | ||
297 | { | 304 | { |
298 | fprintf (stderr, | 305 | fprintf (outfile, "}\n"); |
299 | "Finished iterating over topology, %d total connections!\n", | 306 | fclose (outfile); |
300 | topology_connections); | 307 | GNUNET_SCHEDULER_add_now (&finish_testing, NULL); |
301 | if (outfile != NULL) | ||
302 | { | ||
303 | fprintf (outfile, "}\n"); | ||
304 | fclose (outfile); | ||
305 | GNUNET_SCHEDULER_add_now (&finish_testing, NULL); | ||
306 | } | ||
307 | } | 308 | } |
309 | } | ||
308 | } | 310 | } |
309 | 311 | ||
310 | static int | 312 | static int |
@@ -317,24 +319,25 @@ process_mtype (void *cls, | |||
317 | FILE *dotOutFileFinished; | 319 | FILE *dotOutFileFinished; |
318 | struct TestMessageContext *pos = cls; | 320 | struct TestMessageContext *pos = cls; |
319 | struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message; | 321 | struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message; |
322 | |||
320 | if (pos->uid != ntohl (msg->uid)) | 323 | if (pos->uid != ntohl (msg->uid)) |
321 | return GNUNET_OK; | 324 | return GNUNET_OK; |
322 | 325 | ||
323 | #if VERBOSE | 326 | #if VERBOSE |
324 | if ((total_messages_received) % modnum == 0) | 327 | if ((total_messages_received) % modnum == 0) |
325 | { | 328 | { |
326 | if (total_messages_received == 0) | 329 | if (total_messages_received == 0) |
327 | fprintf (stdout, "0%%"); | 330 | fprintf (stdout, "0%%"); |
328 | else | 331 | else |
329 | fprintf (stdout, "%d%%", | 332 | fprintf (stdout, "%d%%", |
330 | (int) (((float) total_messages_received / | 333 | (int) (((float) total_messages_received / |
331 | expected_messages) * 100)); | 334 | expected_messages) * 100)); |
332 | 335 | ||
333 | } | 336 | } |
334 | else if (total_messages_received % dotnum == 0) | 337 | else if (total_messages_received % dotnum == 0) |
335 | { | 338 | { |
336 | fprintf (stdout, "."); | 339 | fprintf (stdout, "."); |
337 | } | 340 | } |
338 | fflush (stdout); | 341 | fflush (stdout); |
339 | #endif | 342 | #endif |
340 | 343 | ||
@@ -350,27 +353,26 @@ process_mtype (void *cls, | |||
350 | #endif | 353 | #endif |
351 | 354 | ||
352 | if (total_messages_received == expected_messages) | 355 | if (total_messages_received == expected_messages) |
353 | { | 356 | { |
354 | #if VERBOSE | 357 | #if VERBOSE |
355 | fprintf (stdout, "100%%]\n"); | 358 | fprintf (stdout, "100%%]\n"); |
356 | #endif | 359 | #endif |
357 | GNUNET_SCHEDULER_cancel (die_task); | 360 | GNUNET_SCHEDULER_cancel (die_task); |
358 | GNUNET_asprintf (&dotOutFileNameFinished, "%s.dot", "final_topology"); | 361 | GNUNET_asprintf (&dotOutFileNameFinished, "%s.dot", "final_topology"); |
359 | dotOutFileFinished = fopen (dotOutFileNameFinished, "w"); | 362 | dotOutFileFinished = fopen (dotOutFileNameFinished, "w"); |
360 | GNUNET_free (dotOutFileNameFinished); | 363 | GNUNET_free (dotOutFileNameFinished); |
361 | if (dotOutFileFinished != NULL) | 364 | if (dotOutFileFinished != NULL) |
362 | { | ||
363 | fprintf (dotOutFileFinished, "strict graph G {\n"); | ||
364 | } | ||
365 | topology_connections = 0; | ||
366 | GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished); | ||
367 | //GNUNET_SCHEDULER_add_now (&finish_testing, NULL); | ||
368 | } | ||
369 | else | ||
370 | { | 365 | { |
371 | pos->disconnect_task = | 366 | fprintf (dotOutFileFinished, "strict graph G {\n"); |
372 | GNUNET_SCHEDULER_add_now (&disconnect_cores, pos); | ||
373 | } | 367 | } |
368 | topology_connections = 0; | ||
369 | GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished); | ||
370 | //GNUNET_SCHEDULER_add_now (&finish_testing, NULL); | ||
371 | } | ||
372 | else | ||
373 | { | ||
374 | pos->disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cores, pos); | ||
375 | } | ||
374 | 376 | ||
375 | return GNUNET_OK; | 377 | return GNUNET_OK; |
376 | } | 378 | } |
@@ -379,6 +381,7 @@ static void | |||
379 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 381 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
380 | { | 382 | { |
381 | char *msg = cls; | 383 | char *msg = cls; |
384 | |||
382 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 385 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
383 | "End badly was called (%s)... stopping daemons.\n", msg); | 386 | "End badly was called (%s)... stopping daemons.\n", msg); |
384 | struct TestMessageContext *pos; | 387 | struct TestMessageContext *pos; |
@@ -386,21 +389,21 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
386 | 389 | ||
387 | pos = test_messages; | 390 | pos = test_messages; |
388 | while (pos != NULL) | 391 | while (pos != NULL) |
392 | { | ||
393 | if (pos->peer1handle != NULL) | ||
389 | { | 394 | { |
390 | if (pos->peer1handle != NULL) | 395 | GNUNET_CORE_disconnect (pos->peer1handle); |
391 | { | 396 | pos->peer1handle = NULL; |
392 | GNUNET_CORE_disconnect (pos->peer1handle); | ||
393 | pos->peer1handle = NULL; | ||
394 | } | ||
395 | if (pos->peer2handle != NULL) | ||
396 | { | ||
397 | GNUNET_CORE_disconnect (pos->peer2handle); | ||
398 | pos->peer2handle = NULL; | ||
399 | } | ||
400 | free_pos = pos; | ||
401 | pos = pos->next; | ||
402 | GNUNET_free (free_pos); | ||
403 | } | 397 | } |
398 | if (pos->peer2handle != NULL) | ||
399 | { | ||
400 | GNUNET_CORE_disconnect (pos->peer2handle); | ||
401 | pos->peer2handle = NULL; | ||
402 | } | ||
403 | free_pos = pos; | ||
404 | pos = pos->next; | ||
405 | GNUNET_free (free_pos); | ||
406 | } | ||
404 | 407 | ||
405 | #if VERBOSE | 408 | #if VERBOSE |
406 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 409 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -413,18 +416,18 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
413 | #endif | 416 | #endif |
414 | 417 | ||
415 | if (pg != NULL) | 418 | if (pg != NULL) |
416 | { | 419 | { |
417 | GNUNET_TESTING_daemons_stop (pg, timeout, &shutdown_callback, NULL); | 420 | GNUNET_TESTING_daemons_stop (pg, timeout, &shutdown_callback, NULL); |
418 | ok = 7331; /* Opposite of leet */ | 421 | ok = 7331; /* Opposite of leet */ |
419 | } | 422 | } |
420 | else | 423 | else |
421 | ok = 401; /* Never got peers started */ | 424 | ok = 401; /* Never got peers started */ |
422 | 425 | ||
423 | if (dotOutFile != NULL) | 426 | if (dotOutFile != NULL) |
424 | { | 427 | { |
425 | fprintf (dotOutFile, "}"); | 428 | fprintf (dotOutFile, "}"); |
426 | fclose (dotOutFile); | 429 | fclose (dotOutFile); |
427 | } | 430 | } |
428 | } | 431 | } |
429 | 432 | ||
430 | static size_t | 433 | static size_t |
@@ -471,30 +474,31 @@ init_notify_peer2 (void *cls, | |||
471 | 474 | ||
472 | pos->peer2connected = GNUNET_YES; | 475 | pos->peer2connected = GNUNET_YES; |
473 | if (pos->peer1notified == GNUNET_YES) /* Peer 1 has been notified of connection to peer 2 */ | 476 | if (pos->peer1notified == GNUNET_YES) /* Peer 1 has been notified of connection to peer 2 */ |
474 | { | 477 | { |
475 | #if VERBOSE > 1 | 478 | #if VERBOSE > 1 |
476 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 479 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
477 | "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n", | 480 | "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n", |
478 | GNUNET_i2s (my_identity), GNUNET_h2s(&pos->peer1->id.hashPubKey)); | 481 | GNUNET_i2s (my_identity), |
482 | GNUNET_h2s (&pos->peer1->id.hashPubKey)); | ||
479 | #endif | 483 | #endif |
480 | if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle, | 484 | if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle, |
481 | 0, | 485 | 0, |
482 | timeout, | 486 | timeout, |
483 | &pos->peer2->id, | 487 | &pos->peer2->id, |
484 | sizeof (struct | 488 | sizeof (struct |
485 | GNUNET_TestMessage), | 489 | GNUNET_TestMessage), |
486 | &transmit_ready, pos)) | 490 | &transmit_ready, pos)) |
487 | { | 491 | { |
488 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 492 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
489 | "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", | 493 | "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", |
490 | GNUNET_i2s (&pos->peer2->id)); | 494 | GNUNET_i2s (&pos->peer2->id)); |
491 | transmit_ready_failed++; | 495 | transmit_ready_failed++; |
492 | } | 496 | } |
493 | else | 497 | else |
494 | { | 498 | { |
495 | transmit_ready_scheduled++; | 499 | transmit_ready_scheduled++; |
496 | } | ||
497 | } | 500 | } |
501 | } | ||
498 | } | 502 | } |
499 | 503 | ||
500 | /** | 504 | /** |
@@ -504,50 +508,52 @@ init_notify_peer2 (void *cls, | |||
504 | * @param peer peer identity this notification is about | 508 | * @param peer peer identity this notification is about |
505 | * @param atsi performance data for the connection | 509 | * @param atsi performance data for the connection |
506 | */ | 510 | */ |
507 | static void connect_notify_peers (void *cls, | 511 | static void |
508 | const struct | 512 | connect_notify_peers (void *cls, |
509 | GNUNET_PeerIdentity *peer, | 513 | const struct |
510 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 514 | GNUNET_PeerIdentity *peer, |
515 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | ||
511 | { | 516 | { |
512 | struct TestMessageContext *pos = cls; | 517 | struct TestMessageContext *pos = cls; |
513 | 518 | ||
514 | if (0 == memcmp(peer, &pos->peer2->id, sizeof(struct GNUNET_PeerIdentity))) | 519 | if (0 == memcmp (peer, &pos->peer2->id, sizeof (struct GNUNET_PeerIdentity))) |
515 | { | 520 | { |
516 | pos->peer1notified = GNUNET_YES; | 521 | pos->peer1notified = GNUNET_YES; |
517 | #if VERBOSE > 1 | 522 | #if VERBOSE > 1 |
518 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 523 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
519 | "Peer `%s' notified of connection to peer `%s'\n", | 524 | "Peer `%s' notified of connection to peer `%s'\n", |
520 | GNUNET_i2s (&pos->peer1->id), GNUNET_h2s(&peer->hashPubKey)); | 525 | GNUNET_i2s (&pos->peer1->id), GNUNET_h2s (&peer->hashPubKey)); |
521 | #endif | 526 | #endif |
522 | } | 527 | } |
523 | else | 528 | else |
524 | return; | 529 | return; |
525 | 530 | ||
526 | if (pos->peer2connected == GNUNET_YES) /* Already connected and notified of connection, send message! */ | 531 | if (pos->peer2connected == GNUNET_YES) /* Already connected and notified of connection, send message! */ |
527 | { | 532 | { |
528 | #if VERBOSE > 1 | 533 | #if VERBOSE > 1 |
529 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 534 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
530 | "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n", | 535 | "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n", |
531 | GNUNET_i2s (&pos->peer2->id), GNUNET_h2s(&pos->peer1->id.hashPubKey)); | 536 | GNUNET_i2s (&pos->peer2->id), |
537 | GNUNET_h2s (&pos->peer1->id.hashPubKey)); | ||
532 | #endif | 538 | #endif |
533 | if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle, | 539 | if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle, |
534 | 0, | 540 | 0, |
535 | timeout, | 541 | timeout, |
536 | &pos->peer2->id, | 542 | &pos->peer2->id, |
537 | sizeof (struct | 543 | sizeof (struct |
538 | GNUNET_TestMessage), | 544 | GNUNET_TestMessage), |
539 | &transmit_ready, pos)) | 545 | &transmit_ready, pos)) |
540 | { | 546 | { |
541 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 547 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
542 | "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", | 548 | "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", |
543 | GNUNET_i2s (&pos->peer2->id)); | 549 | GNUNET_i2s (&pos->peer2->id)); |
544 | transmit_ready_failed++; | 550 | transmit_ready_failed++; |
545 | } | 551 | } |
546 | else | 552 | else |
547 | { | 553 | { |
548 | transmit_ready_scheduled++; | 554 | transmit_ready_scheduled++; |
549 | } | ||
550 | } | 555 | } |
556 | } | ||
551 | } | 557 | } |
552 | 558 | ||
553 | static void | 559 | static void |
@@ -558,6 +564,7 @@ init_notify_peer1 (void *cls, | |||
558 | *publicKey) | 564 | *publicKey) |
559 | { | 565 | { |
560 | struct TestMessageContext *pos = cls; | 566 | struct TestMessageContext *pos = cls; |
567 | |||
561 | total_server_connections++; | 568 | total_server_connections++; |
562 | 569 | ||
563 | #if VERBOSE > 1 | 570 | #if VERBOSE > 1 |
@@ -588,27 +595,27 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
588 | struct TestMessageContext *pos = cls; | 595 | struct TestMessageContext *pos = cls; |
589 | 596 | ||
590 | if ((pos == test_messages) && (settle_time.rel_value > 0)) | 597 | if ((pos == test_messages) && (settle_time.rel_value > 0)) |
591 | { | 598 | { |
592 | topology_connections = 0; | 599 | topology_connections = 0; |
593 | GNUNET_TESTING_get_topology (pg, &topology_cb, NULL); | 600 | GNUNET_TESTING_get_topology (pg, &topology_cb, NULL); |
594 | } | 601 | } |
595 | if (( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)|| (cls == NULL)) | 602 | if (((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) || (cls == NULL)) |
596 | return; | 603 | return; |
597 | 604 | ||
598 | if (die_task == GNUNET_SCHEDULER_NO_TASK) | 605 | if (die_task == GNUNET_SCHEDULER_NO_TASK) |
599 | { | 606 | { |
600 | die_task = GNUNET_SCHEDULER_add_delayed (test_timeout, | 607 | die_task = GNUNET_SCHEDULER_add_delayed (test_timeout, |
601 | &end_badly, | 608 | &end_badly, |
602 | "from send test messages (timeout)"); | 609 | "from send test messages (timeout)"); |
603 | } | 610 | } |
604 | 611 | ||
605 | if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS) | 612 | if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS) |
606 | { | 613 | { |
607 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 614 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
608 | (GNUNET_TIME_UNIT_SECONDS, 1), | 615 | (GNUNET_TIME_UNIT_SECONDS, 1), |
609 | &send_test_messages, pos); | 616 | &send_test_messages, pos); |
610 | return; /* Otherwise we'll double schedule messages here! */ | 617 | return; /* Otherwise we'll double schedule messages here! */ |
611 | } | 618 | } |
612 | 619 | ||
613 | /* | 620 | /* |
614 | * Connect to the sending peer | 621 | * Connect to the sending peer |
@@ -626,15 +633,15 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
626 | GNUNET_assert (pos->peer1handle != NULL); | 633 | GNUNET_assert (pos->peer1handle != NULL); |
627 | 634 | ||
628 | if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS) | 635 | if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS) |
629 | { | 636 | { |
630 | GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next); | 637 | GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next); |
631 | } | 638 | } |
632 | else | 639 | else |
633 | { | 640 | { |
634 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 641 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
635 | (GNUNET_TIME_UNIT_SECONDS, 1), | 642 | (GNUNET_TIME_UNIT_SECONDS, 1), |
636 | &send_test_messages, pos->next); | 643 | &send_test_messages, pos->next); |
637 | } | 644 | } |
638 | } | 645 | } |
639 | 646 | ||
640 | 647 | ||
@@ -650,113 +657,114 @@ topology_callback (void *cls, | |||
650 | const char *emsg) | 657 | const char *emsg) |
651 | { | 658 | { |
652 | struct TestMessageContext *temp_context; | 659 | struct TestMessageContext *temp_context; |
660 | |||
653 | if (emsg == NULL) | 661 | if (emsg == NULL) |
654 | { | 662 | { |
655 | #if VERBOSE | 663 | #if VERBOSE |
656 | if ((total_connections) % modnum == 0) | 664 | if ((total_connections) % modnum == 0) |
657 | { | 665 | { |
658 | if (total_connections == 0) | 666 | if (total_connections == 0) |
659 | fprintf (stdout, "0%%"); | 667 | fprintf (stdout, "0%%"); |
660 | else | 668 | else |
661 | fprintf (stdout, "%d%%", | 669 | fprintf (stdout, "%d%%", |
662 | (int) (((float) total_connections / | 670 | (int) (((float) total_connections / |
663 | expected_connections) * 100)); | 671 | expected_connections) * 100)); |
664 | 672 | ||
665 | } | 673 | } |
666 | else if (total_connections % dotnum == 0) | 674 | else if (total_connections % dotnum == 0) |
667 | { | 675 | { |
668 | fprintf (stdout, "."); | 676 | fprintf (stdout, "."); |
669 | } | 677 | } |
670 | fflush (stdout); | 678 | fflush (stdout); |
671 | #endif | 679 | #endif |
672 | total_connections++; | 680 | total_connections++; |
673 | #if VERBOSE > 1 | 681 | #if VERBOSE > 1 |
674 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "connected peer %s to peer %s\n", | 682 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "connected peer %s to peer %s\n", |
675 | first_daemon->shortname, second_daemon->shortname); | 683 | first_daemon->shortname, second_daemon->shortname); |
676 | #endif | 684 | #endif |
677 | temp_context = GNUNET_malloc (sizeof (struct TestMessageContext)); | 685 | temp_context = GNUNET_malloc (sizeof (struct TestMessageContext)); |
678 | temp_context->peer1 = first_daemon; | 686 | temp_context->peer1 = first_daemon; |
679 | temp_context->peer2 = second_daemon; | 687 | temp_context->peer2 = second_daemon; |
680 | temp_context->next = test_messages; | 688 | temp_context->next = test_messages; |
681 | temp_context->uid = total_connections; | 689 | temp_context->uid = total_connections; |
682 | temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK; | 690 | temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK; |
683 | test_messages = temp_context; | 691 | test_messages = temp_context; |
684 | 692 | ||
685 | expected_messages++; | 693 | expected_messages++; |
686 | if (dotOutFile != NULL) | 694 | if (dotOutFile != NULL) |
687 | fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname, | 695 | fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname, |
688 | second_daemon->shortname); | 696 | second_daemon->shortname); |
689 | } | 697 | } |
690 | #if VERBOSE | 698 | #if VERBOSE |
691 | else | 699 | else |
692 | { | 700 | { |
693 | failed_connections++; | 701 | failed_connections++; |
694 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 702 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
695 | "Failed to connect peer %s to peer %s with error :\n%s\n", | 703 | "Failed to connect peer %s to peer %s with error :\n%s\n", |
696 | first_daemon->shortname, second_daemon->shortname, emsg); | 704 | first_daemon->shortname, second_daemon->shortname, emsg); |
697 | } | 705 | } |
698 | #endif | 706 | #endif |
699 | 707 | ||
700 | if (total_connections == expected_connections) | 708 | if (total_connections == expected_connections) |
701 | { | 709 | { |
702 | #if VERBOSE | 710 | #if VERBOSE |
703 | fprintf (stdout, "100%%]\n"); | 711 | fprintf (stdout, "100%%]\n"); |
704 | #endif | 712 | #endif |
705 | #if VERBOSE | 713 | #if VERBOSE |
706 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 714 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
707 | "Created %d total connections, which is our target number! Calling send messages.\n", | 715 | "Created %d total connections, which is our target number! Calling send messages.\n", |
708 | total_connections); | 716 | total_connections); |
709 | #endif | 717 | #endif |
710 | modnum = expected_messages / 4; | 718 | modnum = expected_messages / 4; |
711 | dotnum = (expected_messages / 50) + 1; | 719 | dotnum = (expected_messages / 50) + 1; |
712 | GNUNET_SCHEDULER_cancel (die_task); | 720 | GNUNET_SCHEDULER_cancel (die_task); |
713 | die_task = GNUNET_SCHEDULER_NO_TASK; | 721 | die_task = GNUNET_SCHEDULER_NO_TASK; |
714 | #if DELAY_FOR_LOGGING | 722 | #if DELAY_FOR_LOGGING |
715 | fprintf (stdout, "Sending test messages in 10 seconds.\n"); | 723 | fprintf (stdout, "Sending test messages in 10 seconds.\n"); |
716 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 724 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
717 | (GNUNET_TIME_UNIT_SECONDS, 10), | 725 | (GNUNET_TIME_UNIT_SECONDS, 10), |
718 | &send_test_messages, test_messages); | 726 | &send_test_messages, test_messages); |
719 | gather_log_data (); | 727 | gather_log_data (); |
720 | #else | 728 | #else |
721 | if (settle_time.rel_value > 0) | 729 | if (settle_time.rel_value > 0) |
722 | { | 730 | { |
723 | GNUNET_TESTING_get_topology (pg, &topology_cb, NULL); | 731 | GNUNET_TESTING_get_topology (pg, &topology_cb, NULL); |
724 | } | 732 | } |
725 | GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages, | 733 | GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages, |
726 | test_messages); | 734 | test_messages); |
727 | #endif | 735 | #endif |
728 | #if VERBOSE | 736 | #if VERBOSE |
729 | fprintf (stdout, "Test message progress: ["); | 737 | fprintf (stdout, "Test message progress: ["); |
730 | #endif | 738 | #endif |
731 | 739 | ||
732 | } | 740 | } |
733 | else if (total_connections + failed_connections == expected_connections) | 741 | else if (total_connections + failed_connections == expected_connections) |
742 | { | ||
743 | if (failed_connections < | ||
744 | (unsigned int) (fail_percentage * total_connections)) | ||
734 | { | 745 | { |
735 | if (failed_connections < | 746 | GNUNET_SCHEDULER_cancel (die_task); |
736 | (unsigned int) (fail_percentage * total_connections)) | 747 | die_task = GNUNET_SCHEDULER_NO_TASK; |
737 | { | 748 | GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages); |
738 | GNUNET_SCHEDULER_cancel (die_task); | ||
739 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
740 | GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages); | ||
741 | } | ||
742 | else | ||
743 | { | ||
744 | GNUNET_SCHEDULER_cancel (die_task); | ||
745 | die_task = | ||
746 | GNUNET_SCHEDULER_add_now (&end_badly, | ||
747 | "from topology_callback (too many failed connections)"); | ||
748 | } | ||
749 | } | 749 | } |
750 | else | 750 | else |
751 | { | 751 | { |
752 | GNUNET_SCHEDULER_cancel (die_task); | ||
753 | die_task = | ||
754 | GNUNET_SCHEDULER_add_now (&end_badly, | ||
755 | "from topology_callback (too many failed connections)"); | ||
756 | } | ||
757 | } | ||
758 | else | ||
759 | { | ||
752 | #if VERBOSE > 1 | 760 | #if VERBOSE > 1 |
753 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 761 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
754 | "Have %d total connections, %d failed connections, Want %d (at least %d)\n", | 762 | "Have %d total connections, %d failed connections, Want %d (at least %d)\n", |
755 | total_connections, failed_connections, expected_connections, | 763 | total_connections, failed_connections, expected_connections, |
756 | expected_connections - | 764 | expected_connections - |
757 | (unsigned int) (fail_percentage * expected_connections)); | 765 | (unsigned int) (fail_percentage * expected_connections)); |
758 | #endif | 766 | #endif |
759 | } | 767 | } |
760 | } | 768 | } |
761 | 769 | ||
762 | static void | 770 | static void |
@@ -774,8 +782,8 @@ connect_topology () | |||
774 | { | 782 | { |
775 | expected_connections = -1; | 783 | expected_connections = -1; |
776 | if ((pg != NULL) && (peers_left == 0)) | 784 | if ((pg != NULL) && (peers_left == 0)) |
777 | { | 785 | { |
778 | expected_connections = | 786 | expected_connections = |
779 | GNUNET_TESTING_connect_topology (pg, connection_topology, | 787 | GNUNET_TESTING_connect_topology (pg, connection_topology, |
780 | connect_topology_option, | 788 | connect_topology_option, |
781 | connect_topology_option_modifier, | 789 | connect_topology_option_modifier, |
@@ -783,18 +791,18 @@ connect_topology () | |||
783 | connect_attempts, | 791 | connect_attempts, |
784 | &topology_creation_finished, NULL); | 792 | &topology_creation_finished, NULL); |
785 | #if VERBOSE > 1 | 793 | #if VERBOSE > 1 |
786 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 794 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
787 | "Have %d expected connections\n", expected_connections); | 795 | "Have %d expected connections\n", expected_connections); |
788 | #endif | 796 | #endif |
789 | } | 797 | } |
790 | 798 | ||
791 | GNUNET_SCHEDULER_cancel (die_task); | 799 | GNUNET_SCHEDULER_cancel (die_task); |
792 | if (expected_connections == GNUNET_SYSERR) | 800 | if (expected_connections == GNUNET_SYSERR) |
793 | { | 801 | { |
794 | die_task = | 802 | die_task = |
795 | GNUNET_SCHEDULER_add_now (&end_badly, | 803 | GNUNET_SCHEDULER_add_now (&end_badly, |
796 | "from connect topology (bad return)"); | 804 | "from connect topology (bad return)"); |
797 | } | 805 | } |
798 | 806 | ||
799 | die_task = GNUNET_SCHEDULER_add_delayed (test_timeout, | 807 | die_task = GNUNET_SCHEDULER_add_delayed (test_timeout, |
800 | &end_badly, | 808 | &end_badly, |
@@ -811,23 +819,22 @@ create_topology () | |||
811 | { | 819 | { |
812 | peers_left = num_peers; /* Reset counter */ | 820 | peers_left = num_peers; /* Reset counter */ |
813 | if (GNUNET_TESTING_create_topology | 821 | if (GNUNET_TESTING_create_topology |
814 | (pg, topology, blacklist_topology, | 822 | (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR) |
815 | blacklist_transports) != GNUNET_SYSERR) | 823 | { |
816 | { | ||
817 | #if VERBOSE | 824 | #if VERBOSE |
818 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 825 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
819 | "Topology set up, now starting peers!\n"); | 826 | "Topology set up, now starting peers!\n"); |
820 | fprintf (stdout, "Daemon start progress ["); | 827 | fprintf (stdout, "Daemon start progress ["); |
821 | #endif | 828 | #endif |
822 | GNUNET_TESTING_daemons_continue_startup (pg); | 829 | GNUNET_TESTING_daemons_continue_startup (pg); |
823 | } | 830 | } |
824 | else | 831 | else |
825 | { | 832 | { |
826 | GNUNET_SCHEDULER_cancel (die_task); | 833 | GNUNET_SCHEDULER_cancel (die_task); |
827 | die_task = | 834 | die_task = |
828 | GNUNET_SCHEDULER_add_now (&end_badly, | 835 | GNUNET_SCHEDULER_add_now (&end_badly, |
829 | "from create topology (bad return)"); | 836 | "from create topology (bad return)"); |
830 | } | 837 | } |
831 | GNUNET_SCHEDULER_cancel (die_task); | 838 | GNUNET_SCHEDULER_cancel (die_task); |
832 | die_task = GNUNET_SCHEDULER_add_delayed (test_timeout, | 839 | die_task = GNUNET_SCHEDULER_add_delayed (test_timeout, |
833 | &end_badly, | 840 | &end_badly, |
@@ -842,11 +849,11 @@ peers_started_callback (void *cls, | |||
842 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 849 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
843 | { | 850 | { |
844 | if (emsg != NULL) | 851 | if (emsg != NULL) |
845 | { | 852 | { |
846 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 853 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
847 | "Failed to start daemon with error: `%s'\n", emsg); | 854 | "Failed to start daemon with error: `%s'\n", emsg); |
848 | return; | 855 | return; |
849 | } | 856 | } |
850 | GNUNET_assert (id != NULL); | 857 | GNUNET_assert (id != NULL); |
851 | #if VERBOSE > 1 | 858 | #if VERBOSE > 1 |
852 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n", | 859 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n", |
@@ -854,49 +861,47 @@ peers_started_callback (void *cls, | |||
854 | #endif | 861 | #endif |
855 | #if VERBOSE | 862 | #if VERBOSE |
856 | if ((num_peers - peers_left) % modnum == 0) | 863 | if ((num_peers - peers_left) % modnum == 0) |
857 | { | 864 | { |
858 | if (num_peers - peers_left == 0) | 865 | if (num_peers - peers_left == 0) |
859 | fprintf (stdout, "0%%"); | 866 | fprintf (stdout, "0%%"); |
860 | else | 867 | else |
861 | fprintf (stdout, "%d%%", | 868 | fprintf (stdout, "%d%%", |
862 | (int) (((float) (num_peers - peers_left) / | 869 | (int) (((float) (num_peers - peers_left) / num_peers) * 100)); |
863 | num_peers) * 100)); | 870 | |
864 | 871 | } | |
865 | } | ||
866 | else if ((num_peers - peers_left) % dotnum == 0) | 872 | else if ((num_peers - peers_left) % dotnum == 0) |
867 | { | 873 | { |
868 | fprintf (stdout, "."); | 874 | fprintf (stdout, "."); |
869 | } | 875 | } |
870 | fflush (stdout); | 876 | fflush (stdout); |
871 | #endif | 877 | #endif |
872 | peers_left--; | 878 | peers_left--; |
873 | if (peers_left == 0) | 879 | if (peers_left == 0) |
874 | { | 880 | { |
875 | #if VERBOSE | 881 | #if VERBOSE |
876 | fprintf (stdout, "100%%]\n"); | 882 | fprintf (stdout, "100%%]\n"); |
877 | #endif | 883 | #endif |
878 | #if VERBOSE | 884 | #if VERBOSE |
879 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 885 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
880 | "All %d daemons started, now connecting peers!\n", | 886 | "All %d daemons started, now connecting peers!\n", num_peers); |
881 | num_peers); | ||
882 | #endif | 887 | #endif |
883 | GNUNET_SCHEDULER_cancel (die_task); | 888 | GNUNET_SCHEDULER_cancel (die_task); |
884 | /* Set up task in case topology creation doesn't finish | 889 | /* Set up task in case topology creation doesn't finish |
885 | * within a reasonable amount of time */ | 890 | * within a reasonable amount of time */ |
886 | die_task = GNUNET_SCHEDULER_add_delayed (timeout, | 891 | die_task = GNUNET_SCHEDULER_add_delayed (timeout, |
887 | &end_badly, | 892 | &end_badly, |
888 | "from peers_started_callback"); | 893 | "from peers_started_callback"); |
889 | #if DELAY_FOR_LOGGING | 894 | #if DELAY_FOR_LOGGING |
890 | fprintf (stdout, "Connecting topology in 10 seconds\n"); | 895 | fprintf (stdout, "Connecting topology in 10 seconds\n"); |
891 | gather_log_data (); | 896 | gather_log_data (); |
892 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 897 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
893 | (GNUNET_TIME_UNIT_SECONDS, 10), | 898 | (GNUNET_TIME_UNIT_SECONDS, 10), |
894 | &connect_topology, NULL); | 899 | &connect_topology, NULL); |
895 | #else | 900 | #else |
896 | connect_topology (); | 901 | connect_topology (); |
897 | #endif | 902 | #endif |
898 | ok = 0; | 903 | ok = 0; |
899 | } | 904 | } |
900 | } | 905 | } |
901 | 906 | ||
902 | /** | 907 | /** |
@@ -913,10 +918,10 @@ hostkey_callback (void *cls, | |||
913 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 918 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
914 | { | 919 | { |
915 | if (emsg != NULL) | 920 | if (emsg != NULL) |
916 | { | 921 | { |
917 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 922 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
918 | "Hostkey callback received error: %s\n", emsg); | 923 | "Hostkey callback received error: %s\n", emsg); |
919 | } | 924 | } |
920 | 925 | ||
921 | #if VERBOSE > 1 | 926 | #if VERBOSE > 1 |
922 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 927 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -926,39 +931,37 @@ hostkey_callback (void *cls, | |||
926 | 931 | ||
927 | #if VERBOSE | 932 | #if VERBOSE |
928 | if ((num_peers - peers_left) % modnum == 0) | 933 | if ((num_peers - peers_left) % modnum == 0) |
929 | { | 934 | { |
930 | if (num_peers - peers_left == 0) | 935 | if (num_peers - peers_left == 0) |
931 | fprintf (stdout, "0%%"); | 936 | fprintf (stdout, "0%%"); |
932 | else | 937 | else |
933 | fprintf (stdout, "%d%%", | 938 | fprintf (stdout, "%d%%", |
934 | (int) (((float) (num_peers - peers_left) / | 939 | (int) (((float) (num_peers - peers_left) / num_peers) * 100)); |
935 | num_peers) * 100)); | 940 | |
936 | 941 | } | |
937 | } | ||
938 | else if ((num_peers - peers_left) % dotnum == 0) | 942 | else if ((num_peers - peers_left) % dotnum == 0) |
939 | { | 943 | { |
940 | fprintf (stdout, "."); | 944 | fprintf (stdout, "."); |
941 | } | 945 | } |
942 | fflush (stdout); | 946 | fflush (stdout); |
943 | #endif | 947 | #endif |
944 | peers_left--; | 948 | peers_left--; |
945 | if (peers_left == 0) | 949 | if (peers_left == 0) |
946 | { | 950 | { |
947 | #if VERBOSE | 951 | #if VERBOSE |
948 | fprintf (stdout, "100%%]\n"); | 952 | fprintf (stdout, "100%%]\n"); |
949 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 953 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
950 | "All %d hostkeys created, now creating topology!\n", | 954 | "All %d hostkeys created, now creating topology!\n", num_peers); |
951 | num_peers); | ||
952 | #endif | 955 | #endif |
953 | GNUNET_SCHEDULER_cancel (die_task); | 956 | GNUNET_SCHEDULER_cancel (die_task); |
954 | /* Set up task in case topology creation doesn't finish | 957 | /* Set up task in case topology creation doesn't finish |
955 | * within a reasonable amount of time */ | 958 | * within a reasonable amount of time */ |
956 | die_task = GNUNET_SCHEDULER_add_delayed (test_timeout, | 959 | die_task = GNUNET_SCHEDULER_add_delayed (test_timeout, |
957 | &end_badly, | 960 | &end_badly, |
958 | "from create_topology"); | 961 | "from create_topology"); |
959 | GNUNET_SCHEDULER_add_now (&create_topology, NULL); | 962 | GNUNET_SCHEDULER_add_now (&create_topology, NULL); |
960 | ok = 0; | 963 | ok = 0; |
961 | } | 964 | } |
962 | } | 965 | } |
963 | 966 | ||
964 | static void | 967 | static void |
@@ -972,13 +975,14 @@ run (void *cls, | |||
972 | char *connect_topology_option_str; | 975 | char *connect_topology_option_str; |
973 | char *connect_topology_option_modifier_string; | 976 | char *connect_topology_option_modifier_string; |
974 | unsigned long long temp_settle; | 977 | unsigned long long temp_settle; |
978 | |||
975 | ok = 1; | 979 | ok = 1; |
976 | 980 | ||
977 | dotOutFile = fopen (dotOutFileName, "w"); | 981 | dotOutFile = fopen (dotOutFileName, "w"); |
978 | if (dotOutFile != NULL) | 982 | if (dotOutFile != NULL) |
979 | { | 983 | { |
980 | fprintf (dotOutFile, "strict graph G {\n"); | 984 | fprintf (dotOutFile, "strict graph G {\n"); |
981 | } | 985 | } |
982 | 986 | ||
983 | #if VERBOSE | 987 | #if VERBOSE |
984 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 988 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -988,21 +992,21 @@ run (void *cls, | |||
988 | if (GNUNET_YES != | 992 | if (GNUNET_YES != |
989 | GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome", | 993 | GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome", |
990 | &test_directory)) | 994 | &test_directory)) |
991 | { | 995 | { |
992 | ok = 404; | 996 | ok = 404; |
993 | return; | 997 | return; |
994 | } | 998 | } |
995 | 999 | ||
996 | if ((GNUNET_YES == | 1000 | if ((GNUNET_YES == |
997 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology", | 1001 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology", |
998 | &topology_str)) | 1002 | &topology_str)) |
999 | && (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str))) | 1003 | && (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str))) |
1000 | { | 1004 | { |
1001 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1005 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1002 | "Invalid topology `%s' given for section %s option %s\n", | 1006 | "Invalid topology `%s' given for section %s option %s\n", |
1003 | topology_str, "TESTING", "TOPOLOGY"); | 1007 | topology_str, "TESTING", "TOPOLOGY"); |
1004 | topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */ | 1008 | topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */ |
1005 | } | 1009 | } |
1006 | 1010 | ||
1007 | if ((GNUNET_YES == | 1011 | if ((GNUNET_YES == |
1008 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", | 1012 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
@@ -1011,11 +1015,11 @@ run (void *cls, | |||
1011 | && (GNUNET_NO == | 1015 | && (GNUNET_NO == |
1012 | GNUNET_TESTING_topology_get (&connection_topology, | 1016 | GNUNET_TESTING_topology_get (&connection_topology, |
1013 | connect_topology_str))) | 1017 | connect_topology_str))) |
1014 | { | 1018 | { |
1015 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1019 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1016 | "Invalid connect topology `%s' given for section %s option %s\n", | 1020 | "Invalid connect topology `%s' given for section %s option %s\n", |
1017 | connect_topology_str, "TESTING", "CONNECT_TOPOLOGY"); | 1021 | connect_topology_str, "TESTING", "CONNECT_TOPOLOGY"); |
1018 | } | 1022 | } |
1019 | GNUNET_free_non_null (connect_topology_str); | 1023 | GNUNET_free_non_null (connect_topology_str); |
1020 | if ((GNUNET_YES == | 1024 | if ((GNUNET_YES == |
1021 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", | 1025 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
@@ -1024,31 +1028,31 @@ run (void *cls, | |||
1024 | && (GNUNET_NO == | 1028 | && (GNUNET_NO == |
1025 | GNUNET_TESTING_topology_option_get (&connect_topology_option, | 1029 | GNUNET_TESTING_topology_option_get (&connect_topology_option, |
1026 | connect_topology_option_str))) | 1030 | connect_topology_option_str))) |
1027 | { | 1031 | { |
1028 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1032 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1029 | "Invalid connect topology option `%s' given for section %s option %s\n", | 1033 | "Invalid connect topology option `%s' given for section %s option %s\n", |
1030 | connect_topology_option_str, "TESTING", | 1034 | connect_topology_option_str, "TESTING", |
1031 | "CONNECT_TOPOLOGY_OPTION"); | 1035 | "CONNECT_TOPOLOGY_OPTION"); |
1032 | connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */ | 1036 | connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */ |
1033 | } | 1037 | } |
1034 | GNUNET_free_non_null (connect_topology_option_str); | 1038 | GNUNET_free_non_null (connect_topology_option_str); |
1035 | if (GNUNET_YES == | 1039 | if (GNUNET_YES == |
1036 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", | 1040 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
1037 | "connect_topology_option_modifier", | 1041 | "connect_topology_option_modifier", |
1038 | &connect_topology_option_modifier_string)) | 1042 | &connect_topology_option_modifier_string)) |
1043 | { | ||
1044 | if (sscanf | ||
1045 | (connect_topology_option_modifier_string, "%lf", | ||
1046 | &connect_topology_option_modifier) != 1) | ||
1039 | { | 1047 | { |
1040 | if (sscanf | 1048 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1041 | (connect_topology_option_modifier_string, "%lf", | 1049 | _ |
1042 | &connect_topology_option_modifier) != 1) | 1050 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
1043 | { | 1051 | connect_topology_option_modifier_string, |
1044 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1052 | "connect_topology_option_modifier", "TESTING"); |
1045 | _ | ||
1046 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | ||
1047 | connect_topology_option_modifier_string, | ||
1048 | "connect_topology_option_modifier", "TESTING"); | ||
1049 | } | ||
1050 | GNUNET_free (connect_topology_option_modifier_string); | ||
1051 | } | 1053 | } |
1054 | GNUNET_free (connect_topology_option_modifier_string); | ||
1055 | } | ||
1052 | 1056 | ||
1053 | if (GNUNET_YES != | 1057 | if (GNUNET_YES != |
1054 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", | 1058 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
@@ -1063,11 +1067,11 @@ run (void *cls, | |||
1063 | && (GNUNET_NO == | 1067 | && (GNUNET_NO == |
1064 | GNUNET_TESTING_topology_get (&blacklist_topology, | 1068 | GNUNET_TESTING_topology_get (&blacklist_topology, |
1065 | blacklist_topology_str))) | 1069 | blacklist_topology_str))) |
1066 | { | 1070 | { |
1067 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1071 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1068 | "Invalid topology `%s' given for section %s option %s\n", | 1072 | "Invalid topology `%s' given for section %s option %s\n", |
1069 | topology_str, "TESTING", "BLACKLIST_TOPOLOGY"); | 1073 | topology_str, "TESTING", "BLACKLIST_TOPOLOGY"); |
1070 | } | 1074 | } |
1071 | GNUNET_free_non_null (topology_str); | 1075 | GNUNET_free_non_null (topology_str); |
1072 | GNUNET_free_non_null (blacklist_topology_str); | 1076 | GNUNET_free_non_null (blacklist_topology_str); |
1073 | 1077 | ||
@@ -1075,7 +1079,7 @@ run (void *cls, | |||
1075 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "settle_time", | 1079 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "settle_time", |
1076 | &temp_settle)) | 1080 | &temp_settle)) |
1077 | settle_time = | 1081 | settle_time = |
1078 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle); | 1082 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle); |
1079 | 1083 | ||
1080 | if (GNUNET_SYSERR == | 1084 | if (GNUNET_SYSERR == |
1081 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers", | 1085 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers", |
@@ -1086,21 +1090,23 @@ run (void *cls, | |||
1086 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_timeout", | 1090 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_timeout", |
1087 | &temp_settle)) | 1091 | &temp_settle)) |
1088 | connect_timeout = | 1092 | connect_timeout = |
1089 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle); | 1093 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle); |
1090 | else | 1094 | else |
1091 | { | 1095 | { |
1092 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", "testing", "connect_timeout"); | 1096 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", |
1093 | return; | 1097 | "testing", "connect_timeout"); |
1094 | } | 1098 | return; |
1099 | } | ||
1095 | 1100 | ||
1096 | 1101 | ||
1097 | if (GNUNET_OK != | 1102 | if (GNUNET_OK != |
1098 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_attempts", | 1103 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_attempts", |
1099 | &connect_attempts)) | 1104 | &connect_attempts)) |
1100 | { | 1105 | { |
1101 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", "testing", "connect_attempts"); | 1106 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", |
1102 | return; | 1107 | "testing", "connect_attempts"); |
1103 | } | 1108 | return; |
1109 | } | ||
1104 | 1110 | ||
1105 | main_cfg = cfg; | 1111 | main_cfg = cfg; |
1106 | 1112 | ||
@@ -1109,12 +1115,18 @@ run (void *cls, | |||
1109 | /** | 1115 | /** |
1110 | * How long until we fail the whole testcase? | 1116 | * How long until we fail the whole testcase? |
1111 | */ | 1117 | */ |
1112 | test_timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START), num_peers * 2); | 1118 | test_timeout = |
1119 | GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_multiply | ||
1120 | (GNUNET_TIME_UNIT_SECONDS, | ||
1121 | SECONDS_PER_PEER_START), num_peers * 2); | ||
1113 | 1122 | ||
1114 | /** | 1123 | /** |
1115 | * How long until we give up on starting the peers? | 1124 | * How long until we give up on starting the peers? |
1116 | */ | 1125 | */ |
1117 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START), num_peers); | 1126 | timeout = |
1127 | GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_multiply | ||
1128 | (GNUNET_TIME_UNIT_SECONDS, | ||
1129 | SECONDS_PER_PEER_START), num_peers); | ||
1118 | 1130 | ||
1119 | modnum = num_peers / 4; | 1131 | modnum = num_peers / 4; |
1120 | dotnum = (num_peers / 50) + 1; | 1132 | dotnum = (num_peers / 50) + 1; |
@@ -1123,9 +1135,9 @@ run (void *cls, | |||
1123 | #endif | 1135 | #endif |
1124 | /* Set up a task to end testing if peer start fails */ | 1136 | /* Set up a task to end testing if peer start fails */ |
1125 | die_task = | 1137 | die_task = |
1126 | GNUNET_SCHEDULER_add_delayed (timeout, | 1138 | GNUNET_SCHEDULER_add_delayed (timeout, |
1127 | &end_badly, | 1139 | &end_badly, |
1128 | "didn't generate all hostkeys within a reasonable amount of time!!!"); | 1140 | "didn't generate all hostkeys within a reasonable amount of time!!!"); |
1129 | 1141 | ||
1130 | GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1); | 1142 | GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1); |
1131 | pg = GNUNET_TESTING_daemons_start (cfg, | 1143 | pg = GNUNET_TESTING_daemons_start (cfg, |
@@ -1144,10 +1156,12 @@ check () | |||
1144 | { | 1156 | { |
1145 | char *binary_name; | 1157 | char *binary_name; |
1146 | char *config_file_name; | 1158 | char *config_file_name; |
1159 | |||
1147 | GNUNET_asprintf (&binary_name, "test-testing-topology-%s", topology_string); | 1160 | GNUNET_asprintf (&binary_name, "test-testing-topology-%s", topology_string); |
1148 | GNUNET_asprintf (&config_file_name, "test_testing_data_topology_%s.conf", | 1161 | GNUNET_asprintf (&config_file_name, "test_testing_data_topology_%s.conf", |
1149 | topology_string); | 1162 | topology_string); |
1150 | int ret; | 1163 | int ret; |
1164 | |||
1151 | char *const argv[] = { binary_name, | 1165 | char *const argv[] = { binary_name, |
1152 | "-c", | 1166 | "-c", |
1153 | config_file_name, | 1167 | config_file_name, |
@@ -1162,11 +1176,11 @@ check () | |||
1162 | ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 1176 | ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
1163 | argv, binary_name, "nohelp", options, &run, &ok); | 1177 | argv, binary_name, "nohelp", options, &run, &ok); |
1164 | if (ret != GNUNET_OK) | 1178 | if (ret != GNUNET_OK) |
1165 | { | 1179 | { |
1166 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1180 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1167 | "`test-testing-topology-%s': Failed with error code %d\n", | 1181 | "`test-testing-topology-%s': Failed with error code %d\n", |
1168 | topology_string, ret); | 1182 | topology_string, ret); |
1169 | } | 1183 | } |
1170 | GNUNET_free (binary_name); | 1184 | GNUNET_free (binary_name); |
1171 | GNUNET_free (config_file_name); | 1185 | GNUNET_free (config_file_name); |
1172 | return ok; | 1186 | return ok; |
@@ -1206,10 +1220,10 @@ main (int argc, char *argv[]) | |||
1206 | * of by the testing framework. | 1220 | * of by the testing framework. |
1207 | */ | 1221 | */ |
1208 | if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) | 1222 | if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) |
1209 | { | 1223 | { |
1210 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1224 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1211 | "Failed to remove testing directory %s\n", test_directory); | 1225 | "Failed to remove testing directory %s\n", test_directory); |
1212 | } | 1226 | } |
1213 | GNUNET_free (our_binary_name); | 1227 | GNUNET_free (our_binary_name); |
1214 | return ret; | 1228 | return ret; |
1215 | } | 1229 | } |
diff --git a/src/testing/test_testing_peergroup.c b/src/testing/test_testing_peergroup.c index 6359af754..f06864036 100644 --- a/src/testing/test_testing_peergroup.c +++ b/src/testing/test_testing_peergroup.c | |||
@@ -46,37 +46,35 @@ void | |||
46 | shutdown_callback (void *cls, const char *emsg) | 46 | shutdown_callback (void *cls, const char *emsg) |
47 | { | 47 | { |
48 | if (emsg != NULL) | 48 | if (emsg != NULL) |
49 | { | 49 | { |
50 | #if VERBOSE | 50 | #if VERBOSE |
51 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n"); | 51 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n"); |
52 | #endif | 52 | #endif |
53 | if (ok == 0) | 53 | if (ok == 0) |
54 | ok = 666; | 54 | ok = 666; |
55 | } | 55 | } |
56 | else | 56 | else |
57 | { | 57 | { |
58 | #if VERBOSE | 58 | #if VERBOSE |
59 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 59 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n"); |
60 | "All peers successfully shut down!\n"); | ||
61 | #endif | 60 | #endif |
62 | ok = 0; | 61 | ok = 0; |
63 | } | 62 | } |
64 | } | 63 | } |
65 | 64 | ||
66 | 65 | ||
67 | static void | 66 | static void |
68 | my_cb (void *cls, | 67 | my_cb (void *cls, const char *emsg) |
69 | const char *emsg) | ||
70 | { | 68 | { |
71 | if (emsg != NULL) | 69 | if (emsg != NULL) |
72 | { | 70 | { |
73 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 71 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
74 | "Peergroup callback called with error, aborting test!\n"); | 72 | "Peergroup callback called with error, aborting test!\n"); |
75 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n"); | 73 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n"); |
76 | ok = 1; | 74 | ok = 1; |
77 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 75 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
78 | return; | 76 | return; |
79 | } | 77 | } |
80 | 78 | ||
81 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 79 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
82 | "Peer Group started successfully, ending test!\n"); | 80 | "Peer Group started successfully, ending test!\n"); |
@@ -106,22 +104,19 @@ run (void *cls, | |||
106 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | 104 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
107 | { | 105 | { |
108 | struct GNUNET_CONFIGURATION_Handle *testing_cfg; | 106 | struct GNUNET_CONFIGURATION_Handle *testing_cfg; |
107 | |||
109 | ok = 1; | 108 | ok = 1; |
110 | testing_cfg = GNUNET_CONFIGURATION_create(); | 109 | testing_cfg = GNUNET_CONFIGURATION_create (); |
111 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_load(testing_cfg, cfgfile)); | 110 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (testing_cfg, cfgfile)); |
112 | #if VERBOSE | 111 | #if VERBOSE |
113 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); | 112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); |
114 | GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing", | 113 | GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing", |
115 | "use_progressbars", | 114 | "use_progressbars", "YES"); |
116 | "YES"); | ||
117 | #endif | 115 | #endif |
118 | peers_left = NUM_PEERS; | 116 | peers_left = NUM_PEERS; |
119 | pg = GNUNET_TESTING_peergroup_start(testing_cfg, | 117 | pg = GNUNET_TESTING_peergroup_start (testing_cfg, |
120 | peers_left, | 118 | peers_left, |
121 | TIMEOUT, | 119 | TIMEOUT, NULL, &my_cb, NULL, NULL); |
122 | NULL, | ||
123 | &my_cb, NULL, | ||
124 | NULL); | ||
125 | GNUNET_assert (pg != NULL); | 120 | GNUNET_assert (pg != NULL); |
126 | } | 121 | } |
127 | 122 | ||
diff --git a/src/testing/test_testing_reconnect.c b/src/testing/test_testing_reconnect.c index 7cec78f98..1e028779f 100644 --- a/src/testing/test_testing_reconnect.c +++ b/src/testing/test_testing_reconnect.c | |||
@@ -54,51 +54,50 @@ static int phase; | |||
54 | * Run the next phase of starting daemons, connecting them and | 54 | * Run the next phase of starting daemons, connecting them and |
55 | * stopping them again. | 55 | * stopping them again. |
56 | */ | 56 | */ |
57 | static void | 57 | static void run_phase (); |
58 | run_phase (); | ||
59 | 58 | ||
60 | static void | 59 | static void |
61 | end2_cb (void *cls, const char *emsg) | 60 | end2_cb (void *cls, const char *emsg) |
62 | { | 61 | { |
63 | 62 | ||
64 | if (emsg != NULL) | 63 | if (emsg != NULL) |
65 | { | 64 | { |
66 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ending with error: %s\n", emsg); | 65 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ending with error: %s\n", emsg); |
67 | ok = 1; | 66 | ok = 1; |
68 | } | 67 | } |
69 | else | 68 | else |
69 | { | ||
70 | if (phase < NUM_PHASES) | ||
70 | { | 71 | { |
71 | if (phase < NUM_PHASES) | 72 | fprintf (stderr, "."); |
72 | { | 73 | run_phase (); |
73 | fprintf (stderr, "."); | 74 | return; |
74 | run_phase(); | 75 | } |
75 | return; | 76 | fprintf (stderr, ".\n"); |
76 | } | ||
77 | fprintf (stderr, ".\n"); | ||
78 | #if VERBOSE | 77 | #if VERBOSE |
79 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 78 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
80 | "Both daemons terminated, will now exit.\n"); | 79 | "Both daemons terminated, will now exit.\n"); |
81 | #endif | 80 | #endif |
82 | ok = 0; | 81 | ok = 0; |
83 | } | 82 | } |
84 | } | 83 | } |
85 | 84 | ||
86 | static void | 85 | static void |
87 | end1_cb (void *cls, const char *emsg) | 86 | end1_cb (void *cls, const char *emsg) |
88 | { | 87 | { |
89 | if (emsg != NULL) | 88 | if (emsg != NULL) |
90 | { | 89 | { |
91 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Stopping daemon 1 gave: %s\n", | 90 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Stopping daemon 1 gave: %s\n", |
92 | emsg); | 91 | emsg); |
93 | ok = 1; | 92 | ok = 1; |
94 | } | 93 | } |
95 | else | 94 | else |
96 | { | 95 | { |
97 | ok = 0; | 96 | ok = 0; |
98 | } | 97 | } |
99 | 98 | ||
100 | GNUNET_TESTING_daemon_stop (d2, TIMEOUT, &end2_cb, NULL, | 99 | GNUNET_TESTING_daemon_stop (d2, TIMEOUT, &end2_cb, NULL, |
101 | (phase == NUM_PHASES) ? GNUNET_YES : GNUNET_NO, | 100 | (phase == NUM_PHASES) ? GNUNET_YES : GNUNET_NO, |
102 | GNUNET_NO); | 101 | GNUNET_NO); |
103 | d2 = NULL; | 102 | d2 = NULL; |
104 | } | 103 | } |
@@ -106,8 +105,8 @@ end1_cb (void *cls, const char *emsg) | |||
106 | static void | 105 | static void |
107 | finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 106 | finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
108 | { | 107 | { |
109 | GNUNET_TESTING_daemon_stop (d1, TIMEOUT, &end1_cb, NULL, | 108 | GNUNET_TESTING_daemon_stop (d1, TIMEOUT, &end1_cb, NULL, |
110 | (phase == NUM_PHASES) ? GNUNET_YES : GNUNET_NO, | 109 | (phase == NUM_PHASES) ? GNUNET_YES : GNUNET_NO, |
111 | GNUNET_NO); | 110 | GNUNET_NO); |
112 | d1 = NULL; | 111 | d1 = NULL; |
113 | } | 112 | } |
@@ -147,8 +146,7 @@ my_cb2 (void *cls, | |||
147 | #endif | 146 | #endif |
148 | GNUNET_TESTING_daemons_connect (d1, d2, | 147 | GNUNET_TESTING_daemons_connect (d1, d2, |
149 | TIMEOUT, CONNECT_ATTEMPTS, | 148 | TIMEOUT, CONNECT_ATTEMPTS, |
150 | GNUNET_YES, | 149 | GNUNET_YES, &my_connect_complete, NULL); |
151 | &my_connect_complete, NULL); | ||
152 | } | 150 | } |
153 | 151 | ||
154 | 152 | ||
@@ -163,9 +161,8 @@ my_cb1 (void *cls, | |||
163 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
164 | "Daemon `%s' started.\n", GNUNET_i2s (id)); | 162 | "Daemon `%s' started.\n", GNUNET_i2s (id)); |
165 | #endif | 163 | #endif |
166 | d2 = | 164 | d2 = GNUNET_TESTING_daemon_start (c2, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL, |
167 | GNUNET_TESTING_daemon_start (c2, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL, NULL, NULL, | 165 | NULL, NULL, &my_cb2, NULL); |
168 | &my_cb2, NULL); | ||
169 | GNUNET_assert (d2 != NULL); | 166 | GNUNET_assert (d2 != NULL); |
170 | } | 167 | } |
171 | 168 | ||
@@ -186,13 +183,12 @@ run (void *cls, | |||
186 | run_phase (); | 183 | run_phase (); |
187 | } | 184 | } |
188 | 185 | ||
189 | static void | 186 | static void |
190 | run_phase () | 187 | run_phase () |
191 | { | 188 | { |
192 | phase++; | 189 | phase++; |
193 | d1 = | 190 | d1 = GNUNET_TESTING_daemon_start (c1, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL, |
194 | GNUNET_TESTING_daemon_start (c1, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL, NULL, NULL, | 191 | NULL, NULL, &my_cb1, NULL); |
195 | &my_cb1, NULL); | ||
196 | GNUNET_assert (d1 != NULL); | 192 | GNUNET_assert (d1 != NULL); |
197 | } | 193 | } |
198 | 194 | ||
diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c index 7360ab943..73b49e469 100644 --- a/src/testing/test_testing_topology.c +++ b/src/testing/test_testing_topology.c | |||
@@ -107,7 +107,7 @@ static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY | |||
107 | static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */ | 107 | static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */ |
108 | 108 | ||
109 | static enum GNUNET_TESTING_TopologyOption connect_topology_option = | 109 | static enum GNUNET_TESTING_TopologyOption connect_topology_option = |
110 | GNUNET_TESTING_TOPOLOGY_OPTION_ALL; | 110 | GNUNET_TESTING_TOPOLOGY_OPTION_ALL; |
111 | 111 | ||
112 | static double connect_topology_option_modifier = 0.0; | 112 | static double connect_topology_option_modifier = 0.0; |
113 | 113 | ||
@@ -168,20 +168,19 @@ void | |||
168 | shutdown_callback (void *cls, const char *emsg) | 168 | shutdown_callback (void *cls, const char *emsg) |
169 | { | 169 | { |
170 | if (emsg != NULL) | 170 | if (emsg != NULL) |
171 | { | 171 | { |
172 | #if VERBOSE | 172 | #if VERBOSE |
173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n"); | 173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n"); |
174 | #endif | 174 | #endif |
175 | if (ok == 0) | 175 | if (ok == 0) |
176 | ok = 666; | 176 | ok = 666; |
177 | } | 177 | } |
178 | else | 178 | else |
179 | { | 179 | { |
180 | #if VERBOSE | 180 | #if VERBOSE |
181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n"); |
182 | "All peers successfully shut down!\n"); | ||
183 | #endif | 182 | #endif |
184 | } | 183 | } |
185 | } | 184 | } |
186 | 185 | ||
187 | #if DELAY_FOR_LOGGING | 186 | #if DELAY_FOR_LOGGING |
@@ -191,6 +190,7 @@ gather_log_data () | |||
191 | char *peer_number; | 190 | char *peer_number; |
192 | char *connect_number; | 191 | char *connect_number; |
193 | struct GNUNET_OS_Process *mem_process; | 192 | struct GNUNET_OS_Process *mem_process; |
193 | |||
194 | GNUNET_asprintf (&peer_number, "%llu", num_peers); | 194 | GNUNET_asprintf (&peer_number, "%llu", num_peers); |
195 | GNUNET_asprintf (&connect_number, "%llu", expected_connections); | 195 | GNUNET_asprintf (&connect_number, "%llu", expected_connections); |
196 | mem_process = GNUNET_OS_start_process (NULL, NULL, "./memsize.pl", | 196 | mem_process = GNUNET_OS_start_process (NULL, NULL, "./memsize.pl", |
@@ -209,6 +209,7 @@ finish_testing () | |||
209 | GNUNET_assert (pg != NULL); | 209 | GNUNET_assert (pg != NULL); |
210 | struct TestMessageContext *pos; | 210 | struct TestMessageContext *pos; |
211 | struct TestMessageContext *free_pos; | 211 | struct TestMessageContext *free_pos; |
212 | |||
212 | #if VERBOSE | 213 | #if VERBOSE |
213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
214 | "Called finish testing, stopping daemons.\n"); | 215 | "Called finish testing, stopping daemons.\n"); |
@@ -216,25 +217,25 @@ finish_testing () | |||
216 | 217 | ||
217 | pos = test_messages; | 218 | pos = test_messages; |
218 | while (pos != NULL) | 219 | while (pos != NULL) |
220 | { | ||
221 | if (pos->peer1handle != NULL) | ||
219 | { | 222 | { |
220 | if (pos->peer1handle != NULL) | 223 | GNUNET_CORE_disconnect (pos->peer1handle); |
221 | { | 224 | pos->peer1handle = NULL; |
222 | GNUNET_CORE_disconnect (pos->peer1handle); | ||
223 | pos->peer1handle = NULL; | ||
224 | } | ||
225 | if (pos->peer2handle != NULL) | ||
226 | { | ||
227 | GNUNET_CORE_disconnect (pos->peer2handle); | ||
228 | pos->peer2handle = NULL; | ||
229 | } | ||
230 | free_pos = pos; | ||
231 | pos = pos->next; | ||
232 | if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK) | ||
233 | { | ||
234 | GNUNET_SCHEDULER_cancel (free_pos->disconnect_task); | ||
235 | } | ||
236 | GNUNET_free (free_pos); | ||
237 | } | 225 | } |
226 | if (pos->peer2handle != NULL) | ||
227 | { | ||
228 | GNUNET_CORE_disconnect (pos->peer2handle); | ||
229 | pos->peer2handle = NULL; | ||
230 | } | ||
231 | free_pos = pos; | ||
232 | pos = pos->next; | ||
233 | if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK) | ||
234 | { | ||
235 | GNUNET_SCHEDULER_cancel (free_pos->disconnect_task); | ||
236 | } | ||
237 | GNUNET_free (free_pos); | ||
238 | } | ||
238 | #if VERBOSE | 239 | #if VERBOSE |
239 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 240 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
240 | "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", | 241 | "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", |
@@ -248,10 +249,10 @@ finish_testing () | |||
248 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 249 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
249 | 250 | ||
250 | if (dotOutFile != NULL) | 251 | if (dotOutFile != NULL) |
251 | { | 252 | { |
252 | fprintf (dotOutFile, "}"); | 253 | fprintf (dotOutFile, "}"); |
253 | fclose (dotOutFile); | 254 | fclose (dotOutFile); |
254 | } | 255 | } |
255 | 256 | ||
256 | ok = 0; | 257 | ok = 0; |
257 | } | 258 | } |
@@ -321,31 +322,31 @@ topology_cb (void *cls, | |||
321 | const struct GNUNET_PeerIdentity *second, const char *emsg) | 322 | const struct GNUNET_PeerIdentity *second, const char *emsg) |
322 | { | 323 | { |
323 | FILE *outfile = cls; | 324 | FILE *outfile = cls; |
325 | |||
324 | if (first != NULL) | 326 | if (first != NULL) |
327 | { | ||
328 | if (outfile != NULL) | ||
325 | { | 329 | { |
326 | if (outfile != NULL) | 330 | fprintf (outfile, "\t\"%s\" -- ", GNUNET_i2s (first)); |
327 | { | 331 | fprintf (outfile, "\"%s\";\n", GNUNET_i2s (second)); |
328 | fprintf (outfile, "\t\"%s\" -- ", GNUNET_i2s (first)); | ||
329 | fprintf (outfile, "\"%s\";\n", GNUNET_i2s (second)); | ||
330 | } | ||
331 | topology_connections++; | ||
332 | } | 332 | } |
333 | topology_connections++; | ||
334 | } | ||
333 | else | 335 | else |
336 | { | ||
337 | fprintf (stderr, | ||
338 | "Finished iterating over topology, %d total connections!\n", | ||
339 | topology_connections); | ||
340 | if (outfile != NULL) | ||
334 | { | 341 | { |
335 | fprintf (stderr, | 342 | fprintf (outfile, "}\n"); |
336 | "Finished iterating over topology, %d total connections!\n", | 343 | fclose (outfile); |
337 | topology_connections); | ||
338 | if (outfile != NULL) | ||
339 | { | ||
340 | fprintf (outfile, "}\n"); | ||
341 | fclose (outfile); | ||
342 | #if DO_STATS | 344 | #if DO_STATS |
343 | GNUNET_TESTING_get_statistics (pg, &stats_finished, &stats_print, | 345 | GNUNET_TESTING_get_statistics (pg, &stats_finished, &stats_print, NULL); |
344 | NULL); | ||
345 | #endif | 346 | #endif |
346 | GNUNET_SCHEDULER_add_now (&finish_testing, NULL); | 347 | GNUNET_SCHEDULER_add_now (&finish_testing, NULL); |
347 | } | ||
348 | } | 348 | } |
349 | } | ||
349 | } | 350 | } |
350 | 351 | ||
351 | static int | 352 | static int |
@@ -358,24 +359,25 @@ process_mtype (void *cls, | |||
358 | FILE *dotOutFileFinished; | 359 | FILE *dotOutFileFinished; |
359 | struct TestMessageContext *pos = cls; | 360 | struct TestMessageContext *pos = cls; |
360 | struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message; | 361 | struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message; |
362 | |||
361 | if (pos->uid != ntohl (msg->uid)) | 363 | if (pos->uid != ntohl (msg->uid)) |
362 | return GNUNET_OK; | 364 | return GNUNET_OK; |
363 | 365 | ||
364 | #if PROGRESS_BARS | 366 | #if PROGRESS_BARS |
365 | if ((total_messages_received) % modnum == 0) | 367 | if ((total_messages_received) % modnum == 0) |
366 | { | 368 | { |
367 | if (total_messages_received == 0) | 369 | if (total_messages_received == 0) |
368 | fprintf (stdout, "0%%"); | 370 | fprintf (stdout, "0%%"); |
369 | else | 371 | else |
370 | fprintf (stdout, "%d%%", | 372 | fprintf (stdout, "%d%%", |
371 | (int) (((float) total_messages_received / | 373 | (int) (((float) total_messages_received / |
372 | expected_messages) * 100)); | 374 | expected_messages) * 100)); |
373 | 375 | ||
374 | } | 376 | } |
375 | else if (total_messages_received % dotnum == 0) | 377 | else if (total_messages_received % dotnum == 0) |
376 | { | 378 | { |
377 | fprintf (stdout, "."); | 379 | fprintf (stdout, "."); |
378 | } | 380 | } |
379 | fflush (stdout); | 381 | fflush (stdout); |
380 | #endif | 382 | #endif |
381 | 383 | ||
@@ -391,27 +393,26 @@ process_mtype (void *cls, | |||
391 | #endif | 393 | #endif |
392 | 394 | ||
393 | if (total_messages_received == expected_messages) | 395 | if (total_messages_received == expected_messages) |
394 | { | 396 | { |
395 | #if PROGRESS_BARS | 397 | #if PROGRESS_BARS |
396 | fprintf (stdout, "100%%]\n"); | 398 | fprintf (stdout, "100%%]\n"); |
397 | #endif | 399 | #endif |
398 | GNUNET_SCHEDULER_cancel (die_task); | 400 | GNUNET_SCHEDULER_cancel (die_task); |
399 | GNUNET_asprintf (&dotOutFileNameFinished, "%s.dot", "final_topology"); | 401 | GNUNET_asprintf (&dotOutFileNameFinished, "%s.dot", "final_topology"); |
400 | dotOutFileFinished = fopen (dotOutFileNameFinished, "w"); | 402 | dotOutFileFinished = fopen (dotOutFileNameFinished, "w"); |
401 | GNUNET_free (dotOutFileNameFinished); | 403 | GNUNET_free (dotOutFileNameFinished); |
402 | if (dotOutFileFinished != NULL) | 404 | if (dotOutFileFinished != NULL) |
403 | { | ||
404 | fprintf (dotOutFileFinished, "strict graph G {\n"); | ||
405 | } | ||
406 | topology_connections = 0; | ||
407 | GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished); | ||
408 | //GNUNET_SCHEDULER_add_now (&finish_testing, NULL); | ||
409 | } | ||
410 | else | ||
411 | { | 405 | { |
412 | pos->disconnect_task = | 406 | fprintf (dotOutFileFinished, "strict graph G {\n"); |
413 | GNUNET_SCHEDULER_add_now (&disconnect_cores, pos); | ||
414 | } | 407 | } |
408 | topology_connections = 0; | ||
409 | GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished); | ||
410 | //GNUNET_SCHEDULER_add_now (&finish_testing, NULL); | ||
411 | } | ||
412 | else | ||
413 | { | ||
414 | pos->disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cores, pos); | ||
415 | } | ||
415 | 416 | ||
416 | return GNUNET_OK; | 417 | return GNUNET_OK; |
417 | } | 418 | } |
@@ -420,6 +421,7 @@ static void | |||
420 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 421 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
421 | { | 422 | { |
422 | char *msg = cls; | 423 | char *msg = cls; |
424 | |||
423 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 425 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
424 | "End badly was called (%s)... stopping daemons.\n", msg); | 426 | "End badly was called (%s)... stopping daemons.\n", msg); |
425 | struct TestMessageContext *pos; | 427 | struct TestMessageContext *pos; |
@@ -427,21 +429,21 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
427 | 429 | ||
428 | pos = test_messages; | 430 | pos = test_messages; |
429 | while (pos != NULL) | 431 | while (pos != NULL) |
432 | { | ||
433 | if (pos->peer1handle != NULL) | ||
430 | { | 434 | { |
431 | if (pos->peer1handle != NULL) | 435 | GNUNET_CORE_disconnect (pos->peer1handle); |
432 | { | 436 | pos->peer1handle = NULL; |
433 | GNUNET_CORE_disconnect (pos->peer1handle); | ||
434 | pos->peer1handle = NULL; | ||
435 | } | ||
436 | if (pos->peer2handle != NULL) | ||
437 | { | ||
438 | GNUNET_CORE_disconnect (pos->peer2handle); | ||
439 | pos->peer2handle = NULL; | ||
440 | } | ||
441 | free_pos = pos; | ||
442 | pos = pos->next; | ||
443 | GNUNET_free (free_pos); | ||
444 | } | 437 | } |
438 | if (pos->peer2handle != NULL) | ||
439 | { | ||
440 | GNUNET_CORE_disconnect (pos->peer2handle); | ||
441 | pos->peer2handle = NULL; | ||
442 | } | ||
443 | free_pos = pos; | ||
444 | pos = pos->next; | ||
445 | GNUNET_free (free_pos); | ||
446 | } | ||
445 | 447 | ||
446 | #if VERBOSE | 448 | #if VERBOSE |
447 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 449 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -454,18 +456,18 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
454 | #endif | 456 | #endif |
455 | 457 | ||
456 | if (pg != NULL) | 458 | if (pg != NULL) |
457 | { | 459 | { |
458 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 460 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
459 | ok = 7331; /* Opposite of leet */ | 461 | ok = 7331; /* Opposite of leet */ |
460 | } | 462 | } |
461 | else | 463 | else |
462 | ok = 401; /* Never got peers started */ | 464 | ok = 401; /* Never got peers started */ |
463 | 465 | ||
464 | if (dotOutFile != NULL) | 466 | if (dotOutFile != NULL) |
465 | { | 467 | { |
466 | fprintf (dotOutFile, "}"); | 468 | fprintf (dotOutFile, "}"); |
467 | fclose (dotOutFile); | 469 | fclose (dotOutFile); |
468 | } | 470 | } |
469 | } | 471 | } |
470 | 472 | ||
471 | static size_t | 473 | static size_t |
@@ -512,31 +514,32 @@ init_notify_peer2 (void *cls, | |||
512 | 514 | ||
513 | pos->peer2connected = GNUNET_YES; | 515 | pos->peer2connected = GNUNET_YES; |
514 | if (pos->peer1notified == GNUNET_YES) /* Peer 1 has been notified of connection to peer 2 */ | 516 | if (pos->peer1notified == GNUNET_YES) /* Peer 1 has been notified of connection to peer 2 */ |
515 | { | 517 | { |
516 | #if VERBOSE > 1 | 518 | #if VERBOSE > 1 |
517 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 519 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
518 | "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n", | 520 | "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n", |
519 | GNUNET_i2s (my_identity), GNUNET_h2s(&pos->peer1->id.hashPubKey)); | 521 | GNUNET_i2s (my_identity), |
522 | GNUNET_h2s (&pos->peer1->id.hashPubKey)); | ||
520 | #endif | 523 | #endif |
521 | if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle, | 524 | if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle, |
522 | GNUNET_YES, | 525 | GNUNET_YES, |
523 | 0, | 526 | 0, |
524 | TIMEOUT, | 527 | TIMEOUT, |
525 | &pos->peer2->id, | 528 | &pos->peer2->id, |
526 | sizeof (struct | 529 | sizeof (struct |
527 | GNUNET_TestMessage), | 530 | GNUNET_TestMessage), |
528 | &transmit_ready, pos)) | 531 | &transmit_ready, pos)) |
529 | { | 532 | { |
530 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 533 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
531 | "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", | 534 | "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", |
532 | GNUNET_i2s (&pos->peer2->id)); | 535 | GNUNET_i2s (&pos->peer2->id)); |
533 | transmit_ready_failed++; | 536 | transmit_ready_failed++; |
534 | } | 537 | } |
535 | else | 538 | else |
536 | { | 539 | { |
537 | transmit_ready_scheduled++; | 540 | transmit_ready_scheduled++; |
538 | } | ||
539 | } | 541 | } |
542 | } | ||
540 | } | 543 | } |
541 | 544 | ||
542 | /** | 545 | /** |
@@ -546,51 +549,53 @@ init_notify_peer2 (void *cls, | |||
546 | * @param peer peer identity this notification is about | 549 | * @param peer peer identity this notification is about |
547 | * @param atsi performance data for the connection | 550 | * @param atsi performance data for the connection |
548 | */ | 551 | */ |
549 | static void connect_notify_peers (void *cls, | 552 | static void |
550 | const struct | 553 | connect_notify_peers (void *cls, |
551 | GNUNET_PeerIdentity *peer, | 554 | const struct |
552 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 555 | GNUNET_PeerIdentity *peer, |
556 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | ||
553 | { | 557 | { |
554 | struct TestMessageContext *pos = cls; | 558 | struct TestMessageContext *pos = cls; |
555 | 559 | ||
556 | if (0 == memcmp(peer, &pos->peer2->id, sizeof(struct GNUNET_PeerIdentity))) | 560 | if (0 == memcmp (peer, &pos->peer2->id, sizeof (struct GNUNET_PeerIdentity))) |
557 | { | 561 | { |
558 | pos->peer1notified = GNUNET_YES; | 562 | pos->peer1notified = GNUNET_YES; |
559 | #if VERBOSE > 1 | 563 | #if VERBOSE > 1 |
560 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 564 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
561 | "Peer `%s' notified of connection to peer `%s'\n", | 565 | "Peer `%s' notified of connection to peer `%s'\n", |
562 | GNUNET_i2s (&pos->peer1->id), GNUNET_h2s(&peer->hashPubKey)); | 566 | GNUNET_i2s (&pos->peer1->id), GNUNET_h2s (&peer->hashPubKey)); |
563 | #endif | 567 | #endif |
564 | } | 568 | } |
565 | else | 569 | else |
566 | return; | 570 | return; |
567 | 571 | ||
568 | if (pos->peer2connected == GNUNET_YES) /* Already connected and notified of connection, send message! */ | 572 | if (pos->peer2connected == GNUNET_YES) /* Already connected and notified of connection, send message! */ |
569 | { | 573 | { |
570 | #if VERBOSE > 1 | 574 | #if VERBOSE > 1 |
571 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 575 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
572 | "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n", | 576 | "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n", |
573 | GNUNET_i2s (&pos->peer2->id), GNUNET_h2s(&pos->peer1->id.hashPubKey)); | 577 | GNUNET_i2s (&pos->peer2->id), |
578 | GNUNET_h2s (&pos->peer1->id.hashPubKey)); | ||
574 | #endif | 579 | #endif |
575 | if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle, | 580 | if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle, |
576 | GNUNET_YES, | 581 | GNUNET_YES, |
577 | 0, | 582 | 0, |
578 | TIMEOUT, | 583 | TIMEOUT, |
579 | &pos->peer2->id, | 584 | &pos->peer2->id, |
580 | sizeof (struct | 585 | sizeof (struct |
581 | GNUNET_TestMessage), | 586 | GNUNET_TestMessage), |
582 | &transmit_ready, pos)) | 587 | &transmit_ready, pos)) |
583 | { | 588 | { |
584 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 589 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
585 | "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", | 590 | "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", |
586 | GNUNET_i2s (&pos->peer2->id)); | 591 | GNUNET_i2s (&pos->peer2->id)); |
587 | transmit_ready_failed++; | 592 | transmit_ready_failed++; |
588 | } | 593 | } |
589 | else | 594 | else |
590 | { | 595 | { |
591 | transmit_ready_scheduled++; | 596 | transmit_ready_scheduled++; |
592 | } | ||
593 | } | 597 | } |
598 | } | ||
594 | } | 599 | } |
595 | 600 | ||
596 | static void | 601 | static void |
@@ -601,6 +606,7 @@ init_notify_peer1 (void *cls, | |||
601 | *publicKey) | 606 | *publicKey) |
602 | { | 607 | { |
603 | struct TestMessageContext *pos = cls; | 608 | struct TestMessageContext *pos = cls; |
609 | |||
604 | total_server_connections++; | 610 | total_server_connections++; |
605 | 611 | ||
606 | #if VERBOSE > 1 | 612 | #if VERBOSE > 1 |
@@ -631,27 +637,27 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
631 | struct TestMessageContext *pos = cls; | 637 | struct TestMessageContext *pos = cls; |
632 | 638 | ||
633 | if ((pos == test_messages) && (settle_time.rel_value > 0)) | 639 | if ((pos == test_messages) && (settle_time.rel_value > 0)) |
634 | { | 640 | { |
635 | topology_connections = 0; | 641 | topology_connections = 0; |
636 | GNUNET_TESTING_get_topology (pg, &topology_cb, NULL); | 642 | GNUNET_TESTING_get_topology (pg, &topology_cb, NULL); |
637 | } | 643 | } |
638 | if (( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)|| (cls == NULL)) | 644 | if (((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) || (cls == NULL)) |
639 | return; | 645 | return; |
640 | 646 | ||
641 | if (die_task == GNUNET_SCHEDULER_NO_TASK) | 647 | if (die_task == GNUNET_SCHEDULER_NO_TASK) |
642 | { | 648 | { |
643 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, | 649 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, |
644 | &end_badly, | 650 | &end_badly, |
645 | "from send test messages (timeout)"); | 651 | "from send test messages (timeout)"); |
646 | } | 652 | } |
647 | 653 | ||
648 | if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS) | 654 | if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS) |
649 | { | 655 | { |
650 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 656 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
651 | (GNUNET_TIME_UNIT_SECONDS, 1), | 657 | (GNUNET_TIME_UNIT_SECONDS, 1), |
652 | &send_test_messages, pos); | 658 | &send_test_messages, pos); |
653 | return; /* Otherwise we'll double schedule messages here! */ | 659 | return; /* Otherwise we'll double schedule messages here! */ |
654 | } | 660 | } |
655 | 661 | ||
656 | /* | 662 | /* |
657 | * Connect to the sending peer | 663 | * Connect to the sending peer |
@@ -669,15 +675,15 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
669 | GNUNET_assert (pos->peer1handle != NULL); | 675 | GNUNET_assert (pos->peer1handle != NULL); |
670 | 676 | ||
671 | if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS) | 677 | if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS) |
672 | { | 678 | { |
673 | GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next); | 679 | GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next); |
674 | } | 680 | } |
675 | else | 681 | else |
676 | { | 682 | { |
677 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 683 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
678 | (GNUNET_TIME_UNIT_SECONDS, 1), | 684 | (GNUNET_TIME_UNIT_SECONDS, 1), |
679 | &send_test_messages, pos->next); | 685 | &send_test_messages, pos->next); |
680 | } | 686 | } |
681 | } | 687 | } |
682 | 688 | ||
683 | 689 | ||
@@ -693,117 +699,118 @@ topology_callback (void *cls, | |||
693 | const char *emsg) | 699 | const char *emsg) |
694 | { | 700 | { |
695 | struct TestMessageContext *temp_context; | 701 | struct TestMessageContext *temp_context; |
702 | |||
696 | if (emsg == NULL) | 703 | if (emsg == NULL) |
697 | { | 704 | { |
698 | #if PROGRESS_BARS | 705 | #if PROGRESS_BARS |
699 | if ((total_connections) % modnum == 0) | 706 | if ((total_connections) % modnum == 0) |
700 | { | 707 | { |
701 | if (total_connections == 0) | 708 | if (total_connections == 0) |
702 | fprintf (stdout, "0%%"); | 709 | fprintf (stdout, "0%%"); |
703 | else | 710 | else |
704 | fprintf (stdout, "%d%%", | 711 | fprintf (stdout, "%d%%", |
705 | (int) (((float) total_connections / | 712 | (int) (((float) total_connections / |
706 | expected_connections) * 100)); | 713 | expected_connections) * 100)); |
707 | 714 | ||
708 | } | 715 | } |
709 | else if (total_connections % dotnum == 0) | 716 | else if (total_connections % dotnum == 0) |
710 | { | 717 | { |
711 | fprintf (stdout, "."); | 718 | fprintf (stdout, "."); |
712 | } | 719 | } |
713 | fflush (stdout); | 720 | fflush (stdout); |
714 | #endif | 721 | #endif |
715 | total_connections++; | 722 | total_connections++; |
716 | #if VERBOSE > 1 | 723 | #if VERBOSE > 1 |
717 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "connected peer %s to peer %s\n", | 724 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "connected peer %s to peer %s\n", |
718 | first_daemon->shortname, second_daemon->shortname); | 725 | first_daemon->shortname, second_daemon->shortname); |
719 | #endif | 726 | #endif |
720 | temp_context = GNUNET_malloc (sizeof (struct TestMessageContext)); | 727 | temp_context = GNUNET_malloc (sizeof (struct TestMessageContext)); |
721 | temp_context->peer1 = first_daemon; | 728 | temp_context->peer1 = first_daemon; |
722 | temp_context->peer2 = second_daemon; | 729 | temp_context->peer2 = second_daemon; |
723 | temp_context->next = test_messages; | 730 | temp_context->next = test_messages; |
724 | temp_context->uid = total_connections; | 731 | temp_context->uid = total_connections; |
725 | temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK; | 732 | temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK; |
726 | test_messages = temp_context; | 733 | test_messages = temp_context; |
727 | 734 | ||
728 | expected_messages++; | 735 | expected_messages++; |
729 | if (dotOutFile != NULL) | 736 | if (dotOutFile != NULL) |
730 | fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname, | 737 | fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname, |
731 | second_daemon->shortname); | 738 | second_daemon->shortname); |
732 | } | 739 | } |
733 | #if VERBOSE | 740 | #if VERBOSE |
734 | else | 741 | else |
735 | { | 742 | { |
736 | failed_connections++; | 743 | failed_connections++; |
737 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 744 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
738 | "Failed to connect peer %s to peer %s with error :\n%s\n", | 745 | "Failed to connect peer %s to peer %s with error :\n%s\n", |
739 | first_daemon->shortname, second_daemon->shortname, emsg); | 746 | first_daemon->shortname, second_daemon->shortname, emsg); |
740 | } | 747 | } |
741 | #endif | 748 | #endif |
742 | 749 | ||
743 | if (total_connections == expected_connections) | 750 | if (total_connections == expected_connections) |
744 | { | 751 | { |
745 | #if PROGRESS_BARS | 752 | #if PROGRESS_BARS |
746 | fprintf (stdout, "100%%]\n"); | 753 | fprintf (stdout, "100%%]\n"); |
747 | #endif | 754 | #endif |
748 | #if VERBOSE | 755 | #if VERBOSE |
749 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 756 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
750 | "Created %d total connections, which is our target number! Calling send messages.\n", | 757 | "Created %d total connections, which is our target number! Calling send messages.\n", |
751 | total_connections); | 758 | total_connections); |
752 | #endif | 759 | #endif |
753 | modnum = expected_messages / 4; | 760 | modnum = expected_messages / 4; |
754 | dotnum = (expected_messages / 50) + 1; | 761 | dotnum = (expected_messages / 50) + 1; |
755 | if (modnum == 0) | 762 | if (modnum == 0) |
756 | modnum = 1; | 763 | modnum = 1; |
757 | if (dotnum == 0) | 764 | if (dotnum == 0) |
758 | dotnum = 1; | 765 | dotnum = 1; |
759 | GNUNET_SCHEDULER_cancel (die_task); | 766 | GNUNET_SCHEDULER_cancel (die_task); |
760 | die_task = GNUNET_SCHEDULER_NO_TASK; | 767 | die_task = GNUNET_SCHEDULER_NO_TASK; |
761 | #if DELAY_FOR_LOGGING | 768 | #if DELAY_FOR_LOGGING |
762 | fprintf (stdout, "Sending test messages in 10 seconds.\n"); | 769 | fprintf (stdout, "Sending test messages in 10 seconds.\n"); |
763 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 770 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
764 | (GNUNET_TIME_UNIT_SECONDS, 10), | 771 | (GNUNET_TIME_UNIT_SECONDS, 10), |
765 | &send_test_messages, test_messages); | 772 | &send_test_messages, test_messages); |
766 | gather_log_data (); | 773 | gather_log_data (); |
767 | #else | 774 | #else |
768 | if (settle_time.rel_value > 0) | 775 | if (settle_time.rel_value > 0) |
769 | { | 776 | { |
770 | GNUNET_TESTING_get_topology (pg, &topology_cb, NULL); | 777 | GNUNET_TESTING_get_topology (pg, &topology_cb, NULL); |
771 | } | 778 | } |
772 | GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages, | 779 | GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages, |
773 | test_messages); | 780 | test_messages); |
774 | #endif | 781 | #endif |
775 | #if PROGRESS_BARS | 782 | #if PROGRESS_BARS |
776 | fprintf (stdout, "Test message progress: ["); | 783 | fprintf (stdout, "Test message progress: ["); |
777 | #endif | 784 | #endif |
778 | 785 | ||
779 | } | 786 | } |
780 | else if (total_connections + failed_connections == expected_connections) | 787 | else if (total_connections + failed_connections == expected_connections) |
788 | { | ||
789 | if (failed_connections < | ||
790 | (unsigned int) (fail_percentage * total_connections)) | ||
781 | { | 791 | { |
782 | if (failed_connections < | 792 | GNUNET_SCHEDULER_cancel (die_task); |
783 | (unsigned int) (fail_percentage * total_connections)) | 793 | die_task = GNUNET_SCHEDULER_NO_TASK; |
784 | { | 794 | GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages); |
785 | GNUNET_SCHEDULER_cancel (die_task); | ||
786 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
787 | GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages); | ||
788 | } | ||
789 | else | ||
790 | { | ||
791 | GNUNET_SCHEDULER_cancel (die_task); | ||
792 | die_task = | ||
793 | GNUNET_SCHEDULER_add_now (&end_badly, | ||
794 | "from topology_callback (too many failed connections)"); | ||
795 | } | ||
796 | } | 795 | } |
797 | else | 796 | else |
798 | { | 797 | { |
798 | GNUNET_SCHEDULER_cancel (die_task); | ||
799 | die_task = | ||
800 | GNUNET_SCHEDULER_add_now (&end_badly, | ||
801 | "from topology_callback (too many failed connections)"); | ||
802 | } | ||
803 | } | ||
804 | else | ||
805 | { | ||
799 | #if VERBOSE > 1 | 806 | #if VERBOSE > 1 |
800 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 807 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
801 | "Have %d total connections, %d failed connections, Want %d (at least %d)\n", | 808 | "Have %d total connections, %d failed connections, Want %d (at least %d)\n", |
802 | total_connections, failed_connections, expected_connections, | 809 | total_connections, failed_connections, expected_connections, |
803 | expected_connections - | 810 | expected_connections - |
804 | (unsigned int) (fail_percentage * expected_connections)); | 811 | (unsigned int) (fail_percentage * expected_connections)); |
805 | #endif | 812 | #endif |
806 | } | 813 | } |
807 | } | 814 | } |
808 | 815 | ||
809 | static void | 816 | static void |
@@ -821,8 +828,8 @@ connect_topology () | |||
821 | { | 828 | { |
822 | expected_connections = -1; | 829 | expected_connections = -1; |
823 | if ((pg != NULL) && (peers_left == 0)) | 830 | if ((pg != NULL) && (peers_left == 0)) |
824 | { | 831 | { |
825 | expected_connections = | 832 | expected_connections = |
826 | GNUNET_TESTING_connect_topology (pg, connection_topology, | 833 | GNUNET_TESTING_connect_topology (pg, connection_topology, |
827 | connect_topology_option, | 834 | connect_topology_option, |
828 | connect_topology_option_modifier, | 835 | connect_topology_option_modifier, |
@@ -830,19 +837,19 @@ connect_topology () | |||
830 | connect_attempts, | 837 | connect_attempts, |
831 | &topology_creation_finished, NULL); | 838 | &topology_creation_finished, NULL); |
832 | #if PROGRESS_BARS | 839 | #if PROGRESS_BARS |
833 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 840 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
834 | "Have %d expected connections\n", expected_connections); | 841 | "Have %d expected connections\n", expected_connections); |
835 | #endif | 842 | #endif |
836 | } | 843 | } |
837 | 844 | ||
838 | GNUNET_SCHEDULER_cancel (die_task); | 845 | GNUNET_SCHEDULER_cancel (die_task); |
839 | if (expected_connections < 1) | 846 | if (expected_connections < 1) |
840 | { | 847 | { |
841 | die_task = | 848 | die_task = |
842 | GNUNET_SCHEDULER_add_now (&end_badly, | 849 | GNUNET_SCHEDULER_add_now (&end_badly, |
843 | "from connect topology (bad return)"); | 850 | "from connect topology (bad return)"); |
844 | return; | 851 | return; |
845 | } | 852 | } |
846 | 853 | ||
847 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 854 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
848 | (GNUNET_TIME_UNIT_SECONDS, | 855 | (GNUNET_TIME_UNIT_SECONDS, |
@@ -865,23 +872,22 @@ create_topology () | |||
865 | { | 872 | { |
866 | peers_left = num_peers; /* Reset counter */ | 873 | peers_left = num_peers; /* Reset counter */ |
867 | if (GNUNET_TESTING_create_topology | 874 | if (GNUNET_TESTING_create_topology |
868 | (pg, topology, blacklist_topology, | 875 | (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR) |
869 | blacklist_transports) != GNUNET_SYSERR) | 876 | { |
870 | { | ||
871 | #if PROGRESS_BARS | 877 | #if PROGRESS_BARS |
872 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 878 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
873 | "Topology set up, now starting peers!\n"); | 879 | "Topology set up, now starting peers!\n"); |
874 | fprintf (stdout, "Daemon start progress ["); | 880 | fprintf (stdout, "Daemon start progress ["); |
875 | #endif | 881 | #endif |
876 | GNUNET_TESTING_daemons_continue_startup (pg); | 882 | GNUNET_TESTING_daemons_continue_startup (pg); |
877 | } | 883 | } |
878 | else | 884 | else |
879 | { | 885 | { |
880 | GNUNET_SCHEDULER_cancel (die_task); | 886 | GNUNET_SCHEDULER_cancel (die_task); |
881 | die_task = | 887 | die_task = |
882 | GNUNET_SCHEDULER_add_now (&end_badly, | 888 | GNUNET_SCHEDULER_add_now (&end_badly, |
883 | "from create topology (bad return)"); | 889 | "from create topology (bad return)"); |
884 | } | 890 | } |
885 | GNUNET_SCHEDULER_cancel (die_task); | 891 | GNUNET_SCHEDULER_cancel (die_task); |
886 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 892 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
887 | (GNUNET_TIME_UNIT_SECONDS, | 893 | (GNUNET_TIME_UNIT_SECONDS, |
@@ -898,11 +904,11 @@ peers_started_callback (void *cls, | |||
898 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 904 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
899 | { | 905 | { |
900 | if (emsg != NULL) | 906 | if (emsg != NULL) |
901 | { | 907 | { |
902 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 908 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
903 | "Failed to start daemon with error: `%s'\n", emsg); | 909 | "Failed to start daemon with error: `%s'\n", emsg); |
904 | return; | 910 | return; |
905 | } | 911 | } |
906 | GNUNET_assert (id != NULL); | 912 | GNUNET_assert (id != NULL); |
907 | #if VERBOSE > 1 | 913 | #if VERBOSE > 1 |
908 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n", | 914 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n", |
@@ -910,50 +916,48 @@ peers_started_callback (void *cls, | |||
910 | #endif | 916 | #endif |
911 | #if PROGRESS_BARS | 917 | #if PROGRESS_BARS |
912 | if ((num_peers - peers_left) % modnum == 0) | 918 | if ((num_peers - peers_left) % modnum == 0) |
913 | { | 919 | { |
914 | if (num_peers - peers_left == 0) | 920 | if (num_peers - peers_left == 0) |
915 | fprintf (stdout, "0%%"); | 921 | fprintf (stdout, "0%%"); |
916 | else | 922 | else |
917 | fprintf (stdout, "%d%%", | 923 | fprintf (stdout, "%d%%", |
918 | (int) (((float) (num_peers - peers_left) / | 924 | (int) (((float) (num_peers - peers_left) / num_peers) * 100)); |
919 | num_peers) * 100)); | 925 | |
920 | 926 | } | |
921 | } | ||
922 | else if ((num_peers - peers_left) % dotnum == 0) | 927 | else if ((num_peers - peers_left) % dotnum == 0) |
923 | { | 928 | { |
924 | fprintf (stdout, "."); | 929 | fprintf (stdout, "."); |
925 | } | 930 | } |
926 | fflush (stdout); | 931 | fflush (stdout); |
927 | #endif | 932 | #endif |
928 | peers_left--; | 933 | peers_left--; |
929 | if (peers_left == 0) | 934 | if (peers_left == 0) |
930 | { | 935 | { |
931 | #if PROGRESS_BARS | 936 | #if PROGRESS_BARS |
932 | fprintf (stdout, "100%%]\n"); | 937 | fprintf (stdout, "100%%]\n"); |
933 | #endif | 938 | #endif |
934 | #if VERBOSE | 939 | #if VERBOSE |
935 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 940 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
936 | "All %d daemons started, now connecting peers!\n", | 941 | "All %d daemons started, now connecting peers!\n", num_peers); |
937 | num_peers); | ||
938 | #endif | 942 | #endif |
939 | GNUNET_SCHEDULER_cancel (die_task); | 943 | GNUNET_SCHEDULER_cancel (die_task); |
940 | /* Set up task in case topology creation doesn't finish | 944 | /* Set up task in case topology creation doesn't finish |
941 | * within a reasonable amount of time */ | 945 | * within a reasonable amount of time */ |
942 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 946 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
943 | (GNUNET_TIME_UNIT_MINUTES, 8), | 947 | (GNUNET_TIME_UNIT_MINUTES, 8), |
944 | &end_badly, | 948 | &end_badly, |
945 | "from peers_started_callback"); | 949 | "from peers_started_callback"); |
946 | #if DELAY_FOR_LOGGING | 950 | #if DELAY_FOR_LOGGING |
947 | fprintf (stdout, "Connecting topology in 10 seconds\n"); | 951 | fprintf (stdout, "Connecting topology in 10 seconds\n"); |
948 | gather_log_data (); | 952 | gather_log_data (); |
949 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 953 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
950 | (GNUNET_TIME_UNIT_SECONDS, 10), | 954 | (GNUNET_TIME_UNIT_SECONDS, 10), |
951 | &connect_topology, NULL); | 955 | &connect_topology, NULL); |
952 | #else | 956 | #else |
953 | connect_topology (); | 957 | connect_topology (); |
954 | #endif | 958 | #endif |
955 | ok = 0; | 959 | ok = 0; |
956 | } | 960 | } |
957 | } | 961 | } |
958 | 962 | ||
959 | /** | 963 | /** |
@@ -970,10 +974,10 @@ hostkey_callback (void *cls, | |||
970 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 974 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
971 | { | 975 | { |
972 | if (emsg != NULL) | 976 | if (emsg != NULL) |
973 | { | 977 | { |
974 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 978 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
975 | "Hostkey callback received error: %s\n", emsg); | 979 | "Hostkey callback received error: %s\n", emsg); |
976 | } | 980 | } |
977 | 981 | ||
978 | #if VERBOSE > 1 | 982 | #if VERBOSE > 1 |
979 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 983 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -983,39 +987,37 @@ hostkey_callback (void *cls, | |||
983 | 987 | ||
984 | #if PROGRESS_BARS | 988 | #if PROGRESS_BARS |
985 | if ((num_peers - peers_left) % modnum == 0) | 989 | if ((num_peers - peers_left) % modnum == 0) |
986 | { | 990 | { |
987 | if (num_peers - peers_left == 0) | 991 | if (num_peers - peers_left == 0) |
988 | fprintf (stdout, "0%%"); | 992 | fprintf (stdout, "0%%"); |
989 | else | 993 | else |
990 | fprintf (stdout, "%d%%", | 994 | fprintf (stdout, "%d%%", |
991 | (int) (((float) (num_peers - peers_left) / | 995 | (int) (((float) (num_peers - peers_left) / num_peers) * 100)); |
992 | num_peers) * 100)); | 996 | |
993 | 997 | } | |
994 | } | ||
995 | else if ((num_peers - peers_left) % dotnum == 0) | 998 | else if ((num_peers - peers_left) % dotnum == 0) |
996 | { | 999 | { |
997 | fprintf (stdout, "."); | 1000 | fprintf (stdout, "."); |
998 | } | 1001 | } |
999 | fflush (stdout); | 1002 | fflush (stdout); |
1000 | #endif | 1003 | #endif |
1001 | peers_left--; | 1004 | peers_left--; |
1002 | if (peers_left == 0) | 1005 | if (peers_left == 0) |
1003 | { | 1006 | { |
1004 | #if PROGRESS_BARS | 1007 | #if PROGRESS_BARS |
1005 | fprintf (stdout, "100%%]\n"); | 1008 | fprintf (stdout, "100%%]\n"); |
1006 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1009 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1007 | "All %d hostkeys created, now creating topology!\n", | 1010 | "All %d hostkeys created, now creating topology!\n", num_peers); |
1008 | num_peers); | ||
1009 | #endif | 1011 | #endif |
1010 | GNUNET_SCHEDULER_cancel (die_task); | 1012 | GNUNET_SCHEDULER_cancel (die_task); |
1011 | /* Set up task in case topology creation doesn't finish | 1013 | /* Set up task in case topology creation doesn't finish |
1012 | * within a reasonable amount of time */ | 1014 | * within a reasonable amount of time */ |
1013 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 1015 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
1014 | &end_badly, | 1016 | &end_badly, |
1015 | "from create_topology"); | 1017 | "from create_topology"); |
1016 | GNUNET_SCHEDULER_add_now (&create_topology, NULL); | 1018 | GNUNET_SCHEDULER_add_now (&create_topology, NULL); |
1017 | ok = 0; | 1019 | ok = 0; |
1018 | } | 1020 | } |
1019 | } | 1021 | } |
1020 | 1022 | ||
1021 | static void | 1023 | static void |
@@ -1030,13 +1032,14 @@ run (void *cls, | |||
1030 | char *connect_topology_option_modifier_string; | 1032 | char *connect_topology_option_modifier_string; |
1031 | unsigned long long temp_settle; | 1033 | unsigned long long temp_settle; |
1032 | unsigned long long max_outstanding_connections; | 1034 | unsigned long long max_outstanding_connections; |
1035 | |||
1033 | ok = 1; | 1036 | ok = 1; |
1034 | 1037 | ||
1035 | dotOutFile = fopen (dotOutFileName, "w"); | 1038 | dotOutFile = fopen (dotOutFileName, "w"); |
1036 | if (dotOutFile != NULL) | 1039 | if (dotOutFile != NULL) |
1037 | { | 1040 | { |
1038 | fprintf (dotOutFile, "strict graph G {\n"); | 1041 | fprintf (dotOutFile, "strict graph G {\n"); |
1039 | } | 1042 | } |
1040 | 1043 | ||
1041 | #if VERBOSE | 1044 | #if VERBOSE |
1042 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1045 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1046,21 +1049,21 @@ run (void *cls, | |||
1046 | if (GNUNET_YES != | 1049 | if (GNUNET_YES != |
1047 | GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome", | 1050 | GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome", |
1048 | &test_directory)) | 1051 | &test_directory)) |
1049 | { | 1052 | { |
1050 | ok = 404; | 1053 | ok = 404; |
1051 | return; | 1054 | return; |
1052 | } | 1055 | } |
1053 | 1056 | ||
1054 | if ((GNUNET_YES == | 1057 | if ((GNUNET_YES == |
1055 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology", | 1058 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology", |
1056 | &topology_str)) | 1059 | &topology_str)) |
1057 | && (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str))) | 1060 | && (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str))) |
1058 | { | 1061 | { |
1059 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1062 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1060 | "Invalid topology `%s' given for section %s option %s\n", | 1063 | "Invalid topology `%s' given for section %s option %s\n", |
1061 | topology_str, "TESTING", "TOPOLOGY"); | 1064 | topology_str, "TESTING", "TOPOLOGY"); |
1062 | topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */ | 1065 | topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */ |
1063 | } | 1066 | } |
1064 | 1067 | ||
1065 | if ((GNUNET_YES == | 1068 | if ((GNUNET_YES == |
1066 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", | 1069 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
@@ -1069,11 +1072,11 @@ run (void *cls, | |||
1069 | && (GNUNET_NO == | 1072 | && (GNUNET_NO == |
1070 | GNUNET_TESTING_topology_get (&connection_topology, | 1073 | GNUNET_TESTING_topology_get (&connection_topology, |
1071 | connect_topology_str))) | 1074 | connect_topology_str))) |
1072 | { | 1075 | { |
1073 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1076 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1074 | "Invalid connect topology `%s' given for section %s option %s\n", | 1077 | "Invalid connect topology `%s' given for section %s option %s\n", |
1075 | connect_topology_str, "TESTING", "CONNECT_TOPOLOGY"); | 1078 | connect_topology_str, "TESTING", "CONNECT_TOPOLOGY"); |
1076 | } | 1079 | } |
1077 | GNUNET_free_non_null (connect_topology_str); | 1080 | GNUNET_free_non_null (connect_topology_str); |
1078 | if ((GNUNET_YES == | 1081 | if ((GNUNET_YES == |
1079 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", | 1082 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
@@ -1082,31 +1085,31 @@ run (void *cls, | |||
1082 | && (GNUNET_NO == | 1085 | && (GNUNET_NO == |
1083 | GNUNET_TESTING_topology_option_get (&connect_topology_option, | 1086 | GNUNET_TESTING_topology_option_get (&connect_topology_option, |
1084 | connect_topology_option_str))) | 1087 | connect_topology_option_str))) |
1085 | { | 1088 | { |
1086 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1089 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1087 | "Invalid connect topology option `%s' given for section %s option %s\n", | 1090 | "Invalid connect topology option `%s' given for section %s option %s\n", |
1088 | connect_topology_option_str, "TESTING", | 1091 | connect_topology_option_str, "TESTING", |
1089 | "CONNECT_TOPOLOGY_OPTION"); | 1092 | "CONNECT_TOPOLOGY_OPTION"); |
1090 | connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */ | 1093 | connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */ |
1091 | } | 1094 | } |
1092 | GNUNET_free_non_null (connect_topology_option_str); | 1095 | GNUNET_free_non_null (connect_topology_option_str); |
1093 | if (GNUNET_YES == | 1096 | if (GNUNET_YES == |
1094 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", | 1097 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
1095 | "connect_topology_option_modifier", | 1098 | "connect_topology_option_modifier", |
1096 | &connect_topology_option_modifier_string)) | 1099 | &connect_topology_option_modifier_string)) |
1100 | { | ||
1101 | if (sscanf | ||
1102 | (connect_topology_option_modifier_string, "%lf", | ||
1103 | &connect_topology_option_modifier) != 1) | ||
1097 | { | 1104 | { |
1098 | if (sscanf | 1105 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1099 | (connect_topology_option_modifier_string, "%lf", | 1106 | _ |
1100 | &connect_topology_option_modifier) != 1) | 1107 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
1101 | { | 1108 | connect_topology_option_modifier_string, |
1102 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1109 | "connect_topology_option_modifier", "TESTING"); |
1103 | _ | ||
1104 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | ||
1105 | connect_topology_option_modifier_string, | ||
1106 | "connect_topology_option_modifier", "TESTING"); | ||
1107 | } | ||
1108 | GNUNET_free (connect_topology_option_modifier_string); | ||
1109 | } | 1110 | } |
1111 | GNUNET_free (connect_topology_option_modifier_string); | ||
1112 | } | ||
1110 | 1113 | ||
1111 | if (GNUNET_YES != | 1114 | if (GNUNET_YES != |
1112 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", | 1115 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
@@ -1121,11 +1124,11 @@ run (void *cls, | |||
1121 | && (GNUNET_NO == | 1124 | && (GNUNET_NO == |
1122 | GNUNET_TESTING_topology_get (&blacklist_topology, | 1125 | GNUNET_TESTING_topology_get (&blacklist_topology, |
1123 | blacklist_topology_str))) | 1126 | blacklist_topology_str))) |
1124 | { | 1127 | { |
1125 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1128 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1126 | "Invalid topology `%s' given for section %s option %s\n", | 1129 | "Invalid topology `%s' given for section %s option %s\n", |
1127 | topology_str, "TESTING", "BLACKLIST_TOPOLOGY"); | 1130 | topology_str, "TESTING", "BLACKLIST_TOPOLOGY"); |
1128 | } | 1131 | } |
1129 | GNUNET_free_non_null (topology_str); | 1132 | GNUNET_free_non_null (topology_str); |
1130 | GNUNET_free_non_null (blacklist_topology_str); | 1133 | GNUNET_free_non_null (blacklist_topology_str); |
1131 | 1134 | ||
@@ -1133,35 +1136,39 @@ run (void *cls, | |||
1133 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "settle_time", | 1136 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "settle_time", |
1134 | &temp_settle)) | 1137 | &temp_settle)) |
1135 | settle_time = | 1138 | settle_time = |
1136 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle); | 1139 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle); |
1137 | 1140 | ||
1138 | if (GNUNET_OK == | 1141 | if (GNUNET_OK == |
1139 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_timeout", | 1142 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_timeout", |
1140 | &temp_settle)) | 1143 | &temp_settle)) |
1141 | connect_timeout = | 1144 | connect_timeout = |
1142 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle); | 1145 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle); |
1143 | else | 1146 | else |
1144 | { | 1147 | { |
1145 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", "testing", "connect_timeout"); | 1148 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", |
1146 | return; | 1149 | "testing", "connect_timeout"); |
1147 | } | 1150 | return; |
1151 | } | ||
1148 | 1152 | ||
1149 | 1153 | ||
1150 | if (GNUNET_OK != | 1154 | if (GNUNET_OK != |
1151 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_attempts", | 1155 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_attempts", |
1152 | &connect_attempts)) | 1156 | &connect_attempts)) |
1153 | { | 1157 | { |
1154 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", "testing", "connect_attempts"); | 1158 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", |
1155 | return; | 1159 | "testing", "connect_attempts"); |
1156 | } | 1160 | return; |
1161 | } | ||
1157 | 1162 | ||
1158 | if (GNUNET_OK != | 1163 | if (GNUNET_OK != |
1159 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "max_outstanding_connections", | 1164 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", |
1160 | &max_outstanding_connections)) | 1165 | "max_outstanding_connections", |
1161 | { | 1166 | &max_outstanding_connections)) |
1162 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", "testing", "max_outstanding_connections"); | 1167 | { |
1163 | return; | 1168 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", |
1164 | } | 1169 | "testing", "max_outstanding_connections"); |
1170 | return; | ||
1171 | } | ||
1165 | 1172 | ||
1166 | if (GNUNET_SYSERR == | 1173 | if (GNUNET_SYSERR == |
1167 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers", | 1174 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers", |
@@ -1182,11 +1189,11 @@ run (void *cls, | |||
1182 | #endif | 1189 | #endif |
1183 | /* Set up a task to end testing if peer start fails */ | 1190 | /* Set up a task to end testing if peer start fails */ |
1184 | die_task = | 1191 | die_task = |
1185 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 1192 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
1186 | (GNUNET_TIME_UNIT_SECONDS, | 1193 | (GNUNET_TIME_UNIT_SECONDS, |
1187 | SECONDS_PER_PEER_START * num_peers), | 1194 | SECONDS_PER_PEER_START * num_peers), |
1188 | &end_badly, | 1195 | &end_badly, |
1189 | "didn't generate all hostkeys within a reasonable amount of time!!!"); | 1196 | "didn't generate all hostkeys within a reasonable amount of time!!!"); |
1190 | 1197 | ||
1191 | GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1); | 1198 | GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1); |
1192 | pg = GNUNET_TESTING_daemons_start (cfg, | 1199 | pg = GNUNET_TESTING_daemons_start (cfg, |
@@ -1207,10 +1214,12 @@ check () | |||
1207 | { | 1214 | { |
1208 | char *binary_name; | 1215 | char *binary_name; |
1209 | char *config_file_name; | 1216 | char *config_file_name; |
1217 | |||
1210 | GNUNET_asprintf (&binary_name, "test-testing-topology-%s", topology_string); | 1218 | GNUNET_asprintf (&binary_name, "test-testing-topology-%s", topology_string); |
1211 | GNUNET_asprintf (&config_file_name, "test_testing_data_topology_%s.conf", | 1219 | GNUNET_asprintf (&config_file_name, "test_testing_data_topology_%s.conf", |
1212 | topology_string); | 1220 | topology_string); |
1213 | int ret; | 1221 | int ret; |
1222 | |||
1214 | char *const argv[] = { binary_name, | 1223 | char *const argv[] = { binary_name, |
1215 | "-c", | 1224 | "-c", |
1216 | config_file_name, | 1225 | config_file_name, |
@@ -1225,11 +1234,11 @@ check () | |||
1225 | ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 1234 | ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
1226 | argv, binary_name, "nohelp", options, &run, &ok); | 1235 | argv, binary_name, "nohelp", options, &run, &ok); |
1227 | if (ret != GNUNET_OK) | 1236 | if (ret != GNUNET_OK) |
1228 | { | 1237 | { |
1229 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1238 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1230 | "`test-testing-topology-%s': Failed with error code %d\n", | 1239 | "`test-testing-topology-%s': Failed with error code %d\n", |
1231 | topology_string, ret); | 1240 | topology_string, ret); |
1232 | } | 1241 | } |
1233 | GNUNET_free (binary_name); | 1242 | GNUNET_free (binary_name); |
1234 | GNUNET_free (config_file_name); | 1243 | GNUNET_free (config_file_name); |
1235 | return ok; | 1244 | return ok; |
@@ -1273,10 +1282,10 @@ main (int argc, char *argv[]) | |||
1273 | * of by the testing framework. | 1282 | * of by the testing framework. |
1274 | */ | 1283 | */ |
1275 | if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) | 1284 | if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) |
1276 | { | 1285 | { |
1277 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1286 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1278 | "Failed to remove testing directory %s\n", test_directory); | 1287 | "Failed to remove testing directory %s\n", test_directory); |
1279 | } | 1288 | } |
1280 | GNUNET_free (our_binary_name); | 1289 | GNUNET_free (our_binary_name); |
1281 | return ret; | 1290 | return ret; |
1282 | } | 1291 | } |
diff --git a/src/testing/test_testing_topology_blacklist.c b/src/testing/test_testing_topology_blacklist.c index ea32e339d..f9185b6fc 100644 --- a/src/testing/test_testing_topology_blacklist.c +++ b/src/testing/test_testing_topology_blacklist.c | |||
@@ -106,20 +106,19 @@ void | |||
106 | shutdown_callback (void *cls, const char *emsg) | 106 | shutdown_callback (void *cls, const char *emsg) |
107 | { | 107 | { |
108 | if (emsg != NULL) | 108 | if (emsg != NULL) |
109 | { | 109 | { |
110 | #if VERBOSE | 110 | #if VERBOSE |
111 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n"); | 111 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n"); |
112 | #endif | 112 | #endif |
113 | if (ok == 0) | 113 | if (ok == 0) |
114 | ok = 666; | 114 | ok = 666; |
115 | } | 115 | } |
116 | else | 116 | else |
117 | { | 117 | { |
118 | #if VERBOSE | 118 | #if VERBOSE |
119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n"); |
120 | "All peers successfully shut down!\n"); | ||
121 | #endif | 120 | #endif |
122 | } | 121 | } |
123 | } | 122 | } |
124 | 123 | ||
125 | static void | 124 | static void |
@@ -140,10 +139,10 @@ finish_testing () | |||
140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "daemons_stop finished\n"); | 139 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "daemons_stop finished\n"); |
141 | #endif | 140 | #endif |
142 | if (dotOutFile != NULL) | 141 | if (dotOutFile != NULL) |
143 | { | 142 | { |
144 | fprintf (dotOutFile, "}"); | 143 | fprintf (dotOutFile, "}"); |
145 | fclose (dotOutFile); | 144 | fclose (dotOutFile); |
146 | } | 145 | } |
147 | 146 | ||
148 | ok = 0; | 147 | ok = 0; |
149 | } | 148 | } |
@@ -152,22 +151,23 @@ static void | |||
152 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 151 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
153 | { | 152 | { |
154 | char *msg = cls; | 153 | char *msg = cls; |
154 | |||
155 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 155 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
156 | "End badly was called (%s)... stopping daemons.\n", msg); | 156 | "End badly was called (%s)... stopping daemons.\n", msg); |
157 | 157 | ||
158 | if (pg != NULL) | 158 | if (pg != NULL) |
159 | { | 159 | { |
160 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 160 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
161 | ok = 7331; /* Opposite of leet */ | 161 | ok = 7331; /* Opposite of leet */ |
162 | } | 162 | } |
163 | else | 163 | else |
164 | ok = 401; /* Never got peers started */ | 164 | ok = 401; /* Never got peers started */ |
165 | 165 | ||
166 | if (dotOutFile != NULL) | 166 | if (dotOutFile != NULL) |
167 | { | 167 | { |
168 | fprintf (dotOutFile, "}"); | 168 | fprintf (dotOutFile, "}"); |
169 | fclose (dotOutFile); | 169 | fclose (dotOutFile); |
170 | } | 170 | } |
171 | } | 171 | } |
172 | 172 | ||
173 | 173 | ||
@@ -184,70 +184,70 @@ topology_callback (void *cls, | |||
184 | const char *emsg) | 184 | const char *emsg) |
185 | { | 185 | { |
186 | if (emsg == NULL) | 186 | if (emsg == NULL) |
187 | { | 187 | { |
188 | total_connections++; | 188 | total_connections++; |
189 | #if VERBOSE | 189 | #if VERBOSE |
190 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s\n", | 190 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s\n", |
191 | first_daemon->shortname, second_daemon->shortname); | 191 | first_daemon->shortname, second_daemon->shortname); |
192 | #endif | 192 | #endif |
193 | if (dotOutFile != NULL) | 193 | if (dotOutFile != NULL) |
194 | fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname, | 194 | fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname, |
195 | second_daemon->shortname); | 195 | second_daemon->shortname); |
196 | } | 196 | } |
197 | 197 | ||
198 | else | 198 | else |
199 | { | 199 | { |
200 | failed_connections++; | 200 | failed_connections++; |
201 | #if VERBOSE | 201 | #if VERBOSE |
202 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 202 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
203 | "Failed to connect peer %s to peer %s with error :\n%s\n", | 203 | "Failed to connect peer %s to peer %s with error :\n%s\n", |
204 | first_daemon->shortname, second_daemon->shortname, emsg); | 204 | first_daemon->shortname, second_daemon->shortname, emsg); |
205 | #endif | 205 | #endif |
206 | } | 206 | } |
207 | 207 | ||
208 | 208 | ||
209 | if (total_connections == expected_connections) | 209 | if (total_connections == expected_connections) |
210 | { | 210 | { |
211 | #if VERBOSE | 211 | #if VERBOSE |
212 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 212 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
213 | "Created %d total connections, which is our target number (that's bad)!\n", | 213 | "Created %d total connections, which is our target number (that's bad)!\n", |
214 | total_connections); | 214 | total_connections); |
215 | #endif | 215 | #endif |
216 | 216 | ||
217 | GNUNET_SCHEDULER_cancel (die_task); | 217 | GNUNET_SCHEDULER_cancel (die_task); |
218 | die_task = GNUNET_SCHEDULER_NO_TASK; | 218 | die_task = GNUNET_SCHEDULER_NO_TASK; |
219 | die_task = | 219 | die_task = |
220 | GNUNET_SCHEDULER_add_now (&end_badly, | 220 | GNUNET_SCHEDULER_add_now (&end_badly, |
221 | "from topology_callback (too many successful connections)"); | 221 | "from topology_callback (too many successful connections)"); |
222 | } | 222 | } |
223 | else if (total_connections + failed_connections == expected_connections) | 223 | else if (total_connections + failed_connections == expected_connections) |
224 | { | ||
225 | if ((failed_connections == expected_failed_connections) | ||
226 | && (total_connections == | ||
227 | expected_connections - expected_failed_connections)) | ||
228 | { | ||
229 | GNUNET_SCHEDULER_cancel (die_task); | ||
230 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
231 | die_task = GNUNET_SCHEDULER_add_now (&finish_testing, NULL); | ||
232 | } | ||
233 | else | ||
224 | { | 234 | { |
225 | if ((failed_connections == expected_failed_connections) | 235 | GNUNET_SCHEDULER_cancel (die_task); |
226 | && (total_connections == | 236 | die_task = |
227 | expected_connections - expected_failed_connections)) | 237 | GNUNET_SCHEDULER_add_now (&end_badly, |
228 | { | 238 | "from topology_callback (wrong number of failed connections)"); |
229 | GNUNET_SCHEDULER_cancel (die_task); | ||
230 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
231 | die_task = GNUNET_SCHEDULER_add_now (&finish_testing, NULL); | ||
232 | } | ||
233 | else | ||
234 | { | ||
235 | GNUNET_SCHEDULER_cancel (die_task); | ||
236 | die_task = | ||
237 | GNUNET_SCHEDULER_add_now (&end_badly, | ||
238 | "from topology_callback (wrong number of failed connections)"); | ||
239 | } | ||
240 | } | 239 | } |
240 | } | ||
241 | else | 241 | else |
242 | { | 242 | { |
243 | #if VERBOSE | 243 | #if VERBOSE |
244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
245 | "Have %d total connections, %d failed connections, Want %d (failed) and %d (successful)\n", | 245 | "Have %d total connections, %d failed connections, Want %d (failed) and %d (successful)\n", |
246 | total_connections, failed_connections, | 246 | total_connections, failed_connections, |
247 | expected_failed_connections, | 247 | expected_failed_connections, |
248 | expected_connections - expected_failed_connections); | 248 | expected_connections - expected_failed_connections); |
249 | #endif | 249 | #endif |
250 | } | 250 | } |
251 | } | 251 | } |
252 | 252 | ||
253 | static void | 253 | static void |
@@ -255,27 +255,26 @@ connect_topology () | |||
255 | { | 255 | { |
256 | expected_connections = -1; | 256 | expected_connections = -1; |
257 | if ((pg != NULL) && (peers_left == 0)) | 257 | if ((pg != NULL) && (peers_left == 0)) |
258 | { | 258 | { |
259 | expected_connections = | 259 | expected_connections = |
260 | GNUNET_TESTING_connect_topology (pg, connection_topology, | 260 | GNUNET_TESTING_connect_topology (pg, connection_topology, |
261 | connect_topology_option, | 261 | connect_topology_option, |
262 | connect_topology_option_modifier, | 262 | connect_topology_option_modifier, |
263 | connect_timeout, | 263 | connect_timeout, |
264 | connect_attempts, | 264 | connect_attempts, NULL, NULL); |
265 | NULL, NULL); | ||
266 | #if VERBOSE | 265 | #if VERBOSE |
267 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 266 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
268 | "Have %d expected connections\n", expected_connections); | 267 | "Have %d expected connections\n", expected_connections); |
269 | #endif | 268 | #endif |
270 | } | 269 | } |
271 | 270 | ||
272 | GNUNET_SCHEDULER_cancel (die_task); | 271 | GNUNET_SCHEDULER_cancel (die_task); |
273 | if (expected_connections == GNUNET_SYSERR) | 272 | if (expected_connections == GNUNET_SYSERR) |
274 | { | 273 | { |
275 | die_task = | 274 | die_task = |
276 | GNUNET_SCHEDULER_add_now (&end_badly, | 275 | GNUNET_SCHEDULER_add_now (&end_badly, |
277 | "from connect topology (bad return)"); | 276 | "from connect topology (bad return)"); |
278 | } | 277 | } |
279 | 278 | ||
280 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, | 279 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, |
281 | &end_badly, | 280 | &end_badly, |
@@ -287,22 +286,21 @@ create_topology () | |||
287 | { | 286 | { |
288 | peers_left = num_peers; /* Reset counter */ | 287 | peers_left = num_peers; /* Reset counter */ |
289 | if (GNUNET_TESTING_create_topology | 288 | if (GNUNET_TESTING_create_topology |
290 | (pg, topology, blacklist_topology, | 289 | (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR) |
291 | blacklist_transports) != GNUNET_SYSERR) | 290 | { |
292 | { | ||
293 | #if VERBOSE | 291 | #if VERBOSE |
294 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
295 | "Topology set up, now starting peers!\n"); | 293 | "Topology set up, now starting peers!\n"); |
296 | #endif | 294 | #endif |
297 | GNUNET_TESTING_daemons_continue_startup (pg); | 295 | GNUNET_TESTING_daemons_continue_startup (pg); |
298 | } | 296 | } |
299 | else | 297 | else |
300 | { | 298 | { |
301 | GNUNET_SCHEDULER_cancel (die_task); | 299 | GNUNET_SCHEDULER_cancel (die_task); |
302 | die_task = | 300 | die_task = |
303 | GNUNET_SCHEDULER_add_now (&end_badly, | 301 | GNUNET_SCHEDULER_add_now (&end_badly, |
304 | "from create topology (bad return)"); | 302 | "from create topology (bad return)"); |
305 | } | 303 | } |
306 | GNUNET_SCHEDULER_cancel (die_task); | 304 | GNUNET_SCHEDULER_cancel (die_task); |
307 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, | 305 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, |
308 | &end_badly, | 306 | &end_badly, |
@@ -317,11 +315,11 @@ peers_started_callback (void *cls, | |||
317 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 315 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
318 | { | 316 | { |
319 | if (emsg != NULL) | 317 | if (emsg != NULL) |
320 | { | 318 | { |
321 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
322 | "Failed to start daemon with error: `%s'\n", emsg); | 320 | "Failed to start daemon with error: `%s'\n", emsg); |
323 | return; | 321 | return; |
324 | } | 322 | } |
325 | GNUNET_assert (id != NULL); | 323 | GNUNET_assert (id != NULL); |
326 | #if VERBOSE | 324 | #if VERBOSE |
327 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n", | 325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n", |
@@ -329,22 +327,21 @@ peers_started_callback (void *cls, | |||
329 | #endif | 327 | #endif |
330 | peers_left--; | 328 | peers_left--; |
331 | if (peers_left == 0) | 329 | if (peers_left == 0) |
332 | { | 330 | { |
333 | #if VERBOSE | 331 | #if VERBOSE |
334 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 332 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
335 | "All %d daemons started, now creating topology!\n", | 333 | "All %d daemons started, now creating topology!\n", num_peers); |
336 | num_peers); | ||
337 | #endif | 334 | #endif |
338 | GNUNET_SCHEDULER_cancel (die_task); | 335 | GNUNET_SCHEDULER_cancel (die_task); |
339 | /* Set up task in case topology creation doesn't finish | 336 | /* Set up task in case topology creation doesn't finish |
340 | * within a reasonable amount of time */ | 337 | * within a reasonable amount of time */ |
341 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 338 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
342 | (GNUNET_TIME_UNIT_MINUTES, 5), | 339 | (GNUNET_TIME_UNIT_MINUTES, 5), |
343 | &end_badly, | 340 | &end_badly, |
344 | "from peers_started_callback"); | 341 | "from peers_started_callback"); |
345 | connect_topology (); | 342 | connect_topology (); |
346 | ok = 0; | 343 | ok = 0; |
347 | } | 344 | } |
348 | } | 345 | } |
349 | 346 | ||
350 | /** | 347 | /** |
@@ -361,10 +358,10 @@ hostkey_callback (void *cls, | |||
361 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 358 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
362 | { | 359 | { |
363 | if (emsg != NULL) | 360 | if (emsg != NULL) |
364 | { | 361 | { |
365 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 362 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
366 | "Hostkey callback received error: %s\n", emsg); | 363 | "Hostkey callback received error: %s\n", emsg); |
367 | } | 364 | } |
368 | 365 | ||
369 | #if VERBOSE | 366 | #if VERBOSE |
370 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 367 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -372,22 +369,21 @@ hostkey_callback (void *cls, | |||
372 | #endif | 369 | #endif |
373 | peers_left--; | 370 | peers_left--; |
374 | if (peers_left == 0) | 371 | if (peers_left == 0) |
375 | { | 372 | { |
376 | #if VERBOSE | 373 | #if VERBOSE |
377 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 374 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
378 | "All %d hostkeys created, now creating topology!\n", | 375 | "All %d hostkeys created, now creating topology!\n", num_peers); |
379 | num_peers); | ||
380 | #endif | 376 | #endif |
381 | GNUNET_SCHEDULER_cancel (die_task); | 377 | GNUNET_SCHEDULER_cancel (die_task); |
382 | /* Set up task in case topology creation doesn't finish | 378 | /* Set up task in case topology creation doesn't finish |
383 | * within a reasonable amount of time */ | 379 | * within a reasonable amount of time */ |
384 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 380 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
385 | (GNUNET_TIME_UNIT_MINUTES, 5), | 381 | (GNUNET_TIME_UNIT_MINUTES, 5), |
386 | &end_badly, | 382 | &end_badly, |
387 | "from hostkey_callback"); | 383 | "from hostkey_callback"); |
388 | GNUNET_SCHEDULER_add_now (&create_topology, NULL); | 384 | GNUNET_SCHEDULER_add_now (&create_topology, NULL); |
389 | ok = 0; | 385 | ok = 0; |
390 | } | 386 | } |
391 | } | 387 | } |
392 | 388 | ||
393 | static void | 389 | static void |
@@ -401,13 +397,14 @@ run (void *cls, | |||
401 | unsigned long long connect_topology_option_num; | 397 | unsigned long long connect_topology_option_num; |
402 | unsigned long long temp_connect; | 398 | unsigned long long temp_connect; |
403 | char *connect_topology_option_modifier_string; | 399 | char *connect_topology_option_modifier_string; |
400 | |||
404 | ok = 1; | 401 | ok = 1; |
405 | 402 | ||
406 | dotOutFile = fopen (dotOutFileName, "w"); | 403 | dotOutFile = fopen (dotOutFileName, "w"); |
407 | if (dotOutFile != NULL) | 404 | if (dotOutFile != NULL) |
408 | { | 405 | { |
409 | fprintf (dotOutFile, "strict graph G {\n"); | 406 | fprintf (dotOutFile, "strict graph G {\n"); |
410 | } | 407 | } |
411 | 408 | ||
412 | #if VERBOSE | 409 | #if VERBOSE |
413 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 410 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -417,14 +414,14 @@ run (void *cls, | |||
417 | if (GNUNET_YES != | 414 | if (GNUNET_YES != |
418 | GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome", | 415 | GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome", |
419 | &test_directory)) | 416 | &test_directory)) |
417 | { | ||
418 | ok = 404; | ||
419 | if (dotOutFile != NULL) | ||
420 | { | 420 | { |
421 | ok = 404; | 421 | fclose (dotOutFile); |
422 | if (dotOutFile != NULL) | ||
423 | { | ||
424 | fclose (dotOutFile); | ||
425 | } | ||
426 | return; | ||
427 | } | 422 | } |
423 | return; | ||
424 | } | ||
428 | 425 | ||
429 | if (GNUNET_YES == | 426 | if (GNUNET_YES == |
430 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "topology", | 427 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "topology", |
@@ -447,41 +444,41 @@ run (void *cls, | |||
447 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", | 444 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
448 | "connect_topology_option_modifier", | 445 | "connect_topology_option_modifier", |
449 | &connect_topology_option_modifier_string)) | 446 | &connect_topology_option_modifier_string)) |
447 | { | ||
448 | if (sscanf | ||
449 | (connect_topology_option_modifier_string, "%lf", | ||
450 | &connect_topology_option_modifier) != 1) | ||
450 | { | 451 | { |
451 | if (sscanf | 452 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
452 | (connect_topology_option_modifier_string, "%lf", | 453 | _ |
453 | &connect_topology_option_modifier) != 1) | 454 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
454 | { | 455 | connect_topology_option_modifier_string, |
455 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 456 | "connect_topology_option_modifier", "TESTING"); |
456 | _ | ||
457 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | ||
458 | connect_topology_option_modifier_string, | ||
459 | "connect_topology_option_modifier", "TESTING"); | ||
460 | GNUNET_free (connect_topology_option_modifier_string); | ||
461 | ok = 707; | ||
462 | if (dotOutFile != NULL) | ||
463 | { | ||
464 | fclose (dotOutFile); | ||
465 | } | ||
466 | return; | ||
467 | } | ||
468 | GNUNET_free (connect_topology_option_modifier_string); | 457 | GNUNET_free (connect_topology_option_modifier_string); |
458 | ok = 707; | ||
459 | if (dotOutFile != NULL) | ||
460 | { | ||
461 | fclose (dotOutFile); | ||
462 | } | ||
463 | return; | ||
469 | } | 464 | } |
465 | GNUNET_free (connect_topology_option_modifier_string); | ||
466 | } | ||
470 | 467 | ||
471 | if (GNUNET_OK != | 468 | if (GNUNET_OK != |
472 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", | 469 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
473 | "blacklist_transports", | 470 | "blacklist_transports", |
474 | &blacklist_transports)) | 471 | &blacklist_transports)) |
472 | { | ||
473 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
474 | "No transports specified for blacklisting in blacklist testcase (this shouldn't happen!)\n"); | ||
475 | ok = 808; | ||
476 | if (dotOutFile != NULL) | ||
475 | { | 477 | { |
476 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 478 | fclose (dotOutFile); |
477 | "No transports specified for blacklisting in blacklist testcase (this shouldn't happen!)\n"); | ||
478 | ok = 808; | ||
479 | if (dotOutFile != NULL) | ||
480 | { | ||
481 | fclose (dotOutFile); | ||
482 | } | ||
483 | return; | ||
484 | } | 479 | } |
480 | return; | ||
481 | } | ||
485 | 482 | ||
486 | if (GNUNET_YES == | 483 | if (GNUNET_YES == |
487 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", | 484 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", |
@@ -498,21 +495,23 @@ run (void *cls, | |||
498 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_timeout", | 495 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_timeout", |
499 | &temp_connect)) | 496 | &temp_connect)) |
500 | connect_timeout = | 497 | connect_timeout = |
501 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_connect); | 498 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_connect); |
502 | else | 499 | else |
503 | { | 500 | { |
504 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", "testing", "connect_timeout"); | 501 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", |
505 | return; | 502 | "testing", "connect_timeout"); |
506 | } | 503 | return; |
504 | } | ||
507 | 505 | ||
508 | 506 | ||
509 | if (GNUNET_OK != | 507 | if (GNUNET_OK != |
510 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_attempts", | 508 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_attempts", |
511 | &connect_attempts)) | 509 | &connect_attempts)) |
512 | { | 510 | { |
513 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", "testing", "connect_attempts"); | 511 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", |
514 | return; | 512 | "testing", "connect_attempts"); |
515 | } | 513 | return; |
514 | } | ||
516 | 515 | ||
517 | main_cfg = cfg; | 516 | main_cfg = cfg; |
518 | 517 | ||
@@ -546,6 +545,7 @@ static int | |||
546 | check () | 545 | check () |
547 | { | 546 | { |
548 | int ret; | 547 | int ret; |
548 | |||
549 | char *const argv[] = { "test-testing-topology-blacklist", | 549 | char *const argv[] = { "test-testing-topology-blacklist", |
550 | "-c", | 550 | "-c", |
551 | "test_testing_data_topology_blacklist.conf", | 551 | "test_testing_data_topology_blacklist.conf", |
@@ -561,11 +561,11 @@ check () | |||
561 | argv, "test-testing-topology-blacklist", "nohelp", | 561 | argv, "test-testing-topology-blacklist", "nohelp", |
562 | options, &run, &ok); | 562 | options, &run, &ok); |
563 | if (ret != GNUNET_OK) | 563 | if (ret != GNUNET_OK) |
564 | { | 564 | { |
565 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 565 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
566 | "`test-testing-topology-blacklist': Failed with error code %d\n", | 566 | "`test-testing-topology-blacklist': Failed with error code %d\n", |
567 | ret); | 567 | ret); |
568 | } | 568 | } |
569 | 569 | ||
570 | return ok; | 570 | return ok; |
571 | } | 571 | } |
@@ -589,14 +589,13 @@ main (int argc, char *argv[]) | |||
589 | * of by the testing framework. | 589 | * of by the testing framework. |
590 | */ | 590 | */ |
591 | if (test_directory != NULL) | 591 | if (test_directory != NULL) |
592 | { | ||
593 | if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) | ||
592 | { | 594 | { |
593 | if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) | 595 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
594 | { | 596 | "Failed to remove testing directory %s\n", test_directory); |
595 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
596 | "Failed to remove testing directory %s\n", | ||
597 | test_directory); | ||
598 | } | ||
599 | } | 597 | } |
598 | } | ||
600 | 599 | ||
601 | return ret; | 600 | return ret; |
602 | } | 601 | } |
diff --git a/src/testing/test_testing_topology_churn.c b/src/testing/test_testing_topology_churn.c index b92288199..ee800c52c 100644 --- a/src/testing/test_testing_topology_churn.c +++ b/src/testing/test_testing_topology_churn.c | |||
@@ -79,20 +79,19 @@ void | |||
79 | shutdown_callback (void *cls, const char *emsg) | 79 | shutdown_callback (void *cls, const char *emsg) |
80 | { | 80 | { |
81 | if (emsg != NULL) | 81 | if (emsg != NULL) |
82 | { | 82 | { |
83 | #if VERBOSE | 83 | #if VERBOSE |
84 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n"); | 84 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n"); |
85 | #endif | 85 | #endif |
86 | if (ok == 0) | 86 | if (ok == 0) |
87 | ok = 666; | 87 | ok = 666; |
88 | } | 88 | } |
89 | else | 89 | else |
90 | { | 90 | { |
91 | #if VERBOSE | 91 | #if VERBOSE |
92 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 92 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n"); |
93 | "All peers successfully shut down!\n"); | ||
94 | #endif | 93 | #endif |
95 | } | 94 | } |
96 | } | 95 | } |
97 | 96 | ||
98 | static void | 97 | static void |
@@ -123,14 +122,15 @@ static void | |||
123 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 122 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
124 | { | 123 | { |
125 | char *msg = cls; | 124 | char *msg = cls; |
125 | |||
126 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 126 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
127 | "End badly was called (%s)... stopping daemons.\n", msg); | 127 | "End badly was called (%s)... stopping daemons.\n", msg); |
128 | 128 | ||
129 | if (pg != NULL) | 129 | if (pg != NULL) |
130 | { | 130 | { |
131 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 131 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
132 | ok = 7331; /* Opposite of leet */ | 132 | ok = 7331; /* Opposite of leet */ |
133 | } | 133 | } |
134 | else | 134 | else |
135 | ok = 401; /* Never got peers started */ | 135 | ok = 401; /* Never got peers started */ |
136 | 136 | ||
@@ -154,18 +154,18 @@ void | |||
154 | churn_callback (void *cls, const char *emsg) | 154 | churn_callback (void *cls, const char *emsg) |
155 | { | 155 | { |
156 | if (emsg == NULL) | 156 | if (emsg == NULL) |
157 | { | 157 | { |
158 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Successfully churned peers!\n", | 158 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Successfully churned peers!\n", |
159 | emsg); | 159 | emsg); |
160 | GNUNET_SCHEDULER_add_now (churn_ctx.next_task, NULL); | 160 | GNUNET_SCHEDULER_add_now (churn_ctx.next_task, NULL); |
161 | } | 161 | } |
162 | else | 162 | else |
163 | { | 163 | { |
164 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 164 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
165 | "Failed to churn peers with error `%s'\n", emsg); | 165 | "Failed to churn peers with error `%s'\n", emsg); |
166 | GNUNET_SCHEDULER_cancel (die_task); | 166 | GNUNET_SCHEDULER_cancel (die_task); |
167 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 167 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); |
168 | } | 168 | } |
169 | } | 169 | } |
170 | 170 | ||
171 | 171 | ||
@@ -204,11 +204,11 @@ peers_started_callback (void *cls, | |||
204 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 204 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
205 | { | 205 | { |
206 | if (emsg != NULL) | 206 | if (emsg != NULL) |
207 | { | 207 | { |
208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
209 | "Failed to start daemon with error: `%s'\n", emsg); | 209 | "Failed to start daemon with error: `%s'\n", emsg); |
210 | return; | 210 | return; |
211 | } | 211 | } |
212 | GNUNET_assert (id != NULL); | 212 | GNUNET_assert (id != NULL); |
213 | #if VERBOSE | 213 | #if VERBOSE |
214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n", | 214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n", |
@@ -216,21 +216,21 @@ peers_started_callback (void *cls, | |||
216 | #endif | 216 | #endif |
217 | peers_left--; | 217 | peers_left--; |
218 | if (peers_left == 0) | 218 | if (peers_left == 0) |
219 | { | 219 | { |
220 | #if VERBOSE | 220 | #if VERBOSE |
221 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 221 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
222 | "All %d daemons started, now testing churn!\n", num_peers); | 222 | "All %d daemons started, now testing churn!\n", num_peers); |
223 | #endif | 223 | #endif |
224 | GNUNET_SCHEDULER_cancel (die_task); | 224 | GNUNET_SCHEDULER_cancel (die_task); |
225 | /* Set up task in case topology creation doesn't finish | 225 | /* Set up task in case topology creation doesn't finish |
226 | * within a reasonable amount of time */ | 226 | * within a reasonable amount of time */ |
227 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 227 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
228 | (GNUNET_TIME_UNIT_MINUTES, 5), | 228 | (GNUNET_TIME_UNIT_MINUTES, 5), |
229 | &end_badly, | 229 | &end_badly, |
230 | "from peers_started_callback"); | 230 | "from peers_started_callback"); |
231 | churn_peers_off (); | 231 | churn_peers_off (); |
232 | ok = 0; | 232 | ok = 0; |
233 | } | 233 | } |
234 | } | 234 | } |
235 | 235 | ||
236 | 236 | ||
@@ -249,10 +249,10 @@ run (void *cls, | |||
249 | if (GNUNET_YES != | 249 | if (GNUNET_YES != |
250 | GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome", | 250 | GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome", |
251 | &test_directory)) | 251 | &test_directory)) |
252 | { | 252 | { |
253 | ok = 404; | 253 | ok = 404; |
254 | return; | 254 | return; |
255 | } | 255 | } |
256 | 256 | ||
257 | if (GNUNET_SYSERR == | 257 | if (GNUNET_SYSERR == |
258 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers", | 258 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers", |
@@ -293,6 +293,7 @@ static int | |||
293 | check () | 293 | check () |
294 | { | 294 | { |
295 | int ret; | 295 | int ret; |
296 | |||
296 | char *const argv[] = { "test-testing-topology-churn", | 297 | char *const argv[] = { "test-testing-topology-churn", |
297 | "-c", | 298 | "-c", |
298 | "test_testing_data_topology_churn.conf", | 299 | "test_testing_data_topology_churn.conf", |
@@ -308,11 +309,11 @@ check () | |||
308 | argv, "test-testing-topology-churn", "nohelp", | 309 | argv, "test-testing-topology-churn", "nohelp", |
309 | options, &run, &ok); | 310 | options, &run, &ok); |
310 | if (ret != GNUNET_OK) | 311 | if (ret != GNUNET_OK) |
311 | { | 312 | { |
312 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 313 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
313 | "`test-testing-topology-churn': Failed with error code %d\n", | 314 | "`test-testing-topology-churn': Failed with error code %d\n", |
314 | ret); | 315 | ret); |
315 | } | 316 | } |
316 | 317 | ||
317 | return ok; | 318 | return ok; |
318 | } | 319 | } |
@@ -336,14 +337,13 @@ main (int argc, char *argv[]) | |||
336 | * of by the testing framework. | 337 | * of by the testing framework. |
337 | */ | 338 | */ |
338 | if (test_directory != NULL) | 339 | if (test_directory != NULL) |
340 | { | ||
341 | if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) | ||
339 | { | 342 | { |
340 | if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) | 343 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
341 | { | 344 | "Failed to remove testing directory %s\n", test_directory); |
342 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
343 | "Failed to remove testing directory %s\n", | ||
344 | test_directory); | ||
345 | } | ||
346 | } | 345 | } |
346 | } | ||
347 | 347 | ||
348 | return ret; | 348 | return ret; |
349 | } | 349 | } |
diff --git a/src/testing/testing.c b/src/testing/testing.c index 975f34496..c21166775 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -67,13 +67,13 @@ static struct GNUNET_CORE_MessageHandler no_handlers[] = { {NULL, 0, 0} }; | |||
67 | 67 | ||
68 | #if EMPTY_HACK | 68 | #if EMPTY_HACK |
69 | static int | 69 | static int |
70 | test_address (void *cls, | 70 | test_address (void *cls, |
71 | const char *tname, | 71 | const char *tname, |
72 | struct GNUNET_TIME_Absolute expiration, | 72 | struct GNUNET_TIME_Absolute expiration, |
73 | const void *addr, | 73 | const void *addr, uint16_t addrlen) |
74 | uint16_t addrlen) | ||
75 | { | 74 | { |
76 | int *empty = cls; | 75 | int *empty = cls; |
76 | |||
77 | *empty = GNUNET_NO; | 77 | *empty = GNUNET_NO; |
78 | return GNUNET_OK; | 78 | return GNUNET_OK; |
79 | } | 79 | } |
@@ -87,11 +87,11 @@ test_address (void *cls, | |||
87 | * @param message HELLO message of peer | 87 | * @param message HELLO message of peer |
88 | */ | 88 | */ |
89 | static void | 89 | static void |
90 | process_hello (void *cls, | 90 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) |
91 | const struct GNUNET_MessageHeader *message) | ||
92 | { | 91 | { |
93 | struct GNUNET_TESTING_Daemon *daemon = cls; | 92 | struct GNUNET_TESTING_Daemon *daemon = cls; |
94 | int msize; | 93 | int msize; |
94 | |||
95 | #if WAIT_FOR_HELLO | 95 | #if WAIT_FOR_HELLO |
96 | GNUNET_TESTING_NotifyDaemonRunning cb; | 96 | GNUNET_TESTING_NotifyDaemonRunning cb; |
97 | #endif | 97 | #endif |
@@ -100,50 +100,48 @@ process_hello (void *cls, | |||
100 | 100 | ||
101 | empty = GNUNET_YES; | 101 | empty = GNUNET_YES; |
102 | GNUNET_assert (message != NULL); | 102 | GNUNET_assert (message != NULL); |
103 | GNUNET_HELLO_iterate_addresses ((const struct GNUNET_HELLO_Message*) message, | 103 | GNUNET_HELLO_iterate_addresses ((const struct GNUNET_HELLO_Message *) message, |
104 | GNUNET_NO, | 104 | GNUNET_NO, &test_address, &empty); |
105 | &test_address, | ||
106 | &empty); | ||
107 | if (GNUNET_YES == empty) | 105 | if (GNUNET_YES == empty) |
108 | { | 106 | { |
109 | #if DEBUG_TESTING | 107 | #if DEBUG_TESTING |
110 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Skipping empty HELLO address\n"); |
111 | "Skipping empty HELLO address\n"); | ||
112 | #endif | 109 | #endif |
113 | return; | 110 | return; |
114 | } | 111 | } |
115 | #endif | 112 | #endif |
116 | if (daemon == NULL) | 113 | if (daemon == NULL) |
117 | return; | 114 | return; |
118 | 115 | ||
119 | GNUNET_assert (daemon->phase == SP_GET_HELLO || daemon->phase == SP_START_DONE); | 116 | GNUNET_assert (daemon->phase == SP_GET_HELLO || |
117 | daemon->phase == SP_START_DONE); | ||
120 | #if WAIT_FOR_HELLO | 118 | #if WAIT_FOR_HELLO |
121 | cb = daemon->cb; | 119 | cb = daemon->cb; |
122 | #endif | 120 | #endif |
123 | daemon->cb = NULL; | 121 | daemon->cb = NULL; |
124 | if (daemon->task != GNUNET_SCHEDULER_NO_TASK) /* Assertion here instead? */ | 122 | if (daemon->task != GNUNET_SCHEDULER_NO_TASK) /* Assertion here instead? */ |
125 | GNUNET_SCHEDULER_cancel(daemon->task); | 123 | GNUNET_SCHEDULER_cancel (daemon->task); |
126 | 124 | ||
127 | if (daemon->server != NULL) | 125 | if (daemon->server != NULL) |
128 | { | 126 | { |
129 | #if DEBUG_TESTING | 127 | #if DEBUG_TESTING |
130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
131 | "Received `%s' from transport service of `%4s', disconnecting core!\n", | 129 | "Received `%s' from transport service of `%4s', disconnecting core!\n", |
132 | "HELLO", GNUNET_i2s (&daemon->id)); | 130 | "HELLO", GNUNET_i2s (&daemon->id)); |
133 | #endif | 131 | #endif |
134 | GNUNET_CORE_disconnect (daemon->server); | 132 | GNUNET_CORE_disconnect (daemon->server); |
135 | daemon->server = NULL; | 133 | daemon->server = NULL; |
136 | } | 134 | } |
137 | 135 | ||
138 | msize = ntohs (message->size); | 136 | msize = ntohs (message->size); |
139 | if (msize < 1) | 137 | if (msize < 1) |
140 | { | 138 | { |
141 | return; | 139 | return; |
142 | } | 140 | } |
143 | if (daemon->th != NULL) | 141 | if (daemon->th != NULL) |
144 | { | 142 | { |
145 | GNUNET_TRANSPORT_get_hello_cancel (daemon->th, &process_hello, daemon); | 143 | GNUNET_TRANSPORT_get_hello_cancel (daemon->th, &process_hello, daemon); |
146 | } | 144 | } |
147 | #if DEBUG_TESTING | 145 | #if DEBUG_TESTING |
148 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 146 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
149 | "Received `%s' from transport service of `%4s'\n", | 147 | "Received `%s' from transport service of `%4s'\n", |
@@ -155,18 +153,15 @@ process_hello (void *cls, | |||
155 | memcpy (daemon->hello, message, msize); | 153 | memcpy (daemon->hello, message, msize); |
156 | 154 | ||
157 | if (daemon->th != NULL) | 155 | if (daemon->th != NULL) |
158 | { | 156 | { |
159 | GNUNET_TRANSPORT_disconnect (daemon->th); | 157 | GNUNET_TRANSPORT_disconnect (daemon->th); |
160 | daemon->th = NULL; | 158 | daemon->th = NULL; |
161 | } | 159 | } |
162 | daemon->phase = SP_START_DONE; | 160 | daemon->phase = SP_START_DONE; |
163 | 161 | ||
164 | #if WAIT_FOR_HELLO | 162 | #if WAIT_FOR_HELLO |
165 | if (NULL != cb) /* FIXME: what happens when this callback calls GNUNET_TESTING_daemon_stop? */ | 163 | if (NULL != cb) /* FIXME: what happens when this callback calls GNUNET_TESTING_daemon_stop? */ |
166 | cb (daemon->cb_cls, | 164 | cb (daemon->cb_cls, &daemon->id, daemon->cfg, daemon, NULL); |
167 | &daemon->id, | ||
168 | daemon->cfg, | ||
169 | daemon, NULL); | ||
170 | #endif | 165 | #endif |
171 | } | 166 | } |
172 | 167 | ||
@@ -198,36 +193,36 @@ testing_init (void *cls, | |||
198 | d->phase = SP_GET_HELLO; | 193 | d->phase = SP_GET_HELLO; |
199 | 194 | ||
200 | if (server == NULL) | 195 | if (server == NULL) |
201 | { | 196 | { |
202 | d->server = NULL; | 197 | d->server = NULL; |
203 | if (GNUNET_YES == d->dead) | 198 | if (GNUNET_YES == d->dead) |
204 | GNUNET_TESTING_daemon_stop (d, | 199 | GNUNET_TESTING_daemon_stop (d, |
205 | GNUNET_TIME_absolute_get_remaining | 200 | GNUNET_TIME_absolute_get_remaining |
206 | (d->max_timeout), d->dead_cb, | 201 | (d->max_timeout), d->dead_cb, |
207 | d->dead_cb_cls, GNUNET_YES, GNUNET_NO); | 202 | d->dead_cb_cls, GNUNET_YES, GNUNET_NO); |
208 | else if (NULL != d->cb) | 203 | else if (NULL != d->cb) |
209 | d->cb (d->cb_cls, NULL, d->cfg, d, | 204 | d->cb (d->cb_cls, NULL, d->cfg, d, |
210 | _("Failed to connect to core service\n")); | 205 | _("Failed to connect to core service\n")); |
211 | return; | 206 | return; |
212 | } | 207 | } |
213 | #if DEBUG_TESTING | 208 | #if DEBUG_TESTING |
214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 209 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
215 | "Successfully started peer `%4s'.\n", GNUNET_i2s (my_identity)); | 210 | "Successfully started peer `%4s'.\n", GNUNET_i2s (my_identity)); |
216 | #endif | 211 | #endif |
217 | d->id = *my_identity; /* FIXME: shouldn't we already have this from reading the hostkey file? */ | 212 | d->id = *my_identity; /* FIXME: shouldn't we already have this from reading the hostkey file? */ |
218 | if (d->shortname == NULL) | 213 | if (d->shortname == NULL) |
219 | d->shortname = strdup (GNUNET_i2s (my_identity)); | 214 | d->shortname = strdup (GNUNET_i2s (my_identity)); |
220 | d->server = server; | 215 | d->server = server; |
221 | d->running = GNUNET_YES; | 216 | d->running = GNUNET_YES; |
222 | 217 | ||
223 | if (GNUNET_NO == d->running) | 218 | if (GNUNET_NO == d->running) |
224 | { | 219 | { |
225 | #if DEBUG_TESTING | 220 | #if DEBUG_TESTING |
226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 221 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
227 | "Peer is dead (d->running == GNUNET_NO)\n"); | 222 | "Peer is dead (d->running == GNUNET_NO)\n"); |
228 | #endif | 223 | #endif |
229 | return; | 224 | return; |
230 | } | 225 | } |
231 | #if DEBUG_TESTING | 226 | #if DEBUG_TESTING |
232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 227 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
233 | "Successfully started peer `%4s', connecting to transport service.\n", | 228 | "Successfully started peer `%4s', connecting to transport service.\n", |
@@ -236,17 +231,17 @@ testing_init (void *cls, | |||
236 | 231 | ||
237 | d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL); | 232 | d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL); |
238 | if (d->th == NULL) | 233 | if (d->th == NULL) |
239 | { | 234 | { |
240 | if (GNUNET_YES == d->dead) | 235 | if (GNUNET_YES == d->dead) |
241 | GNUNET_TESTING_daemon_stop (d, | 236 | GNUNET_TESTING_daemon_stop (d, |
242 | GNUNET_TIME_absolute_get_remaining | 237 | GNUNET_TIME_absolute_get_remaining |
243 | (d->max_timeout), d->dead_cb, | 238 | (d->max_timeout), d->dead_cb, |
244 | d->dead_cb_cls, GNUNET_YES, GNUNET_NO); | 239 | d->dead_cb_cls, GNUNET_YES, GNUNET_NO); |
245 | else if (NULL != d->cb) | 240 | else if (NULL != d->cb) |
246 | d->cb (d->cb_cls, &d->id, d->cfg, d, | 241 | d->cb (d->cb_cls, &d->id, d->cfg, d, |
247 | _("Failed to connect to transport service!\n")); | 242 | _("Failed to connect to transport service!\n")); |
248 | return; | 243 | return; |
249 | } | 244 | } |
250 | #if DEBUG_TESTING | 245 | #if DEBUG_TESTING |
251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 246 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
252 | "Connected to transport service `%s', getting HELLO\n", | 247 | "Connected to transport service `%s', getting HELLO\n", |
@@ -256,10 +251,10 @@ testing_init (void *cls, | |||
256 | GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d); | 251 | GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d); |
257 | /* wait some more */ | 252 | /* wait some more */ |
258 | if (d->task != GNUNET_SCHEDULER_NO_TASK) | 253 | if (d->task != GNUNET_SCHEDULER_NO_TASK) |
259 | GNUNET_SCHEDULER_cancel(d->task); | 254 | GNUNET_SCHEDULER_cancel (d->task); |
260 | d->task | 255 | d->task |
261 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | 256 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, |
262 | &start_fsm, d); | 257 | &start_fsm, d); |
263 | } | 258 | } |
264 | #endif | 259 | #endif |
265 | 260 | ||
@@ -273,8 +268,7 @@ testing_init (void *cls, | |||
273 | * @param tc task scheduler context | 268 | * @param tc task scheduler context |
274 | */ | 269 | */ |
275 | static void | 270 | static void |
276 | notify_daemon_started (void *cls, | 271 | notify_daemon_started (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
277 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
278 | { | 272 | { |
279 | struct GNUNET_TESTING_Daemon *d = cls; | 273 | struct GNUNET_TESTING_Daemon *d = cls; |
280 | GNUNET_TESTING_NotifyDaemonRunning cb; | 274 | GNUNET_TESTING_NotifyDaemonRunning cb; |
@@ -303,711 +297,697 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
303 | int bytes_read; | 297 | int bytes_read; |
304 | 298 | ||
305 | #if DEBUG_TESTING | 299 | #if DEBUG_TESTING |
306 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 300 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer FSM is in phase %u.\n", d->phase); |
307 | "Peer FSM is in phase %u.\n", d->phase); | ||
308 | #endif | 301 | #endif |
309 | 302 | ||
310 | d->task = GNUNET_SCHEDULER_NO_TASK; | 303 | d->task = GNUNET_SCHEDULER_NO_TASK; |
311 | switch (d->phase) | 304 | switch (d->phase) |
305 | { | ||
306 | case SP_COPYING: | ||
307 | /* confirm copying complete */ | ||
308 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | ||
309 | { | ||
310 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) | ||
311 | { | ||
312 | cb = d->cb; | ||
313 | d->cb = NULL; | ||
314 | if (NULL != cb) | ||
315 | cb (d->cb_cls, | ||
316 | NULL, | ||
317 | d->cfg, d, | ||
318 | _ | ||
319 | ("`scp' does not seem to terminate (timeout copying config).\n")); | ||
320 | return; | ||
321 | } | ||
322 | /* wait some more */ | ||
323 | d->task | ||
324 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
325 | &start_fsm, d); | ||
326 | return; | ||
327 | } | ||
328 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | ||
312 | { | 329 | { |
313 | case SP_COPYING: | 330 | cb = d->cb; |
314 | /* confirm copying complete */ | 331 | d->cb = NULL; |
315 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | 332 | if (NULL != cb) |
333 | cb (d->cb_cls, NULL, d->cfg, d, _("`scp' did not complete cleanly.\n")); | ||
334 | return; | ||
335 | } | ||
336 | GNUNET_OS_process_close (d->proc); | ||
337 | #if DEBUG_TESTING | ||
338 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
339 | "Successfully copied configuration file.\n"); | ||
340 | #endif | ||
341 | d->phase = SP_COPIED; | ||
342 | /* fall-through */ | ||
343 | case SP_COPIED: | ||
344 | /* Start create hostkey process if we don't already know the peer identity! */ | ||
345 | if (GNUNET_NO == d->have_hostkey) | ||
346 | { | ||
347 | d->pipe_stdout = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES); | ||
348 | if (d->pipe_stdout == NULL) | ||
349 | { | ||
350 | cb = d->cb; | ||
351 | d->cb = NULL; | ||
352 | if (NULL != cb) | ||
353 | cb (d->cb_cls, | ||
354 | NULL, | ||
355 | d->cfg, | ||
356 | d, | ||
357 | (NULL == d->hostname) | ||
358 | ? _("Failed to create pipe for `gnunet-peerinfo' process.\n") | ||
359 | : _("Failed to create pipe for `ssh' process.\n")); | ||
360 | return; | ||
361 | } | ||
362 | if (NULL == d->hostname) | ||
363 | { | ||
364 | #if DEBUG_TESTING | ||
365 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
366 | "Starting `%s', with command `%s %s %s %s'.\n", | ||
367 | "gnunet-peerinfo", "gnunet-peerinfo", "-c", d->cfgfile, | ||
368 | "-sq"); | ||
369 | #endif | ||
370 | d->proc = | ||
371 | GNUNET_OS_start_process (NULL, d->pipe_stdout, "gnunet-peerinfo", | ||
372 | "gnunet-peerinfo", "-c", d->cfgfile, | ||
373 | "-sq", NULL); | ||
374 | GNUNET_DISK_pipe_close_end (d->pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); | ||
375 | } | ||
376 | else | ||
377 | { | ||
378 | if (d->username != NULL) | ||
379 | GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname); | ||
380 | else | ||
381 | dst = GNUNET_strdup (d->hostname); | ||
382 | |||
383 | #if DEBUG_TESTING | ||
384 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
385 | "Starting `%s', with command `%s %s %s %s %s %s'.\n", | ||
386 | "gnunet-peerinfo", "ssh", dst, "gnunet-peerinfo", "-c", | ||
387 | d->cfgfile, "-sq"); | ||
388 | #endif | ||
389 | if (d->ssh_port_str == NULL) | ||
316 | { | 390 | { |
317 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == | 391 | d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", "ssh", |
318 | 0) | 392 | #if !DEBUG_TESTING |
319 | { | 393 | "-q", |
320 | cb = d->cb; | 394 | #endif |
321 | d->cb = NULL; | 395 | dst, |
322 | if (NULL != cb) | 396 | "gnunet-peerinfo", |
323 | cb (d->cb_cls, | 397 | "-c", d->cfgfile, "-sq", NULL); |
324 | NULL, | ||
325 | d->cfg, d, | ||
326 | _ | ||
327 | ("`scp' does not seem to terminate (timeout copying config).\n")); | ||
328 | return; | ||
329 | } | ||
330 | /* wait some more */ | ||
331 | d->task | ||
332 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
333 | &start_fsm, d); | ||
334 | return; | ||
335 | } | 398 | } |
336 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | 399 | else |
337 | { | 400 | { |
338 | cb = d->cb; | 401 | d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", |
339 | d->cb = NULL; | 402 | "ssh", "-p", d->ssh_port_str, |
340 | if (NULL != cb) | 403 | #if !DEBUG_TESTING |
341 | cb (d->cb_cls, | 404 | "-q", |
342 | NULL, d->cfg, d, _("`scp' did not complete cleanly.\n")); | 405 | #endif |
343 | return; | 406 | dst, |
407 | "gnunet-peerinfo", | ||
408 | "-c", d->cfgfile, "-sq", NULL); | ||
344 | } | 409 | } |
345 | GNUNET_OS_process_close(d->proc); | 410 | GNUNET_DISK_pipe_close_end (d->pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); |
411 | GNUNET_free (dst); | ||
412 | } | ||
413 | if (NULL == d->proc) | ||
414 | { | ||
415 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
416 | _("Could not start `%s' process to create hostkey.\n"), | ||
417 | (NULL == d->hostname) ? "gnunet-peerinfo" : "ssh"); | ||
418 | cb = d->cb; | ||
419 | d->cb = NULL; | ||
420 | if (NULL != cb) | ||
421 | cb (d->cb_cls, | ||
422 | NULL, | ||
423 | d->cfg, | ||
424 | d, | ||
425 | (NULL == d->hostname) | ||
426 | ? _("Failed to start `gnunet-peerinfo' process.\n") | ||
427 | : _("Failed to start `ssh' process.\n")); | ||
428 | GNUNET_DISK_pipe_close (d->pipe_stdout); | ||
429 | return; | ||
430 | } | ||
346 | #if DEBUG_TESTING | 431 | #if DEBUG_TESTING |
347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 432 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
348 | "Successfully copied configuration file.\n"); | 433 | "Started `%s', waiting for hostkey.\n", "gnunet-peerinfo"); |
349 | #endif | 434 | #endif |
350 | d->phase = SP_COPIED; | 435 | d->phase = SP_HOSTKEY_CREATE; |
351 | /* fall-through */ | 436 | d->task |
352 | case SP_COPIED: | 437 | = |
353 | /* Start create hostkey process if we don't already know the peer identity!*/ | 438 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining |
354 | if (GNUNET_NO == d->have_hostkey) | 439 | (d->max_timeout), |
355 | { | 440 | GNUNET_DISK_pipe_handle |
356 | d->pipe_stdout = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES); | 441 | (d->pipe_stdout, |
357 | if (d->pipe_stdout == NULL) | 442 | GNUNET_DISK_PIPE_END_READ), |
358 | { | 443 | &start_fsm, d); |
359 | cb = d->cb; | 444 | } |
360 | d->cb = NULL; | 445 | else /* Already have a hostkey! */ |
361 | if (NULL != cb) | 446 | { |
362 | cb (d->cb_cls, | 447 | if (d->hostkey_callback != NULL) |
363 | NULL, | 448 | { |
364 | d->cfg, | 449 | d->hostkey_callback (d->hostkey_cls, &d->id, d, NULL); |
365 | d, | 450 | d->hostkey_callback = NULL; |
366 | (NULL == d->hostname) | 451 | d->phase = SP_HOSTKEY_CREATED; |
367 | ? _("Failed to create pipe for `gnunet-peerinfo' process.\n") | 452 | } |
368 | : _("Failed to create pipe for `ssh' process.\n")); | 453 | else |
369 | return; | 454 | d->phase = SP_TOPOLOGY_SETUP; |
370 | } | 455 | |
371 | if (NULL == d->hostname) | 456 | /* wait some more */ |
372 | { | 457 | d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d); |
373 | #if DEBUG_TESTING | 458 | } |
374 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 459 | break; |
375 | "Starting `%s', with command `%s %s %s %s'.\n", | 460 | case SP_HOSTKEY_CREATE: |
376 | "gnunet-peerinfo", "gnunet-peerinfo", "-c", d->cfgfile, | 461 | bytes_read = |
377 | "-sq"); | ||
378 | #endif | ||
379 | d->proc = | ||
380 | GNUNET_OS_start_process (NULL, d->pipe_stdout, "gnunet-peerinfo", | ||
381 | "gnunet-peerinfo", "-c", d->cfgfile, | ||
382 | "-sq", NULL); | ||
383 | GNUNET_DISK_pipe_close_end (d->pipe_stdout, | ||
384 | GNUNET_DISK_PIPE_END_WRITE); | ||
385 | } | ||
386 | else | ||
387 | { | ||
388 | if (d->username != NULL) | ||
389 | GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname); | ||
390 | else | ||
391 | dst = GNUNET_strdup (d->hostname); | ||
392 | |||
393 | #if DEBUG_TESTING | ||
394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
395 | "Starting `%s', with command `%s %s %s %s %s %s'.\n", | ||
396 | "gnunet-peerinfo", "ssh", dst, "gnunet-peerinfo", "-c", | ||
397 | d->cfgfile, "-sq"); | ||
398 | #endif | ||
399 | if (d->ssh_port_str == NULL) | ||
400 | { | ||
401 | d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", | ||
402 | "ssh", | ||
403 | #if !DEBUG_TESTING | ||
404 | "-q", | ||
405 | #endif | ||
406 | dst, | ||
407 | "gnunet-peerinfo", | ||
408 | "-c", d->cfgfile, "-sq", | ||
409 | NULL); | ||
410 | } | ||
411 | else | ||
412 | { | ||
413 | d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", | ||
414 | "ssh", "-p", d->ssh_port_str, | ||
415 | #if !DEBUG_TESTING | ||
416 | "-q", | ||
417 | #endif | ||
418 | dst, | ||
419 | "gnunet-peerinfo", | ||
420 | "-c", d->cfgfile, "-sq", | ||
421 | NULL); | ||
422 | } | ||
423 | GNUNET_DISK_pipe_close_end (d->pipe_stdout, | ||
424 | GNUNET_DISK_PIPE_END_WRITE); | ||
425 | GNUNET_free (dst); | ||
426 | } | ||
427 | if (NULL == d->proc) | ||
428 | { | ||
429 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
430 | _("Could not start `%s' process to create hostkey.\n"), | ||
431 | (NULL == d->hostname) ? "gnunet-peerinfo" : "ssh"); | ||
432 | cb = d->cb; | ||
433 | d->cb = NULL; | ||
434 | if (NULL != cb) | ||
435 | cb (d->cb_cls, | ||
436 | NULL, | ||
437 | d->cfg, | ||
438 | d, | ||
439 | (NULL == d->hostname) | ||
440 | ? _("Failed to start `gnunet-peerinfo' process.\n") | ||
441 | : _("Failed to start `ssh' process.\n")); | ||
442 | GNUNET_DISK_pipe_close (d->pipe_stdout); | ||
443 | return; | ||
444 | } | ||
445 | #if DEBUG_TESTING | ||
446 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
447 | "Started `%s', waiting for hostkey.\n", "gnunet-peerinfo"); | ||
448 | #endif | ||
449 | d->phase = SP_HOSTKEY_CREATE; | ||
450 | d->task | ||
451 | = | ||
452 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining | ||
453 | (d->max_timeout), | ||
454 | GNUNET_DISK_pipe_handle | ||
455 | (d->pipe_stdout, | ||
456 | GNUNET_DISK_PIPE_END_READ), | ||
457 | &start_fsm, d); | ||
458 | } | ||
459 | else /* Already have a hostkey! */ | ||
460 | { | ||
461 | if (d->hostkey_callback != NULL) | ||
462 | { | ||
463 | d->hostkey_callback (d->hostkey_cls, &d->id, d, NULL); | ||
464 | d->hostkey_callback = NULL; | ||
465 | d->phase = SP_HOSTKEY_CREATED; | ||
466 | } | ||
467 | else | ||
468 | d->phase = SP_TOPOLOGY_SETUP; | ||
469 | |||
470 | /* wait some more */ | ||
471 | d->task | ||
472 | = GNUNET_SCHEDULER_add_now (&start_fsm, d); | ||
473 | } | ||
474 | break; | ||
475 | case SP_HOSTKEY_CREATE: | ||
476 | bytes_read = | ||
477 | GNUNET_DISK_file_read (GNUNET_DISK_pipe_handle | 462 | GNUNET_DISK_file_read (GNUNET_DISK_pipe_handle |
478 | (d->pipe_stdout, GNUNET_DISK_PIPE_END_READ), | 463 | (d->pipe_stdout, GNUNET_DISK_PIPE_END_READ), |
479 | &d->hostkeybuf[d->hostkeybufpos], | 464 | &d->hostkeybuf[d->hostkeybufpos], |
480 | sizeof (d->hostkeybuf) - d->hostkeybufpos); | 465 | sizeof (d->hostkeybuf) - d->hostkeybufpos); |
481 | if (bytes_read > 0) | 466 | if (bytes_read > 0) |
482 | d->hostkeybufpos += bytes_read; | 467 | d->hostkeybufpos += bytes_read; |
483 | 468 | ||
484 | if ((d->hostkeybufpos < 104) && (bytes_read > 0)) | 469 | if ((d->hostkeybufpos < 104) && (bytes_read > 0)) |
485 | { | 470 | { |
486 | /* keep reading */ | 471 | /* keep reading */ |
487 | d->task | 472 | d->task |
488 | = | 473 | = |
489 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining | 474 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining |
490 | (d->max_timeout), | 475 | (d->max_timeout), |
491 | GNUNET_DISK_pipe_handle | 476 | GNUNET_DISK_pipe_handle |
492 | (d->pipe_stdout, | 477 | (d->pipe_stdout, |
493 | GNUNET_DISK_PIPE_END_READ), | 478 | GNUNET_DISK_PIPE_END_READ), |
494 | &start_fsm, d); | 479 | &start_fsm, d); |
495 | return; | 480 | return; |
496 | } | 481 | } |
497 | d->hostkeybuf[103] = '\0'; | 482 | d->hostkeybuf[103] = '\0'; |
498 | 483 | ||
499 | if ((bytes_read < 0) || | 484 | if ((bytes_read < 0) || |
500 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (d->hostkeybuf, | 485 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (d->hostkeybuf, |
501 | &d->id.hashPubKey))) | 486 | &d->id.hashPubKey))) |
502 | { | 487 | { |
503 | /* error */ | 488 | /* error */ |
504 | if (bytes_read < 0) | 489 | if (bytes_read < 0) |
505 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 490 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
506 | _("Error reading from gnunet-peerinfo: %s\n"), | 491 | _("Error reading from gnunet-peerinfo: %s\n"), |
507 | STRERROR (errno)); | 492 | STRERROR (errno)); |
508 | else | 493 | else |
509 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 494 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
510 | _("Malformed output from gnunet-peerinfo!\n")); | 495 | _("Malformed output from gnunet-peerinfo!\n")); |
511 | cb = d->cb; | 496 | cb = d->cb; |
512 | d->cb = NULL; | 497 | d->cb = NULL; |
513 | GNUNET_DISK_pipe_close (d->pipe_stdout); | ||
514 | d->pipe_stdout = NULL; | ||
515 | (void) GNUNET_OS_process_kill (d->proc, SIGKILL); | ||
516 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc)); | ||
517 | GNUNET_OS_process_close (d->proc); | ||
518 | d->proc = NULL; | ||
519 | if (NULL != cb) | ||
520 | cb (d->cb_cls, NULL, d->cfg, d, _("`Failed to get hostkey!\n")); | ||
521 | return; | ||
522 | } | ||
523 | d->shortname = GNUNET_strdup(GNUNET_i2s(&d->id)); | ||
524 | GNUNET_DISK_pipe_close (d->pipe_stdout); | 498 | GNUNET_DISK_pipe_close (d->pipe_stdout); |
525 | d->pipe_stdout = NULL; | 499 | d->pipe_stdout = NULL; |
526 | (void) GNUNET_OS_process_kill (d->proc, SIGKILL); | 500 | (void) GNUNET_OS_process_kill (d->proc, SIGKILL); |
527 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc)); | 501 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc)); |
528 | GNUNET_OS_process_close (d->proc); | 502 | GNUNET_OS_process_close (d->proc); |
529 | d->proc = NULL; | 503 | d->proc = NULL; |
530 | d->have_hostkey = GNUNET_YES; | 504 | if (NULL != cb) |
531 | if (d->hostkey_callback != NULL) | 505 | cb (d->cb_cls, NULL, d->cfg, d, _("`Failed to get hostkey!\n")); |
532 | { | 506 | return; |
533 | d->hostkey_callback (d->hostkey_cls, &d->id, d, NULL); | 507 | } |
534 | d->hostkey_callback = NULL; | 508 | d->shortname = GNUNET_strdup (GNUNET_i2s (&d->id)); |
535 | d->phase = SP_HOSTKEY_CREATED; | 509 | GNUNET_DISK_pipe_close (d->pipe_stdout); |
536 | } | 510 | d->pipe_stdout = NULL; |
537 | else | 511 | (void) GNUNET_OS_process_kill (d->proc, SIGKILL); |
538 | { | 512 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc)); |
539 | d->phase = SP_TOPOLOGY_SETUP; | 513 | GNUNET_OS_process_close (d->proc); |
540 | } | 514 | d->proc = NULL; |
515 | d->have_hostkey = GNUNET_YES; | ||
516 | if (d->hostkey_callback != NULL) | ||
517 | { | ||
518 | d->hostkey_callback (d->hostkey_cls, &d->id, d, NULL); | ||
519 | d->hostkey_callback = NULL; | ||
520 | d->phase = SP_HOSTKEY_CREATED; | ||
521 | } | ||
522 | else | ||
523 | { | ||
524 | d->phase = SP_TOPOLOGY_SETUP; | ||
525 | } | ||
541 | #if DEBUG_TESTING | 526 | #if DEBUG_TESTING |
542 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully got hostkey!\n"); | 527 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully got hostkey!\n"); |
543 | #endif | 528 | #endif |
544 | /* Fall through */ | 529 | /* Fall through */ |
545 | case SP_HOSTKEY_CREATED: | 530 | case SP_HOSTKEY_CREATED: |
546 | /* wait for topology finished */ | 531 | /* wait for topology finished */ |
547 | if ((GNUNET_YES == d->dead) | 532 | if ((GNUNET_YES == d->dead) |
548 | || (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == | 533 | || (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)) |
549 | 0)) | 534 | { |
550 | { | 535 | cb = d->cb; |
551 | cb = d->cb; | 536 | d->cb = NULL; |
552 | d->cb = NULL; | 537 | if (NULL != cb) |
553 | if (NULL != cb) | 538 | cb (d->cb_cls, |
554 | cb (d->cb_cls, | 539 | NULL, d->cfg, d, _("`Failed while waiting for topology setup!\n")); |
555 | NULL, | 540 | return; |
556 | d->cfg, d, _("`Failed while waiting for topology setup!\n")); | 541 | } |
557 | return; | ||
558 | } | ||
559 | 542 | ||
560 | d->task | 543 | d->task |
561 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | 544 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, |
562 | &start_fsm, d); | 545 | &start_fsm, d); |
563 | break; | 546 | break; |
564 | case SP_TOPOLOGY_SETUP: /* Indicates topology setup has completed! */ | 547 | case SP_TOPOLOGY_SETUP: /* Indicates topology setup has completed! */ |
565 | /* start GNUnet on remote host */ | 548 | /* start GNUnet on remote host */ |
566 | if (NULL == d->hostname) | 549 | if (NULL == d->hostname) |
567 | { | 550 | { |
568 | #if DEBUG_TESTING | 551 | #if DEBUG_TESTING |
569 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 552 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
570 | "Starting `%s', with command `%s %s %s %s %s %s'.\n", | 553 | "Starting `%s', with command `%s %s %s %s %s %s'.\n", |
571 | "gnunet-arm", "gnunet-arm", "-c", d->cfgfile, | 554 | "gnunet-arm", "gnunet-arm", "-c", d->cfgfile, |
572 | "-L", "DEBUG", "-s"); | 555 | "-L", "DEBUG", "-s"); |
573 | #endif | 556 | #endif |
574 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", | 557 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", |
575 | "gnunet-arm", "-c", d->cfgfile, | 558 | "gnunet-arm", "-c", d->cfgfile, |
576 | #if DEBUG_TESTING | 559 | #if DEBUG_TESTING |
577 | "-L", "DEBUG", | 560 | "-L", "DEBUG", |
578 | #endif | 561 | #endif |
579 | "-s", "-q", "-T", GNUNET_TIME_relative_to_string(GNUNET_TIME_absolute_get_remaining(d->max_timeout)), NULL); | 562 | "-s", "-q", "-T", |
580 | } | 563 | GNUNET_TIME_relative_to_string |
564 | (GNUNET_TIME_absolute_get_remaining | ||
565 | (d->max_timeout)), NULL); | ||
566 | } | ||
567 | else | ||
568 | { | ||
569 | if (d->username != NULL) | ||
570 | GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname); | ||
581 | else | 571 | else |
582 | { | 572 | dst = GNUNET_strdup (d->hostname); |
583 | if (d->username != NULL) | ||
584 | GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname); | ||
585 | else | ||
586 | dst = GNUNET_strdup (d->hostname); | ||
587 | 573 | ||
588 | #if DEBUG_TESTING | 574 | #if DEBUG_TESTING |
589 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 575 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
590 | "Starting `%s', with command `%s %s %s %s %s %s %s %s'.\n", | 576 | "Starting `%s', with command `%s %s %s %s %s %s %s %s'.\n", |
591 | "gnunet-arm", "ssh", dst, "gnunet-arm", "-c", | 577 | "gnunet-arm", "ssh", dst, "gnunet-arm", "-c", |
592 | d->cfgfile, "-L", "DEBUG", "-s", "-q"); | 578 | d->cfgfile, "-L", "DEBUG", "-s", "-q"); |
593 | #endif | 579 | #endif |
594 | if (d->ssh_port_str == NULL) | 580 | if (d->ssh_port_str == NULL) |
595 | { | 581 | { |
596 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", | 582 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", |
597 | #if !DEBUG_TESTING | 583 | #if !DEBUG_TESTING |
598 | "-q", | 584 | "-q", |
599 | #endif | 585 | #endif |
600 | dst, "gnunet-arm", | 586 | dst, "gnunet-arm", |
601 | #if DEBUG_TESTING | 587 | #if DEBUG_TESTING |
602 | "-L", "DEBUG", | 588 | "-L", "DEBUG", |
603 | #endif | 589 | #endif |
604 | "-c", d->cfgfile, "-s", "-q", | 590 | "-c", d->cfgfile, "-s", "-q", |
605 | "-T", GNUNET_TIME_relative_to_string(GNUNET_TIME_absolute_get_remaining(d->max_timeout)), | 591 | "-T", |
606 | NULL); | 592 | GNUNET_TIME_relative_to_string |
607 | } | 593 | (GNUNET_TIME_absolute_get_remaining |
608 | else | 594 | (d->max_timeout)), NULL); |
609 | { | 595 | } |
596 | else | ||
597 | { | ||
610 | 598 | ||
611 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", | 599 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", |
612 | "ssh", "-p", d->ssh_port_str, | 600 | "ssh", "-p", d->ssh_port_str, |
613 | #if !DEBUG_TESTING | 601 | #if !DEBUG_TESTING |
614 | "-q", | 602 | "-q", |
615 | #endif | 603 | #endif |
616 | dst, "gnunet-arm", | 604 | dst, "gnunet-arm", |
617 | #if DEBUG_TESTING | 605 | #if DEBUG_TESTING |
618 | "-L", "DEBUG", | 606 | "-L", "DEBUG", |
619 | #endif | 607 | #endif |
620 | "-c", d->cfgfile, "-s", "-q", | 608 | "-c", d->cfgfile, "-s", "-q", |
621 | "-T", GNUNET_TIME_relative_to_string(GNUNET_TIME_absolute_get_remaining(d->max_timeout)), | 609 | "-T", |
622 | NULL); | 610 | GNUNET_TIME_relative_to_string |
623 | } | 611 | (GNUNET_TIME_absolute_get_remaining |
624 | GNUNET_free (dst); | 612 | (d->max_timeout)), NULL); |
625 | } | 613 | } |
626 | if (NULL == d->proc) | 614 | GNUNET_free (dst); |
627 | { | 615 | } |
628 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 616 | if (NULL == d->proc) |
629 | _("Could not start `%s' process to start GNUnet.\n"), | 617 | { |
630 | (NULL == d->hostname) ? "gnunet-arm" : "ssh"); | 618 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
631 | cb = d->cb; | 619 | _("Could not start `%s' process to start GNUnet.\n"), |
632 | d->cb = NULL; | 620 | (NULL == d->hostname) ? "gnunet-arm" : "ssh"); |
633 | if (NULL != cb) | 621 | cb = d->cb; |
634 | cb (d->cb_cls, | 622 | d->cb = NULL; |
635 | NULL, | 623 | if (NULL != cb) |
636 | d->cfg, | 624 | cb (d->cb_cls, |
637 | d, | 625 | NULL, |
638 | (NULL == d->hostname) | 626 | d->cfg, |
639 | ? _("Failed to start `gnunet-arm' process.\n") | 627 | d, |
640 | : _("Failed to start `ssh' process.\n")); | 628 | (NULL == d->hostname) |
641 | return; | 629 | ? _("Failed to start `gnunet-arm' process.\n") |
642 | } | 630 | : _("Failed to start `ssh' process.\n")); |
631 | return; | ||
632 | } | ||
643 | #if DEBUG_TESTING | 633 | #if DEBUG_TESTING |
644 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 634 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
645 | "Started `%s', waiting for `%s' to be up.\n", | 635 | "Started `%s', waiting for `%s' to be up.\n", |
646 | "gnunet-arm", "gnunet-service-core"); | 636 | "gnunet-arm", "gnunet-service-core"); |
647 | #endif | 637 | #endif |
648 | d->phase = SP_START_ARMING; | 638 | d->phase = SP_START_ARMING; |
649 | d->task | 639 | d->task |
650 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | 640 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, |
651 | &start_fsm, d); | 641 | &start_fsm, d); |
652 | break; | 642 | break; |
653 | case SP_START_ARMING: | 643 | case SP_START_ARMING: |
654 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | 644 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) |
655 | { | 645 | { |
656 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == | 646 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) |
657 | 0) | 647 | { |
658 | { | 648 | cb = d->cb; |
659 | cb = d->cb; | 649 | d->cb = NULL; |
660 | d->cb = NULL; | 650 | if (NULL != cb) |
661 | if (NULL != cb) | 651 | cb (d->cb_cls, |
662 | cb (d->cb_cls, | 652 | NULL, |
663 | NULL, | 653 | d->cfg, |
664 | d->cfg, | 654 | d, |
665 | d, | 655 | (NULL == d->hostname) |
666 | (NULL == d->hostname) | 656 | ? _("`gnunet-arm' does not seem to terminate.\n") |
667 | ? _("`gnunet-arm' does not seem to terminate.\n") | 657 | : _("`ssh' does not seem to terminate.\n")); |
668 | : _("`ssh' does not seem to terminate.\n")); | 658 | GNUNET_CONFIGURATION_destroy (d->cfg); |
669 | GNUNET_CONFIGURATION_destroy (d->cfg); | 659 | GNUNET_free (d->cfgfile); |
670 | GNUNET_free (d->cfgfile); | 660 | GNUNET_free_non_null (d->hostname); |
671 | GNUNET_free_non_null (d->hostname); | 661 | GNUNET_free_non_null (d->username); |
672 | GNUNET_free_non_null (d->username); | 662 | GNUNET_free (d->proc); |
673 | GNUNET_free(d->proc); | 663 | GNUNET_free (d); |
674 | GNUNET_free(d); | 664 | return; |
675 | return; | 665 | } |
676 | } | 666 | /* wait some more */ |
677 | /* wait some more */ | 667 | d->task |
678 | d->task | 668 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, |
679 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | 669 | &start_fsm, d); |
680 | &start_fsm, d); | 670 | return; |
681 | return; | 671 | } |
682 | } | ||
683 | #if DEBUG_TESTING | 672 | #if DEBUG_TESTING |
684 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 673 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
685 | "Successfully started `%s'.\n", "gnunet-arm"); | 674 | "Successfully started `%s'.\n", "gnunet-arm"); |
686 | #endif | 675 | #endif |
687 | GNUNET_free(d->proc); | 676 | GNUNET_free (d->proc); |
688 | d->phase = SP_START_CORE; | 677 | d->phase = SP_START_CORE; |
689 | #if DEBUG_TESTING | 678 | #if DEBUG_TESTING |
690 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 679 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Calling CORE_connect\n"); |
691 | "Calling CORE_connect\n"); | ||
692 | #endif | 680 | #endif |
693 | /* Fall through */ | 681 | /* Fall through */ |
694 | case SP_START_CORE: | 682 | case SP_START_CORE: |
695 | if (d->server != NULL) | 683 | if (d->server != NULL) |
696 | GNUNET_CORE_disconnect(d->server); | 684 | GNUNET_CORE_disconnect (d->server); |
697 | 685 | ||
698 | #if WAIT_FOR_HELLO | 686 | #if WAIT_FOR_HELLO |
699 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == | 687 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) |
700 | 0) | 688 | { |
701 | { | 689 | cb = d->cb; |
702 | cb = d->cb; | 690 | d->cb = NULL; |
703 | d->cb = NULL; | 691 | if (NULL != cb) |
704 | if (NULL != cb) | 692 | cb (d->cb_cls, |
705 | cb (d->cb_cls, | 693 | NULL, |
706 | NULL, | 694 | d->cfg, d, _("Unable to connect to CORE service for peer!\n")); |
707 | d->cfg, | 695 | GNUNET_CONFIGURATION_destroy (d->cfg); |
708 | d, | 696 | GNUNET_free (d->cfgfile); |
709 | _("Unable to connect to CORE service for peer!\n")); | 697 | GNUNET_free_non_null (d->hostname); |
710 | GNUNET_CONFIGURATION_destroy (d->cfg); | 698 | GNUNET_free_non_null (d->username); |
711 | GNUNET_free (d->cfgfile); | 699 | GNUNET_free (d); |
712 | GNUNET_free_non_null (d->hostname); | 700 | return; |
713 | GNUNET_free_non_null (d->username); | 701 | } |
714 | GNUNET_free (d); | 702 | d->server = GNUNET_CORE_connect (d->cfg, 1, |
715 | return; | 703 | d, |
716 | } | 704 | &testing_init, |
717 | d->server = GNUNET_CORE_connect (d->cfg, 1, | 705 | NULL, NULL, NULL, |
718 | d, | 706 | NULL, GNUNET_NO, |
719 | &testing_init, | 707 | NULL, GNUNET_NO, no_handlers); |
720 | NULL, NULL, NULL, | 708 | d->task |
721 | NULL, GNUNET_NO, | 709 | = |
722 | NULL, GNUNET_NO, no_handlers); | 710 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
723 | d->task | 711 | (GNUNET_CONSTANTS_SERVICE_RETRY, 2), |
724 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_CONSTANTS_SERVICE_RETRY, 2), | 712 | &start_fsm, d); |
725 | &start_fsm, d); | ||
726 | #else | 713 | #else |
727 | d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL); | 714 | d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL); |
728 | if (d->th == NULL) | 715 | if (d->th == NULL) |
729 | { | 716 | { |
730 | if (GNUNET_YES == d->dead) | 717 | if (GNUNET_YES == d->dead) |
731 | GNUNET_TESTING_daemon_stop (d, | 718 | GNUNET_TESTING_daemon_stop (d, |
732 | GNUNET_TIME_absolute_get_remaining | 719 | GNUNET_TIME_absolute_get_remaining |
733 | (d->max_timeout), d->dead_cb, | 720 | (d->max_timeout), d->dead_cb, |
734 | d->dead_cb_cls, GNUNET_YES, GNUNET_NO); | 721 | d->dead_cb_cls, GNUNET_YES, GNUNET_NO); |
735 | else if (NULL != d->cb) | 722 | else if (NULL != d->cb) |
736 | d->cb (d->cb_cls, &d->id, d->cfg, d, | 723 | d->cb (d->cb_cls, &d->id, d->cfg, d, |
737 | _("Failed to connect to transport service!\n")); | 724 | _("Failed to connect to transport service!\n")); |
738 | return; | 725 | return; |
739 | } | 726 | } |
740 | #if DEBUG_TESTING | 727 | #if DEBUG_TESTING |
741 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 728 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
742 | "Connected to transport service `%s', getting HELLO\n", | 729 | "Connected to transport service `%s', getting HELLO\n", |
743 | GNUNET_i2s (&d->id)); | 730 | GNUNET_i2s (&d->id)); |
744 | #endif | 731 | #endif |
745 | 732 | ||
746 | GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d); | 733 | GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d); |
747 | GNUNET_SCHEDULER_add_now (¬ify_daemon_started, d); | 734 | GNUNET_SCHEDULER_add_now (¬ify_daemon_started, d); |
748 | /*cb = d->cb; | 735 | /*cb = d->cb; |
736 | * d->cb = NULL; | ||
737 | * if (NULL != cb) | ||
738 | * cb (d->cb_cls, &d->id, d->cfg, d, NULL); */ | ||
739 | d->running = GNUNET_YES; | ||
740 | d->phase = SP_GET_HELLO; | ||
741 | #endif | ||
742 | break; | ||
743 | case SP_GET_HELLO: | ||
744 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) | ||
745 | { | ||
746 | if (d->server != NULL) | ||
747 | GNUNET_CORE_disconnect (d->server); | ||
748 | if (d->th != NULL) | ||
749 | GNUNET_TRANSPORT_disconnect (d->th); | ||
750 | cb = d->cb; | ||
749 | d->cb = NULL; | 751 | d->cb = NULL; |
750 | if (NULL != cb) | 752 | if (NULL != cb) |
751 | cb (d->cb_cls, &d->id, d->cfg, d, NULL);*/ | 753 | cb (d->cb_cls, NULL, d->cfg, d, _("Unable to get HELLO for peer!\n")); |
752 | d->running = GNUNET_YES; | 754 | GNUNET_CONFIGURATION_destroy (d->cfg); |
753 | d->phase = SP_GET_HELLO; | 755 | GNUNET_free (d->cfgfile); |
754 | #endif | 756 | GNUNET_free_non_null (d->hostname); |
755 | break; | 757 | GNUNET_free_non_null (d->username); |
756 | case SP_GET_HELLO: | 758 | GNUNET_free (d); |
757 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == | 759 | return; |
758 | 0) | 760 | } |
759 | { | 761 | if (d->hello != NULL) |
760 | if (d->server != NULL) | 762 | return; |
761 | GNUNET_CORE_disconnect(d->server); | 763 | GNUNET_assert (d->task == GNUNET_SCHEDULER_NO_TASK); |
762 | if (d->th != NULL) | 764 | d->task |
763 | GNUNET_TRANSPORT_disconnect(d->th); | 765 | = |
764 | cb = d->cb; | 766 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
765 | d->cb = NULL; | 767 | (GNUNET_CONSTANTS_SERVICE_RETRY, 2), |
766 | if (NULL != cb) | 768 | &start_fsm, d); |
767 | cb (d->cb_cls, | 769 | break; |
768 | NULL, | 770 | case SP_START_DONE: |
769 | d->cfg, | 771 | GNUNET_break (0); |
770 | d, | 772 | break; |
771 | _("Unable to get HELLO for peer!\n")); | 773 | case SP_SERVICE_START: |
772 | GNUNET_CONFIGURATION_destroy (d->cfg); | 774 | /* confirm gnunet-arm exited */ |
773 | GNUNET_free (d->cfgfile); | 775 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) |
774 | GNUNET_free_non_null (d->hostname); | 776 | { |
775 | GNUNET_free_non_null (d->username); | 777 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) |
776 | GNUNET_free (d); | 778 | { |
777 | return; | 779 | cb = d->cb; |
778 | } | 780 | d->cb = NULL; |
779 | if (d->hello != NULL) | 781 | if (NULL != cb) |
782 | cb (d->cb_cls, | ||
783 | NULL, | ||
784 | d->cfg, | ||
785 | d, | ||
786 | (NULL == d->hostname) | ||
787 | ? _("`gnunet-arm' does not seem to terminate.\n") | ||
788 | : _("`ssh' does not seem to terminate.\n")); | ||
780 | return; | 789 | return; |
781 | GNUNET_assert(d->task == GNUNET_SCHEDULER_NO_TASK); | 790 | } |
791 | /* wait some more */ | ||
782 | d->task | 792 | d->task |
783 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_CONSTANTS_SERVICE_RETRY, 2), | 793 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, |
784 | &start_fsm, d); | 794 | &start_fsm, d); |
785 | break; | 795 | return; |
786 | case SP_START_DONE: | 796 | } |
787 | GNUNET_break (0); | ||
788 | break; | ||
789 | case SP_SERVICE_START: | ||
790 | /* confirm gnunet-arm exited */ | ||
791 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | ||
792 | { | ||
793 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == | ||
794 | 0) | ||
795 | { | ||
796 | cb = d->cb; | ||
797 | d->cb = NULL; | ||
798 | if (NULL != cb) | ||
799 | cb (d->cb_cls, | ||
800 | NULL, | ||
801 | d->cfg, | ||
802 | d, | ||
803 | (NULL == d->hostname) | ||
804 | ? _("`gnunet-arm' does not seem to terminate.\n") | ||
805 | : _("`ssh' does not seem to terminate.\n")); | ||
806 | return; | ||
807 | } | ||
808 | /* wait some more */ | ||
809 | d->task | ||
810 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
811 | &start_fsm, d); | ||
812 | return; | ||
813 | } | ||
814 | #if EXTRA_CHECKS | 797 | #if EXTRA_CHECKS |
815 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | 798 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) |
816 | { | 799 | { |
817 | cb = d->cb; | ||
818 | d->cb = NULL; | ||
819 | if (NULL != cb) | ||
820 | cb (d->cb_cls, | ||
821 | NULL, | ||
822 | d->cfg, | ||
823 | d, | ||
824 | (NULL == d->hostname) | ||
825 | ? _("`gnunet-arm' terminated with non-zero exit status (or timed out)!\n") | ||
826 | : _("`ssh' does not seem to terminate.\n")); | ||
827 | return; | ||
828 | } | ||
829 | #endif | ||
830 | #if DEBUG_TESTING | ||
831 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service startup complete!\n"); | ||
832 | #endif | ||
833 | cb = d->cb; | 800 | cb = d->cb; |
834 | d->cb = NULL; | 801 | d->cb = NULL; |
835 | d->phase = SP_START_DONE; | ||
836 | if (NULL != cb) | 802 | if (NULL != cb) |
837 | cb (d->cb_cls, &d->id, d->cfg, d, NULL); | 803 | cb (d->cb_cls, |
838 | break; | 804 | NULL, |
839 | case SP_SERVICE_SHUTDOWN_START: | 805 | d->cfg, |
840 | /* confirm copying complete */ | 806 | d, |
841 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | 807 | (NULL == d->hostname) |
842 | { | 808 | ? |
843 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == | 809 | _ |
844 | 0) | 810 | ("`gnunet-arm' terminated with non-zero exit status (or timed out)!\n") |
845 | { | 811 | : _("`ssh' does not seem to terminate.\n")); |
846 | if (NULL != d->dead_cb) | 812 | return; |
847 | d->dead_cb (d->dead_cb_cls, | 813 | } |
848 | _ | ||
849 | ("either `gnunet-arm' or `ssh' does not seem to terminate.\n")); | ||
850 | return; | ||
851 | } | ||
852 | /* wait some more */ | ||
853 | d->task | ||
854 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
855 | &start_fsm, d); | ||
856 | return; | ||
857 | } | ||
858 | #if EXTRA_CHECKS | ||
859 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | ||
860 | { | ||
861 | if (NULL != d->dead_cb) | ||
862 | d->dead_cb (d->dead_cb_cls, | ||
863 | _ | ||
864 | ("shutdown (either `gnunet-arm' or `ssh') did not complete cleanly.\n")); | ||
865 | return; | ||
866 | } | ||
867 | #endif | 814 | #endif |
868 | #if DEBUG_TESTING | 815 | #if DEBUG_TESTING |
869 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n"); | 816 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service startup complete!\n"); |
870 | #endif | 817 | #endif |
818 | cb = d->cb; | ||
819 | d->cb = NULL; | ||
820 | d->phase = SP_START_DONE; | ||
821 | if (NULL != cb) | ||
822 | cb (d->cb_cls, &d->id, d->cfg, d, NULL); | ||
823 | break; | ||
824 | case SP_SERVICE_SHUTDOWN_START: | ||
825 | /* confirm copying complete */ | ||
826 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | ||
827 | { | ||
828 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) | ||
829 | { | ||
830 | if (NULL != d->dead_cb) | ||
831 | d->dead_cb (d->dead_cb_cls, | ||
832 | _ | ||
833 | ("either `gnunet-arm' or `ssh' does not seem to terminate.\n")); | ||
834 | return; | ||
835 | } | ||
836 | /* wait some more */ | ||
837 | d->task | ||
838 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
839 | &start_fsm, d); | ||
840 | return; | ||
841 | } | ||
842 | #if EXTRA_CHECKS | ||
843 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | ||
844 | { | ||
871 | if (NULL != d->dead_cb) | 845 | if (NULL != d->dead_cb) |
872 | d->dead_cb (d->dead_cb_cls, NULL); | 846 | d->dead_cb (d->dead_cb_cls, |
873 | break; | 847 | _ |
874 | case SP_SHUTDOWN_START: | 848 | ("shutdown (either `gnunet-arm' or `ssh') did not complete cleanly.\n")); |
875 | /* confirm copying complete */ | 849 | return; |
876 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | 850 | } |
877 | { | ||
878 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == | ||
879 | 0) | ||
880 | { | ||
881 | if (NULL != d->dead_cb) | ||
882 | d->dead_cb (d->dead_cb_cls, | ||
883 | _ | ||
884 | ("either `gnunet-arm' or `ssh' does not seem to terminate.\n")); | ||
885 | if (d->th != NULL) | ||
886 | { | ||
887 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, | ||
888 | d); | ||
889 | GNUNET_TRANSPORT_disconnect (d->th); | ||
890 | d->th = NULL; | ||
891 | } | ||
892 | GNUNET_CONFIGURATION_destroy (d->cfg); | ||
893 | GNUNET_free (d->cfgfile); | ||
894 | GNUNET_free_non_null (d->hello); | ||
895 | GNUNET_free_non_null (d->hostname); | ||
896 | GNUNET_free_non_null (d->username); | ||
897 | GNUNET_free_non_null (d->shortname); | ||
898 | GNUNET_free_non_null (d->proc); | ||
899 | d->proc = NULL; | ||
900 | GNUNET_free (d); | ||
901 | return; | ||
902 | } | ||
903 | /* wait some more */ | ||
904 | d->task | ||
905 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
906 | &start_fsm, d); | ||
907 | return; | ||
908 | } | ||
909 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | ||
910 | { | ||
911 | if (NULL != d->dead_cb) | ||
912 | d->dead_cb (d->dead_cb_cls, | ||
913 | _ | ||
914 | ("shutdown (either `gnunet-arm' or `ssh') did not complete cleanly.\n")); | ||
915 | if (d->th != NULL) | ||
916 | { | ||
917 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); | ||
918 | GNUNET_TRANSPORT_disconnect (d->th); | ||
919 | d->th = NULL; | ||
920 | } | ||
921 | if (d->server != NULL) | ||
922 | { | ||
923 | GNUNET_CORE_disconnect (d->server); | ||
924 | d->server = NULL; | ||
925 | } | ||
926 | GNUNET_CONFIGURATION_destroy (d->cfg); | ||
927 | GNUNET_free (d->cfgfile); | ||
928 | GNUNET_free_non_null (d->hello); | ||
929 | GNUNET_free_non_null (d->hostname); | ||
930 | GNUNET_free_non_null (d->username); | ||
931 | GNUNET_free_non_null (d->shortname); | ||
932 | GNUNET_free_non_null (d->proc); | ||
933 | d->proc = NULL; | ||
934 | GNUNET_free (d); | ||
935 | return; | ||
936 | } | ||
937 | #if DEBUG_TESTING | ||
938 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer shutdown complete.\n"); | ||
939 | #endif | 851 | #endif |
940 | if (d->server != NULL) | 852 | #if DEBUG_TESTING |
941 | { | 853 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n"); |
942 | GNUNET_CORE_disconnect (d->server); | 854 | #endif |
943 | d->server = NULL; | 855 | if (NULL != d->dead_cb) |
944 | } | 856 | d->dead_cb (d->dead_cb_cls, NULL); |
945 | 857 | break; | |
946 | if (d->th != NULL) | 858 | case SP_SHUTDOWN_START: |
859 | /* confirm copying complete */ | ||
860 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | ||
861 | { | ||
862 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) | ||
863 | { | ||
864 | if (NULL != d->dead_cb) | ||
865 | d->dead_cb (d->dead_cb_cls, | ||
866 | _ | ||
867 | ("either `gnunet-arm' or `ssh' does not seem to terminate.\n")); | ||
868 | if (d->th != NULL) | ||
947 | { | 869 | { |
948 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); | 870 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); |
949 | GNUNET_TRANSPORT_disconnect (d->th); | 871 | GNUNET_TRANSPORT_disconnect (d->th); |
950 | d->th = NULL; | 872 | d->th = NULL; |
951 | } | 873 | } |
952 | 874 | GNUNET_CONFIGURATION_destroy (d->cfg); | |
875 | GNUNET_free (d->cfgfile); | ||
876 | GNUNET_free_non_null (d->hello); | ||
877 | GNUNET_free_non_null (d->hostname); | ||
878 | GNUNET_free_non_null (d->username); | ||
879 | GNUNET_free_non_null (d->shortname); | ||
880 | GNUNET_free_non_null (d->proc); | ||
881 | d->proc = NULL; | ||
882 | GNUNET_free (d); | ||
883 | return; | ||
884 | } | ||
885 | /* wait some more */ | ||
886 | d->task | ||
887 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
888 | &start_fsm, d); | ||
889 | return; | ||
890 | } | ||
891 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | ||
892 | { | ||
953 | if (NULL != d->dead_cb) | 893 | if (NULL != d->dead_cb) |
954 | d->dead_cb (d->dead_cb_cls, NULL); | 894 | d->dead_cb (d->dead_cb_cls, |
955 | 895 | _ | |
956 | /* state clean up and notifications */ | 896 | ("shutdown (either `gnunet-arm' or `ssh') did not complete cleanly.\n")); |
957 | if (d->churn == GNUNET_NO) | 897 | if (d->th != NULL) |
958 | { | 898 | { |
959 | GNUNET_CONFIGURATION_destroy (d->cfg); | 899 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); |
960 | GNUNET_free (d->cfgfile); | 900 | GNUNET_TRANSPORT_disconnect (d->th); |
961 | GNUNET_free_non_null (d->hostname); | 901 | d->th = NULL; |
962 | GNUNET_free_non_null (d->username); | 902 | } |
963 | } | 903 | if (d->server != NULL) |
964 | 904 | { | |
905 | GNUNET_CORE_disconnect (d->server); | ||
906 | d->server = NULL; | ||
907 | } | ||
908 | GNUNET_CONFIGURATION_destroy (d->cfg); | ||
909 | GNUNET_free (d->cfgfile); | ||
965 | GNUNET_free_non_null (d->hello); | 910 | GNUNET_free_non_null (d->hello); |
966 | d->hello = NULL; | 911 | GNUNET_free_non_null (d->hostname); |
912 | GNUNET_free_non_null (d->username); | ||
967 | GNUNET_free_non_null (d->shortname); | 913 | GNUNET_free_non_null (d->shortname); |
968 | GNUNET_free_non_null (d->proc); | 914 | GNUNET_free_non_null (d->proc); |
969 | d->proc = NULL; | 915 | d->proc = NULL; |
970 | d->shortname = NULL; | 916 | GNUNET_free (d); |
971 | if (d->churn == GNUNET_NO) | 917 | return; |
972 | GNUNET_free (d); | 918 | } |
973 | |||
974 | break; | ||
975 | case SP_CONFIG_UPDATE: | ||
976 | /* confirm copying complete */ | ||
977 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | ||
978 | { | ||
979 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) /* FIXME: config update should take timeout parameter! */ | ||
980 | { | ||
981 | cb = d->cb; | ||
982 | d->cb = NULL; | ||
983 | if (NULL != cb) | ||
984 | cb (d->cb_cls, | ||
985 | NULL, | ||
986 | d->cfg, d, _("`scp' does not seem to terminate.\n")); | ||
987 | return; | ||
988 | } | ||
989 | /* wait some more */ | ||
990 | d->task | ||
991 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
992 | &start_fsm, d); | ||
993 | return; | ||
994 | } | ||
995 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | ||
996 | { | ||
997 | if (NULL != d->update_cb) | ||
998 | d->update_cb (d->update_cb_cls, | ||
999 | _("`scp' did not complete cleanly.\n")); | ||
1000 | return; | ||
1001 | } | ||
1002 | #if DEBUG_TESTING | 919 | #if DEBUG_TESTING |
1003 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 920 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer shutdown complete.\n"); |
1004 | "Successfully copied configuration file.\n"); | ||
1005 | #endif | 921 | #endif |
922 | if (d->server != NULL) | ||
923 | { | ||
924 | GNUNET_CORE_disconnect (d->server); | ||
925 | d->server = NULL; | ||
926 | } | ||
927 | |||
928 | if (d->th != NULL) | ||
929 | { | ||
930 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); | ||
931 | GNUNET_TRANSPORT_disconnect (d->th); | ||
932 | d->th = NULL; | ||
933 | } | ||
934 | |||
935 | if (NULL != d->dead_cb) | ||
936 | d->dead_cb (d->dead_cb_cls, NULL); | ||
937 | |||
938 | /* state clean up and notifications */ | ||
939 | if (d->churn == GNUNET_NO) | ||
940 | { | ||
941 | GNUNET_CONFIGURATION_destroy (d->cfg); | ||
942 | GNUNET_free (d->cfgfile); | ||
943 | GNUNET_free_non_null (d->hostname); | ||
944 | GNUNET_free_non_null (d->username); | ||
945 | } | ||
946 | |||
947 | GNUNET_free_non_null (d->hello); | ||
948 | d->hello = NULL; | ||
949 | GNUNET_free_non_null (d->shortname); | ||
950 | GNUNET_free_non_null (d->proc); | ||
951 | d->proc = NULL; | ||
952 | d->shortname = NULL; | ||
953 | if (d->churn == GNUNET_NO) | ||
954 | GNUNET_free (d); | ||
955 | |||
956 | break; | ||
957 | case SP_CONFIG_UPDATE: | ||
958 | /* confirm copying complete */ | ||
959 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | ||
960 | { | ||
961 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) /* FIXME: config update should take timeout parameter! */ | ||
962 | { | ||
963 | cb = d->cb; | ||
964 | d->cb = NULL; | ||
965 | if (NULL != cb) | ||
966 | cb (d->cb_cls, | ||
967 | NULL, d->cfg, d, _("`scp' does not seem to terminate.\n")); | ||
968 | return; | ||
969 | } | ||
970 | /* wait some more */ | ||
971 | d->task | ||
972 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
973 | &start_fsm, d); | ||
974 | return; | ||
975 | } | ||
976 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | ||
977 | { | ||
1006 | if (NULL != d->update_cb) | 978 | if (NULL != d->update_cb) |
1007 | d->update_cb (d->update_cb_cls, NULL); | 979 | d->update_cb (d->update_cb_cls, _("`scp' did not complete cleanly.\n")); |
1008 | d->phase = SP_START_DONE; | 980 | return; |
1009 | break; | ||
1010 | } | 981 | } |
982 | #if DEBUG_TESTING | ||
983 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
984 | "Successfully copied configuration file.\n"); | ||
985 | #endif | ||
986 | if (NULL != d->update_cb) | ||
987 | d->update_cb (d->update_cb_cls, NULL); | ||
988 | d->phase = SP_START_DONE; | ||
989 | break; | ||
990 | } | ||
1011 | } | 991 | } |
1012 | 992 | ||
1013 | /** | 993 | /** |
@@ -1055,77 +1035,81 @@ GNUNET_TESTING_daemon_running (struct GNUNET_TESTING_Daemon *daemon) | |||
1055 | */ | 1035 | */ |
1056 | void | 1036 | void |
1057 | GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d, | 1037 | GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d, |
1058 | char *service, | 1038 | char *service, |
1059 | struct GNUNET_TIME_Relative timeout, | 1039 | struct GNUNET_TIME_Relative |
1060 | GNUNET_TESTING_NotifyDaemonRunning cb, void *cb_cls) | 1040 | timeout, |
1041 | GNUNET_TESTING_NotifyDaemonRunning | ||
1042 | cb, void *cb_cls) | ||
1061 | { | 1043 | { |
1062 | char *arg; | 1044 | char *arg; |
1045 | |||
1063 | d->cb = cb; | 1046 | d->cb = cb; |
1064 | d->cb_cls = cb_cls; | 1047 | d->cb_cls = cb_cls; |
1065 | 1048 | ||
1066 | GNUNET_assert(d->running == GNUNET_YES); | 1049 | GNUNET_assert (d->running == GNUNET_YES); |
1067 | 1050 | ||
1068 | if (d->phase == SP_CONFIG_UPDATE) | 1051 | if (d->phase == SP_CONFIG_UPDATE) |
1069 | { | 1052 | { |
1070 | GNUNET_SCHEDULER_cancel (d->task); | 1053 | GNUNET_SCHEDULER_cancel (d->task); |
1071 | d->phase = SP_START_DONE; | 1054 | d->phase = SP_START_DONE; |
1072 | } | 1055 | } |
1073 | 1056 | ||
1074 | if (d->churned_services == NULL) | 1057 | if (d->churned_services == NULL) |
1075 | { | 1058 | { |
1076 | d->cb(d->cb_cls, &d->id, d->cfg, d, "No service has been churned off yet!!"); | 1059 | d->cb (d->cb_cls, &d->id, d->cfg, d, |
1077 | return; | 1060 | "No service has been churned off yet!!"); |
1078 | } | 1061 | return; |
1062 | } | ||
1079 | d->phase = SP_SERVICE_START; | 1063 | d->phase = SP_SERVICE_START; |
1080 | GNUNET_free(d->churned_services); | 1064 | GNUNET_free (d->churned_services); |
1081 | d->churned_services = NULL; | 1065 | d->churned_services = NULL; |
1082 | d->max_timeout = GNUNET_TIME_relative_to_absolute(timeout); | 1066 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1083 | /* Check if this is a local or remote process */ | 1067 | /* Check if this is a local or remote process */ |
1084 | if (NULL != d->hostname) | 1068 | if (NULL != d->hostname) |
1085 | { | 1069 | { |
1086 | #if DEBUG_TESTING | 1070 | #if DEBUG_TESTING |
1087 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1071 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1088 | "Starting gnunet-arm with config `%s' on host `%s'.\n", | 1072 | "Starting gnunet-arm with config `%s' on host `%s'.\n", |
1089 | d->cfgfile, d->hostname); | 1073 | d->cfgfile, d->hostname); |
1090 | #endif | 1074 | #endif |
1091 | 1075 | ||
1092 | if (d->username != NULL) | 1076 | if (d->username != NULL) |
1093 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); | 1077 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); |
1094 | else | 1078 | else |
1095 | arg = GNUNET_strdup (d->hostname); | 1079 | arg = GNUNET_strdup (d->hostname); |
1096 | 1080 | ||
1097 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", | 1081 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", |
1098 | #if !DEBUG_TESTING | 1082 | #if !DEBUG_TESTING |
1099 | "-q", | 1083 | "-q", |
1100 | #endif | 1084 | #endif |
1101 | arg, "gnunet-arm", | 1085 | arg, "gnunet-arm", |
1102 | #if DEBUG_TESTING | 1086 | #if DEBUG_TESTING |
1103 | "-L", "DEBUG", | 1087 | "-L", "DEBUG", |
1104 | #endif | 1088 | #endif |
1105 | "-c", d->cfgfile, "-i", service, "-q", | 1089 | "-c", d->cfgfile, "-i", service, "-q", |
1106 | "-T", GNUNET_TIME_relative_to_string(timeout), | 1090 | "-T", |
1107 | NULL); | 1091 | GNUNET_TIME_relative_to_string (timeout), |
1108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1092 | NULL); |
1109 | "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i %s -q\n", | 1093 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1110 | arg, "gnunet-arm", d->cfgfile, service); | 1094 | "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i %s -q\n", |
1111 | GNUNET_free (arg); | 1095 | arg, "gnunet-arm", d->cfgfile, service); |
1112 | } | 1096 | GNUNET_free (arg); |
1097 | } | ||
1113 | else | 1098 | else |
1114 | { | 1099 | { |
1115 | #if DEBUG_TESTING | 1100 | #if DEBUG_TESTING |
1116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1101 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1117 | "Starting gnunet-arm with config `%s' locally.\n", | 1102 | "Starting gnunet-arm with config `%s' locally.\n", d->cfgfile); |
1118 | d->cfgfile); | ||
1119 | #endif | 1103 | #endif |
1120 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", | 1104 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm", |
1121 | "gnunet-arm", | ||
1122 | #if DEBUG_TESTING | 1105 | #if DEBUG_TESTING |
1123 | "-L", "DEBUG", | 1106 | "-L", "DEBUG", |
1124 | #endif | 1107 | #endif |
1125 | "-c", d->cfgfile, "-i", service, "-q", | 1108 | "-c", d->cfgfile, "-i", service, "-q", |
1126 | "-T", GNUNET_TIME_relative_to_string(timeout), | 1109 | "-T", |
1127 | NULL); | 1110 | GNUNET_TIME_relative_to_string (timeout), |
1128 | } | 1111 | NULL); |
1112 | } | ||
1129 | 1113 | ||
1130 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); | 1114 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1131 | d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d); | 1115 | d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d); |
@@ -1144,72 +1128,77 @@ void | |||
1144 | GNUNET_TESTING_daemon_start_service (struct GNUNET_TESTING_Daemon *d, | 1128 | GNUNET_TESTING_daemon_start_service (struct GNUNET_TESTING_Daemon *d, |
1145 | char *service, | 1129 | char *service, |
1146 | struct GNUNET_TIME_Relative timeout, | 1130 | struct GNUNET_TIME_Relative timeout, |
1147 | GNUNET_TESTING_NotifyDaemonRunning cb, void *cb_cls) | 1131 | GNUNET_TESTING_NotifyDaemonRunning cb, |
1132 | void *cb_cls) | ||
1148 | { | 1133 | { |
1149 | char *arg; | 1134 | char *arg; |
1135 | |||
1150 | d->cb = cb; | 1136 | d->cb = cb; |
1151 | d->cb_cls = cb_cls; | 1137 | d->cb_cls = cb_cls; |
1152 | 1138 | ||
1153 | GNUNET_assert(service != NULL); | 1139 | GNUNET_assert (service != NULL); |
1154 | GNUNET_assert(d->running == GNUNET_YES); | 1140 | GNUNET_assert (d->running == GNUNET_YES); |
1155 | GNUNET_assert(d->phase == SP_START_DONE); | 1141 | GNUNET_assert (d->phase == SP_START_DONE); |
1156 | 1142 | ||
1157 | #if DEBUG_TESTING | 1143 | #if DEBUG_TESTING |
1158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1159 | _("Starting service %s for peer `%4s'\n"), service, GNUNET_i2s (&d->id)); | 1145 | _("Starting service %s for peer `%4s'\n"), service, |
1146 | GNUNET_i2s (&d->id)); | ||
1160 | #endif | 1147 | #endif |
1161 | 1148 | ||
1162 | d->phase = SP_SERVICE_START; | 1149 | d->phase = SP_SERVICE_START; |
1163 | d->max_timeout = GNUNET_TIME_relative_to_absolute(timeout); | 1150 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1164 | /* Check if this is a local or remote process */ | 1151 | /* Check if this is a local or remote process */ |
1165 | if (NULL != d->hostname) | 1152 | if (NULL != d->hostname) |
1166 | { | 1153 | { |
1167 | #if DEBUG_TESTING | 1154 | #if DEBUG_TESTING |
1168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1155 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1169 | "Starting gnunet-arm with config `%s' on host `%s'.\n", | 1156 | "Starting gnunet-arm with config `%s' on host `%s'.\n", |
1170 | d->cfgfile, d->hostname); | 1157 | d->cfgfile, d->hostname); |
1171 | #endif | 1158 | #endif |
1172 | 1159 | ||
1173 | if (d->username != NULL) | 1160 | if (d->username != NULL) |
1174 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); | 1161 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); |
1175 | else | 1162 | else |
1176 | arg = GNUNET_strdup (d->hostname); | 1163 | arg = GNUNET_strdup (d->hostname); |
1177 | 1164 | ||
1178 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", | 1165 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", |
1179 | #if !DEBUG_TESTING | 1166 | #if !DEBUG_TESTING |
1180 | "-q", | 1167 | "-q", |
1181 | #endif | 1168 | #endif |
1182 | arg, "gnunet-arm", | 1169 | arg, "gnunet-arm", |
1183 | #if DEBUG_TESTING | 1170 | #if DEBUG_TESTING |
1184 | "-L", "DEBUG", | 1171 | "-L", "DEBUG", |
1185 | #endif | 1172 | #endif |
1186 | "-c", d->cfgfile, "-i", service, "-q", | 1173 | "-c", d->cfgfile, "-i", service, "-q", |
1187 | "-T", GNUNET_TIME_relative_to_string(timeout), | 1174 | "-T", |
1188 | NULL); | 1175 | GNUNET_TIME_relative_to_string (timeout), |
1189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1176 | NULL); |
1190 | "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i %s -q -T %s\n", | 1177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1191 | arg, "gnunet-arm", d->cfgfile, service, GNUNET_TIME_relative_to_string(timeout)); | 1178 | "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i %s -q -T %s\n", |
1192 | GNUNET_free (arg); | 1179 | arg, "gnunet-arm", d->cfgfile, service, |
1193 | } | 1180 | GNUNET_TIME_relative_to_string (timeout)); |
1181 | GNUNET_free (arg); | ||
1182 | } | ||
1194 | else | 1183 | else |
1195 | { | 1184 | { |
1196 | #if DEBUG_TESTING | 1185 | #if DEBUG_TESTING |
1197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1186 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1198 | "Starting gnunet-arm with config `%s' locally.\n", | 1187 | "Starting gnunet-arm with config `%s' locally.\n", d->cfgfile); |
1199 | d->cfgfile); | ||
1200 | #endif | 1188 | #endif |
1201 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", | 1189 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm", |
1202 | "gnunet-arm", | ||
1203 | #if DEBUG_TESTING | 1190 | #if DEBUG_TESTING |
1204 | "-L", "DEBUG", | 1191 | "-L", "DEBUG", |
1205 | #endif | 1192 | #endif |
1206 | "-c", d->cfgfile, "-i", service, "-q", | 1193 | "-c", d->cfgfile, "-i", service, "-q", |
1207 | "-T", GNUNET_TIME_relative_to_string(timeout), | 1194 | "-T", |
1208 | NULL); | 1195 | GNUNET_TIME_relative_to_string (timeout), |
1209 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1196 | NULL); |
1210 | "Starting gnunet-arm with command %s -c %s -i %s -q -T %s\n", | 1197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1211 | "gnunet-arm", d->cfgfile, service, GNUNET_TIME_relative_to_string(timeout)); | 1198 | "Starting gnunet-arm with command %s -c %s -i %s -q -T %s\n", |
1212 | } | 1199 | "gnunet-arm", d->cfgfile, service, |
1200 | GNUNET_TIME_relative_to_string (timeout)); | ||
1201 | } | ||
1213 | 1202 | ||
1214 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); | 1203 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1215 | d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d); | 1204 | d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d); |
@@ -1231,11 +1220,11 @@ GNUNET_TESTING_daemon_start_stopped (struct GNUNET_TESTING_Daemon *daemon, | |||
1231 | void *cb_cls) | 1220 | void *cb_cls) |
1232 | { | 1221 | { |
1233 | if (daemon->running == GNUNET_YES) | 1222 | if (daemon->running == GNUNET_YES) |
1234 | { | 1223 | { |
1235 | cb (cb_cls, &daemon->id, daemon->cfg, daemon, | 1224 | cb (cb_cls, &daemon->id, daemon->cfg, daemon, |
1236 | "Daemon already running, can't restart!"); | 1225 | "Daemon already running, can't restart!"); |
1237 | return; | 1226 | return; |
1238 | } | 1227 | } |
1239 | 1228 | ||
1240 | daemon->cb = cb; | 1229 | daemon->cb = cb; |
1241 | daemon->cb_cls = cb_cls; | 1230 | daemon->cb_cls = cb_cls; |
@@ -1298,35 +1287,34 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1298 | ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon)); | 1287 | ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon)); |
1299 | ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname); | 1288 | ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname); |
1300 | if (sshport != 0) | 1289 | if (sshport != 0) |
1301 | { | 1290 | { |
1302 | GNUNET_asprintf (&ret->ssh_port_str, "%d", sshport); | 1291 | GNUNET_asprintf (&ret->ssh_port_str, "%d", sshport); |
1303 | } | 1292 | } |
1304 | else | 1293 | else |
1305 | ret->ssh_port_str = NULL; | 1294 | ret->ssh_port_str = NULL; |
1306 | 1295 | ||
1307 | /* Find service home and base service home directories, create it if it doesn't exist */ | 1296 | /* Find service home and base service home directories, create it if it doesn't exist */ |
1308 | GNUNET_assert(GNUNET_OK == | 1297 | GNUNET_assert (GNUNET_OK == |
1309 | GNUNET_CONFIGURATION_get_value_string (cfg, | 1298 | GNUNET_CONFIGURATION_get_value_string (cfg, |
1310 | "PATHS", | 1299 | "PATHS", |
1311 | "SERVICEHOME", | 1300 | "SERVICEHOME", |
1312 | &servicehome)); | 1301 | &servicehome)); |
1313 | 1302 | ||
1314 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_create (servicehome)); | 1303 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_create (servicehome)); |
1315 | GNUNET_asprintf(&temp_file_name, "%s/gnunet-testing-config", servicehome); | 1304 | GNUNET_asprintf (&temp_file_name, "%s/gnunet-testing-config", servicehome); |
1316 | ret->cfgfile = GNUNET_DISK_mktemp (temp_file_name); | 1305 | ret->cfgfile = GNUNET_DISK_mktemp (temp_file_name); |
1317 | GNUNET_free(temp_file_name); | 1306 | GNUNET_free (temp_file_name); |
1318 | #if DEBUG_TESTING | 1307 | #if DEBUG_TESTING |
1319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1308 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1320 | "Setting up peer with configuration file `%s'.\n", | 1309 | "Setting up peer with configuration file `%s'.\n", ret->cfgfile); |
1321 | ret->cfgfile); | ||
1322 | #endif | 1310 | #endif |
1323 | if (NULL == ret->cfgfile) | 1311 | if (NULL == ret->cfgfile) |
1324 | { | 1312 | { |
1325 | GNUNET_free_non_null (ret->ssh_port_str); | 1313 | GNUNET_free_non_null (ret->ssh_port_str); |
1326 | GNUNET_free_non_null (ret->hostname); | 1314 | GNUNET_free_non_null (ret->hostname); |
1327 | GNUNET_free (ret); | 1315 | GNUNET_free (ret); |
1328 | return NULL; | 1316 | return NULL; |
1329 | } | 1317 | } |
1330 | ret->hostkey_callback = hostkey_callback; | 1318 | ret->hostkey_callback = hostkey_callback; |
1331 | ret->hostkey_cls = hostkey_cls; | 1319 | ret->hostkey_cls = hostkey_cls; |
1332 | ret->cb = cb; | 1320 | ret->cb = cb; |
@@ -1337,46 +1325,47 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1337 | "PATHS", | 1325 | "PATHS", |
1338 | "DEFAULTCONFIG", ret->cfgfile); | 1326 | "DEFAULTCONFIG", ret->cfgfile); |
1339 | 1327 | ||
1340 | if (hostkey != NULL) /* Get the peer identity from the hostkey */ | 1328 | if (hostkey != NULL) /* Get the peer identity from the hostkey */ |
1341 | { | 1329 | { |
1342 | private_key = GNUNET_CRYPTO_rsa_decode_key(hostkey, HOSTKEYFILESIZE); | 1330 | private_key = GNUNET_CRYPTO_rsa_decode_key (hostkey, HOSTKEYFILESIZE); |
1343 | GNUNET_assert(private_key != NULL); | 1331 | GNUNET_assert (private_key != NULL); |
1344 | GNUNET_CRYPTO_rsa_key_get_public (private_key, | 1332 | GNUNET_CRYPTO_rsa_key_get_public (private_key, &public_key); |
1345 | &public_key); | 1333 | GNUNET_CRYPTO_hash (&public_key, |
1346 | GNUNET_CRYPTO_hash(&public_key, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &ret->id.hashPubKey); | 1334 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
1347 | ret->shortname = GNUNET_strdup(GNUNET_i2s(&ret->id)); | 1335 | &ret->id.hashPubKey); |
1348 | ret->have_hostkey = GNUNET_YES; | 1336 | ret->shortname = GNUNET_strdup (GNUNET_i2s (&ret->id)); |
1349 | GNUNET_CRYPTO_rsa_key_free(private_key); | 1337 | ret->have_hostkey = GNUNET_YES; |
1350 | } | 1338 | GNUNET_CRYPTO_rsa_key_free (private_key); |
1339 | } | ||
1351 | 1340 | ||
1352 | /* Write hostkey to file, if we were given one */ | 1341 | /* Write hostkey to file, if we were given one */ |
1353 | hostkeyfile = NULL; | 1342 | hostkeyfile = NULL; |
1354 | if (hostkey != NULL) | 1343 | if (hostkey != NULL) |
1355 | { | 1344 | { |
1356 | GNUNET_asprintf(&hostkeyfile, "%s/.hostkey", servicehome); | 1345 | GNUNET_asprintf (&hostkeyfile, "%s/.hostkey", servicehome); |
1357 | fn = | 1346 | fn = GNUNET_DISK_file_open (hostkeyfile, |
1358 | GNUNET_DISK_file_open (hostkeyfile, | 1347 | GNUNET_DISK_OPEN_READWRITE |
1359 | GNUNET_DISK_OPEN_READWRITE | 1348 | | GNUNET_DISK_OPEN_CREATE, |
1360 | | GNUNET_DISK_OPEN_CREATE, | 1349 | GNUNET_DISK_PERM_USER_READ | |
1361 | GNUNET_DISK_PERM_USER_READ | | 1350 | GNUNET_DISK_PERM_USER_WRITE); |
1362 | GNUNET_DISK_PERM_USER_WRITE); | 1351 | GNUNET_assert (fn != NULL); |
1363 | GNUNET_assert(fn != NULL); | 1352 | GNUNET_assert (HOSTKEYFILESIZE == |
1364 | GNUNET_assert(HOSTKEYFILESIZE == GNUNET_DISK_file_write(fn, hostkey, HOSTKEYFILESIZE)); | 1353 | GNUNET_DISK_file_write (fn, hostkey, HOSTKEYFILESIZE)); |
1365 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fn)); | 1354 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fn)); |
1366 | } | 1355 | } |
1367 | 1356 | ||
1368 | /* write configuration to temporary file */ | 1357 | /* write configuration to temporary file */ |
1369 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (ret->cfg, ret->cfgfile)) | 1358 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (ret->cfg, ret->cfgfile)) |
1370 | { | 1359 | { |
1371 | if (0 != UNLINK (ret->cfgfile)) | 1360 | if (0 != UNLINK (ret->cfgfile)) |
1372 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 1361 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
1373 | "unlink", ret->cfgfile); | 1362 | "unlink", ret->cfgfile); |
1374 | GNUNET_CONFIGURATION_destroy (ret->cfg); | 1363 | GNUNET_CONFIGURATION_destroy (ret->cfg); |
1375 | GNUNET_free_non_null (ret->hostname); | 1364 | GNUNET_free_non_null (ret->hostname); |
1376 | GNUNET_free (ret->cfgfile); | 1365 | GNUNET_free (ret->cfgfile); |
1377 | GNUNET_free (ret); | 1366 | GNUNET_free (ret); |
1378 | return NULL; | 1367 | return NULL; |
1379 | } | 1368 | } |
1380 | if (ssh_username != NULL) | 1369 | if (ssh_username != NULL) |
1381 | username = GNUNET_strdup (ssh_username); | 1370 | username = GNUNET_strdup (ssh_username); |
1382 | if ((ssh_username == NULL) && (GNUNET_OK != | 1371 | if ((ssh_username == NULL) && (GNUNET_OK != |
@@ -1384,103 +1373,103 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1384 | "TESTING", | 1373 | "TESTING", |
1385 | "USERNAME", | 1374 | "USERNAME", |
1386 | &username))) | 1375 | &username))) |
1387 | { | 1376 | { |
1388 | if (NULL != getenv ("USER")) | 1377 | if (NULL != getenv ("USER")) |
1389 | username = GNUNET_strdup (getenv ("USER")); | 1378 | username = GNUNET_strdup (getenv ("USER")); |
1390 | else | 1379 | else |
1391 | username = NULL; | 1380 | username = NULL; |
1392 | } | 1381 | } |
1393 | ret->username = username; | 1382 | ret->username = username; |
1394 | 1383 | ||
1395 | if (GNUNET_NO == pretend) /* Copy files, enter finite state machine */ | 1384 | if (GNUNET_NO == pretend) /* Copy files, enter finite state machine */ |
1385 | { | ||
1386 | /* copy directory to remote host */ | ||
1387 | if (NULL != hostname) | ||
1396 | { | 1388 | { |
1397 | /* copy directory to remote host */ | ||
1398 | if (NULL != hostname) | ||
1399 | { | ||
1400 | #if DEBUG_TESTING | 1389 | #if DEBUG_TESTING |
1401 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1390 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1402 | "Copying configuration directory to host `%s'.\n", hostname); | 1391 | "Copying configuration directory to host `%s'.\n", hostname); |
1403 | #endif | 1392 | #endif |
1404 | baseservicehome = GNUNET_strdup(servicehome); | 1393 | baseservicehome = GNUNET_strdup (servicehome); |
1405 | /* Remove trailing /'s */ | 1394 | /* Remove trailing /'s */ |
1406 | while (baseservicehome[strlen(baseservicehome) - 1] == '/') | 1395 | while (baseservicehome[strlen (baseservicehome) - 1] == '/') |
1407 | baseservicehome[strlen(baseservicehome) - 1] = '\0'; | 1396 | baseservicehome[strlen (baseservicehome) - 1] = '\0'; |
1408 | /* Find next directory /, jump one ahead */ | 1397 | /* Find next directory /, jump one ahead */ |
1409 | slash = strrchr(baseservicehome, '/'); | 1398 | slash = strrchr (baseservicehome, '/'); |
1410 | if (slash != NULL) | 1399 | if (slash != NULL) |
1411 | *(++slash) = '\0'; | 1400 | *(++slash) = '\0'; |
1412 | 1401 | ||
1413 | ret->phase = SP_COPYING; | 1402 | ret->phase = SP_COPYING; |
1414 | if (NULL != username) | 1403 | if (NULL != username) |
1415 | GNUNET_asprintf (&arg, "%s@%s:%s", username, hostname, baseservicehome); | 1404 | GNUNET_asprintf (&arg, "%s@%s:%s", username, hostname, baseservicehome); |
1416 | else | 1405 | else |
1417 | GNUNET_asprintf (&arg, "%s:%s", hostname, baseservicehome); | 1406 | GNUNET_asprintf (&arg, "%s:%s", hostname, baseservicehome); |
1418 | GNUNET_free(baseservicehome); | 1407 | GNUNET_free (baseservicehome); |
1419 | if (ret->ssh_port_str == NULL) | 1408 | if (ret->ssh_port_str == NULL) |
1420 | { | 1409 | { |
1421 | ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", "-r", | 1410 | ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", "-r", |
1422 | #if !DEBUG_TESTING | 1411 | #if !DEBUG_TESTING |
1423 | "-q", | 1412 | "-q", |
1424 | #endif | 1413 | #endif |
1425 | servicehome, arg, NULL); | 1414 | servicehome, arg, NULL); |
1426 | #if DEBUG_TESTING | 1415 | #if DEBUG_TESTING |
1427 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1416 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1428 | "copying directory with command scp -r %s %s\n", | 1417 | "copying directory with command scp -r %s %s\n", |
1429 | servicehome, | 1418 | servicehome, arg); |
1430 | arg); | ||
1431 | #endif | ||
1432 | } | ||
1433 | else | ||
1434 | { | ||
1435 | ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", | ||
1436 | "scp", "-r", "-P", ret->ssh_port_str, | ||
1437 | #if !DEBUG_TESTING | ||
1438 | "-q", | ||
1439 | #endif | ||
1440 | servicehome, arg, NULL); | ||
1441 | } | ||
1442 | GNUNET_free (arg); | ||
1443 | if (NULL == ret->proc) | ||
1444 | { | ||
1445 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1446 | _ | ||
1447 | ("Could not start `%s' process to copy configuration directory.\n"), | ||
1448 | "scp"); | ||
1449 | if (0 != UNLINK (ret->cfgfile)) | ||
1450 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
1451 | "unlink", ret->cfgfile); | ||
1452 | GNUNET_CONFIGURATION_destroy (ret->cfg); | ||
1453 | GNUNET_free_non_null (ret->hostname); | ||
1454 | GNUNET_free_non_null (ret->username); | ||
1455 | GNUNET_free (ret->cfgfile); | ||
1456 | GNUNET_free (ret); | ||
1457 | if ((hostkey != NULL) && (0 != UNLINK(hostkeyfile))) | ||
1458 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
1459 | "unlink", hostkeyfile); | ||
1460 | GNUNET_free_non_null(hostkeyfile); | ||
1461 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (servicehome)); | ||
1462 | GNUNET_free(servicehome); | ||
1463 | return NULL; | ||
1464 | } | ||
1465 | |||
1466 | ret->task | ||
1467 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
1468 | &start_fsm, ret); | ||
1469 | GNUNET_free_non_null(hostkeyfile); | ||
1470 | GNUNET_free(servicehome); | ||
1471 | return ret; | ||
1472 | } | ||
1473 | #if DEBUG_TESTING | ||
1474 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1475 | "No need to copy configuration file since we are running locally.\n"); | ||
1476 | #endif | 1419 | #endif |
1477 | ret->phase = SP_COPIED; | 1420 | } |
1478 | GNUNET_SCHEDULER_add_continuation (&start_fsm, | 1421 | else |
1479 | ret, | 1422 | { |
1480 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 1423 | ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", |
1424 | "scp", "-r", "-P", | ||
1425 | ret->ssh_port_str, | ||
1426 | #if !DEBUG_TESTING | ||
1427 | "-q", | ||
1428 | #endif | ||
1429 | servicehome, arg, NULL); | ||
1430 | } | ||
1431 | GNUNET_free (arg); | ||
1432 | if (NULL == ret->proc) | ||
1433 | { | ||
1434 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1435 | _ | ||
1436 | ("Could not start `%s' process to copy configuration directory.\n"), | ||
1437 | "scp"); | ||
1438 | if (0 != UNLINK (ret->cfgfile)) | ||
1439 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
1440 | "unlink", ret->cfgfile); | ||
1441 | GNUNET_CONFIGURATION_destroy (ret->cfg); | ||
1442 | GNUNET_free_non_null (ret->hostname); | ||
1443 | GNUNET_free_non_null (ret->username); | ||
1444 | GNUNET_free (ret->cfgfile); | ||
1445 | GNUNET_free (ret); | ||
1446 | if ((hostkey != NULL) && (0 != UNLINK (hostkeyfile))) | ||
1447 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
1448 | "unlink", hostkeyfile); | ||
1449 | GNUNET_free_non_null (hostkeyfile); | ||
1450 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (servicehome)); | ||
1451 | GNUNET_free (servicehome); | ||
1452 | return NULL; | ||
1453 | } | ||
1454 | |||
1455 | ret->task | ||
1456 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
1457 | &start_fsm, ret); | ||
1458 | GNUNET_free_non_null (hostkeyfile); | ||
1459 | GNUNET_free (servicehome); | ||
1460 | return ret; | ||
1481 | } | 1461 | } |
1482 | GNUNET_free_non_null(hostkeyfile); | 1462 | #if DEBUG_TESTING |
1483 | GNUNET_free(servicehome); | 1463 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1464 | "No need to copy configuration file since we are running locally.\n"); | ||
1465 | #endif | ||
1466 | ret->phase = SP_COPIED; | ||
1467 | GNUNET_SCHEDULER_add_continuation (&start_fsm, | ||
1468 | ret, | ||
1469 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
1470 | } | ||
1471 | GNUNET_free_non_null (hostkeyfile); | ||
1472 | GNUNET_free (servicehome); | ||
1484 | return ret; | 1473 | return ret; |
1485 | } | 1474 | } |
1486 | 1475 | ||
@@ -1502,31 +1491,31 @@ GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d, | |||
1502 | 1491 | ||
1503 | del_arg = NULL; | 1492 | del_arg = NULL; |
1504 | if (NULL != d->cb) | 1493 | if (NULL != d->cb) |
1505 | { | 1494 | { |
1506 | d->dead = GNUNET_YES; | 1495 | d->dead = GNUNET_YES; |
1507 | return; | 1496 | return; |
1508 | } | 1497 | } |
1509 | 1498 | ||
1510 | d->cb = cb; | 1499 | d->cb = cb; |
1511 | d->cb_cls = cb_cls; | 1500 | d->cb_cls = cb_cls; |
1512 | 1501 | ||
1513 | if (d->phase == SP_CONFIG_UPDATE) | 1502 | if (d->phase == SP_CONFIG_UPDATE) |
1514 | { | 1503 | { |
1515 | GNUNET_SCHEDULER_cancel (d->task); | 1504 | GNUNET_SCHEDULER_cancel (d->task); |
1516 | d->phase = SP_START_DONE; | 1505 | d->phase = SP_START_DONE; |
1517 | } | 1506 | } |
1518 | if (d->server != NULL) | 1507 | if (d->server != NULL) |
1519 | { | 1508 | { |
1520 | GNUNET_CORE_disconnect (d->server); | 1509 | GNUNET_CORE_disconnect (d->server); |
1521 | d->server = NULL; | 1510 | d->server = NULL; |
1522 | } | 1511 | } |
1523 | 1512 | ||
1524 | if (d->th != NULL) | 1513 | if (d->th != NULL) |
1525 | { | 1514 | { |
1526 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); | 1515 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); |
1527 | GNUNET_TRANSPORT_disconnect (d->th); | 1516 | GNUNET_TRANSPORT_disconnect (d->th); |
1528 | d->th = NULL; | 1517 | d->th = NULL; |
1529 | } | 1518 | } |
1530 | /* state clean up and notifications */ | 1519 | /* state clean up and notifications */ |
1531 | GNUNET_free_non_null (d->hello); | 1520 | GNUNET_free_non_null (d->hello); |
1532 | 1521 | ||
@@ -1539,50 +1528,48 @@ GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d, | |||
1539 | 1528 | ||
1540 | /* Check if this is a local or remote process */ | 1529 | /* Check if this is a local or remote process */ |
1541 | if (NULL != d->hostname) | 1530 | if (NULL != d->hostname) |
1542 | { | 1531 | { |
1543 | #if DEBUG_TESTING | 1532 | #if DEBUG_TESTING |
1544 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1533 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1545 | "Stopping gnunet-arm with config `%s' on host `%s'.\n", | 1534 | "Stopping gnunet-arm with config `%s' on host `%s'.\n", |
1546 | d->cfgfile, d->hostname); | 1535 | d->cfgfile, d->hostname); |
1547 | #endif | 1536 | #endif |
1548 | 1537 | ||
1549 | if (d->username != NULL) | 1538 | if (d->username != NULL) |
1550 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); | 1539 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); |
1551 | else | 1540 | else |
1552 | arg = GNUNET_strdup (d->hostname); | 1541 | arg = GNUNET_strdup (d->hostname); |
1553 | 1542 | ||
1554 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", | 1543 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", |
1555 | #if !DEBUG_TESTING | 1544 | #if !DEBUG_TESTING |
1556 | "-q", | 1545 | "-q", |
1557 | #endif | 1546 | #endif |
1558 | arg, "gnunet-arm", | 1547 | arg, "gnunet-arm", |
1559 | #if DEBUG_TESTING | 1548 | #if DEBUG_TESTING |
1560 | "-L", "DEBUG", | 1549 | "-L", "DEBUG", |
1561 | #endif | 1550 | #endif |
1562 | "-c", d->cfgfile, "-e", "-r", NULL); | 1551 | "-c", d->cfgfile, "-e", "-r", NULL); |
1563 | /* Use -r to restart arm and all services */ | 1552 | /* Use -r to restart arm and all services */ |
1564 | 1553 | ||
1565 | GNUNET_free (arg); | 1554 | GNUNET_free (arg); |
1566 | } | 1555 | } |
1567 | else | 1556 | else |
1568 | { | 1557 | { |
1569 | #if DEBUG_TESTING | 1558 | #if DEBUG_TESTING |
1570 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1559 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1571 | "Stopping gnunet-arm with config `%s' locally.\n", | 1560 | "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile); |
1572 | d->cfgfile); | ||
1573 | #endif | 1561 | #endif |
1574 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", | 1562 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm", |
1575 | "gnunet-arm", | ||
1576 | #if DEBUG_TESTING | 1563 | #if DEBUG_TESTING |
1577 | "-L", "DEBUG", | 1564 | "-L", "DEBUG", |
1578 | #endif | 1565 | #endif |
1579 | "-c", d->cfgfile, "-e", "-r", NULL); | 1566 | "-c", d->cfgfile, "-e", "-r", NULL); |
1580 | } | 1567 | } |
1581 | 1568 | ||
1582 | GNUNET_free_non_null (del_arg); | 1569 | GNUNET_free_non_null (del_arg); |
1583 | d->task | 1570 | d->task |
1584 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | 1571 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, |
1585 | &start_fsm, d); | 1572 | &start_fsm, d); |
1586 | 1573 | ||
1587 | } | 1574 | } |
1588 | 1575 | ||
@@ -1604,78 +1591,80 @@ void | |||
1604 | GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d, | 1591 | GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d, |
1605 | char *service, | 1592 | char *service, |
1606 | struct GNUNET_TIME_Relative timeout, | 1593 | struct GNUNET_TIME_Relative timeout, |
1607 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) | 1594 | GNUNET_TESTING_NotifyCompletion cb, |
1595 | void *cb_cls) | ||
1608 | { | 1596 | { |
1609 | char *arg; | 1597 | char *arg; |
1598 | |||
1610 | d->dead_cb = cb; | 1599 | d->dead_cb = cb; |
1611 | d->dead_cb_cls = cb_cls; | 1600 | d->dead_cb_cls = cb_cls; |
1612 | 1601 | ||
1613 | GNUNET_assert(d->running == GNUNET_YES); | 1602 | GNUNET_assert (d->running == GNUNET_YES); |
1614 | 1603 | ||
1615 | if (d->phase == SP_CONFIG_UPDATE) | 1604 | if (d->phase == SP_CONFIG_UPDATE) |
1616 | { | 1605 | { |
1617 | GNUNET_SCHEDULER_cancel (d->task); | 1606 | GNUNET_SCHEDULER_cancel (d->task); |
1618 | d->phase = SP_START_DONE; | 1607 | d->phase = SP_START_DONE; |
1619 | } | 1608 | } |
1620 | 1609 | ||
1621 | #if DEBUG_TESTING | 1610 | #if DEBUG_TESTING |
1622 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1611 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1623 | _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id)); | 1612 | _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id)); |
1624 | #endif | 1613 | #endif |
1625 | if (d->churned_services != NULL) | 1614 | if (d->churned_services != NULL) |
1626 | { | 1615 | { |
1627 | d->dead_cb(d->dead_cb_cls, "A service has already been turned off!!"); | 1616 | d->dead_cb (d->dead_cb_cls, "A service has already been turned off!!"); |
1628 | return; | 1617 | return; |
1629 | } | 1618 | } |
1630 | d->phase = SP_SERVICE_SHUTDOWN_START; | 1619 | d->phase = SP_SERVICE_SHUTDOWN_START; |
1631 | d->churned_services = GNUNET_strdup(service); | 1620 | d->churned_services = GNUNET_strdup (service); |
1632 | d->max_timeout = GNUNET_TIME_relative_to_absolute(timeout); | 1621 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1633 | /* Check if this is a local or remote process */ | 1622 | /* Check if this is a local or remote process */ |
1634 | if (NULL != d->hostname) | 1623 | if (NULL != d->hostname) |
1635 | { | 1624 | { |
1636 | #if DEBUG_TESTING | 1625 | #if DEBUG_TESTING |
1637 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1626 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1638 | "Stopping gnunet-arm with config `%s' on host `%s'.\n", | 1627 | "Stopping gnunet-arm with config `%s' on host `%s'.\n", |
1639 | d->cfgfile, d->hostname); | 1628 | d->cfgfile, d->hostname); |
1640 | #endif | 1629 | #endif |
1641 | 1630 | ||
1642 | if (d->username != NULL) | 1631 | if (d->username != NULL) |
1643 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); | 1632 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); |
1644 | else | 1633 | else |
1645 | arg = GNUNET_strdup (d->hostname); | 1634 | arg = GNUNET_strdup (d->hostname); |
1646 | 1635 | ||
1647 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", | 1636 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", |
1648 | #if !DEBUG_TESTING | 1637 | #if !DEBUG_TESTING |
1649 | "-q", | 1638 | "-q", |
1650 | #endif | 1639 | #endif |
1651 | arg, "gnunet-arm", | 1640 | arg, "gnunet-arm", |
1652 | #if DEBUG_TESTING | 1641 | #if DEBUG_TESTING |
1653 | "-L", "DEBUG", | 1642 | "-L", "DEBUG", |
1654 | #endif | 1643 | #endif |
1655 | "-c", d->cfgfile, "-k", service, "-q", | 1644 | "-c", d->cfgfile, "-k", service, "-q", |
1656 | "-T", GNUNET_TIME_relative_to_string(timeout), | 1645 | "-T", |
1657 | NULL); | 1646 | GNUNET_TIME_relative_to_string (timeout), |
1658 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1647 | NULL); |
1659 | "Stopping gnunet-arm with command ssh %s gnunet-arm -c %s -k %s -q\n", | 1648 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1660 | arg, "gnunet-arm", d->cfgfile, service); | 1649 | "Stopping gnunet-arm with command ssh %s gnunet-arm -c %s -k %s -q\n", |
1661 | GNUNET_free (arg); | 1650 | arg, "gnunet-arm", d->cfgfile, service); |
1662 | } | 1651 | GNUNET_free (arg); |
1652 | } | ||
1663 | else | 1653 | else |
1664 | { | 1654 | { |
1665 | #if DEBUG_TESTING | 1655 | #if DEBUG_TESTING |
1666 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1656 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1667 | "Stopping gnunet-arm with config `%s' locally.\n", | 1657 | "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile); |
1668 | d->cfgfile); | ||
1669 | #endif | 1658 | #endif |
1670 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", | 1659 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm", |
1671 | "gnunet-arm", | ||
1672 | #if DEBUG_TESTING | 1660 | #if DEBUG_TESTING |
1673 | "-L", "DEBUG", | 1661 | "-L", "DEBUG", |
1674 | #endif | 1662 | #endif |
1675 | "-c", d->cfgfile, "-k", service, "-q", | 1663 | "-c", d->cfgfile, "-k", service, "-q", |
1676 | "-T", GNUNET_TIME_relative_to_string(timeout), | 1664 | "-T", |
1677 | NULL); | 1665 | GNUNET_TIME_relative_to_string (timeout), |
1678 | } | 1666 | NULL); |
1667 | } | ||
1679 | 1668 | ||
1680 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); | 1669 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1681 | d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d); | 1670 | d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d); |
@@ -1702,51 +1691,52 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | |||
1702 | { | 1691 | { |
1703 | char *arg; | 1692 | char *arg; |
1704 | char *del_arg; | 1693 | char *del_arg; |
1694 | |||
1705 | d->dead_cb = cb; | 1695 | d->dead_cb = cb; |
1706 | d->dead_cb_cls = cb_cls; | 1696 | d->dead_cb_cls = cb_cls; |
1707 | 1697 | ||
1708 | if (NULL != d->cb) | 1698 | if (NULL != d->cb) |
1709 | { | 1699 | { |
1710 | #if DEBUG_TESTING | 1700 | #if DEBUG_TESTING |
1711 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1701 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1712 | _("Setting d->dead on peer `%4s'\n"), GNUNET_i2s (&d->id)); | 1702 | _("Setting d->dead on peer `%4s'\n"), GNUNET_i2s (&d->id)); |
1713 | #endif | 1703 | #endif |
1714 | d->dead = GNUNET_YES; | 1704 | d->dead = GNUNET_YES; |
1715 | return; | 1705 | return; |
1716 | } | 1706 | } |
1717 | 1707 | ||
1718 | if ((d->running == GNUNET_NO) && (d->churn == GNUNET_YES)) /* Peer has already been stopped in churn context! */ | 1708 | if ((d->running == GNUNET_NO) && (d->churn == GNUNET_YES)) /* Peer has already been stopped in churn context! */ |
1719 | { | 1709 | { |
1720 | /* Free what was left from churning! */ | 1710 | /* Free what was left from churning! */ |
1721 | GNUNET_assert (d->cfg != NULL); | 1711 | GNUNET_assert (d->cfg != NULL); |
1722 | GNUNET_CONFIGURATION_destroy (d->cfg); | 1712 | GNUNET_CONFIGURATION_destroy (d->cfg); |
1723 | if (delete_files == GNUNET_YES) | 1713 | if (delete_files == GNUNET_YES) |
1724 | { | 1714 | { |
1725 | if (0 != UNLINK (d->cfgfile)) | 1715 | if (0 != UNLINK (d->cfgfile)) |
1726 | { | 1716 | { |
1727 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "unlink"); | 1717 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "unlink"); |
1728 | } | 1718 | } |
1729 | } | 1719 | } |
1730 | GNUNET_free (d->cfgfile); | 1720 | GNUNET_free (d->cfgfile); |
1731 | GNUNET_free_non_null (d->hostname); | 1721 | GNUNET_free_non_null (d->hostname); |
1732 | GNUNET_free_non_null (d->username); | 1722 | GNUNET_free_non_null (d->username); |
1733 | if (NULL != d->dead_cb) | 1723 | if (NULL != d->dead_cb) |
1734 | d->dead_cb (d->dead_cb_cls, NULL); | 1724 | d->dead_cb (d->dead_cb_cls, NULL); |
1735 | GNUNET_free (d); | 1725 | GNUNET_free (d); |
1736 | return; | 1726 | return; |
1737 | } | 1727 | } |
1738 | 1728 | ||
1739 | del_arg = NULL; | 1729 | del_arg = NULL; |
1740 | if (delete_files == GNUNET_YES) | 1730 | if (delete_files == GNUNET_YES) |
1741 | { | 1731 | { |
1742 | GNUNET_asprintf (&del_arg, "-d"); | 1732 | GNUNET_asprintf (&del_arg, "-d"); |
1743 | } | 1733 | } |
1744 | 1734 | ||
1745 | if (d->phase == SP_CONFIG_UPDATE) | 1735 | if (d->phase == SP_CONFIG_UPDATE) |
1746 | { | 1736 | { |
1747 | GNUNET_SCHEDULER_cancel (d->task); | 1737 | GNUNET_SCHEDULER_cancel (d->task); |
1748 | d->phase = SP_START_DONE; | 1738 | d->phase = SP_START_DONE; |
1749 | } | 1739 | } |
1750 | /** Move this call to scheduled shutdown as fix for CORE_connect calling daemon_stop? | 1740 | /** Move this call to scheduled shutdown as fix for CORE_connect calling daemon_stop? |
1751 | if (d->server != NULL) | 1741 | if (d->server != NULL) |
1752 | { | 1742 | { |
@@ -1764,58 +1754,58 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | |||
1764 | if (allow_restart == GNUNET_YES) | 1754 | if (allow_restart == GNUNET_YES) |
1765 | d->churn = GNUNET_YES; | 1755 | d->churn = GNUNET_YES; |
1766 | if (d->th != NULL) | 1756 | if (d->th != NULL) |
1767 | { | 1757 | { |
1768 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); | 1758 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); |
1769 | GNUNET_TRANSPORT_disconnect (d->th); | 1759 | GNUNET_TRANSPORT_disconnect (d->th); |
1770 | d->th = NULL; | 1760 | d->th = NULL; |
1771 | } | 1761 | } |
1772 | /* Check if this is a local or remote process */ | 1762 | /* Check if this is a local or remote process */ |
1773 | if (NULL != d->hostname) | 1763 | if (NULL != d->hostname) |
1774 | { | 1764 | { |
1775 | #if DEBUG_TESTING | 1765 | #if DEBUG_TESTING |
1776 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1766 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1777 | "Stopping gnunet-arm with config `%s' on host `%s'.\n", | 1767 | "Stopping gnunet-arm with config `%s' on host `%s'.\n", |
1778 | d->cfgfile, d->hostname); | 1768 | d->cfgfile, d->hostname); |
1779 | #endif | 1769 | #endif |
1780 | 1770 | ||
1781 | if (d->username != NULL) | 1771 | if (d->username != NULL) |
1782 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); | 1772 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); |
1783 | else | 1773 | else |
1784 | arg = GNUNET_strdup (d->hostname); | 1774 | arg = GNUNET_strdup (d->hostname); |
1785 | 1775 | ||
1786 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", | 1776 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", |
1787 | #if !DEBUG_TESTING | 1777 | #if !DEBUG_TESTING |
1788 | "-q", | 1778 | "-q", |
1789 | #endif | 1779 | #endif |
1790 | arg, "gnunet-arm", | 1780 | arg, "gnunet-arm", |
1791 | #if DEBUG_TESTING | 1781 | #if DEBUG_TESTING |
1792 | "-L", "DEBUG", | 1782 | "-L", "DEBUG", |
1793 | #endif | 1783 | #endif |
1794 | "-c", d->cfgfile, "-e", "-q", | 1784 | "-c", d->cfgfile, "-e", "-q", |
1795 | "-T", GNUNET_TIME_relative_to_string(timeout), | 1785 | "-T", |
1796 | del_arg, NULL); | 1786 | GNUNET_TIME_relative_to_string (timeout), |
1797 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1787 | del_arg, NULL); |
1798 | "Stopping gnunet-arm with command ssh %s gnunet-arm -c %s -e -q %s\n", | 1788 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1799 | arg, "gnunet-arm", d->cfgfile, del_arg); | 1789 | "Stopping gnunet-arm with command ssh %s gnunet-arm -c %s -e -q %s\n", |
1800 | /* Use -e to end arm, and -d to remove temp files */ | 1790 | arg, "gnunet-arm", d->cfgfile, del_arg); |
1801 | GNUNET_free (arg); | 1791 | /* Use -e to end arm, and -d to remove temp files */ |
1802 | } | 1792 | GNUNET_free (arg); |
1793 | } | ||
1803 | else | 1794 | else |
1804 | { | 1795 | { |
1805 | #if DEBUG_TESTING | 1796 | #if DEBUG_TESTING |
1806 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1797 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1807 | "Stopping gnunet-arm with config `%s' locally.\n", | 1798 | "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile); |
1808 | d->cfgfile); | ||
1809 | #endif | 1799 | #endif |
1810 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", | 1800 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm", |
1811 | "gnunet-arm", | ||
1812 | #if DEBUG_TESTING | 1801 | #if DEBUG_TESTING |
1813 | "-L", "DEBUG", | 1802 | "-L", "DEBUG", |
1814 | #endif | 1803 | #endif |
1815 | "-c", d->cfgfile, "-e", "-q", | 1804 | "-c", d->cfgfile, "-e", "-q", |
1816 | "-T", GNUNET_TIME_relative_to_string(timeout), | 1805 | "-T", |
1817 | del_arg, NULL); | 1806 | GNUNET_TIME_relative_to_string (timeout), |
1818 | } | 1807 | del_arg, NULL); |
1808 | } | ||
1819 | 1809 | ||
1820 | GNUNET_free_non_null (del_arg); | 1810 | GNUNET_free_non_null (del_arg); |
1821 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); | 1811 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
@@ -1840,30 +1830,30 @@ GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d, | |||
1840 | char *arg; | 1830 | char *arg; |
1841 | 1831 | ||
1842 | if (d->phase != SP_START_DONE) | 1832 | if (d->phase != SP_START_DONE) |
1843 | { | 1833 | { |
1844 | if (NULL != cb) | 1834 | if (NULL != cb) |
1845 | cb (cb_cls, | 1835 | cb (cb_cls, |
1846 | _ | 1836 | _ |
1847 | ("Peer not yet running, can not change configuration at this point.")); | 1837 | ("Peer not yet running, can not change configuration at this point.")); |
1848 | return; | 1838 | return; |
1849 | } | 1839 | } |
1850 | 1840 | ||
1851 | /* 1) write configuration to temporary file */ | 1841 | /* 1) write configuration to temporary file */ |
1852 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, d->cfgfile)) | 1842 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, d->cfgfile)) |
1853 | { | 1843 | { |
1854 | if (NULL != cb) | 1844 | if (NULL != cb) |
1855 | cb (cb_cls, _("Failed to write new configuration to disk.")); | 1845 | cb (cb_cls, _("Failed to write new configuration to disk.")); |
1856 | return; | 1846 | return; |
1857 | } | 1847 | } |
1858 | 1848 | ||
1859 | /* 2) copy file to remote host (if necessary) */ | 1849 | /* 2) copy file to remote host (if necessary) */ |
1860 | if (NULL == d->hostname) | 1850 | if (NULL == d->hostname) |
1861 | { | 1851 | { |
1862 | /* signal success */ | 1852 | /* signal success */ |
1863 | if (NULL != cb) | 1853 | if (NULL != cb) |
1864 | cb (cb_cls, NULL); | 1854 | cb (cb_cls, NULL); |
1865 | return; | 1855 | return; |
1866 | } | 1856 | } |
1867 | #if DEBUG_TESTING | 1857 | #if DEBUG_TESTING |
1868 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1858 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1869 | "Copying updated configuration file to remote host `%s'.\n", | 1859 | "Copying updated configuration file to remote host `%s'.\n", |
@@ -1881,21 +1871,21 @@ GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d, | |||
1881 | d->cfgfile, arg, NULL); | 1871 | d->cfgfile, arg, NULL); |
1882 | GNUNET_free (arg); | 1872 | GNUNET_free (arg); |
1883 | if (NULL == d->proc) | 1873 | if (NULL == d->proc) |
1884 | { | 1874 | { |
1885 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1875 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1886 | _ | 1876 | _ |
1887 | ("Could not start `%s' process to copy configuration file.\n"), | 1877 | ("Could not start `%s' process to copy configuration file.\n"), |
1888 | "scp"); | 1878 | "scp"); |
1889 | if (NULL != cb) | 1879 | if (NULL != cb) |
1890 | cb (cb_cls, _("Failed to copy new configuration to remote machine.")); | 1880 | cb (cb_cls, _("Failed to copy new configuration to remote machine.")); |
1891 | d->phase = SP_START_DONE; | 1881 | d->phase = SP_START_DONE; |
1892 | return; | 1882 | return; |
1893 | } | 1883 | } |
1894 | d->update_cb = cb; | 1884 | d->update_cb = cb; |
1895 | d->update_cb_cls = cb_cls; | 1885 | d->update_cb_cls = cb_cls; |
1896 | d->task | 1886 | d->task |
1897 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | 1887 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, |
1898 | &start_fsm, d); | 1888 | &start_fsm, d); |
1899 | } | 1889 | } |
1900 | 1890 | ||
1901 | 1891 | ||
@@ -2004,39 +1994,39 @@ reattempt_daemons_connect (void *cls, | |||
2004 | * @param tc reason tells us if we succeeded or failed | 1994 | * @param tc reason tells us if we succeeded or failed |
2005 | */ | 1995 | */ |
2006 | static void | 1996 | static void |
2007 | notify_connect_result (void *cls, | 1997 | notify_connect_result (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
2008 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
2009 | { | 1998 | { |
2010 | struct ConnectContext *ctx = cls; | 1999 | struct ConnectContext *ctx = cls; |
2000 | |||
2011 | ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 2001 | ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
2012 | if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK) | 2002 | if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK) |
2013 | { | 2003 | { |
2014 | GNUNET_SCHEDULER_cancel (ctx->hello_send_task); | 2004 | GNUNET_SCHEDULER_cancel (ctx->hello_send_task); |
2015 | ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; | 2005 | ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; |
2016 | } | 2006 | } |
2017 | 2007 | ||
2018 | if (ctx->connect_request_handle != NULL) | 2008 | if (ctx->connect_request_handle != NULL) |
2019 | { | 2009 | { |
2020 | GNUNET_CORE_peer_request_connect_cancel (ctx->connect_request_handle); | 2010 | GNUNET_CORE_peer_request_connect_cancel (ctx->connect_request_handle); |
2021 | ctx->connect_request_handle = NULL; | 2011 | ctx->connect_request_handle = NULL; |
2022 | } | 2012 | } |
2023 | 2013 | ||
2024 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 2014 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
2025 | { | 2015 | { |
2026 | if (ctx->d1th != NULL) | 2016 | if (ctx->d1th != NULL) |
2027 | GNUNET_TRANSPORT_disconnect (ctx->d1th); | 2017 | GNUNET_TRANSPORT_disconnect (ctx->d1th); |
2028 | ctx->d1th = NULL; | 2018 | ctx->d1th = NULL; |
2029 | if (ctx->d1core != NULL) | 2019 | if (ctx->d1core != NULL) |
2030 | GNUNET_CORE_disconnect (ctx->d1core); | 2020 | GNUNET_CORE_disconnect (ctx->d1core); |
2031 | #if CONNECT_CORE2 | 2021 | #if CONNECT_CORE2 |
2032 | if (ctx->d2core != NULL) | 2022 | if (ctx->d2core != NULL) |
2033 | GNUNET_CORE_disconnect (ctx->d2core); | 2023 | GNUNET_CORE_disconnect (ctx->d2core); |
2034 | ctx->d2core = NULL; | 2024 | ctx->d2core = NULL; |
2035 | #endif | 2025 | #endif |
2036 | ctx->d1core = NULL; | 2026 | ctx->d1core = NULL; |
2037 | GNUNET_free (ctx); | 2027 | GNUNET_free (ctx); |
2038 | return; | 2028 | return; |
2039 | } | 2029 | } |
2040 | 2030 | ||
2041 | if (ctx->d1th != NULL) | 2031 | if (ctx->d1th != NULL) |
2042 | GNUNET_TRANSPORT_disconnect (ctx->d1th); | 2032 | GNUNET_TRANSPORT_disconnect (ctx->d1th); |
@@ -2046,38 +2036,37 @@ notify_connect_result (void *cls, | |||
2046 | ctx->d1core = NULL; | 2036 | ctx->d1core = NULL; |
2047 | 2037 | ||
2048 | if (ctx->connected == GNUNET_YES) | 2038 | if (ctx->connected == GNUNET_YES) |
2039 | { | ||
2040 | if (ctx->cb != NULL) | ||
2049 | { | 2041 | { |
2050 | if (ctx->cb != NULL) | 2042 | ctx->cb (ctx->cb_cls, |
2051 | { | 2043 | &ctx->d1->id, |
2052 | ctx->cb (ctx->cb_cls, | 2044 | &ctx->d2->id, |
2053 | &ctx->d1->id, | 2045 | ctx->distance, |
2054 | &ctx->d2->id, | 2046 | ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, NULL); |
2055 | ctx->distance, | ||
2056 | ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, NULL); | ||
2057 | } | ||
2058 | } | 2047 | } |
2048 | } | ||
2059 | else if (ctx->connect_attempts > 0) | 2049 | else if (ctx->connect_attempts > 0) |
2060 | { | 2050 | { |
2061 | ctx->d1core_ready = GNUNET_NO; | 2051 | ctx->d1core_ready = GNUNET_NO; |
2062 | #if CONNECT_CORE2 | 2052 | #if CONNECT_CORE2 |
2063 | if (ctx->d2core != NULL) | 2053 | if (ctx->d2core != NULL) |
2064 | { | 2054 | { |
2065 | GNUNET_CORE_disconnect (ctx->d2core); | 2055 | GNUNET_CORE_disconnect (ctx->d2core); |
2066 | ctx->d2core = NULL; | 2056 | ctx->d2core = NULL; |
2067 | } | ||
2068 | #endif | ||
2069 | GNUNET_SCHEDULER_add_now (&reattempt_daemons_connect, ctx); | ||
2070 | return; | ||
2071 | } | 2057 | } |
2058 | #endif | ||
2059 | GNUNET_SCHEDULER_add_now (&reattempt_daemons_connect, ctx); | ||
2060 | return; | ||
2061 | } | ||
2072 | else | 2062 | else |
2063 | { | ||
2064 | if (ctx->cb != NULL) | ||
2073 | { | 2065 | { |
2074 | if (ctx->cb != NULL) | 2066 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, |
2075 | { | 2067 | ctx->d2->cfg, ctx->d1, ctx->d2, _("Peers failed to connect")); |
2076 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, | ||
2077 | ctx->d2->cfg, ctx->d1, ctx->d2, | ||
2078 | _("Peers failed to connect")); | ||
2079 | } | ||
2080 | } | 2068 | } |
2069 | } | ||
2081 | 2070 | ||
2082 | GNUNET_free (ctx); | 2071 | GNUNET_free (ctx); |
2083 | } | 2072 | } |
@@ -2100,24 +2089,23 @@ connect_notify (void *cls, | |||
2100 | 2089 | ||
2101 | #if DEBUG_TESTING | 2090 | #if DEBUG_TESTING |
2102 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2091 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2103 | "Connected peer %s to peer %s\n", | 2092 | "Connected peer %s to peer %s\n", |
2104 | ctx->d1->shortname, GNUNET_i2s(peer)); | 2093 | ctx->d1->shortname, GNUNET_i2s (peer)); |
2105 | #endif | 2094 | #endif |
2106 | 2095 | ||
2107 | if (0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity))) | 2096 | if (0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
2108 | { | 2097 | { |
2109 | 2098 | ||
2110 | ctx->connected = GNUNET_YES; | 2099 | ctx->connected = GNUNET_YES; |
2111 | ctx->distance = 0; /* FIXME: distance */ | 2100 | ctx->distance = 0; /* FIXME: distance */ |
2112 | if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK) | 2101 | if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK) |
2113 | { | 2102 | { |
2114 | GNUNET_SCHEDULER_cancel(ctx->hello_send_task); | 2103 | GNUNET_SCHEDULER_cancel (ctx->hello_send_task); |
2115 | ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; | 2104 | ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; |
2116 | } | ||
2117 | GNUNET_SCHEDULER_cancel (ctx->timeout_task); | ||
2118 | ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, | ||
2119 | ctx); | ||
2120 | } | 2105 | } |
2106 | GNUNET_SCHEDULER_cancel (ctx->timeout_task); | ||
2107 | ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, ctx); | ||
2108 | } | ||
2121 | } | 2109 | } |
2122 | 2110 | ||
2123 | #if CONNECT_CORE2 | 2111 | #if CONNECT_CORE2 |
@@ -2137,13 +2125,12 @@ connect_notify_core2 (void *cls, | |||
2137 | struct ConnectContext *ctx = cls; | 2125 | struct ConnectContext *ctx = cls; |
2138 | 2126 | ||
2139 | if (memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)) == 0) | 2127 | if (memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)) == 0) |
2140 | { | 2128 | { |
2141 | ctx->connected = GNUNET_YES; | 2129 | ctx->connected = GNUNET_YES; |
2142 | ctx->distance = 0; /* FIXME: distance */ | 2130 | ctx->distance = 0; /* FIXME: distance */ |
2143 | GNUNET_SCHEDULER_cancel (ctx->timeout_task); | 2131 | GNUNET_SCHEDULER_cancel (ctx->timeout_task); |
2144 | ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, | 2132 | ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, ctx); |
2145 | ctx); | 2133 | } |
2146 | } | ||
2147 | 2134 | ||
2148 | } | 2135 | } |
2149 | #endif | 2136 | #endif |
@@ -2155,8 +2142,7 @@ connect_notify_core2 (void *cls, | |||
2155 | * @param success was the request successful? | 2142 | * @param success was the request successful? |
2156 | */ | 2143 | */ |
2157 | void | 2144 | void |
2158 | core_connect_request_cont (void *cls, | 2145 | core_connect_request_cont (void *cls, int success) |
2159 | int success) | ||
2160 | { | 2146 | { |
2161 | struct ConnectContext *ctx = cls; | 2147 | struct ConnectContext *ctx = cls; |
2162 | 2148 | ||
@@ -2168,37 +2154,38 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2168 | { | 2154 | { |
2169 | struct ConnectContext *ctx = cls; | 2155 | struct ConnectContext *ctx = cls; |
2170 | struct GNUNET_MessageHeader *hello; | 2156 | struct GNUNET_MessageHeader *hello; |
2157 | |||
2171 | ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; | 2158 | ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; |
2172 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 2159 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
2173 | return; | 2160 | return; |
2174 | if ((ctx->d1core_ready == GNUNET_YES) && (ctx->d2->hello != NULL) | 2161 | if ((ctx->d1core_ready == GNUNET_YES) && (ctx->d2->hello != NULL) |
2175 | && (NULL != GNUNET_HELLO_get_header (ctx->d2->hello)) | 2162 | && (NULL != GNUNET_HELLO_get_header (ctx->d2->hello)) |
2176 | && (ctx->d1->phase == SP_START_DONE) | 2163 | && (ctx->d1->phase == SP_START_DONE) && (ctx->d2->phase == SP_START_DONE)) |
2177 | && (ctx->d2->phase == SP_START_DONE)) | 2164 | { |
2178 | { | 2165 | hello = GNUNET_HELLO_get_header (ctx->d2->hello); |
2179 | hello = GNUNET_HELLO_get_header (ctx->d2->hello); | 2166 | GNUNET_assert (hello != NULL); |
2180 | GNUNET_assert (hello != NULL); | ||
2181 | #if DEBUG_TESTING | 2167 | #if DEBUG_TESTING |
2182 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Offering hello of %s to %s\n", ctx->d2->shortname, ctx->d1->shortname); | 2168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Offering hello of %s to %s\n", |
2169 | ctx->d2->shortname, ctx->d1->shortname); | ||
2183 | #endif | 2170 | #endif |
2184 | GNUNET_TRANSPORT_offer_hello (ctx->d1th, hello, NULL, NULL); | 2171 | GNUNET_TRANSPORT_offer_hello (ctx->d1th, hello, NULL, NULL); |
2185 | GNUNET_assert (ctx->d1core != NULL); | 2172 | GNUNET_assert (ctx->d1core != NULL); |
2186 | ctx->connect_request_handle = | 2173 | ctx->connect_request_handle = |
2187 | GNUNET_CORE_peer_request_connect (ctx->d1core, | 2174 | GNUNET_CORE_peer_request_connect (ctx->d1core, |
2188 | &ctx->d2->id, | 2175 | &ctx->d2->id, |
2189 | &core_connect_request_cont, ctx); | 2176 | &core_connect_request_cont, ctx); |
2190 | 2177 | ||
2191 | #if DEBUG_TESTING | 2178 | #if DEBUG_TESTING |
2192 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2179 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2193 | "Sending connect request to CORE of %s for peer %s\n", | 2180 | "Sending connect request to CORE of %s for peer %s\n", |
2194 | GNUNET_i2s (&ctx->d1->id), | 2181 | GNUNET_i2s (&ctx->d1->id), |
2195 | GNUNET_h2s (&ctx->d2->id.hashPubKey)); | 2182 | GNUNET_h2s (&ctx->d2->id.hashPubKey)); |
2196 | #endif | 2183 | #endif |
2197 | ctx->timeout_hello = | 2184 | ctx->timeout_hello = |
2198 | GNUNET_TIME_relative_add (ctx->timeout_hello, | 2185 | GNUNET_TIME_relative_add (ctx->timeout_hello, |
2199 | GNUNET_TIME_relative_multiply | 2186 | GNUNET_TIME_relative_multiply |
2200 | (GNUNET_TIME_UNIT_MILLISECONDS, 500)); | 2187 | (GNUNET_TIME_UNIT_MILLISECONDS, 500)); |
2201 | } | 2188 | } |
2202 | ctx->hello_send_task = GNUNET_SCHEDULER_add_delayed (ctx->timeout_hello, | 2189 | ctx->hello_send_task = GNUNET_SCHEDULER_add_delayed (ctx->timeout_hello, |
2203 | &send_hello, ctx); | 2190 | &send_hello, ctx); |
2204 | } | 2191 | } |
@@ -2213,30 +2200,29 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2213 | */ | 2200 | */ |
2214 | void | 2201 | void |
2215 | core_init_notify (void *cls, | 2202 | core_init_notify (void *cls, |
2216 | struct GNUNET_CORE_Handle * server, | 2203 | struct GNUNET_CORE_Handle *server, |
2217 | const struct GNUNET_PeerIdentity * | 2204 | const struct GNUNET_PeerIdentity *my_identity, |
2218 | my_identity, | ||
2219 | const struct | 2205 | const struct |
2220 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded * | 2206 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) |
2221 | publicKey) | ||
2222 | { | 2207 | { |
2223 | struct ConnectContext *connect_ctx = cls; | 2208 | struct ConnectContext *connect_ctx = cls; |
2209 | |||
2224 | connect_ctx->d1core_ready = GNUNET_YES; | 2210 | connect_ctx->d1core_ready = GNUNET_YES; |
2225 | 2211 | ||
2226 | if (connect_ctx->send_hello == GNUNET_NO) | 2212 | if (connect_ctx->send_hello == GNUNET_NO) |
2227 | { | 2213 | { |
2228 | connect_ctx->connect_request_handle = | 2214 | connect_ctx->connect_request_handle = |
2229 | GNUNET_CORE_peer_request_connect (connect_ctx->d1core, | 2215 | GNUNET_CORE_peer_request_connect (connect_ctx->d1core, |
2230 | &connect_ctx->d2->id, | 2216 | &connect_ctx->d2->id, |
2231 | &core_connect_request_cont, connect_ctx); | 2217 | &core_connect_request_cont, |
2232 | GNUNET_assert(connect_ctx->connect_request_handle != NULL); | 2218 | connect_ctx); |
2219 | GNUNET_assert (connect_ctx->connect_request_handle != NULL); | ||
2233 | #if DEBUG_TESTING | 2220 | #if DEBUG_TESTING |
2234 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2221 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2235 | "Sending connect request to CORE of %s for peer %s\n", | 2222 | "Sending connect request to CORE of %s for peer %s\n", |
2236 | connect_ctx->d1->shortname, | 2223 | connect_ctx->d1->shortname, connect_ctx->d2->shortname); |
2237 | connect_ctx->d2->shortname); | ||
2238 | #endif | 2224 | #endif |
2239 | } | 2225 | } |
2240 | 2226 | ||
2241 | } | 2227 | } |
2242 | 2228 | ||
@@ -2246,11 +2232,12 @@ reattempt_daemons_connect (void *cls, | |||
2246 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 2232 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
2247 | { | 2233 | { |
2248 | struct ConnectContext *ctx = cls; | 2234 | struct ConnectContext *ctx = cls; |
2249 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 2235 | |
2250 | { | 2236 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
2251 | GNUNET_free(ctx); | 2237 | { |
2252 | return; | 2238 | GNUNET_free (ctx); |
2253 | } | 2239 | return; |
2240 | } | ||
2254 | #if DEBUG_TESTING_RECONNECT | 2241 | #if DEBUG_TESTING_RECONNECT |
2255 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2242 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2256 | "re-attempting connect of peer %s to peer %s\n", | 2243 | "re-attempting connect of peer %s to peer %s\n", |
@@ -2266,72 +2253,77 @@ reattempt_daemons_connect (void *cls, | |||
2266 | NULL, GNUNET_NO, | 2253 | NULL, GNUNET_NO, |
2267 | NULL, GNUNET_NO, no_handlers); | 2254 | NULL, GNUNET_NO, no_handlers); |
2268 | if (ctx->d1core == NULL) | 2255 | if (ctx->d1core == NULL) |
2269 | { | 2256 | { |
2270 | if (NULL != ctx->cb) | 2257 | if (NULL != ctx->cb) |
2271 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, | 2258 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, |
2272 | ctx->d2->cfg, ctx->d1, ctx->d2, | 2259 | ctx->d2->cfg, ctx->d1, ctx->d2, |
2273 | _("Failed to connect to core service of first peer!\n")); | 2260 | _("Failed to connect to core service of first peer!\n")); |
2274 | GNUNET_free (ctx); | 2261 | GNUNET_free (ctx); |
2275 | return; | 2262 | return; |
2276 | } | 2263 | } |
2277 | 2264 | ||
2278 | /* Don't know reason for initial connect failure, update the HELLO for the second peer */ | 2265 | /* Don't know reason for initial connect failure, update the HELLO for the second peer */ |
2279 | if (NULL != ctx->d2->hello) | 2266 | if (NULL != ctx->d2->hello) |
2267 | { | ||
2268 | GNUNET_free (ctx->d2->hello); | ||
2269 | ctx->d2->hello = NULL; | ||
2270 | if (NULL != ctx->d2->th) | ||
2280 | { | 2271 | { |
2281 | GNUNET_free(ctx->d2->hello); | 2272 | GNUNET_TRANSPORT_get_hello_cancel (ctx->d2->th, &process_hello, ctx->d2); |
2282 | ctx->d2->hello = NULL; | 2273 | GNUNET_TRANSPORT_disconnect (ctx->d2->th); |
2283 | if (NULL != ctx->d2->th) | ||
2284 | { | ||
2285 | GNUNET_TRANSPORT_get_hello_cancel(ctx->d2->th, &process_hello, ctx->d2); | ||
2286 | GNUNET_TRANSPORT_disconnect(ctx->d2->th); | ||
2287 | } | ||
2288 | ctx->d2->th = GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL, NULL); | ||
2289 | GNUNET_assert(ctx->d2->th != NULL); | ||
2290 | GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2); | ||
2291 | } | 2274 | } |
2275 | ctx->d2->th = | ||
2276 | GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL, | ||
2277 | NULL); | ||
2278 | GNUNET_assert (ctx->d2->th != NULL); | ||
2279 | GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2); | ||
2280 | } | ||
2292 | 2281 | ||
2293 | if ((NULL == ctx->d2->hello) && (ctx->d2->th == NULL)) | 2282 | if ((NULL == ctx->d2->hello) && (ctx->d2->th == NULL)) |
2283 | { | ||
2284 | ctx->d2->th = | ||
2285 | GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL, | ||
2286 | NULL); | ||
2287 | if (ctx->d2->th == NULL) | ||
2294 | { | 2288 | { |
2295 | ctx->d2->th = GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL, NULL); | 2289 | GNUNET_CORE_disconnect (ctx->d1core); |
2296 | if (ctx->d2->th == NULL) | 2290 | GNUNET_free (ctx); |
2297 | { | 2291 | if (NULL != ctx->cb) |
2298 | GNUNET_CORE_disconnect (ctx->d1core); | 2292 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, |
2299 | GNUNET_free (ctx); | 2293 | ctx->d2->cfg, ctx->d1, ctx->d2, |
2300 | if (NULL != ctx->cb) | 2294 | _("Failed to connect to transport service!\n")); |
2301 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, | 2295 | return; |
2302 | _("Failed to connect to transport service!\n")); | ||
2303 | return; | ||
2304 | } | ||
2305 | GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2); | ||
2306 | } | 2296 | } |
2297 | GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2); | ||
2298 | } | ||
2307 | 2299 | ||
2308 | if (ctx->send_hello == GNUNET_YES) | 2300 | if (ctx->send_hello == GNUNET_YES) |
2301 | { | ||
2302 | ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg, | ||
2303 | &ctx->d1->id, | ||
2304 | ctx->d1, NULL, NULL, NULL); | ||
2305 | if (ctx->d1th == NULL) | ||
2309 | { | 2306 | { |
2310 | ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg, | 2307 | GNUNET_CORE_disconnect (ctx->d1core); |
2311 | &ctx->d1->id, | 2308 | GNUNET_free (ctx); |
2312 | ctx->d1, NULL, NULL, NULL); | 2309 | if (NULL != ctx->cb) |
2313 | if (ctx->d1th == NULL) | 2310 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, |
2314 | { | 2311 | ctx->d2->cfg, ctx->d1, ctx->d2, |
2315 | GNUNET_CORE_disconnect (ctx->d1core); | 2312 | _("Failed to connect to transport service!\n")); |
2316 | GNUNET_free (ctx); | 2313 | return; |
2317 | if (NULL != ctx->cb) | ||
2318 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, | ||
2319 | ctx->d2->cfg, ctx->d1, ctx->d2, | ||
2320 | _("Failed to connect to transport service!\n")); | ||
2321 | return; | ||
2322 | } | ||
2323 | ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx); | ||
2324 | } | 2314 | } |
2315 | ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx); | ||
2316 | } | ||
2325 | else | 2317 | else |
2326 | { | 2318 | { |
2327 | ctx->connect_request_handle = | 2319 | ctx->connect_request_handle = |
2328 | GNUNET_CORE_peer_request_connect (ctx->d1core, | 2320 | GNUNET_CORE_peer_request_connect (ctx->d1core, |
2329 | &ctx->d2->id, | 2321 | &ctx->d2->id, |
2330 | &core_connect_request_cont, ctx); | 2322 | &core_connect_request_cont, ctx); |
2331 | } | 2323 | } |
2332 | ctx->timeout_task = | 2324 | ctx->timeout_task = |
2333 | GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout, | 2325 | GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout, |
2334 | ¬ify_connect_result, ctx); | 2326 | ¬ify_connect_result, ctx); |
2335 | } | 2327 | } |
2336 | 2328 | ||
2337 | /** | 2329 | /** |
@@ -2354,79 +2346,85 @@ core_initial_iteration (void *cls, | |||
2354 | 2346 | ||
2355 | if ((peer != NULL) && | 2347 | if ((peer != NULL) && |
2356 | (0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)))) | 2348 | (0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)))) |
2349 | { | ||
2350 | ctx->connected = GNUNET_YES; | ||
2351 | ctx->distance = 0; /* FIXME: distance */ | ||
2352 | return; | ||
2353 | } | ||
2354 | else if (peer == NULL) /* End of iteration over peers */ | ||
2355 | { | ||
2356 | if (ctx->connected == GNUNET_YES) | ||
2357 | { | 2357 | { |
2358 | ctx->connected = GNUNET_YES; | 2358 | ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, |
2359 | ctx->distance = 0; /* FIXME: distance */ | 2359 | ctx); |
2360 | return; | 2360 | return; |
2361 | } | 2361 | } |
2362 | else if (peer == NULL) /* End of iteration over peers */ | ||
2363 | { | ||
2364 | if (ctx->connected == GNUNET_YES) | ||
2365 | { | ||
2366 | ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, | ||
2367 | ctx); | ||
2368 | return; | ||
2369 | } | ||
2370 | 2362 | ||
2371 | /* Peer not already connected, need to schedule connect request! */ | 2363 | /* Peer not already connected, need to schedule connect request! */ |
2372 | if (ctx->d1core == NULL) | 2364 | if (ctx->d1core == NULL) |
2373 | { | 2365 | { |
2374 | #if DEBUG_TESTING | 2366 | #if DEBUG_TESTING |
2375 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2367 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2376 | "Peers are NOT connected, connecting to core!\n"); | 2368 | "Peers are NOT connected, connecting to core!\n"); |
2377 | #endif | 2369 | #endif |
2378 | ctx->d1core = GNUNET_CORE_connect (ctx->d1->cfg, 1, | 2370 | ctx->d1core = GNUNET_CORE_connect (ctx->d1->cfg, 1, |
2379 | ctx, | 2371 | ctx, |
2380 | &core_init_notify, | 2372 | &core_init_notify, |
2381 | &connect_notify, NULL, NULL, | 2373 | &connect_notify, NULL, NULL, |
2382 | NULL, GNUNET_NO, | 2374 | NULL, GNUNET_NO, |
2383 | NULL, GNUNET_NO, no_handlers); | 2375 | NULL, GNUNET_NO, no_handlers); |
2384 | } | 2376 | } |
2385 | 2377 | ||
2386 | if (ctx->d1core == NULL) | 2378 | if (ctx->d1core == NULL) |
2387 | { | 2379 | { |
2388 | GNUNET_free (ctx); | 2380 | GNUNET_free (ctx); |
2389 | if (NULL != ctx->cb) | 2381 | if (NULL != ctx->cb) |
2390 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, | 2382 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, |
2391 | _("Failed to connect to core service of first peer!\n")); | 2383 | ctx->d2->cfg, ctx->d1, ctx->d2, |
2392 | return; | 2384 | _("Failed to connect to core service of first peer!\n")); |
2393 | } | 2385 | return; |
2386 | } | ||
2394 | 2387 | ||
2395 | if ((NULL == ctx->d2->hello) && (ctx->d2->th == NULL)) /* Do not yet have the second peer's hello, set up a task to get it */ | 2388 | if ((NULL == ctx->d2->hello) && (ctx->d2->th == NULL)) /* Do not yet have the second peer's hello, set up a task to get it */ |
2396 | { | 2389 | { |
2397 | ctx->d2->th = GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL, NULL); | 2390 | ctx->d2->th = |
2398 | if (ctx->d2->th == NULL) | 2391 | GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, |
2399 | { | 2392 | NULL, NULL); |
2400 | GNUNET_CORE_disconnect (ctx->d1core); | 2393 | if (ctx->d2->th == NULL) |
2401 | GNUNET_free (ctx); | 2394 | { |
2402 | if (NULL != ctx->cb) | 2395 | GNUNET_CORE_disconnect (ctx->d1core); |
2403 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, | 2396 | GNUNET_free (ctx); |
2404 | _("Failed to connect to transport service!\n")); | 2397 | if (NULL != ctx->cb) |
2405 | return; | 2398 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, |
2406 | } | 2399 | ctx->d2->cfg, ctx->d1, ctx->d2, |
2407 | GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2); | 2400 | _("Failed to connect to transport service!\n")); |
2408 | } | 2401 | return; |
2402 | } | ||
2403 | GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2); | ||
2404 | } | ||
2409 | 2405 | ||
2410 | if (ctx->send_hello == GNUNET_YES) | 2406 | if (ctx->send_hello == GNUNET_YES) |
2411 | { | 2407 | { |
2412 | ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg, | 2408 | ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg, |
2413 | &ctx->d1->id, ctx->d1, NULL, NULL, NULL); | 2409 | &ctx->d1->id, ctx->d1, NULL, NULL, |
2414 | if (ctx->d1th == NULL) | 2410 | NULL); |
2415 | { | 2411 | if (ctx->d1th == NULL) |
2416 | GNUNET_CORE_disconnect (ctx->d1core); | 2412 | { |
2417 | GNUNET_free (ctx); | 2413 | GNUNET_CORE_disconnect (ctx->d1core); |
2418 | if (NULL != ctx->cb) | 2414 | GNUNET_free (ctx); |
2419 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, | 2415 | if (NULL != ctx->cb) |
2420 | _("Failed to connect to transport service!\n")); | 2416 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, |
2421 | return; | 2417 | ctx->d2->cfg, ctx->d1, ctx->d2, |
2422 | } | 2418 | _("Failed to connect to transport service!\n")); |
2423 | ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx); | 2419 | return; |
2424 | } | 2420 | } |
2421 | ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx); | ||
2422 | } | ||
2425 | 2423 | ||
2426 | ctx->timeout_task = | 2424 | ctx->timeout_task = |
2427 | GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout, | 2425 | GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout, |
2428 | ¬ify_connect_result, ctx); | 2426 | ¬ify_connect_result, ctx); |
2429 | } | 2427 | } |
2430 | } | 2428 | } |
2431 | 2429 | ||
2432 | 2430 | ||
@@ -2456,20 +2454,21 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, | |||
2456 | struct ConnectContext *ctx; | 2454 | struct ConnectContext *ctx; |
2457 | 2455 | ||
2458 | if ((d1->running == GNUNET_NO) || (d2->running == GNUNET_NO)) | 2456 | if ((d1->running == GNUNET_NO) || (d2->running == GNUNET_NO)) |
2459 | { | 2457 | { |
2460 | if (NULL != cb) | 2458 | if (NULL != cb) |
2461 | cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2, | 2459 | cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2, |
2462 | _("Peers are not fully running yet, can not connect!\n")); | 2460 | _("Peers are not fully running yet, can not connect!\n")); |
2463 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Peers are not up!\n"); | 2461 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Peers are not up!\n"); |
2464 | return; | 2462 | return; |
2465 | } | 2463 | } |
2466 | 2464 | ||
2467 | ctx = GNUNET_malloc (sizeof (struct ConnectContext)); | 2465 | ctx = GNUNET_malloc (sizeof (struct ConnectContext)); |
2468 | ctx->d1 = d1; | 2466 | ctx->d1 = d1; |
2469 | ctx->d2 = d2; | 2467 | ctx->d2 = d2; |
2470 | ctx->timeout_hello = | 2468 | ctx->timeout_hello = |
2471 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500); | 2469 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500); |
2472 | ctx->relative_timeout = GNUNET_TIME_relative_divide(timeout, max_connect_attempts); | 2470 | ctx->relative_timeout = |
2471 | GNUNET_TIME_relative_divide (timeout, max_connect_attempts); | ||
2473 | ctx->cb = cb; | 2472 | ctx->cb = cb; |
2474 | ctx->cb_cls = cb_cls; | 2473 | ctx->cb_cls = cb_cls; |
2475 | ctx->connect_attempts = max_connect_attempts; | 2474 | ctx->connect_attempts = max_connect_attempts; |
@@ -2482,8 +2481,10 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, | |||
2482 | #endif | 2481 | #endif |
2483 | 2482 | ||
2484 | /* Core is up! Iterate over all _known_ peers first to check if we are already connected to the peer! */ | 2483 | /* Core is up! Iterate over all _known_ peers first to check if we are already connected to the peer! */ |
2485 | GNUNET_assert(GNUNET_OK == GNUNET_CORE_is_peer_connected (ctx->d1->cfg, &ctx->d2->id, &core_initial_iteration, ctx)); | 2484 | GNUNET_assert (GNUNET_OK == |
2486 | /*GNUNET_assert(GNUNET_OK == GNUNET_CORE_iterate_peers (ctx->d1->cfg, &core_initial_iteration, ctx));*/ | 2485 | GNUNET_CORE_is_peer_connected (ctx->d1->cfg, &ctx->d2->id, |
2486 | &core_initial_iteration, ctx)); | ||
2487 | /*GNUNET_assert(GNUNET_OK == GNUNET_CORE_iterate_peers (ctx->d1->cfg, &core_initial_iteration, ctx)); */ | ||
2487 | } | 2488 | } |
2488 | 2489 | ||
2489 | /* end of testing.c */ | 2490 | /* end of testing.c */ |
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index 9bf24882c..723afd456 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c | |||
@@ -88,9 +88,11 @@ enum PeerLists | |||
88 | * in a certain topology. | 88 | * in a certain topology. |
89 | */ | 89 | */ |
90 | typedef unsigned int | 90 | typedef unsigned int |
91 | (*GNUNET_TESTING_ConnectionProcessor)(struct GNUNET_TESTING_PeerGroup * pg, | 91 | (*GNUNET_TESTING_ConnectionProcessor) (struct GNUNET_TESTING_PeerGroup * pg, |
92 | unsigned int first, unsigned int second, | 92 | unsigned int first, |
93 | enum PeerLists list, unsigned int check); | 93 | unsigned int second, |
94 | enum PeerLists list, | ||
95 | unsigned int check); | ||
94 | 96 | ||
95 | /** | 97 | /** |
96 | * Context for handling churning a peer group | 98 | * Context for handling churning a peer group |
@@ -1015,10 +1017,10 @@ struct ProgressMeter | |||
1015 | */ | 1017 | */ |
1016 | static void | 1018 | static void |
1017 | hash_from_uid (uint32_t uid, GNUNET_HashCode * hash) | 1019 | hash_from_uid (uint32_t uid, GNUNET_HashCode * hash) |
1018 | { | 1020 | { |
1019 | memset (hash, 0, sizeof (GNUNET_HashCode)); | 1021 | memset (hash, 0, sizeof (GNUNET_HashCode)); |
1020 | *((uint32_t *) hash) = uid; | 1022 | *((uint32_t *) hash) = uid; |
1021 | } | 1023 | } |
1022 | 1024 | ||
1023 | /** | 1025 | /** |
1024 | * Convert hash code to unique ID. | 1026 | * Convert hash code to unique ID. |
@@ -1028,15 +1030,15 @@ hash_from_uid (uint32_t uid, GNUNET_HashCode * hash) | |||
1028 | */ | 1030 | */ |
1029 | static void | 1031 | static void |
1030 | uid_from_hash (const GNUNET_HashCode * hash, uint32_t * uid) | 1032 | uid_from_hash (const GNUNET_HashCode * hash, uint32_t * uid) |
1031 | { | 1033 | { |
1032 | memcpy (uid, hash, sizeof (uint32_t)); | 1034 | memcpy (uid, hash, sizeof (uint32_t)); |
1033 | } | 1035 | } |
1034 | #endif | 1036 | #endif |
1035 | 1037 | ||
1036 | #if USE_SEND_HELLOS | 1038 | #if USE_SEND_HELLOS |
1037 | static struct GNUNET_CORE_MessageHandler no_handlers[] = | 1039 | static struct GNUNET_CORE_MessageHandler no_handlers[] = { |
1038 | { | 1040 | {NULL, 0, 0} |
1039 | { NULL, 0, 0}}; | 1041 | }; |
1040 | #endif | 1042 | #endif |
1041 | 1043 | ||
1042 | /** | 1044 | /** |
@@ -1050,20 +1052,21 @@ static struct GNUNET_CORE_MessageHandler no_handlers[] = | |||
1050 | * @return the progress meter | 1052 | * @return the progress meter |
1051 | */ | 1053 | */ |
1052 | static struct ProgressMeter * | 1054 | static struct ProgressMeter * |
1053 | create_meter(unsigned int total, char * start_string, int print) | 1055 | create_meter (unsigned int total, char *start_string, int print) |
1054 | { | 1056 | { |
1055 | struct ProgressMeter *ret; | 1057 | struct ProgressMeter *ret; |
1056 | ret = GNUNET_malloc(sizeof(struct ProgressMeter)); | 1058 | |
1059 | ret = GNUNET_malloc (sizeof (struct ProgressMeter)); | ||
1057 | ret->print = print; | 1060 | ret->print = print; |
1058 | ret->total = total; | 1061 | ret->total = total; |
1059 | ret->modnum = total / 4; | 1062 | ret->modnum = total / 4; |
1060 | if (ret->modnum == 0) /* Divide by zero check */ | 1063 | if (ret->modnum == 0) /* Divide by zero check */ |
1061 | ret->modnum = 1; | 1064 | ret->modnum = 1; |
1062 | ret->dotnum = (total / 50) + 1; | 1065 | ret->dotnum = (total / 50) + 1; |
1063 | if (start_string != NULL) | 1066 | if (start_string != NULL) |
1064 | ret->startup_string = GNUNET_strdup(start_string); | 1067 | ret->startup_string = GNUNET_strdup (start_string); |
1065 | else | 1068 | else |
1066 | ret->startup_string = GNUNET_strdup(""); | 1069 | ret->startup_string = GNUNET_strdup (""); |
1067 | 1070 | ||
1068 | return ret; | 1071 | return ret; |
1069 | } | 1072 | } |
@@ -1077,27 +1080,27 @@ create_meter(unsigned int total, char * start_string, int print) | |||
1077 | * GNUNET_NO if more items expected | 1080 | * GNUNET_NO if more items expected |
1078 | */ | 1081 | */ |
1079 | static int | 1082 | static int |
1080 | update_meter(struct ProgressMeter *meter) | 1083 | update_meter (struct ProgressMeter *meter) |
1081 | { | 1084 | { |
1082 | if (meter->print == GNUNET_YES) | 1085 | if (meter->print == GNUNET_YES) |
1086 | { | ||
1087 | if (meter->completed % meter->modnum == 0) | ||
1083 | { | 1088 | { |
1084 | if (meter->completed % meter->modnum == 0) | 1089 | if (meter->completed == 0) |
1085 | { | 1090 | { |
1086 | if (meter->completed == 0) | 1091 | fprintf (stdout, "%sProgress: [0%%", meter->startup_string); |
1087 | { | 1092 | } |
1088 | fprintf (stdout, "%sProgress: [0%%", meter->startup_string); | 1093 | else |
1089 | } | 1094 | fprintf (stdout, "%d%%", (int) (((float) meter->completed |
1090 | else | 1095 | / meter->total) * 100)); |
1091 | fprintf (stdout, "%d%%", (int) (((float) meter->completed | ||
1092 | / meter->total) * 100)); | ||
1093 | } | ||
1094 | else if (meter->completed % meter->dotnum == 0) | ||
1095 | fprintf (stdout, "."); | ||
1096 | |||
1097 | if (meter->completed + 1 == meter->total) | ||
1098 | fprintf (stdout, "%d%%]\n", 100); | ||
1099 | fflush (stdout); | ||
1100 | } | 1096 | } |
1097 | else if (meter->completed % meter->dotnum == 0) | ||
1098 | fprintf (stdout, "."); | ||
1099 | |||
1100 | if (meter->completed + 1 == meter->total) | ||
1101 | fprintf (stdout, "%d%%]\n", 100); | ||
1102 | fflush (stdout); | ||
1103 | } | ||
1101 | meter->completed++; | 1104 | meter->completed++; |
1102 | 1105 | ||
1103 | if (meter->completed == meter->total) | 1106 | if (meter->completed == meter->total) |
@@ -1116,7 +1119,7 @@ update_meter(struct ProgressMeter *meter) | |||
1116 | * GNUNET_SYSERR on error | 1119 | * GNUNET_SYSERR on error |
1117 | */ | 1120 | */ |
1118 | static int | 1121 | static int |
1119 | reset_meter(struct ProgressMeter *meter) | 1122 | reset_meter (struct ProgressMeter *meter) |
1120 | { | 1123 | { |
1121 | if (meter == NULL) | 1124 | if (meter == NULL) |
1122 | return GNUNET_SYSERR; | 1125 | return GNUNET_SYSERR; |
@@ -1131,7 +1134,7 @@ reset_meter(struct ProgressMeter *meter) | |||
1131 | * @param meter the meter to free | 1134 | * @param meter the meter to free |
1132 | */ | 1135 | */ |
1133 | static void | 1136 | static void |
1134 | free_meter(struct ProgressMeter *meter) | 1137 | free_meter (struct ProgressMeter *meter) |
1135 | { | 1138 | { |
1136 | GNUNET_free_non_null (meter->startup_string); | 1139 | GNUNET_free_non_null (meter->startup_string); |
1137 | GNUNET_free (meter); | 1140 | GNUNET_free (meter); |
@@ -1147,14 +1150,13 @@ free_meter(struct ProgressMeter *meter) | |||
1147 | * known topology, GNUNET_NO if not | 1150 | * known topology, GNUNET_NO if not |
1148 | */ | 1151 | */ |
1149 | int | 1152 | int |
1150 | GNUNET_TESTING_topology_get(enum GNUNET_TESTING_Topology *topology, | 1153 | GNUNET_TESTING_topology_get (enum GNUNET_TESTING_Topology *topology, |
1151 | const char *topology_string) | 1154 | const char *topology_string) |
1152 | { | 1155 | { |
1153 | /** | 1156 | /** |
1154 | * Strings representing topologies in enum | 1157 | * Strings representing topologies in enum |
1155 | */ | 1158 | */ |
1156 | static const char *topology_strings[] = | 1159 | static const char *topology_strings[] = { |
1157 | { | ||
1158 | /** | 1160 | /** |
1159 | * A clique (everyone connected to everyone else). | 1161 | * A clique (everyone connected to everyone else). |
1160 | */ | 1162 | */ |
@@ -1211,20 +1213,22 @@ GNUNET_TESTING_topology_get(enum GNUNET_TESTING_Topology *topology, | |||
1211 | */ | 1213 | */ |
1212 | "FROM_FILE", | 1214 | "FROM_FILE", |
1213 | 1215 | ||
1214 | NULL }; | 1216 | NULL |
1217 | }; | ||
1215 | 1218 | ||
1216 | int curr = 0; | 1219 | int curr = 0; |
1220 | |||
1217 | if (topology_string == NULL) | 1221 | if (topology_string == NULL) |
1218 | return GNUNET_NO; | 1222 | return GNUNET_NO; |
1219 | while (topology_strings[curr] != NULL) | 1223 | while (topology_strings[curr] != NULL) |
1224 | { | ||
1225 | if (strcasecmp (topology_strings[curr], topology_string) == 0) | ||
1220 | { | 1226 | { |
1221 | if (strcasecmp (topology_strings[curr], topology_string) == 0) | 1227 | *topology = curr; |
1222 | { | 1228 | return GNUNET_YES; |
1223 | *topology = curr; | ||
1224 | return GNUNET_YES; | ||
1225 | } | ||
1226 | curr++; | ||
1227 | } | 1229 | } |
1230 | curr++; | ||
1231 | } | ||
1228 | *topology = GNUNET_TESTING_TOPOLOGY_NONE; | 1232 | *topology = GNUNET_TESTING_TOPOLOGY_NONE; |
1229 | return GNUNET_NO; | 1233 | return GNUNET_NO; |
1230 | } | 1234 | } |
@@ -1239,15 +1243,14 @@ GNUNET_TESTING_topology_get(enum GNUNET_TESTING_Topology *topology, | |||
1239 | * topology option, GNUNET_NO if not | 1243 | * topology option, GNUNET_NO if not |
1240 | */ | 1244 | */ |
1241 | int | 1245 | int |
1242 | GNUNET_TESTING_topology_option_get( | 1246 | GNUNET_TESTING_topology_option_get (enum GNUNET_TESTING_TopologyOption |
1243 | enum GNUNET_TESTING_TopologyOption *topology_option, | 1247 | *topology_option, |
1244 | const char *topology_string) | 1248 | const char *topology_string) |
1245 | { | 1249 | { |
1246 | /** | 1250 | /** |
1247 | * Options for connecting a topology as strings. | 1251 | * Options for connecting a topology as strings. |
1248 | */ | 1252 | */ |
1249 | static const char *topology_option_strings[] = | 1253 | static const char *topology_option_strings[] = { |
1250 | { | ||
1251 | /** | 1254 | /** |
1252 | * Try to connect all peers specified in the topology. | 1255 | * Try to connect all peers specified in the topology. |
1253 | */ | 1256 | */ |
@@ -1283,20 +1286,21 @@ GNUNET_TESTING_topology_option_get( | |||
1283 | */ | 1286 | */ |
1284 | "CONNECT_NONE", | 1287 | "CONNECT_NONE", |
1285 | 1288 | ||
1286 | NULL }; | 1289 | NULL |
1290 | }; | ||
1287 | int curr = 0; | 1291 | int curr = 0; |
1288 | 1292 | ||
1289 | if (topology_string == NULL) | 1293 | if (topology_string == NULL) |
1290 | return GNUNET_NO; | 1294 | return GNUNET_NO; |
1291 | while (NULL != topology_option_strings[curr]) | 1295 | while (NULL != topology_option_strings[curr]) |
1296 | { | ||
1297 | if (strcasecmp (topology_option_strings[curr], topology_string) == 0) | ||
1292 | { | 1298 | { |
1293 | if (strcasecmp (topology_option_strings[curr], topology_string) == 0) | 1299 | *topology_option = curr; |
1294 | { | 1300 | return GNUNET_YES; |
1295 | *topology_option = curr; | ||
1296 | return GNUNET_YES; | ||
1297 | } | ||
1298 | curr++; | ||
1299 | } | 1301 | } |
1302 | curr++; | ||
1303 | } | ||
1300 | *topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_NONE; | 1304 | *topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_NONE; |
1301 | return GNUNET_NO; | 1305 | return GNUNET_NO; |
1302 | } | 1306 | } |
@@ -1312,8 +1316,8 @@ GNUNET_TESTING_topology_option_get( | |||
1312 | * @param value value of the option | 1316 | * @param value value of the option |
1313 | */ | 1317 | */ |
1314 | static void | 1318 | static void |
1315 | update_config(void *cls, const char *section, const char *option, | 1319 | update_config (void *cls, const char *section, const char *option, |
1316 | const char *value) | 1320 | const char *value) |
1317 | { | 1321 | { |
1318 | struct UpdateContext *ctx = cls; | 1322 | struct UpdateContext *ctx = cls; |
1319 | unsigned int ival; | 1323 | unsigned int ival; |
@@ -1327,58 +1331,61 @@ update_config(void *cls, const char *section, const char *option, | |||
1327 | GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section); | 1331 | GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section); |
1328 | 1332 | ||
1329 | if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival))) | 1333 | if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival))) |
1330 | { | 1334 | { |
1331 | if ((ival != 0) && (GNUNET_YES | 1335 | if ((ival != 0) && (GNUNET_YES |
1332 | != GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, "testing", | 1336 | != GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, |
1333 | single_variable))) | 1337 | "testing", |
1334 | { | 1338 | single_variable))) |
1335 | GNUNET_snprintf (cval, sizeof(cval), "%u", ctx->nport++); | 1339 | { |
1336 | value = cval; | 1340 | GNUNET_snprintf (cval, sizeof (cval), "%u", ctx->nport++); |
1337 | } | 1341 | value = cval; |
1338 | else if ((ival != 0) && (GNUNET_YES | 1342 | } |
1339 | == GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, "testing", | 1343 | else if ((ival != 0) && (GNUNET_YES |
1340 | single_variable)) | 1344 | == GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, |
1341 | && GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing", | 1345 | "testing", |
1342 | per_host_variable, | 1346 | single_variable)) |
1343 | &num_per_host)) | 1347 | && GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing", |
1344 | { | 1348 | per_host_variable, |
1345 | GNUNET_snprintf (cval, sizeof(cval), "%u", ival + ctx->fdnum | 1349 | &num_per_host)) |
1346 | % num_per_host); | 1350 | { |
1347 | value = cval; | 1351 | GNUNET_snprintf (cval, sizeof (cval), "%u", ival + ctx->fdnum |
1348 | } | 1352 | % num_per_host); |
1349 | 1353 | value = cval; | |
1350 | /* FIXME: REMOVE FOREVER HACK HACK HACK */ | 1354 | } |
1351 | if (0 == strcasecmp (section, "transport-tcp")) | 1355 | |
1352 | GNUNET_CONFIGURATION_set_value_string (ctx->ret, section, "ADVERTISED_PORT", value); | 1356 | /* FIXME: REMOVE FOREVER HACK HACK HACK */ |
1353 | } | 1357 | if (0 == strcasecmp (section, "transport-tcp")) |
1358 | GNUNET_CONFIGURATION_set_value_string (ctx->ret, section, | ||
1359 | "ADVERTISED_PORT", value); | ||
1360 | } | ||
1354 | 1361 | ||
1355 | if (0 == strcmp (option, "UNIXPATH")) | 1362 | if (0 == strcmp (option, "UNIXPATH")) |
1363 | { | ||
1364 | if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, | ||
1365 | "testing", | ||
1366 | single_variable)) | ||
1356 | { | 1367 | { |
1357 | if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, | 1368 | GNUNET_snprintf (uval, sizeof (uval), "/tmp/test-service-%s-%u", |
1358 | "testing", | 1369 | section, ctx->upnum++); |
1359 | single_variable)) | 1370 | value = uval; |
1360 | { | ||
1361 | GNUNET_snprintf (uval, sizeof(uval), "/tmp/test-service-%s-%u", | ||
1362 | section, ctx->upnum++); | ||
1363 | value = uval; | ||
1364 | } | ||
1365 | else if ((GNUNET_YES | ||
1366 | == GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing", | ||
1367 | per_host_variable, | ||
1368 | &num_per_host)) | ||
1369 | && (num_per_host > 0)) | ||
1370 | |||
1371 | { | ||
1372 | GNUNET_snprintf (uval, sizeof(uval), "/tmp/test-service-%s-%u", | ||
1373 | section, ctx->fdnum % num_per_host); | ||
1374 | value = uval; | ||
1375 | } | ||
1376 | } | 1371 | } |
1372 | else if ((GNUNET_YES | ||
1373 | == GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing", | ||
1374 | per_host_variable, | ||
1375 | &num_per_host)) | ||
1376 | && (num_per_host > 0)) | ||
1377 | 1377 | ||
1378 | if ((0 == strcmp (option, "HOSTNAME")) && (ctx->hostname != NULL)) | ||
1379 | { | 1378 | { |
1380 | value = ctx->hostname; | 1379 | GNUNET_snprintf (uval, sizeof (uval), "/tmp/test-service-%s-%u", |
1380 | section, ctx->fdnum % num_per_host); | ||
1381 | value = uval; | ||
1381 | } | 1382 | } |
1383 | } | ||
1384 | |||
1385 | if ((0 == strcmp (option, "HOSTNAME")) && (ctx->hostname != NULL)) | ||
1386 | { | ||
1387 | value = ctx->hostname; | ||
1388 | } | ||
1382 | GNUNET_free (single_variable); | 1389 | GNUNET_free (single_variable); |
1383 | GNUNET_free (per_host_variable); | 1390 | GNUNET_free (per_host_variable); |
1384 | GNUNET_CONFIGURATION_set_value_string (ctx->ret, section, option, value); | 1391 | GNUNET_CONFIGURATION_set_value_string (ctx->ret, section, option, value); |
@@ -1402,9 +1409,9 @@ update_config(void *cls, const char *section, const char *option, | |||
1402 | * @return new configuration, NULL on error | 1409 | * @return new configuration, NULL on error |
1403 | */ | 1410 | */ |
1404 | static struct GNUNET_CONFIGURATION_Handle * | 1411 | static struct GNUNET_CONFIGURATION_Handle * |
1405 | make_config(const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off, | 1412 | make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off, |
1406 | uint16_t * port, uint32_t * upnum, const char *hostname, | 1413 | uint16_t * port, uint32_t * upnum, const char *hostname, |
1407 | uint32_t * fdnum) | 1414 | uint32_t * fdnum) |
1408 | { | 1415 | { |
1409 | struct UpdateContext uc; | 1416 | struct UpdateContext uc; |
1410 | uint16_t orig; | 1417 | uint16_t orig; |
@@ -1424,98 +1431,101 @@ make_config(const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off, | |||
1424 | 1431 | ||
1425 | GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc); | 1432 | GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc); |
1426 | if (uc.nport >= HIGH_PORT) | 1433 | if (uc.nport >= HIGH_PORT) |
1427 | { | 1434 | { |
1428 | *port = orig; | 1435 | *port = orig; |
1429 | GNUNET_CONFIGURATION_destroy (uc.ret); | 1436 | GNUNET_CONFIGURATION_destroy (uc.ret); |
1430 | return NULL; | 1437 | return NULL; |
1431 | } | 1438 | } |
1432 | 1439 | ||
1433 | if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "testing", | 1440 | if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "testing", |
1434 | "skew_variance", | 1441 | "skew_variance", |
1435 | &skew_variance)) | 1442 | &skew_variance)) |
1436 | && (skew_variance > 0)) | 1443 | && (skew_variance > 0)) |
1437 | { | 1444 | { |
1438 | skew_offset = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, skew_variance + 1); | 1445 | skew_offset = |
1439 | actual_offset = skew_offset - GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, skew_variance + 1); | 1446 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
1440 | /* Min is -skew_variance, Max is skew_variance */ | 1447 | skew_variance + 1); |
1441 | skew_offset = skew_variance + actual_offset; /* Normal distribution around 0 */ | 1448 | actual_offset = |
1442 | GNUNET_CONFIGURATION_set_value_number(uc.ret, "testing", "skew_offset", skew_offset); | 1449 | skew_offset - GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
1443 | } | 1450 | skew_variance + 1); |
1451 | /* Min is -skew_variance, Max is skew_variance */ | ||
1452 | skew_offset = skew_variance + actual_offset; /* Normal distribution around 0 */ | ||
1453 | GNUNET_CONFIGURATION_set_value_number (uc.ret, "testing", "skew_offset", | ||
1454 | skew_offset); | ||
1455 | } | ||
1444 | 1456 | ||
1445 | if (GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "control_host", | 1457 | if (GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "control_host", |
1446 | &control_host) == GNUNET_OK) | 1458 | &control_host) == GNUNET_OK) |
1447 | { | 1459 | { |
1448 | if (hostname != NULL) | 1460 | if (hostname != NULL) |
1449 | GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1; %s;", control_host, | 1461 | GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1; %s;", control_host, |
1450 | hostname); | 1462 | hostname); |
1451 | else | 1463 | else |
1452 | GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1;", control_host); | 1464 | GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1;", control_host); |
1453 | 1465 | ||
1454 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "core", "ACCEPT_FROM", | 1466 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "core", "ACCEPT_FROM", |
1455 | allowed_hosts); | 1467 | allowed_hosts); |
1456 | 1468 | ||
1457 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nse", "ACCEPT_FROM", | 1469 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nse", "ACCEPT_FROM", |
1458 | allowed_hosts); | 1470 | allowed_hosts); |
1459 | 1471 | ||
1460 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", | 1472 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", |
1461 | "ACCEPT_FROM", allowed_hosts); | 1473 | "ACCEPT_FROM", allowed_hosts); |
1462 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "dht", "ACCEPT_FROM", | 1474 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "dht", "ACCEPT_FROM", |
1463 | allowed_hosts); | 1475 | allowed_hosts); |
1464 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics", | 1476 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics", |
1465 | "ACCEPT_FROM", allowed_hosts); | 1477 | "ACCEPT_FROM", allowed_hosts); |
1466 | 1478 | ||
1467 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "core", "UNIXPATH", ""); | 1479 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "core", "UNIXPATH", ""); |
1468 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", "UNIXPATH", | 1480 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", "UNIXPATH", ""); |
1469 | ""); | 1481 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "dht", "UNIXPATH", ""); |
1470 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "dht", "UNIXPATH", ""); | 1482 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics", "UNIXPATH", |
1471 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics", "UNIXPATH", | 1483 | ""); |
1472 | ""); | 1484 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nse", "UNIXPATH", ""); |
1473 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nse", "UNIXPATH", ""); | 1485 | |
1474 | 1486 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", | |
1475 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", "USE_LOCALADDR", | 1487 | "USE_LOCALADDR", "YES"); |
1476 | "YES"); | 1488 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", |
1477 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", "USE_LOCALADDR", | 1489 | "USE_LOCALADDR", "YES"); |
1478 | "YES"); | 1490 | GNUNET_free_non_null (control_host); |
1479 | GNUNET_free_non_null (control_host); | 1491 | GNUNET_free (allowed_hosts); |
1480 | GNUNET_free (allowed_hosts); | 1492 | } |
1481 | } | ||
1482 | 1493 | ||
1483 | /* arm needs to know to allow connections from the host on which it is running, | 1494 | /* arm needs to know to allow connections from the host on which it is running, |
1484 | * otherwise gnunet-arm is unable to connect to it in some instances */ | 1495 | * otherwise gnunet-arm is unable to connect to it in some instances */ |
1485 | if (hostname != NULL) | 1496 | if (hostname != NULL) |
1486 | { | 1497 | { |
1487 | GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1;", hostname); | 1498 | GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1;", hostname); |
1488 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "BINDTO", | 1499 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "BINDTO", hostname); |
1489 | hostname); | 1500 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "INTERNAL_ADDRESS", |
1490 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "INTERNAL_ADDRESS", | 1501 | hostname); |
1491 | hostname); | 1502 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "EXTERNAL_ADDRESS", |
1492 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "EXTERNAL_ADDRESS", | 1503 | hostname); |
1493 | hostname); | 1504 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "disablev6", "BINDTO", |
1494 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "disablev6", "BINDTO", | 1505 | "YES"); |
1495 | "YES"); | 1506 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", |
1496 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", "USE_LOCALADDR", | 1507 | "USE_LOCALADDR", "YES"); |
1497 | "YES"); | 1508 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", |
1498 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", "USE_LOCALADDR", | 1509 | "USE_LOCALADDR", "YES"); |
1499 | "YES"); | 1510 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "arm", "ACCEPT_FROM", |
1500 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "arm", "ACCEPT_FROM", | 1511 | allowed_hosts); |
1501 | allowed_hosts); | 1512 | GNUNET_free (allowed_hosts); |
1502 | GNUNET_free (allowed_hosts); | 1513 | } |
1503 | } | ||
1504 | else | 1514 | else |
1505 | { | 1515 | { |
1506 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", "USE_LOCALADDR", | 1516 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", |
1507 | "YES"); | 1517 | "USE_LOCALADDR", "YES"); |
1508 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", "USE_LOCALADDR", | 1518 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", |
1509 | "YES"); | 1519 | "USE_LOCALADDR", "YES"); |
1510 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "BINDTO", | 1520 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "BINDTO", |
1511 | "127.0.0.1"); | 1521 | "127.0.0.1"); |
1512 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "INTERNAL_ADDRESS", | 1522 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "INTERNAL_ADDRESS", |
1513 | "127.0.0.1"); | 1523 | "127.0.0.1"); |
1514 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "EXTERNAL_ADDRESS", | 1524 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "EXTERNAL_ADDRESS", |
1515 | "127.0.0.1"); | 1525 | "127.0.0.1"); |
1516 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "disablev6", "BINDTO", | 1526 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "disablev6", "BINDTO", |
1517 | "YES"); | 1527 | "YES"); |
1518 | } | 1528 | } |
1519 | 1529 | ||
1520 | *port = (uint16_t) uc.nport; | 1530 | *port = (uint16_t) uc.nport; |
1521 | *upnum = uc.upnum; | 1531 | *upnum = uc.upnum; |
@@ -1537,10 +1547,12 @@ make_config(const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off, | |||
1537 | * | 1547 | * |
1538 | */ | 1548 | */ |
1539 | static unsigned int | 1549 | static unsigned int |
1540 | remove_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | 1550 | remove_connections (struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, |
1541 | unsigned int second, enum PeerLists list, unsigned int check) | 1551 | unsigned int second, enum PeerLists list, |
1552 | unsigned int check) | ||
1542 | { | 1553 | { |
1543 | int removed; | 1554 | int removed; |
1555 | |||
1544 | #if OLD | 1556 | #if OLD |
1545 | struct PeerConnection **first_list; | 1557 | struct PeerConnection **first_list; |
1546 | struct PeerConnection **second_list; | 1558 | struct PeerConnection **second_list; |
@@ -1560,7 +1572,7 @@ remove_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | |||
1560 | removed = 0; | 1572 | removed = 0; |
1561 | #if OLD | 1573 | #if OLD |
1562 | switch (list) | 1574 | switch (list) |
1563 | { | 1575 | { |
1564 | case ALLOWED: | 1576 | case ALLOWED: |
1565 | first_list = &pg->peers[first].allowed_peers_head; | 1577 | first_list = &pg->peers[first].allowed_peers_head; |
1566 | second_list = &pg->peers[second].allowed_peers_head; | 1578 | second_list = &pg->peers[second].allowed_peers_head; |
@@ -1586,51 +1598,55 @@ remove_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | |||
1586 | second_tail = &pg->peers[second].connect_peers_working_set_tail; | 1598 | second_tail = &pg->peers[second].connect_peers_working_set_tail; |
1587 | break; | 1599 | break; |
1588 | default: | 1600 | default: |
1589 | GNUNET_break(0); | 1601 | GNUNET_break (0); |
1590 | return 0; | 1602 | return 0; |
1591 | } | 1603 | } |
1592 | 1604 | ||
1593 | first_iter = *first_list; | 1605 | first_iter = *first_list; |
1594 | while (first_iter != NULL) | 1606 | while (first_iter != NULL) |
1607 | { | ||
1608 | if (first_iter->index == second) | ||
1595 | { | 1609 | { |
1596 | if (first_iter->index == second) | 1610 | GNUNET_CONTAINER_DLL_remove (*first_list, *first_tail, first_iter); |
1597 | { | 1611 | GNUNET_free (first_iter); |
1598 | GNUNET_CONTAINER_DLL_remove(*first_list, *first_tail, first_iter); | 1612 | removed++; |
1599 | GNUNET_free(first_iter); | 1613 | break; |
1600 | removed++; | ||
1601 | break; | ||
1602 | } | ||
1603 | first_iter = first_iter->next; | ||
1604 | } | 1614 | } |
1615 | first_iter = first_iter->next; | ||
1616 | } | ||
1605 | 1617 | ||
1606 | second_iter = *second_list; | 1618 | second_iter = *second_list; |
1607 | while (second_iter != NULL) | 1619 | while (second_iter != NULL) |
1620 | { | ||
1621 | if (second_iter->index == first) | ||
1608 | { | 1622 | { |
1609 | if (second_iter->index == first) | 1623 | GNUNET_CONTAINER_DLL_remove (*second_list, *second_tail, second_iter); |
1610 | { | 1624 | GNUNET_free (second_iter); |
1611 | GNUNET_CONTAINER_DLL_remove(*second_list, *second_tail, second_iter); | 1625 | removed++; |
1612 | GNUNET_free(second_iter); | 1626 | break; |
1613 | removed++; | ||
1614 | break; | ||
1615 | } | ||
1616 | second_iter = second_iter->next; | ||
1617 | } | 1627 | } |
1628 | second_iter = second_iter->next; | ||
1629 | } | ||
1618 | #else | 1630 | #else |
1619 | if (GNUNET_YES == | 1631 | if (GNUNET_YES == |
1620 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[first].blacklisted_peers, | 1632 | GNUNET_CONTAINER_multihashmap_contains (pg-> |
1621 | &hash_second)) | 1633 | peers[first].blacklisted_peers, |
1622 | { | 1634 | &hash_second)) |
1623 | GNUNET_CONTAINER_multihashmap_remove_all (pg->peers[first].blacklisted_peers, | 1635 | { |
1624 | &hash_second); | 1636 | GNUNET_CONTAINER_multihashmap_remove_all (pg-> |
1625 | } | 1637 | peers[first].blacklisted_peers, |
1638 | &hash_second); | ||
1639 | } | ||
1626 | 1640 | ||
1627 | if (GNUNET_YES == | 1641 | if (GNUNET_YES == |
1628 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[second].blacklisted_peers, | 1642 | GNUNET_CONTAINER_multihashmap_contains (pg-> |
1629 | &hash_first)) | 1643 | peers[second].blacklisted_peers, |
1630 | { | 1644 | &hash_first)) |
1631 | GNUNET_CONTAINER_multihashmap_remove_all (pg->peers[second].blacklisted_peers, | 1645 | { |
1632 | &hash_first); | 1646 | GNUNET_CONTAINER_multihashmap_remove_all (pg-> |
1633 | } | 1647 | peers[second].blacklisted_peers, |
1648 | &hash_first); | ||
1649 | } | ||
1634 | #endif | 1650 | #endif |
1635 | 1651 | ||
1636 | return removed; | 1652 | return removed; |
@@ -1650,8 +1666,8 @@ remove_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | |||
1650 | * | 1666 | * |
1651 | */ | 1667 | */ |
1652 | static unsigned int | 1668 | static unsigned int |
1653 | add_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | 1669 | add_connections (struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, |
1654 | unsigned int second, enum PeerLists list, unsigned int check) | 1670 | unsigned int second, enum PeerLists list, unsigned int check) |
1655 | { | 1671 | { |
1656 | int added; | 1672 | int added; |
1657 | int add_first; | 1673 | int add_first; |
@@ -1667,7 +1683,7 @@ add_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | |||
1667 | struct PeerConnection **second_tail; | 1683 | struct PeerConnection **second_tail; |
1668 | 1684 | ||
1669 | switch (list) | 1685 | switch (list) |
1670 | { | 1686 | { |
1671 | case ALLOWED: | 1687 | case ALLOWED: |
1672 | first_list = &pg->peers[first].allowed_peers_head; | 1688 | first_list = &pg->peers[first].allowed_peers_head; |
1673 | second_list = &pg->peers[second].allowed_peers_head; | 1689 | second_list = &pg->peers[second].allowed_peers_head; |
@@ -1693,56 +1709,56 @@ add_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | |||
1693 | second_tail = &pg->peers[second].connect_peers_working_set_tail; | 1709 | second_tail = &pg->peers[second].connect_peers_working_set_tail; |
1694 | break; | 1710 | break; |
1695 | default: | 1711 | default: |
1696 | GNUNET_break(0); | 1712 | GNUNET_break (0); |
1697 | return 0; | 1713 | return 0; |
1698 | } | 1714 | } |
1699 | 1715 | ||
1700 | add_first = GNUNET_YES; | 1716 | add_first = GNUNET_YES; |
1701 | add_second = GNUNET_YES; | 1717 | add_second = GNUNET_YES; |
1702 | 1718 | ||
1703 | if (check == GNUNET_YES) | 1719 | if (check == GNUNET_YES) |
1720 | { | ||
1721 | first_iter = *first_list; | ||
1722 | while (first_iter != NULL) | ||
1704 | { | 1723 | { |
1705 | first_iter = *first_list; | 1724 | if (first_iter->index == second) |
1706 | while (first_iter != NULL) | 1725 | { |
1707 | { | 1726 | add_first = GNUNET_NO; |
1708 | if (first_iter->index == second) | 1727 | break; |
1709 | { | 1728 | } |
1710 | add_first = GNUNET_NO; | 1729 | first_iter = first_iter->next; |
1711 | break; | 1730 | } |
1712 | } | ||
1713 | first_iter = first_iter->next; | ||
1714 | } | ||
1715 | 1731 | ||
1716 | second_iter = *second_list; | 1732 | second_iter = *second_list; |
1717 | while (second_iter != NULL) | 1733 | while (second_iter != NULL) |
1718 | { | 1734 | { |
1719 | if (second_iter->index == first) | 1735 | if (second_iter->index == first) |
1720 | { | 1736 | { |
1721 | add_second = GNUNET_NO; | 1737 | add_second = GNUNET_NO; |
1722 | break; | 1738 | break; |
1723 | } | 1739 | } |
1724 | second_iter = second_iter->next; | 1740 | second_iter = second_iter->next; |
1725 | } | ||
1726 | } | 1741 | } |
1742 | } | ||
1727 | 1743 | ||
1728 | added = 0; | 1744 | added = 0; |
1729 | if (add_first) | 1745 | if (add_first) |
1730 | { | 1746 | { |
1731 | new_first = GNUNET_malloc (sizeof (struct PeerConnection)); | 1747 | new_first = GNUNET_malloc (sizeof (struct PeerConnection)); |
1732 | new_first->index = second; | 1748 | new_first->index = second; |
1733 | GNUNET_CONTAINER_DLL_insert(*first_list, *first_tail, new_first); | 1749 | GNUNET_CONTAINER_DLL_insert (*first_list, *first_tail, new_first); |
1734 | pg->peers[first].num_connections++; | 1750 | pg->peers[first].num_connections++; |
1735 | added++; | 1751 | added++; |
1736 | } | 1752 | } |
1737 | 1753 | ||
1738 | if (add_second) | 1754 | if (add_second) |
1739 | { | 1755 | { |
1740 | new_second = GNUNET_malloc (sizeof (struct PeerConnection)); | 1756 | new_second = GNUNET_malloc (sizeof (struct PeerConnection)); |
1741 | new_second->index = first; | 1757 | new_second->index = first; |
1742 | GNUNET_CONTAINER_DLL_insert(*second_list, *second_tail, new_second); | 1758 | GNUNET_CONTAINER_DLL_insert (*second_list, *second_tail, new_second); |
1743 | pg->peers[second].num_connections++; | 1759 | pg->peers[second].num_connections++; |
1744 | added++; | 1760 | added++; |
1745 | } | 1761 | } |
1746 | 1762 | ||
1747 | return added; | 1763 | return added; |
1748 | } | 1764 | } |
@@ -1764,8 +1780,8 @@ add_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | |||
1764 | * @return the number of connections created | 1780 | * @return the number of connections created |
1765 | */ | 1781 | */ |
1766 | static unsigned int | 1782 | static unsigned int |
1767 | create_scale_free(struct GNUNET_TESTING_PeerGroup *pg, | 1783 | create_scale_free (struct GNUNET_TESTING_PeerGroup *pg, |
1768 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 1784 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
1769 | { | 1785 | { |
1770 | 1786 | ||
1771 | unsigned int total_connections; | 1787 | unsigned int total_connections; |
@@ -1781,31 +1797,31 @@ create_scale_free(struct GNUNET_TESTING_PeerGroup *pg, | |||
1781 | total_connections = proc (pg, 0, 1, list, GNUNET_YES); | 1797 | total_connections = proc (pg, 0, 1, list, GNUNET_YES); |
1782 | 1798 | ||
1783 | for (outer_count = 1; outer_count < pg->total; outer_count++) | 1799 | for (outer_count = 1; outer_count < pg->total; outer_count++) |
1784 | { | 1800 | { |
1785 | previous_total_connections = total_connections; | 1801 | previous_total_connections = total_connections; |
1786 | for (i = 0; i < outer_count; i++) | 1802 | for (i = 0; i < outer_count; i++) |
1787 | { | 1803 | { |
1788 | probability = pg->peers[i].num_connections | 1804 | probability = pg->peers[i].num_connections |
1789 | / (double) previous_total_connections; | 1805 | / (double) previous_total_connections; |
1790 | random | 1806 | random |
1791 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 1807 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
1792 | UINT64_MAX)) | 1808 | UINT64_MAX)) |
1793 | / ((double) UINT64_MAX); | 1809 | / ((double) UINT64_MAX); |
1794 | #if VERBOSE_TESTING | 1810 | #if VERBOSE_TESTING |
1795 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1811 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1796 | "Considering connecting peer %d to peer %d\n", | 1812 | "Considering connecting peer %d to peer %d\n", |
1797 | outer_count, i); | 1813 | outer_count, i); |
1798 | #endif | 1814 | #endif |
1799 | if (random < probability) | 1815 | if (random < probability) |
1800 | { | 1816 | { |
1801 | #if VERBOSE_TESTING | 1817 | #if VERBOSE_TESTING |
1802 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1818 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1803 | "Connecting peer %d to peer %d\n", outer_count, i); | 1819 | "Connecting peer %d to peer %d\n", outer_count, i); |
1804 | #endif | 1820 | #endif |
1805 | total_connections += proc (pg, outer_count, i, list, GNUNET_YES); | 1821 | total_connections += proc (pg, outer_count, i, list, GNUNET_YES); |
1806 | } | 1822 | } |
1807 | } | ||
1808 | } | 1823 | } |
1824 | } | ||
1809 | 1825 | ||
1810 | return total_connections; | 1826 | return total_connections; |
1811 | } | 1827 | } |
@@ -1838,9 +1854,9 @@ create_scale_free(struct GNUNET_TESTING_PeerGroup *pg, | |||
1838 | * | 1854 | * |
1839 | */ | 1855 | */ |
1840 | static unsigned int | 1856 | static unsigned int |
1841 | create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg, | 1857 | create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg, |
1842 | GNUNET_TESTING_ConnectionProcessor proc, | 1858 | GNUNET_TESTING_ConnectionProcessor proc, |
1843 | enum PeerLists list) | 1859 | enum PeerLists list) |
1844 | { | 1860 | { |
1845 | unsigned int i, j; | 1861 | unsigned int i, j; |
1846 | int nodeToConnect; | 1862 | int nodeToConnect; |
@@ -1855,32 +1871,30 @@ create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg, | |||
1855 | unsigned int useAnd; | 1871 | unsigned int useAnd; |
1856 | int connect_attempts; | 1872 | int connect_attempts; |
1857 | 1873 | ||
1858 | logNModifier = 0.5; /* FIXME: default value? */ | 1874 | logNModifier = 0.5; /* FIXME: default value? */ |
1859 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", | 1875 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", |
1860 | "PERCENTAGE", | 1876 | "PERCENTAGE", |
1861 | &p_string)) | 1877 | &p_string)) |
1862 | { | 1878 | { |
1863 | if (sscanf (p_string, "%lf", &logNModifier) != 1) | 1879 | if (sscanf (p_string, "%lf", &logNModifier) != 1) |
1864 | GNUNET_log ( | 1880 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1865 | GNUNET_ERROR_TYPE_WARNING, | 1881 | _ |
1866 | _ | 1882 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
1867 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 1883 | p_string, "LOGNMODIFIER", "TESTING"); |
1868 | p_string, "LOGNMODIFIER", "TESTING"); | 1884 | GNUNET_free (p_string); |
1869 | GNUNET_free (p_string); | 1885 | } |
1870 | } | 1886 | probability = 0.5; /* FIXME: default percentage? */ |
1871 | probability = 0.5; /* FIXME: default percentage? */ | ||
1872 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", | 1887 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", |
1873 | "PROBABILITY", | 1888 | "PROBABILITY", |
1874 | &p_string)) | 1889 | &p_string)) |
1875 | { | 1890 | { |
1876 | if (sscanf (p_string, "%lf", &probability) != 1) | 1891 | if (sscanf (p_string, "%lf", &probability) != 1) |
1877 | GNUNET_log ( | 1892 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1878 | GNUNET_ERROR_TYPE_WARNING, | 1893 | _ |
1879 | _ | 1894 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
1880 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 1895 | p_string, "PERCENTAGE", "TESTING"); |
1881 | p_string, "PERCENTAGE", "TESTING"); | 1896 | GNUNET_free (p_string); |
1882 | GNUNET_free (p_string); | 1897 | } |
1883 | } | ||
1884 | natLog = log (pg->total); | 1898 | natLog = log (pg->total); |
1885 | connsPerPeer = ceil (natLog * logNModifier); | 1899 | connsPerPeer = ceil (natLog * logNModifier); |
1886 | 1900 | ||
@@ -1893,59 +1907,57 @@ create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg, | |||
1893 | smallWorldConnections = 0; | 1907 | smallWorldConnections = 0; |
1894 | connect_attempts = 0; | 1908 | connect_attempts = 0; |
1895 | for (i = 0; i < pg->total; i++) | 1909 | for (i = 0; i < pg->total; i++) |
1910 | { | ||
1911 | useAnd = 0; | ||
1912 | max = i + connsPerPeer / 2; | ||
1913 | min = i - connsPerPeer / 2; | ||
1914 | |||
1915 | if (max > pg->total - 1) | ||
1896 | { | 1916 | { |
1897 | useAnd = 0; | 1917 | max = max - pg->total; |
1898 | max = i + connsPerPeer / 2; | 1918 | useAnd = 1; |
1899 | min = i - connsPerPeer / 2; | 1919 | } |
1900 | 1920 | ||
1901 | if (max > pg->total - 1) | 1921 | if (min < 0) |
1902 | { | 1922 | { |
1903 | max = max - pg->total; | 1923 | min = pg->total - 1 + min; |
1904 | useAnd = 1; | 1924 | useAnd = 1; |
1905 | } | 1925 | } |
1906 | 1926 | ||
1907 | if (min < 0) | 1927 | for (j = 0; j < connsPerPeer / 2; j++) |
1928 | { | ||
1929 | random | ||
1930 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1931 | UINT64_MAX) | ||
1932 | / ((double) UINT64_MAX)); | ||
1933 | if (random < probability) | ||
1934 | { | ||
1935 | /* Connect to uniformly selected random peer */ | ||
1936 | randomPeer | ||
1937 | = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, pg->total); | ||
1938 | while ((((randomPeer < max) && (randomPeer > min)) && (useAnd | ||
1939 | == 0)) || | ||
1940 | (((randomPeer > min) || (randomPeer < max)) && (useAnd == 1))) | ||
1908 | { | 1941 | { |
1909 | min = pg->total - 1 + min; | 1942 | randomPeer |
1910 | useAnd = 1; | 1943 | = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
1944 | pg->total); | ||
1911 | } | 1945 | } |
1912 | 1946 | smallWorldConnections += proc (pg, i, randomPeer, list, GNUNET_YES); | |
1913 | for (j = 0; j < connsPerPeer / 2; j++) | 1947 | } |
1948 | else | ||
1949 | { | ||
1950 | nodeToConnect = i + j + 1; | ||
1951 | if (nodeToConnect > pg->total - 1) | ||
1914 | { | 1952 | { |
1915 | random | 1953 | nodeToConnect = nodeToConnect - pg->total; |
1916 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1917 | UINT64_MAX) | ||
1918 | / ((double) UINT64_MAX)); | ||
1919 | if (random < probability) | ||
1920 | { | ||
1921 | /* Connect to uniformly selected random peer */ | ||
1922 | randomPeer | ||
1923 | = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1924 | pg->total); | ||
1925 | while ((((randomPeer < max) && (randomPeer > min)) && (useAnd | ||
1926 | == 0)) || (((randomPeer > min) || (randomPeer < max)) | ||
1927 | && (useAnd == 1))) | ||
1928 | { | ||
1929 | randomPeer | ||
1930 | = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1931 | pg->total); | ||
1932 | } | ||
1933 | smallWorldConnections += proc (pg, i, randomPeer, list, | ||
1934 | GNUNET_YES); | ||
1935 | } | ||
1936 | else | ||
1937 | { | ||
1938 | nodeToConnect = i + j + 1; | ||
1939 | if (nodeToConnect > pg->total - 1) | ||
1940 | { | ||
1941 | nodeToConnect = nodeToConnect - pg->total; | ||
1942 | } | ||
1943 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); | ||
1944 | } | ||
1945 | } | 1954 | } |
1946 | 1955 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); | |
1956 | } | ||
1947 | } | 1957 | } |
1948 | 1958 | ||
1959 | } | ||
1960 | |||
1949 | connect_attempts += smallWorldConnections; | 1961 | connect_attempts += smallWorldConnections; |
1950 | 1962 | ||
1951 | return connect_attempts; | 1963 | return connect_attempts; |
@@ -1964,9 +1976,9 @@ create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg, | |||
1964 | * | 1976 | * |
1965 | */ | 1977 | */ |
1966 | static unsigned int | 1978 | static unsigned int |
1967 | create_nated_internet(struct GNUNET_TESTING_PeerGroup *pg, | 1979 | create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, |
1968 | GNUNET_TESTING_ConnectionProcessor proc, | 1980 | GNUNET_TESTING_ConnectionProcessor proc, |
1969 | enum PeerLists list) | 1981 | enum PeerLists list) |
1970 | { | 1982 | { |
1971 | unsigned int outer_count, inner_count; | 1983 | unsigned int outer_count, inner_count; |
1972 | unsigned int cutoff; | 1984 | unsigned int cutoff; |
@@ -1974,38 +1986,37 @@ create_nated_internet(struct GNUNET_TESTING_PeerGroup *pg, | |||
1974 | double nat_percentage; | 1986 | double nat_percentage; |
1975 | char *p_string; | 1987 | char *p_string; |
1976 | 1988 | ||
1977 | nat_percentage = 0.6; /* FIXME: default percentage? */ | 1989 | nat_percentage = 0.6; /* FIXME: default percentage? */ |
1978 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", | 1990 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", |
1979 | "PERCENTAGE", | 1991 | "PERCENTAGE", |
1980 | &p_string)) | 1992 | &p_string)) |
1981 | { | 1993 | { |
1982 | if (sscanf (p_string, "%lf", &nat_percentage) != 1) | 1994 | if (sscanf (p_string, "%lf", &nat_percentage) != 1) |
1983 | GNUNET_log ( | 1995 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1984 | GNUNET_ERROR_TYPE_WARNING, | 1996 | _ |
1985 | _ | 1997 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
1986 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 1998 | p_string, "PERCENTAGE", "TESTING"); |
1987 | p_string, "PERCENTAGE", "TESTING"); | 1999 | GNUNET_free (p_string); |
1988 | GNUNET_free (p_string); | 2000 | } |
1989 | } | ||
1990 | 2001 | ||
1991 | cutoff = (unsigned int) (nat_percentage * pg->total); | 2002 | cutoff = (unsigned int) (nat_percentage * pg->total); |
1992 | connect_attempts = 0; | 2003 | connect_attempts = 0; |
1993 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) | 2004 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) |
2005 | { | ||
2006 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) | ||
1994 | { | 2007 | { |
1995 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) | 2008 | if ((outer_count > cutoff) || (inner_count > cutoff)) |
1996 | { | 2009 | { |
1997 | if ((outer_count > cutoff) || (inner_count > cutoff)) | ||
1998 | { | ||
1999 | #if VERBOSE_TESTING | 2010 | #if VERBOSE_TESTING |
2000 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2011 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2001 | "Connecting peer %d to peer %d\n", | 2012 | "Connecting peer %d to peer %d\n", |
2002 | outer_count, inner_count); | 2013 | outer_count, inner_count); |
2003 | #endif | 2014 | #endif |
2004 | connect_attempts += proc (pg, outer_count, inner_count, list, | 2015 | connect_attempts += proc (pg, outer_count, inner_count, list, |
2005 | GNUNET_YES); | 2016 | GNUNET_YES); |
2006 | } | 2017 | } |
2007 | } | ||
2008 | } | 2018 | } |
2019 | } | ||
2009 | return connect_attempts; | 2020 | return connect_attempts; |
2010 | } | 2021 | } |
2011 | 2022 | ||
@@ -2023,9 +2034,9 @@ create_nated_internet(struct GNUNET_TESTING_PeerGroup *pg, | |||
2023 | * | 2034 | * |
2024 | */ | 2035 | */ |
2025 | static unsigned int | 2036 | static unsigned int |
2026 | create_nated_internet_copy(struct GNUNET_TESTING_PeerGroup *pg, | 2037 | create_nated_internet_copy (struct GNUNET_TESTING_PeerGroup *pg, |
2027 | GNUNET_TESTING_ConnectionProcessor proc, | 2038 | GNUNET_TESTING_ConnectionProcessor proc, |
2028 | enum PeerLists list) | 2039 | enum PeerLists list) |
2029 | { | 2040 | { |
2030 | unsigned int outer_count, inner_count; | 2041 | unsigned int outer_count, inner_count; |
2031 | unsigned int cutoff; | 2042 | unsigned int cutoff; |
@@ -2035,52 +2046,51 @@ create_nated_internet_copy(struct GNUNET_TESTING_PeerGroup *pg, | |||
2035 | unsigned int count; | 2046 | unsigned int count; |
2036 | struct ProgressMeter *conn_meter; | 2047 | struct ProgressMeter *conn_meter; |
2037 | 2048 | ||
2038 | nat_percentage = 0.6; /* FIXME: default percentage? */ | 2049 | nat_percentage = 0.6; /* FIXME: default percentage? */ |
2039 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", | 2050 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", |
2040 | "PERCENTAGE", | 2051 | "PERCENTAGE", |
2041 | &p_string)) | 2052 | &p_string)) |
2042 | { | 2053 | { |
2043 | if (sscanf (p_string, "%lf", &nat_percentage) != 1) | 2054 | if (sscanf (p_string, "%lf", &nat_percentage) != 1) |
2044 | GNUNET_log ( | 2055 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2045 | GNUNET_ERROR_TYPE_WARNING, | 2056 | _ |
2046 | _ | 2057 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
2047 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 2058 | p_string, "PERCENTAGE", "TESTING"); |
2048 | p_string, "PERCENTAGE", "TESTING"); | 2059 | GNUNET_free (p_string); |
2049 | GNUNET_free (p_string); | 2060 | } |
2050 | } | ||
2051 | 2061 | ||
2052 | cutoff = (unsigned int) (nat_percentage * pg->total); | 2062 | cutoff = (unsigned int) (nat_percentage * pg->total); |
2053 | count = 0; | 2063 | count = 0; |
2054 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) | 2064 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) |
2065 | { | ||
2066 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) | ||
2055 | { | 2067 | { |
2056 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) | 2068 | if ((outer_count > cutoff) || (inner_count > cutoff)) |
2057 | { | 2069 | { |
2058 | if ((outer_count > cutoff) || (inner_count > cutoff)) | 2070 | count++; |
2059 | { | 2071 | } |
2060 | count++; | ||
2061 | } | ||
2062 | } | ||
2063 | } | 2072 | } |
2073 | } | ||
2064 | conn_meter = create_meter (count, "NAT COPY", GNUNET_YES); | 2074 | conn_meter = create_meter (count, "NAT COPY", GNUNET_YES); |
2065 | connect_attempts = 0; | 2075 | connect_attempts = 0; |
2066 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) | 2076 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) |
2077 | { | ||
2078 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) | ||
2067 | { | 2079 | { |
2068 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) | 2080 | if ((outer_count > cutoff) || (inner_count > cutoff)) |
2069 | { | 2081 | { |
2070 | if ((outer_count > cutoff) || (inner_count > cutoff)) | ||
2071 | { | ||
2072 | #if VERBOSE_TESTING | 2082 | #if VERBOSE_TESTING |
2073 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2083 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2074 | "Connecting peer %d to peer %d\n", | 2084 | "Connecting peer %d to peer %d\n", |
2075 | outer_count, inner_count); | 2085 | outer_count, inner_count); |
2076 | #endif | 2086 | #endif |
2077 | connect_attempts += proc (pg, outer_count, inner_count, list, | 2087 | connect_attempts += proc (pg, outer_count, inner_count, list, |
2078 | GNUNET_YES); | 2088 | GNUNET_YES); |
2079 | add_connections (pg, outer_count, inner_count, ALLOWED, GNUNET_NO); | 2089 | add_connections (pg, outer_count, inner_count, ALLOWED, GNUNET_NO); |
2080 | update_meter (conn_meter); | 2090 | update_meter (conn_meter); |
2081 | } | 2091 | } |
2082 | } | ||
2083 | } | 2092 | } |
2093 | } | ||
2084 | free_meter (conn_meter); | 2094 | free_meter (conn_meter); |
2085 | 2095 | ||
2086 | return connect_attempts; | 2096 | return connect_attempts; |
@@ -2100,8 +2110,9 @@ create_nated_internet_copy(struct GNUNET_TESTING_PeerGroup *pg, | |||
2100 | * | 2110 | * |
2101 | */ | 2111 | */ |
2102 | static unsigned int | 2112 | static unsigned int |
2103 | create_small_world(struct GNUNET_TESTING_PeerGroup *pg, | 2113 | create_small_world (struct GNUNET_TESTING_PeerGroup *pg, |
2104 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 2114 | GNUNET_TESTING_ConnectionProcessor proc, |
2115 | enum PeerLists list) | ||
2105 | { | 2116 | { |
2106 | unsigned int i, j, k; | 2117 | unsigned int i, j, k; |
2107 | unsigned int square; | 2118 | unsigned int square; |
@@ -2120,62 +2131,60 @@ create_small_world(struct GNUNET_TESTING_PeerGroup *pg, | |||
2120 | unsigned int small_world_it; | 2131 | unsigned int small_world_it; |
2121 | char *p_string; | 2132 | char *p_string; |
2122 | int connect_attempts; | 2133 | int connect_attempts; |
2134 | |||
2123 | square = floor (sqrt (pg->total)); | 2135 | square = floor (sqrt (pg->total)); |
2124 | rows = square; | 2136 | rows = square; |
2125 | cols = square; | 2137 | cols = square; |
2126 | 2138 | ||
2127 | percentage = 0.5; /* FIXME: default percentage? */ | 2139 | percentage = 0.5; /* FIXME: default percentage? */ |
2128 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", | 2140 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", |
2129 | "PERCENTAGE", | 2141 | "PERCENTAGE", |
2130 | &p_string)) | 2142 | &p_string)) |
2131 | { | 2143 | { |
2132 | if (sscanf (p_string, "%lf", &percentage) != 1) | 2144 | if (sscanf (p_string, "%lf", &percentage) != 1) |
2133 | GNUNET_log ( | 2145 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2134 | GNUNET_ERROR_TYPE_WARNING, | ||
2135 | _ | ||
2136 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | ||
2137 | p_string, "PERCENTAGE", "TESTING"); | ||
2138 | GNUNET_free (p_string); | ||
2139 | } | ||
2140 | if (percentage < 0.0) | ||
2141 | { | ||
2142 | GNUNET_log ( | ||
2143 | GNUNET_ERROR_TYPE_WARNING, | ||
2144 | _ | 2146 | _ |
2145 | ("Invalid value `%s' for option `%s' in section `%s': got %f, needed value greater than 0\n"), | 2147 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
2146 | "PERCENTAGE", "TESTING", percentage); | 2148 | p_string, "PERCENTAGE", "TESTING"); |
2147 | percentage = 0.5; | 2149 | GNUNET_free (p_string); |
2148 | } | 2150 | } |
2149 | probability = 0.5; /* FIXME: default percentage? */ | 2151 | if (percentage < 0.0) |
2152 | { | ||
2153 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
2154 | _ | ||
2155 | ("Invalid value `%s' for option `%s' in section `%s': got %f, needed value greater than 0\n"), | ||
2156 | "PERCENTAGE", "TESTING", percentage); | ||
2157 | percentage = 0.5; | ||
2158 | } | ||
2159 | probability = 0.5; /* FIXME: default percentage? */ | ||
2150 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", | 2160 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", |
2151 | "PROBABILITY", | 2161 | "PROBABILITY", |
2152 | &p_string)) | 2162 | &p_string)) |
2153 | { | 2163 | { |
2154 | if (sscanf (p_string, "%lf", &probability) != 1) | 2164 | if (sscanf (p_string, "%lf", &probability) != 1) |
2155 | GNUNET_log ( | 2165 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2156 | GNUNET_ERROR_TYPE_WARNING, | 2166 | _ |
2157 | _ | 2167 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
2158 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 2168 | p_string, "PROBABILITY", "TESTING"); |
2159 | p_string, "PROBABILITY", "TESTING"); | 2169 | GNUNET_free (p_string); |
2160 | GNUNET_free (p_string); | 2170 | } |
2161 | } | ||
2162 | if (square * square != pg->total) | 2171 | if (square * square != pg->total) |
2172 | { | ||
2173 | while (rows * cols < pg->total) | ||
2163 | { | 2174 | { |
2164 | while (rows * cols < pg->total) | 2175 | if (toggle % 2 == 0) |
2165 | { | 2176 | rows++; |
2166 | if (toggle % 2 == 0) | 2177 | else |
2167 | rows++; | 2178 | cols++; |
2168 | else | ||
2169 | cols++; | ||
2170 | 2179 | ||
2171 | toggle++; | 2180 | toggle++; |
2172 | } | ||
2173 | } | 2181 | } |
2182 | } | ||
2174 | #if VERBOSE_TESTING | 2183 | #if VERBOSE_TESTING |
2175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2176 | _ | 2185 | _ |
2177 | ("Connecting nodes in 2d torus topology: %u rows %u columns\n"), | 2186 | ("Connecting nodes in 2d torus topology: %u rows %u columns\n"), |
2178 | rows, cols); | 2187 | rows, cols); |
2179 | #endif | 2188 | #endif |
2180 | 2189 | ||
2181 | connect_attempts = 0; | 2190 | connect_attempts = 0; |
@@ -2185,36 +2194,36 @@ create_small_world(struct GNUNET_TESTING_PeerGroup *pg, | |||
2185 | * to the first in the row to maintain topology. | 2194 | * to the first in the row to maintain topology. |
2186 | */ | 2195 | */ |
2187 | for (i = 0; i < pg->total; i++) | 2196 | for (i = 0; i < pg->total; i++) |
2188 | { | 2197 | { |
2189 | /* First connect to the node to the right */ | 2198 | /* First connect to the node to the right */ |
2190 | if (((i + 1) % cols != 0) && (i + 1 != pg->total)) | 2199 | if (((i + 1) % cols != 0) && (i + 1 != pg->total)) |
2191 | nodeToConnect = i + 1; | 2200 | nodeToConnect = i + 1; |
2192 | else if (i + 1 == pg->total) | 2201 | else if (i + 1 == pg->total) |
2193 | nodeToConnect = rows * cols - cols; | 2202 | nodeToConnect = rows * cols - cols; |
2194 | else | 2203 | else |
2195 | nodeToConnect = i - cols + 1; | 2204 | nodeToConnect = i - cols + 1; |
2196 | |||
2197 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); | ||
2198 | 2205 | ||
2199 | if (i < cols) | 2206 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); |
2200 | { | ||
2201 | nodeToConnect = (rows * cols) - cols + i; | ||
2202 | if (nodeToConnect >= pg->total) | ||
2203 | nodeToConnect -= cols; | ||
2204 | } | ||
2205 | else | ||
2206 | nodeToConnect = i - cols; | ||
2207 | 2207 | ||
2208 | if (nodeToConnect < pg->total) | 2208 | if (i < cols) |
2209 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); | 2209 | { |
2210 | nodeToConnect = (rows * cols) - cols + i; | ||
2211 | if (nodeToConnect >= pg->total) | ||
2212 | nodeToConnect -= cols; | ||
2210 | } | 2213 | } |
2214 | else | ||
2215 | nodeToConnect = i - cols; | ||
2216 | |||
2217 | if (nodeToConnect < pg->total) | ||
2218 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); | ||
2219 | } | ||
2211 | natLog = log (pg->total); | 2220 | natLog = log (pg->total); |
2212 | #if VERBOSE_TESTING > 2 | 2221 | #if VERBOSE_TESTING > 2 |
2213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2222 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2214 | _("natural log of %d is %d, will run %d iterations\n"), | 2223 | _("natural log of %d is %d, will run %d iterations\n"), |
2215 | pg->total, natLog, (int) (natLog * percentage)); | 2224 | pg->total, natLog, (int) (natLog * percentage)); |
2216 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2217 | _("Total connections added thus far: %u!\n"), connect_attempts); | 2226 | _("Total connections added thus far: %u!\n"), connect_attempts); |
2218 | #endif | 2227 | #endif |
2219 | smallWorldConnections = 0; | 2228 | smallWorldConnections = 0; |
2220 | small_world_it = (unsigned int) (natLog * percentage); | 2229 | small_world_it = (unsigned int) (natLog * percentage); |
@@ -2222,42 +2231,41 @@ create_small_world(struct GNUNET_TESTING_PeerGroup *pg, | |||
2222 | small_world_it = 1; | 2231 | small_world_it = 1; |
2223 | GNUNET_assert (small_world_it > 0 && small_world_it < (unsigned int) -1); | 2232 | GNUNET_assert (small_world_it > 0 && small_world_it < (unsigned int) -1); |
2224 | for (i = 0; i < small_world_it; i++) | 2233 | for (i = 0; i < small_world_it; i++) |
2234 | { | ||
2235 | for (j = 0; j < pg->total; j++) | ||
2225 | { | 2236 | { |
2226 | for (j = 0; j < pg->total; j++) | 2237 | /* Determine the row and column of node at position j on the 2d torus */ |
2238 | node1Row = j / cols; | ||
2239 | node1Col = j - (node1Row * cols); | ||
2240 | for (k = 0; k < pg->total; k++) | ||
2241 | { | ||
2242 | /* Determine the row and column of node at position k on the 2d torus */ | ||
2243 | node2Row = k / cols; | ||
2244 | node2Col = k - (node2Row * cols); | ||
2245 | /* Simple Cartesian distance */ | ||
2246 | distance = abs (node1Row - node2Row) + abs (node1Col - node2Col); | ||
2247 | if (distance > 1) | ||
2227 | { | 2248 | { |
2228 | /* Determine the row and column of node at position j on the 2d torus */ | 2249 | /* Calculate probability as 1 over the square of the distance */ |
2229 | node1Row = j / cols; | 2250 | probability = 1.0 / (distance * distance); |
2230 | node1Col = j - (node1Row * cols); | 2251 | /* Choose a random value between 0 and 1 */ |
2231 | for (k = 0; k < pg->total; k++) | 2252 | random |
2232 | { | 2253 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
2233 | /* Determine the row and column of node at position k on the 2d torus */ | 2254 | UINT64_MAX)) |
2234 | node2Row = k / cols; | 2255 | / ((double) UINT64_MAX); |
2235 | node2Col = k - (node2Row * cols); | 2256 | /* If random < probability, then connect the two nodes */ |
2236 | /* Simple Cartesian distance */ | 2257 | if (random < probability) |
2237 | distance = abs (node1Row - node2Row) + abs (node1Col - node2Col); | 2258 | smallWorldConnections += proc (pg, j, k, list, GNUNET_YES); |
2238 | if (distance > 1) | 2259 | |
2239 | { | ||
2240 | /* Calculate probability as 1 over the square of the distance */ | ||
2241 | probability = 1.0 / (distance * distance); | ||
2242 | /* Choose a random value between 0 and 1 */ | ||
2243 | random | ||
2244 | = ((double) GNUNET_CRYPTO_random_u64 ( | ||
2245 | GNUNET_CRYPTO_QUALITY_WEAK, | ||
2246 | UINT64_MAX)) | ||
2247 | / ((double) UINT64_MAX); | ||
2248 | /* If random < probability, then connect the two nodes */ | ||
2249 | if (random < probability) | ||
2250 | smallWorldConnections += proc (pg, j, k, list, GNUNET_YES); | ||
2251 | |||
2252 | } | ||
2253 | } | ||
2254 | } | 2260 | } |
2261 | } | ||
2255 | } | 2262 | } |
2263 | } | ||
2256 | connect_attempts += smallWorldConnections; | 2264 | connect_attempts += smallWorldConnections; |
2257 | #if VERBOSE_TESTING > 2 | 2265 | #if VERBOSE_TESTING > 2 |
2258 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2266 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2259 | _("Total connections added for small world: %d!\n"), | 2267 | _("Total connections added for small world: %d!\n"), |
2260 | smallWorldConnections); | 2268 | smallWorldConnections); |
2261 | #endif | 2269 | #endif |
2262 | return connect_attempts; | 2270 | return connect_attempts; |
2263 | } | 2271 | } |
@@ -2275,8 +2283,9 @@ create_small_world(struct GNUNET_TESTING_PeerGroup *pg, | |||
2275 | * | 2283 | * |
2276 | */ | 2284 | */ |
2277 | static unsigned int | 2285 | static unsigned int |
2278 | create_erdos_renyi(struct GNUNET_TESTING_PeerGroup *pg, | 2286 | create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, |
2279 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 2287 | GNUNET_TESTING_ConnectionProcessor proc, |
2288 | enum PeerLists list) | ||
2280 | { | 2289 | { |
2281 | double temp_rand; | 2290 | double temp_rand; |
2282 | unsigned int outer_count; | 2291 | unsigned int outer_count; |
@@ -2285,40 +2294,38 @@ create_erdos_renyi(struct GNUNET_TESTING_PeerGroup *pg, | |||
2285 | double probability; | 2294 | double probability; |
2286 | char *p_string; | 2295 | char *p_string; |
2287 | 2296 | ||
2288 | probability = 0.5; /* FIXME: default percentage? */ | 2297 | probability = 0.5; /* FIXME: default percentage? */ |
2289 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", | 2298 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", |
2290 | "PROBABILITY", | 2299 | "PROBABILITY", |
2291 | &p_string)) | 2300 | &p_string)) |
2292 | { | 2301 | { |
2293 | if (sscanf (p_string, "%lf", &probability) != 1) | 2302 | if (sscanf (p_string, "%lf", &probability) != 1) |
2294 | GNUNET_log ( | 2303 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2295 | GNUNET_ERROR_TYPE_WARNING, | 2304 | _ |
2296 | _ | 2305 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
2297 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 2306 | p_string, "PROBABILITY", "TESTING"); |
2298 | p_string, "PROBABILITY", "TESTING"); | 2307 | GNUNET_free (p_string); |
2299 | GNUNET_free (p_string); | 2308 | } |
2300 | } | ||
2301 | connect_attempts = 0; | 2309 | connect_attempts = 0; |
2302 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) | 2310 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) |
2311 | { | ||
2312 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) | ||
2303 | { | 2313 | { |
2304 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) | 2314 | temp_rand |
2305 | { | 2315 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
2306 | temp_rand | 2316 | UINT64_MAX)) |
2307 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 2317 | / ((double) UINT64_MAX); |
2308 | UINT64_MAX)) | ||
2309 | / ((double) UINT64_MAX); | ||
2310 | #if VERBOSE_TESTING | 2318 | #if VERBOSE_TESTING |
2311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2312 | _("rand is %f probability is %f\n"), temp_rand, | 2320 | _("rand is %f probability is %f\n"), temp_rand, probability); |
2313 | probability); | 2321 | #endif |
2314 | #endif | 2322 | if (temp_rand < probability) |
2315 | if (temp_rand < probability) | 2323 | { |
2316 | { | 2324 | connect_attempts += proc (pg, outer_count, inner_count, list, |
2317 | connect_attempts += proc (pg, outer_count, inner_count, list, | 2325 | GNUNET_YES); |
2318 | GNUNET_YES); | 2326 | } |
2319 | } | ||
2320 | } | ||
2321 | } | 2327 | } |
2328 | } | ||
2322 | 2329 | ||
2323 | return connect_attempts; | 2330 | return connect_attempts; |
2324 | } | 2331 | } |
@@ -2338,8 +2345,8 @@ create_erdos_renyi(struct GNUNET_TESTING_PeerGroup *pg, | |||
2338 | * | 2345 | * |
2339 | */ | 2346 | */ |
2340 | static unsigned int | 2347 | static unsigned int |
2341 | create_2d_torus(struct GNUNET_TESTING_PeerGroup *pg, | 2348 | create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, |
2342 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 2349 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
2343 | { | 2350 | { |
2344 | unsigned int i; | 2351 | unsigned int i; |
2345 | unsigned int square; | 2352 | unsigned int square; |
@@ -2356,22 +2363,22 @@ create_2d_torus(struct GNUNET_TESTING_PeerGroup *pg, | |||
2356 | cols = square; | 2363 | cols = square; |
2357 | 2364 | ||
2358 | if (square * square != pg->total) | 2365 | if (square * square != pg->total) |
2366 | { | ||
2367 | while (rows * cols < pg->total) | ||
2359 | { | 2368 | { |
2360 | while (rows * cols < pg->total) | 2369 | if (toggle % 2 == 0) |
2361 | { | 2370 | rows++; |
2362 | if (toggle % 2 == 0) | 2371 | else |
2363 | rows++; | 2372 | cols++; |
2364 | else | ||
2365 | cols++; | ||
2366 | 2373 | ||
2367 | toggle++; | 2374 | toggle++; |
2368 | } | ||
2369 | } | 2375 | } |
2376 | } | ||
2370 | #if VERBOSE_TESTING | 2377 | #if VERBOSE_TESTING |
2371 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2378 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2372 | _ | 2379 | _ |
2373 | ("Connecting nodes in 2d torus topology: %u rows %u columns\n"), | 2380 | ("Connecting nodes in 2d torus topology: %u rows %u columns\n"), |
2374 | rows, cols); | 2381 | rows, cols); |
2375 | #endif | 2382 | #endif |
2376 | /* Rows and columns are all sorted out, now iterate over all nodes and connect each | 2383 | /* Rows and columns are all sorted out, now iterate over all nodes and connect each |
2377 | * to the node to its right and above. Once this is over, we'll have our torus! | 2384 | * to the node to its right and above. Once this is over, we'll have our torus! |
@@ -2379,41 +2386,41 @@ create_2d_torus(struct GNUNET_TESTING_PeerGroup *pg, | |||
2379 | * to the first in the row to maintain topology. | 2386 | * to the first in the row to maintain topology. |
2380 | */ | 2387 | */ |
2381 | for (i = 0; i < pg->total; i++) | 2388 | for (i = 0; i < pg->total; i++) |
2382 | { | 2389 | { |
2383 | /* First connect to the node to the right */ | 2390 | /* First connect to the node to the right */ |
2384 | if (((i + 1) % cols != 0) && (i + 1 != pg->total)) | 2391 | if (((i + 1) % cols != 0) && (i + 1 != pg->total)) |
2385 | nodeToConnect = i + 1; | 2392 | nodeToConnect = i + 1; |
2386 | else if (i + 1 == pg->total) | 2393 | else if (i + 1 == pg->total) |
2387 | nodeToConnect = rows * cols - cols; | 2394 | nodeToConnect = rows * cols - cols; |
2388 | else | 2395 | else |
2389 | nodeToConnect = i - cols + 1; | 2396 | nodeToConnect = i - cols + 1; |
2390 | #if VERBOSE_TESTING | 2397 | #if VERBOSE_TESTING |
2391 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2398 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2392 | "Connecting peer %d to peer %d\n", i, nodeToConnect); | 2399 | "Connecting peer %d to peer %d\n", i, nodeToConnect); |
2393 | #endif | 2400 | #endif |
2394 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); | 2401 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); |
2395 | 2402 | ||
2396 | /* Second connect to the node immediately above */ | 2403 | /* Second connect to the node immediately above */ |
2397 | if (i < cols) | 2404 | if (i < cols) |
2398 | { | 2405 | { |
2399 | nodeToConnect = (rows * cols) - cols + i; | 2406 | nodeToConnect = (rows * cols) - cols + i; |
2400 | if (nodeToConnect >= pg->total) | 2407 | if (nodeToConnect >= pg->total) |
2401 | nodeToConnect -= cols; | 2408 | nodeToConnect -= cols; |
2402 | } | 2409 | } |
2403 | else | 2410 | else |
2404 | nodeToConnect = i - cols; | 2411 | nodeToConnect = i - cols; |
2405 | 2412 | ||
2406 | if (nodeToConnect < pg->total) | 2413 | if (nodeToConnect < pg->total) |
2407 | { | 2414 | { |
2408 | #if VERBOSE_TESTING | 2415 | #if VERBOSE_TESTING |
2409 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2416 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2410 | "Connecting peer %d to peer %d\n", i, nodeToConnect); | 2417 | "Connecting peer %d to peer %d\n", i, nodeToConnect); |
2411 | #endif | 2418 | #endif |
2412 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); | 2419 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); |
2413 | } | ||
2414 | |||
2415 | } | 2420 | } |
2416 | 2421 | ||
2422 | } | ||
2423 | |||
2417 | return connect_attempts; | 2424 | return connect_attempts; |
2418 | } | 2425 | } |
2419 | 2426 | ||
@@ -2432,31 +2439,31 @@ create_2d_torus(struct GNUNET_TESTING_PeerGroup *pg, | |||
2432 | * | 2439 | * |
2433 | */ | 2440 | */ |
2434 | static unsigned int | 2441 | static unsigned int |
2435 | create_clique(struct GNUNET_TESTING_PeerGroup *pg, | 2442 | create_clique (struct GNUNET_TESTING_PeerGroup *pg, |
2436 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list, | 2443 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list, |
2437 | unsigned int check) | 2444 | unsigned int check) |
2438 | { | 2445 | { |
2439 | unsigned int outer_count; | 2446 | unsigned int outer_count; |
2440 | unsigned int inner_count; | 2447 | unsigned int inner_count; |
2441 | int connect_attempts; | 2448 | int connect_attempts; |
2442 | struct ProgressMeter *conn_meter; | 2449 | struct ProgressMeter *conn_meter; |
2450 | |||
2443 | connect_attempts = 0; | 2451 | connect_attempts = 0; |
2444 | 2452 | ||
2445 | conn_meter = create_meter ((((pg->total * pg->total) + pg->total) / 2) | 2453 | conn_meter = create_meter ((((pg->total * pg->total) + pg->total) / 2) |
2446 | - pg->total, "Create Clique ", GNUNET_NO); | 2454 | - pg->total, "Create Clique ", GNUNET_NO); |
2447 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) | 2455 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) |
2456 | { | ||
2457 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) | ||
2448 | { | 2458 | { |
2449 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) | ||
2450 | { | ||
2451 | #if VERBOSE_TESTING | 2459 | #if VERBOSE_TESTING |
2452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2460 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2453 | "Connecting peer %d to peer %d\n", | 2461 | "Connecting peer %d to peer %d\n", outer_count, inner_count); |
2454 | outer_count, inner_count); | ||
2455 | #endif | 2462 | #endif |
2456 | connect_attempts += proc (pg, outer_count, inner_count, list, check); | 2463 | connect_attempts += proc (pg, outer_count, inner_count, list, check); |
2457 | update_meter (conn_meter); | 2464 | update_meter (conn_meter); |
2458 | } | ||
2459 | } | 2465 | } |
2466 | } | ||
2460 | reset_meter (conn_meter); | 2467 | reset_meter (conn_meter); |
2461 | free_meter (conn_meter); | 2468 | free_meter (conn_meter); |
2462 | return connect_attempts; | 2469 | return connect_attempts; |
@@ -2475,19 +2482,17 @@ create_clique(struct GNUNET_TESTING_PeerGroup *pg, | |||
2475 | * GNUNET_NO if not. | 2482 | * GNUNET_NO if not. |
2476 | */ | 2483 | */ |
2477 | static int | 2484 | static int |
2478 | unblacklist_iterator (void *cls, | 2485 | unblacklist_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
2479 | const GNUNET_HashCode * key, | 2486 | { |
2480 | void *value) | 2487 | struct UnblacklistContext *un_ctx = cls; |
2481 | { | 2488 | uint32_t second_pos; |
2482 | struct UnblacklistContext *un_ctx = cls; | ||
2483 | uint32_t second_pos; | ||
2484 | 2489 | ||
2485 | uid_from_hash (key, &second_pos); | 2490 | uid_from_hash (key, &second_pos); |
2486 | 2491 | ||
2487 | unblacklist_connections(un_ctx->pg, un_ctx->first_uid, second_pos); | 2492 | unblacklist_connections (un_ctx->pg, un_ctx->first_uid, second_pos); |
2488 | 2493 | ||
2489 | return GNUNET_YES; | 2494 | return GNUNET_YES; |
2490 | } | 2495 | } |
2491 | #endif | 2496 | #endif |
2492 | 2497 | ||
2493 | #if !OLD | 2498 | #if !OLD |
@@ -2510,6 +2515,7 @@ copy_allowed (struct GNUNET_TESTING_PeerGroup *pg, | |||
2510 | unsigned int count; | 2515 | unsigned int count; |
2511 | unsigned int total; | 2516 | unsigned int total; |
2512 | struct PeerConnection *iter; | 2517 | struct PeerConnection *iter; |
2518 | |||
2513 | #if !OLD | 2519 | #if !OLD |
2514 | struct UnblacklistContext un_ctx; | 2520 | struct UnblacklistContext un_ctx; |
2515 | 2521 | ||
@@ -2517,25 +2523,23 @@ copy_allowed (struct GNUNET_TESTING_PeerGroup *pg, | |||
2517 | #endif | 2523 | #endif |
2518 | total = 0; | 2524 | total = 0; |
2519 | for (count = 0; count < pg->total - 1; count++) | 2525 | for (count = 0; count < pg->total - 1; count++) |
2520 | { | 2526 | { |
2521 | #if OLD | 2527 | #if OLD |
2522 | iter = pg->peers[count].allowed_peers_head; | 2528 | iter = pg->peers[count].allowed_peers_head; |
2523 | while (iter != NULL) | 2529 | while (iter != NULL) |
2524 | { | 2530 | { |
2525 | remove_connections (pg, count, iter->index, BLACKLIST, GNUNET_YES); | 2531 | remove_connections (pg, count, iter->index, BLACKLIST, GNUNET_YES); |
2526 | //unblacklist_connections(pg, count, iter->index); | 2532 | //unblacklist_connections(pg, count, iter->index); |
2527 | iter = iter->next; | 2533 | iter = iter->next; |
2528 | } | 2534 | } |
2529 | #else | 2535 | #else |
2530 | un_ctx.first_uid = count; | 2536 | un_ctx.first_uid = count; |
2531 | total += GNUNET_CONTAINER_multihashmap_iterate(pg->peers[count].allowed_peers, | 2537 | total += |
2532 | &unblacklist_iterator, | 2538 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[count].allowed_peers, |
2533 | &un_ctx); | 2539 | &unblacklist_iterator, &un_ctx); |
2534 | #endif | 2540 | #endif |
2535 | } | 2541 | } |
2536 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2542 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unblacklisted %u peers\n", total); |
2537 | "Unblacklisted %u peers\n", | ||
2538 | total); | ||
2539 | return total; | 2543 | return total; |
2540 | } | 2544 | } |
2541 | #endif | 2545 | #endif |
@@ -2553,8 +2557,8 @@ copy_allowed (struct GNUNET_TESTING_PeerGroup *pg, | |||
2553 | * | 2557 | * |
2554 | */ | 2558 | */ |
2555 | static unsigned int | 2559 | static unsigned int |
2556 | create_line(struct GNUNET_TESTING_PeerGroup *pg, | 2560 | create_line (struct GNUNET_TESTING_PeerGroup *pg, |
2557 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 2561 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
2558 | { | 2562 | { |
2559 | unsigned int count; | 2563 | unsigned int count; |
2560 | unsigned int connect_attempts; | 2564 | unsigned int connect_attempts; |
@@ -2562,14 +2566,13 @@ create_line(struct GNUNET_TESTING_PeerGroup *pg, | |||
2562 | connect_attempts = 0; | 2566 | connect_attempts = 0; |
2563 | /* Connect each peer to the next highest numbered peer */ | 2567 | /* Connect each peer to the next highest numbered peer */ |
2564 | for (count = 0; count < pg->total - 1; count++) | 2568 | for (count = 0; count < pg->total - 1; count++) |
2565 | { | 2569 | { |
2566 | #if VERBOSE_TESTING | 2570 | #if VERBOSE_TESTING |
2567 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2571 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2568 | "Connecting peer %d to peer %d\n", | 2572 | "Connecting peer %d to peer %d\n", count, count + 1); |
2569 | count, count + 1); | ||
2570 | #endif | 2573 | #endif |
2571 | connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES); | 2574 | connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES); |
2572 | } | 2575 | } |
2573 | 2576 | ||
2574 | return connect_attempts; | 2577 | return connect_attempts; |
2575 | } | 2578 | } |
@@ -2588,8 +2591,8 @@ create_line(struct GNUNET_TESTING_PeerGroup *pg, | |||
2588 | * | 2591 | * |
2589 | */ | 2592 | */ |
2590 | static unsigned int | 2593 | static unsigned int |
2591 | create_from_file(struct GNUNET_TESTING_PeerGroup *pg, char *filename, | 2594 | create_from_file (struct GNUNET_TESTING_PeerGroup *pg, char *filename, |
2592 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 2595 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
2593 | { | 2596 | { |
2594 | int connect_attempts; | 2597 | int connect_attempts; |
2595 | unsigned int first_peer_index; | 2598 | unsigned int first_peer_index; |
@@ -2606,23 +2609,22 @@ create_from_file(struct GNUNET_TESTING_PeerGroup *pg, char *filename, | |||
2606 | GNUNET_DISK_fn_write (filename, NULL, 0, GNUNET_DISK_PERM_USER_READ); | 2609 | GNUNET_DISK_fn_write (filename, NULL, 0, GNUNET_DISK_PERM_USER_READ); |
2607 | 2610 | ||
2608 | if ((0 != STAT (filename, &frstat)) || (frstat.st_size == 0)) | 2611 | if ((0 != STAT (filename, &frstat)) || (frstat.st_size == 0)) |
2609 | { | 2612 | { |
2610 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2613 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2611 | "Could not open file `%s' specified for topology!", filename); | 2614 | "Could not open file `%s' specified for topology!", filename); |
2612 | return connect_attempts; | 2615 | return connect_attempts; |
2613 | } | 2616 | } |
2614 | 2617 | ||
2615 | data = GNUNET_malloc_large (frstat.st_size); | 2618 | data = GNUNET_malloc_large (frstat.st_size); |
2616 | GNUNET_assert(data != NULL); | 2619 | GNUNET_assert (data != NULL); |
2617 | if (frstat.st_size != GNUNET_DISK_fn_read (filename, data, frstat.st_size)) | 2620 | if (frstat.st_size != GNUNET_DISK_fn_read (filename, data, frstat.st_size)) |
2618 | { | 2621 | { |
2619 | GNUNET_log ( | 2622 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2620 | GNUNET_ERROR_TYPE_ERROR, | 2623 | "Could not read file %s specified for host list, ending test!", |
2621 | "Could not read file %s specified for host list, ending test!", | 2624 | filename); |
2622 | filename); | 2625 | GNUNET_free (data); |
2623 | GNUNET_free (data); | 2626 | return connect_attempts; |
2624 | return connect_attempts; | 2627 | } |
2625 | } | ||
2626 | 2628 | ||
2627 | buf = data; | 2629 | buf = data; |
2628 | count = 0; | 2630 | count = 0; |
@@ -2631,88 +2633,90 @@ create_from_file(struct GNUNET_TESTING_PeerGroup *pg, char *filename, | |||
2631 | /* Each subsequent line should contain this format PEER_INDEX:OTHER_PEER_INDEX[,...] */ | 2633 | /* Each subsequent line should contain this format PEER_INDEX:OTHER_PEER_INDEX[,...] */ |
2632 | curr_state = NUM_PEERS; | 2634 | curr_state = NUM_PEERS; |
2633 | while (count < frstat.st_size - 1) | 2635 | while (count < frstat.st_size - 1) |
2636 | { | ||
2637 | if ((buf[count] == '\n') || (buf[count] == ' ')) | ||
2634 | { | 2638 | { |
2635 | if ((buf[count] == '\n') || (buf[count] == ' ')) | 2639 | count++; |
2636 | { | 2640 | continue; |
2637 | count++; | 2641 | } |
2638 | continue; | ||
2639 | } | ||
2640 | 2642 | ||
2641 | switch (curr_state) | 2643 | switch (curr_state) |
2642 | { | 2644 | { |
2643 | case NUM_PEERS: | 2645 | case NUM_PEERS: |
2644 | errno = 0; | 2646 | errno = 0; |
2645 | total_peers = strtoul(&buf[count], NULL, 10); | 2647 | total_peers = strtoul (&buf[count], NULL, 10); |
2646 | if (errno != 0) | 2648 | if (errno != 0) |
2647 | { | 2649 | { |
2648 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2650 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2649 | "Failed to read number of peers from topology file!\n"); | 2651 | "Failed to read number of peers from topology file!\n"); |
2650 | GNUNET_free (data); | 2652 | GNUNET_free (data); |
2651 | return connect_attempts; | 2653 | return connect_attempts; |
2652 | } | 2654 | } |
2653 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2655 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2654 | "Read %u total peers in topology\n", total_peers); | 2656 | "Read %u total peers in topology\n", total_peers); |
2655 | GNUNET_assert(total_peers == pg->total); | 2657 | GNUNET_assert (total_peers == pg->total); |
2656 | curr_state = PEER_INDEX; | 2658 | curr_state = PEER_INDEX; |
2657 | while ((buf[count] != '\n') && (count < frstat.st_size - 1)) | 2659 | while ((buf[count] != '\n') && (count < frstat.st_size - 1)) |
2658 | count++; | 2660 | count++; |
2659 | count++; | 2661 | count++; |
2660 | break; | 2662 | break; |
2661 | case PEER_INDEX: | 2663 | case PEER_INDEX: |
2662 | errno = 0; | 2664 | errno = 0; |
2663 | first_peer_index = strtoul(&buf[count], NULL, 10); | 2665 | first_peer_index = strtoul (&buf[count], NULL, 10); |
2664 | if (errno != 0) | 2666 | if (errno != 0) |
2665 | { | 2667 | { |
2666 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2668 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2667 | "Failed to read peer index from topology file!\n"); | 2669 | "Failed to read peer index from topology file!\n"); |
2668 | GNUNET_free (data); | 2670 | GNUNET_free (data); |
2669 | return connect_attempts; | 2671 | return connect_attempts; |
2670 | } | 2672 | } |
2671 | while ((buf[count] != ':') && (count < frstat.st_size - 1)) | 2673 | while ((buf[count] != ':') && (count < frstat.st_size - 1)) |
2672 | count++; | 2674 | count++; |
2673 | count++; | 2675 | count++; |
2674 | curr_state = OTHER_PEER_INDEX; | 2676 | curr_state = OTHER_PEER_INDEX; |
2675 | break; | 2677 | break; |
2676 | case COLON: | 2678 | case COLON: |
2677 | if (1 == sscanf (&buf[count], ":")) | 2679 | if (1 == sscanf (&buf[count], ":")) |
2678 | curr_state = OTHER_PEER_INDEX; | 2680 | curr_state = OTHER_PEER_INDEX; |
2679 | count++; | 2681 | count++; |
2680 | break; | 2682 | break; |
2681 | case OTHER_PEER_INDEX: | 2683 | case OTHER_PEER_INDEX: |
2682 | errno = 0; | 2684 | errno = 0; |
2683 | second_peer_index = strtoul(&buf[count], NULL, 10); | 2685 | second_peer_index = strtoul (&buf[count], NULL, 10); |
2684 | if (errno != 0) | 2686 | if (errno != 0) |
2685 | { | 2687 | { |
2686 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2688 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2687 | "Failed to peer index from topology file!\n"); | 2689 | "Failed to peer index from topology file!\n"); |
2688 | GNUNET_free (data); | 2690 | GNUNET_free (data); |
2689 | return connect_attempts; | 2691 | return connect_attempts; |
2690 | } | 2692 | } |
2691 | /* Assume file is written with first peer 1, but array index is 0 */ | 2693 | /* Assume file is written with first peer 1, but array index is 0 */ |
2692 | connect_attempts += proc (pg, first_peer_index - 1, second_peer_index | 2694 | connect_attempts += proc (pg, first_peer_index - 1, second_peer_index |
2693 | - 1, list, GNUNET_YES); | 2695 | - 1, list, GNUNET_YES); |
2694 | while ((buf[count] != '\n') && (buf[count] != ',') && (count | 2696 | while ((buf[count] != '\n') && (buf[count] != ',') && (count |
2695 | < frstat.st_size - 1)) | 2697 | < |
2696 | count++; | 2698 | frstat.st_size - |
2697 | if (buf[count] == '\n') | 2699 | 1)) |
2698 | { | 2700 | count++; |
2699 | curr_state = PEER_INDEX; | 2701 | if (buf[count] == '\n') |
2700 | } | 2702 | { |
2701 | else if (buf[count] != ',') | 2703 | curr_state = PEER_INDEX; |
2702 | { | 2704 | } |
2703 | curr_state = OTHER_PEER_INDEX; | 2705 | else if (buf[count] != ',') |
2704 | } | 2706 | { |
2705 | count++; | 2707 | curr_state = OTHER_PEER_INDEX; |
2706 | break; | 2708 | } |
2707 | default: | 2709 | count++; |
2708 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2710 | break; |
2709 | "Found bad data in topology file while in state %d!\n", | 2711 | default: |
2710 | curr_state); | 2712 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2711 | GNUNET_break(0); | 2713 | "Found bad data in topology file while in state %d!\n", |
2712 | GNUNET_free (data); | 2714 | curr_state); |
2713 | return connect_attempts; | 2715 | GNUNET_break (0); |
2714 | } | 2716 | GNUNET_free (data); |
2717 | return connect_attempts; | ||
2715 | } | 2718 | } |
2719 | } | ||
2716 | GNUNET_free (data); | 2720 | GNUNET_free (data); |
2717 | return connect_attempts; | 2721 | return connect_attempts; |
2718 | } | 2722 | } |
@@ -2730,8 +2734,8 @@ create_from_file(struct GNUNET_TESTING_PeerGroup *pg, char *filename, | |||
2730 | * | 2734 | * |
2731 | */ | 2735 | */ |
2732 | static unsigned int | 2736 | static unsigned int |
2733 | create_ring(struct GNUNET_TESTING_PeerGroup *pg, | 2737 | create_ring (struct GNUNET_TESTING_PeerGroup *pg, |
2734 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 2738 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
2735 | { | 2739 | { |
2736 | unsigned int count; | 2740 | unsigned int count; |
2737 | int connect_attempts; | 2741 | int connect_attempts; |
@@ -2740,13 +2744,13 @@ create_ring(struct GNUNET_TESTING_PeerGroup *pg, | |||
2740 | 2744 | ||
2741 | /* Connect each peer to the next highest numbered peer */ | 2745 | /* Connect each peer to the next highest numbered peer */ |
2742 | for (count = 0; count < pg->total - 1; count++) | 2746 | for (count = 0; count < pg->total - 1; count++) |
2743 | { | 2747 | { |
2744 | #if VERBOSE_TESTING | 2748 | #if VERBOSE_TESTING |
2745 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2749 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2746 | "Connecting peer %d to peer %d\n", count, count + 1); | 2750 | "Connecting peer %d to peer %d\n", count, count + 1); |
2747 | #endif | 2751 | #endif |
2748 | connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES); | 2752 | connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES); |
2749 | } | 2753 | } |
2750 | 2754 | ||
2751 | /* Connect the last peer to the first peer */ | 2755 | /* Connect the last peer to the first peer */ |
2752 | connect_attempts += proc (pg, pg->total - 1, 0, list, GNUNET_YES); | 2756 | connect_attempts += proc (pg, pg->total - 1, 0, list, GNUNET_YES); |
@@ -2774,31 +2778,31 @@ create_ring(struct GNUNET_TESTING_PeerGroup *pg, | |||
2774 | */ | 2778 | */ |
2775 | static int | 2779 | static int |
2776 | friend_file_iterator (void *cls, const GNUNET_HashCode * key, void *value) | 2780 | friend_file_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
2777 | { | 2781 | { |
2778 | FILE *temp_friend_handle = cls; | 2782 | FILE *temp_friend_handle = cls; |
2779 | struct GNUNET_TESTING_Daemon *peer = value; | 2783 | struct GNUNET_TESTING_Daemon *peer = value; |
2780 | struct GNUNET_PeerIdentity *temppeer; | 2784 | struct GNUNET_PeerIdentity *temppeer; |
2781 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; | 2785 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; |
2782 | 2786 | ||
2783 | temppeer = &peer->id; | 2787 | temppeer = &peer->id; |
2784 | GNUNET_CRYPTO_hash_to_enc (&temppeer->hashPubKey, &peer_enc); | 2788 | GNUNET_CRYPTO_hash_to_enc (&temppeer->hashPubKey, &peer_enc); |
2785 | fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc); | 2789 | fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc); |
2786 | 2790 | ||
2787 | return GNUNET_YES; | 2791 | return GNUNET_YES; |
2788 | } | 2792 | } |
2789 | 2793 | ||
2790 | struct BlacklistContext | 2794 | struct BlacklistContext |
2791 | { | 2795 | { |
2792 | /* | 2796 | /* |
2793 | * The (open) file handle to write to | 2797 | * The (open) file handle to write to |
2794 | */ | 2798 | */ |
2795 | FILE *temp_file_handle; | 2799 | FILE *temp_file_handle; |
2796 | 2800 | ||
2797 | /* | 2801 | /* |
2798 | * The transport that this peer will be blacklisted on. | 2802 | * The transport that this peer will be blacklisted on. |
2799 | */ | 2803 | */ |
2800 | char *transport; | 2804 | char *transport; |
2801 | }; | 2805 | }; |
2802 | 2806 | ||
2803 | /** | 2807 | /** |
2804 | * Iterator for writing blacklist data to appropriate files. | 2808 | * Iterator for writing blacklist data to appropriate files. |
@@ -2811,20 +2815,21 @@ struct BlacklistContext | |||
2811 | */ | 2815 | */ |
2812 | static int | 2816 | static int |
2813 | blacklist_file_iterator (void *cls, const GNUNET_HashCode * key, void *value) | 2817 | blacklist_file_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
2814 | { | 2818 | { |
2815 | struct BlacklistContext *blacklist_ctx = cls; | 2819 | struct BlacklistContext *blacklist_ctx = cls; |
2816 | struct GNUNET_TESTING_Daemon *peer = value; | 2820 | struct GNUNET_TESTING_Daemon *peer = value; |
2817 | struct GNUNET_PeerIdentity *temppeer; | 2821 | struct GNUNET_PeerIdentity *temppeer; |
2818 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; | 2822 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; |
2819 | 2823 | ||
2820 | temppeer = &peer->id; | 2824 | temppeer = &peer->id; |
2821 | GNUNET_CRYPTO_hash_to_enc (&temppeer->hashPubKey, &peer_enc); | 2825 | GNUNET_CRYPTO_hash_to_enc (&temppeer->hashPubKey, &peer_enc); |
2822 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Writing entry %s:%s to file\n", blacklist_ctx->transport, (char *) &peer_enc); | 2826 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Writing entry %s:%s to file\n", |
2823 | fprintf (blacklist_ctx->temp_file_handle, "%s:%s\n", | 2827 | blacklist_ctx->transport, (char *) &peer_enc); |
2824 | blacklist_ctx->transport, (char *) &peer_enc); | 2828 | fprintf (blacklist_ctx->temp_file_handle, "%s:%s\n", blacklist_ctx->transport, |
2829 | (char *) &peer_enc); | ||
2825 | 2830 | ||
2826 | return GNUNET_YES; | 2831 | return GNUNET_YES; |
2827 | } | 2832 | } |
2828 | #endif | 2833 | #endif |
2829 | 2834 | ||
2830 | /* | 2835 | /* |
@@ -2835,7 +2840,7 @@ blacklist_file_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
2835 | * @param pg the peer group we are dealing with | 2840 | * @param pg the peer group we are dealing with |
2836 | */ | 2841 | */ |
2837 | static int | 2842 | static int |
2838 | create_and_copy_friend_files(struct GNUNET_TESTING_PeerGroup *pg) | 2843 | create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) |
2839 | { | 2844 | { |
2840 | FILE *temp_friend_handle; | 2845 | FILE *temp_friend_handle; |
2841 | unsigned int pg_iter; | 2846 | unsigned int pg_iter; |
@@ -2843,6 +2848,7 @@ create_and_copy_friend_files(struct GNUNET_TESTING_PeerGroup *pg) | |||
2843 | struct GNUNET_OS_Process **procarr; | 2848 | struct GNUNET_OS_Process **procarr; |
2844 | char *arg; | 2849 | char *arg; |
2845 | char *mytemp; | 2850 | char *mytemp; |
2851 | |||
2846 | #if NOT_STUPID | 2852 | #if NOT_STUPID |
2847 | enum GNUNET_OS_ProcessStatusType type; | 2853 | enum GNUNET_OS_ProcessStatusType type; |
2848 | unsigned long return_code; | 2854 | unsigned long return_code; |
@@ -2858,147 +2864,137 @@ create_and_copy_friend_files(struct GNUNET_TESTING_PeerGroup *pg) | |||
2858 | #endif | 2864 | #endif |
2859 | procarr = GNUNET_malloc (sizeof (struct GNUNET_OS_Process *) * pg->total); | 2865 | procarr = GNUNET_malloc (sizeof (struct GNUNET_OS_Process *) * pg->total); |
2860 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 2866 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
2861 | { | 2867 | { |
2862 | mytemp = GNUNET_DISK_mktemp ("friends"); | 2868 | mytemp = GNUNET_DISK_mktemp ("friends"); |
2863 | GNUNET_assert (mytemp != NULL); | 2869 | GNUNET_assert (mytemp != NULL); |
2864 | temp_friend_handle = fopen (mytemp, "wt"); | 2870 | temp_friend_handle = fopen (mytemp, "wt"); |
2865 | GNUNET_assert (temp_friend_handle != NULL); | 2871 | GNUNET_assert (temp_friend_handle != NULL); |
2866 | #if OLD | 2872 | #if OLD |
2867 | conn_iter = pg->peers[pg_iter].allowed_peers_head; | 2873 | conn_iter = pg->peers[pg_iter].allowed_peers_head; |
2868 | while (conn_iter != NULL) | 2874 | while (conn_iter != NULL) |
2869 | { | 2875 | { |
2870 | GNUNET_CRYPTO_hash_to_enc ( | 2876 | GNUNET_CRYPTO_hash_to_enc (&pg->peers[conn_iter->index].daemon-> |
2871 | &pg->peers[conn_iter->index].daemon->id.hashPubKey, | 2877 | id.hashPubKey, &peer_enc); |
2872 | &peer_enc); | 2878 | fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc); |
2873 | fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc); | 2879 | conn_iter = conn_iter->next; |
2874 | conn_iter = conn_iter->next; | 2880 | } |
2875 | } | ||
2876 | #else | 2881 | #else |
2877 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].allowed_peers, | 2882 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].allowed_peers, |
2878 | &friend_file_iterator, | 2883 | &friend_file_iterator, |
2879 | temp_friend_handle); | 2884 | temp_friend_handle); |
2880 | #endif | 2885 | #endif |
2881 | fclose (temp_friend_handle); | 2886 | fclose (temp_friend_handle); |
2882 | 2887 | ||
2883 | if (GNUNET_OK | 2888 | if (GNUNET_OK |
2884 | != GNUNET_CONFIGURATION_get_value_string (pg->peers[pg_iter]. | 2889 | != |
2885 | daemon->cfg, | 2890 | GNUNET_CONFIGURATION_get_value_string (pg->peers[pg_iter].daemon->cfg, |
2886 | "PATHS", "SERVICEHOME", | 2891 | "PATHS", "SERVICEHOME", |
2887 | &temp_service_path)) | 2892 | &temp_service_path)) |
2888 | { | 2893 | { |
2889 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2894 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2890 | _("No `%s' specified in peer configuration in section `%s', cannot copy friends file!\n"), | 2895 | _ |
2891 | "SERVICEHOME", "PATHS"); | 2896 | ("No `%s' specified in peer configuration in section `%s', cannot copy friends file!\n"), |
2892 | if (UNLINK (mytemp) != 0) | 2897 | "SERVICEHOME", "PATHS"); |
2893 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 2898 | if (UNLINK (mytemp) != 0) |
2894 | "unlink", | 2899 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", mytemp); |
2895 | mytemp); | 2900 | GNUNET_free (mytemp); |
2896 | GNUNET_free (mytemp); | 2901 | break; |
2897 | break; | 2902 | } |
2898 | } | ||
2899 | 2903 | ||
2900 | if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */ | 2904 | if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */ |
2901 | { | 2905 | { |
2902 | GNUNET_asprintf (&arg, "%s/friends", temp_service_path); | 2906 | GNUNET_asprintf (&arg, "%s/friends", temp_service_path); |
2903 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", "mv", | 2907 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", "mv", |
2904 | mytemp, arg, NULL); | 2908 | mytemp, arg, NULL); |
2905 | GNUNET_assert(procarr[pg_iter] != NULL); | 2909 | GNUNET_assert (procarr[pg_iter] != NULL); |
2906 | #if VERBOSE_TESTING | 2910 | #if VERBOSE_TESTING |
2907 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2911 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2908 | "Copying file with command cp %s %s\n", | 2912 | "Copying file with command cp %s %s\n", mytemp, arg); |
2909 | mytemp, | ||
2910 | arg); | ||
2911 | #endif | 2913 | #endif |
2912 | ret = GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: schedule this, throttle! */ | 2914 | ret = GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: schedule this, throttle! */ |
2913 | GNUNET_OS_process_close (procarr[pg_iter]); | 2915 | GNUNET_OS_process_close (procarr[pg_iter]); |
2914 | GNUNET_free (arg); | 2916 | GNUNET_free (arg); |
2915 | } | 2917 | } |
2916 | else /* Remote, scp the file to the correct place */ | 2918 | else /* Remote, scp the file to the correct place */ |
2917 | { | 2919 | { |
2918 | if (NULL != pg->peers[pg_iter].daemon->username) | 2920 | if (NULL != pg->peers[pg_iter].daemon->username) |
2919 | GNUNET_asprintf (&arg, "%s@%s:%s/friends", | 2921 | GNUNET_asprintf (&arg, "%s@%s:%s/friends", |
2920 | pg->peers[pg_iter].daemon->username, | 2922 | pg->peers[pg_iter].daemon->username, |
2921 | pg->peers[pg_iter].daemon->hostname, | 2923 | pg->peers[pg_iter].daemon->hostname, |
2922 | temp_service_path); | 2924 | temp_service_path); |
2923 | else | 2925 | else |
2924 | GNUNET_asprintf (&arg, "%s:%s/friends", | 2926 | GNUNET_asprintf (&arg, "%s:%s/friends", |
2925 | pg->peers[pg_iter].daemon->hostname, | 2927 | pg->peers[pg_iter].daemon->hostname, |
2926 | temp_service_path); | 2928 | temp_service_path); |
2927 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", | 2929 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", |
2928 | mytemp, arg, NULL); | 2930 | mytemp, arg, NULL); |
2929 | GNUNET_assert(procarr[pg_iter] != NULL); | 2931 | GNUNET_assert (procarr[pg_iter] != NULL); |
2930 | ret = GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: schedule this, throttle! */ | 2932 | ret = GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: schedule this, throttle! */ |
2931 | GNUNET_OS_process_close (procarr[pg_iter]); | 2933 | GNUNET_OS_process_close (procarr[pg_iter]); |
2932 | if (ret != GNUNET_OK) | 2934 | if (ret != GNUNET_OK) |
2933 | { | 2935 | { |
2934 | /* FIXME: free contents of 'procarr' array */ | 2936 | /* FIXME: free contents of 'procarr' array */ |
2935 | GNUNET_free (procarr); | 2937 | GNUNET_free (procarr); |
2936 | GNUNET_free (temp_service_path); | 2938 | GNUNET_free (temp_service_path); |
2937 | GNUNET_free (mytemp); | 2939 | GNUNET_free (mytemp); |
2938 | GNUNET_free (arg); | 2940 | GNUNET_free (arg); |
2939 | return ret; | 2941 | return ret; |
2940 | } | 2942 | } |
2941 | procarr[pg_iter] = NULL; | 2943 | procarr[pg_iter] = NULL; |
2942 | #if VERBOSE_TESTING | 2944 | #if VERBOSE_TESTING |
2943 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2945 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2944 | "Copying file with command scp %s %s\n", | 2946 | "Copying file with command scp %s %s\n", mytemp, arg); |
2945 | mytemp, | ||
2946 | arg); | ||
2947 | #endif | 2947 | #endif |
2948 | GNUNET_free (arg); | 2948 | GNUNET_free (arg); |
2949 | } | ||
2950 | GNUNET_free (temp_service_path); | ||
2951 | GNUNET_free (mytemp); | ||
2952 | } | 2949 | } |
2950 | GNUNET_free (temp_service_path); | ||
2951 | GNUNET_free (mytemp); | ||
2952 | } | ||
2953 | 2953 | ||
2954 | #if NOT_STUPID | 2954 | #if NOT_STUPID |
2955 | count = 0; | 2955 | count = 0; |
2956 | ret = GNUNET_SYSERR; | 2956 | ret = GNUNET_SYSERR; |
2957 | while ((count < max_wait) && (ret != GNUNET_OK)) | 2957 | while ((count < max_wait) && (ret != GNUNET_OK)) |
2958 | { | ||
2959 | ret = GNUNET_OK; | ||
2960 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
2958 | { | 2961 | { |
2959 | ret = GNUNET_OK; | ||
2960 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
2961 | { | ||
2962 | #if VERBOSE_TESTING | 2962 | #if VERBOSE_TESTING |
2963 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2963 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2964 | "Checking copy status of file %d\n", | 2964 | "Checking copy status of file %d\n", pg_iter); |
2965 | pg_iter); | ||
2966 | #endif | ||
2967 | if (procarr[pg_iter] != NULL) /* Check for already completed! */ | ||
2968 | { | ||
2969 | if (GNUNET_OS_process_status | ||
2970 | (procarr[pg_iter], &type, &return_code) != GNUNET_OK) | ||
2971 | { | ||
2972 | ret = GNUNET_SYSERR; | ||
2973 | } | ||
2974 | else if ((type != GNUNET_OS_PROCESS_EXITED) | ||
2975 | || (return_code != 0)) | ||
2976 | { | ||
2977 | ret = GNUNET_SYSERR; | ||
2978 | } | ||
2979 | else | ||
2980 | { | ||
2981 | GNUNET_OS_process_close (procarr[pg_iter]); | ||
2982 | procarr[pg_iter] = NULL; | ||
2983 | #if VERBOSE_TESTING | ||
2984 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2985 | "File %d copied\n", | ||
2986 | pg_iter); | ||
2987 | #endif | 2965 | #endif |
2988 | } | 2966 | if (procarr[pg_iter] != NULL) /* Check for already completed! */ |
2989 | } | 2967 | { |
2968 | if (GNUNET_OS_process_status | ||
2969 | (procarr[pg_iter], &type, &return_code) != GNUNET_OK) | ||
2970 | { | ||
2971 | ret = GNUNET_SYSERR; | ||
2990 | } | 2972 | } |
2991 | count++; | 2973 | else if ((type != GNUNET_OS_PROCESS_EXITED) || (return_code != 0)) |
2992 | if (ret == GNUNET_SYSERR) | ||
2993 | { | 2974 | { |
2994 | /* FIXME: why sleep here? -CG */ | 2975 | ret = GNUNET_SYSERR; |
2995 | sleep (1); | 2976 | } |
2977 | else | ||
2978 | { | ||
2979 | GNUNET_OS_process_close (procarr[pg_iter]); | ||
2980 | procarr[pg_iter] = NULL; | ||
2981 | #if VERBOSE_TESTING | ||
2982 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "File %d copied\n", pg_iter); | ||
2983 | #endif | ||
2996 | } | 2984 | } |
2985 | } | ||
2986 | } | ||
2987 | count++; | ||
2988 | if (ret == GNUNET_SYSERR) | ||
2989 | { | ||
2990 | /* FIXME: why sleep here? -CG */ | ||
2991 | sleep (1); | ||
2997 | } | 2992 | } |
2993 | } | ||
2998 | 2994 | ||
2999 | #if VERBOSE_TESTING | 2995 | #if VERBOSE_TESTING |
3000 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2996 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3001 | _("Finished copying all friend files!\n")); | 2997 | _("Finished copying all friend files!\n")); |
3002 | #endif | 2998 | #endif |
3003 | #endif | 2999 | #endif |
3004 | GNUNET_free (procarr); | 3000 | GNUNET_free (procarr); |
@@ -3014,8 +3010,8 @@ create_and_copy_friend_files(struct GNUNET_TESTING_PeerGroup *pg) | |||
3014 | * @param transports space delimited list of transports to blacklist | 3010 | * @param transports space delimited list of transports to blacklist |
3015 | */ | 3011 | */ |
3016 | static int | 3012 | static int |
3017 | create_and_copy_blacklist_files(struct GNUNET_TESTING_PeerGroup *pg, | 3013 | create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, |
3018 | const char *transports) | 3014 | const char *transports) |
3019 | { | 3015 | { |
3020 | FILE *temp_file_handle; | 3016 | FILE *temp_file_handle; |
3021 | unsigned int pg_iter; | 3017 | unsigned int pg_iter; |
@@ -3032,6 +3028,7 @@ create_and_copy_blacklist_files(struct GNUNET_TESTING_PeerGroup *pg, | |||
3032 | unsigned int i; | 3028 | unsigned int i; |
3033 | char *pos; | 3029 | char *pos; |
3034 | char *temp_transports; | 3030 | char *temp_transports; |
3031 | |||
3035 | #if OLD | 3032 | #if OLD |
3036 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; | 3033 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; |
3037 | struct PeerConnection *conn_iter; | 3034 | struct PeerConnection *conn_iter; |
@@ -3041,155 +3038,149 @@ create_and_copy_blacklist_files(struct GNUNET_TESTING_PeerGroup *pg, | |||
3041 | 3038 | ||
3042 | procarr = GNUNET_malloc (sizeof (struct GNUNET_OS_Process *) * pg->total); | 3039 | procarr = GNUNET_malloc (sizeof (struct GNUNET_OS_Process *) * pg->total); |
3043 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3040 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
3044 | { | 3041 | { |
3045 | mytemp = GNUNET_DISK_mktemp ("blacklist"); | 3042 | mytemp = GNUNET_DISK_mktemp ("blacklist"); |
3046 | GNUNET_assert (mytemp != NULL); | 3043 | GNUNET_assert (mytemp != NULL); |
3047 | temp_file_handle = fopen (mytemp, "wt"); | 3044 | temp_file_handle = fopen (mytemp, "wt"); |
3048 | GNUNET_assert (temp_file_handle != NULL); | 3045 | GNUNET_assert (temp_file_handle != NULL); |
3049 | temp_transports = GNUNET_strdup (transports); | 3046 | temp_transports = GNUNET_strdup (transports); |
3050 | #if !OLD | 3047 | #if !OLD |
3051 | blacklist_ctx.temp_file_handle = temp_file_handle; | 3048 | blacklist_ctx.temp_file_handle = temp_file_handle; |
3052 | #endif | 3049 | #endif |
3053 | transport_len = strlen (temp_transports) + 1; | 3050 | transport_len = strlen (temp_transports) + 1; |
3054 | pos = NULL; | 3051 | pos = NULL; |
3055 | 3052 | ||
3056 | for (i = 0; i < transport_len; i++) | 3053 | for (i = 0; i < transport_len; i++) |
3057 | { | 3054 | { |
3058 | if ((temp_transports[i] == ' ') && (pos == NULL)) | 3055 | if ((temp_transports[i] == ' ') && (pos == NULL)) |
3059 | continue; /* At start of string (whitespace) */ | 3056 | continue; /* At start of string (whitespace) */ |
3060 | else if ((temp_transports[i] == ' ') || (temp_transports[i] == '\0')) /* At end of string */ | 3057 | else if ((temp_transports[i] == ' ') || (temp_transports[i] == '\0')) /* At end of string */ |
3061 | { | 3058 | { |
3062 | temp_transports[i] = '\0'; | 3059 | temp_transports[i] = '\0'; |
3063 | #if OLD | 3060 | #if OLD |
3064 | conn_iter = pg->peers[pg_iter].blacklisted_peers_head; | 3061 | conn_iter = pg->peers[pg_iter].blacklisted_peers_head; |
3065 | while (conn_iter != NULL) | 3062 | while (conn_iter != NULL) |
3066 | { | 3063 | { |
3067 | GNUNET_CRYPTO_hash_to_enc ( | 3064 | GNUNET_CRYPTO_hash_to_enc (&pg->peers[conn_iter->index].daemon-> |
3068 | &pg->peers[conn_iter->index].daemon->id.hashPubKey, | 3065 | id.hashPubKey, &peer_enc); |
3069 | &peer_enc); | 3066 | fprintf (temp_file_handle, "%s:%s\n", pos, (char *) &peer_enc); |
3070 | fprintf (temp_file_handle, "%s:%s\n", pos, (char *) &peer_enc); | 3067 | conn_iter = conn_iter->next; |
3071 | conn_iter = conn_iter->next; | ||
3072 | } | ||
3073 | #else | ||
3074 | blacklist_ctx.transport = pos; | ||
3075 | (void) GNUNET_CONTAINER_multihashmap_iterate (pg-> | ||
3076 | peers | ||
3077 | [pg_iter].blacklisted_peers, | ||
3078 | &blacklist_file_iterator, | ||
3079 | &blacklist_ctx); | ||
3080 | #endif | ||
3081 | pos = NULL; | ||
3082 | } /* At beginning of actual string */ | ||
3083 | else if (pos == NULL) | ||
3084 | { | ||
3085 | pos = &temp_transports[i]; | ||
3086 | } | ||
3087 | } | 3068 | } |
3069 | #else | ||
3070 | blacklist_ctx.transport = pos; | ||
3071 | (void) GNUNET_CONTAINER_multihashmap_iterate (pg->peers | ||
3072 | [pg_iter].blacklisted_peers, | ||
3073 | &blacklist_file_iterator, | ||
3074 | &blacklist_ctx); | ||
3075 | #endif | ||
3076 | pos = NULL; | ||
3077 | } /* At beginning of actual string */ | ||
3078 | else if (pos == NULL) | ||
3079 | { | ||
3080 | pos = &temp_transports[i]; | ||
3081 | } | ||
3082 | } | ||
3088 | 3083 | ||
3089 | GNUNET_free (temp_transports); | 3084 | GNUNET_free (temp_transports); |
3090 | fclose (temp_file_handle); | 3085 | fclose (temp_file_handle); |
3091 | 3086 | ||
3092 | if (GNUNET_OK | 3087 | if (GNUNET_OK |
3093 | != GNUNET_CONFIGURATION_get_value_string ( | 3088 | != |
3094 | pg->peers[pg_iter]. daemon->cfg, | 3089 | GNUNET_CONFIGURATION_get_value_string (pg->peers[pg_iter].daemon->cfg, |
3095 | "PATHS", "SERVICEHOME", | 3090 | "PATHS", "SERVICEHOME", |
3096 | &temp_service_path)) | 3091 | &temp_service_path)) |
3097 | { | 3092 | { |
3098 | GNUNET_log ( | 3093 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3099 | GNUNET_ERROR_TYPE_WARNING, | 3094 | _ |
3100 | _ | 3095 | ("No `%s' specified in peer configuration in section `%s', cannot copy friends file!\n"), |
3101 | ("No `%s' specified in peer configuration in section `%s', cannot copy friends file!\n"), | 3096 | "SERVICEHOME", "PATHS"); |
3102 | "SERVICEHOME", "PATHS"); | 3097 | if (UNLINK (mytemp) != 0) |
3103 | if (UNLINK (mytemp) != 0) | 3098 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", mytemp); |
3104 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", | 3099 | GNUNET_free (mytemp); |
3105 | mytemp); | 3100 | break; |
3106 | GNUNET_free (mytemp); | 3101 | } |
3107 | break; | ||
3108 | } | ||
3109 | 3102 | ||
3110 | if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */ | 3103 | if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */ |
3111 | { | 3104 | { |
3112 | GNUNET_asprintf (&arg, "%s/blacklist", temp_service_path); | 3105 | GNUNET_asprintf (&arg, "%s/blacklist", temp_service_path); |
3113 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", "mv", | 3106 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", "mv", |
3114 | mytemp, arg, NULL); | 3107 | mytemp, arg, NULL); |
3115 | #if VERBOSE_TESTING | 3108 | #if VERBOSE_TESTING |
3116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3117 | _("Copying file with command cp %s %s\n"), mytemp, arg); | 3110 | _("Copying file with command cp %s %s\n"), mytemp, arg); |
3118 | #endif | 3111 | #endif |
3119 | 3112 | ||
3120 | GNUNET_free (arg); | 3113 | GNUNET_free (arg); |
3121 | } | 3114 | } |
3122 | else /* Remote, scp the file to the correct place */ | 3115 | else /* Remote, scp the file to the correct place */ |
3123 | { | 3116 | { |
3124 | if (NULL != pg->peers[pg_iter].daemon->username) | 3117 | if (NULL != pg->peers[pg_iter].daemon->username) |
3125 | GNUNET_asprintf (&arg, "%s@%s:%s/blacklist", | 3118 | GNUNET_asprintf (&arg, "%s@%s:%s/blacklist", |
3126 | pg->peers[pg_iter].daemon->username, | 3119 | pg->peers[pg_iter].daemon->username, |
3127 | pg->peers[pg_iter].daemon->hostname, | 3120 | pg->peers[pg_iter].daemon->hostname, |
3128 | temp_service_path); | 3121 | temp_service_path); |
3129 | else | 3122 | else |
3130 | GNUNET_asprintf (&arg, "%s:%s/blacklist", | 3123 | GNUNET_asprintf (&arg, "%s:%s/blacklist", |
3131 | pg->peers[pg_iter].daemon->hostname, | 3124 | pg->peers[pg_iter].daemon->hostname, |
3132 | temp_service_path); | 3125 | temp_service_path); |
3133 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", | 3126 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", |
3134 | mytemp, arg, NULL); | 3127 | mytemp, arg, NULL); |
3135 | GNUNET_assert(procarr[pg_iter] != NULL); | 3128 | GNUNET_assert (procarr[pg_iter] != NULL); |
3136 | GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: add scheduled blacklist file copy that parallelizes file copying! */ | 3129 | GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: add scheduled blacklist file copy that parallelizes file copying! */ |
3137 | 3130 | ||
3138 | #if VERBOSE_TESTING | 3131 | #if VERBOSE_TESTING |
3139 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3140 | _("Copying file with command scp %s %s\n"), mytemp, | 3133 | _("Copying file with command scp %s %s\n"), mytemp, arg); |
3141 | arg); | ||
3142 | #endif | 3134 | #endif |
3143 | GNUNET_free (arg); | 3135 | GNUNET_free (arg); |
3144 | } | ||
3145 | GNUNET_free (temp_service_path); | ||
3146 | GNUNET_free (mytemp); | ||
3147 | } | 3136 | } |
3137 | GNUNET_free (temp_service_path); | ||
3138 | GNUNET_free (mytemp); | ||
3139 | } | ||
3148 | 3140 | ||
3149 | count = 0; | 3141 | count = 0; |
3150 | ret = GNUNET_SYSERR; | 3142 | ret = GNUNET_SYSERR; |
3151 | while ((count < max_wait) && (ret != GNUNET_OK)) | 3143 | while ((count < max_wait) && (ret != GNUNET_OK)) |
3144 | { | ||
3145 | ret = GNUNET_OK; | ||
3146 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
3152 | { | 3147 | { |
3153 | ret = GNUNET_OK; | ||
3154 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
3155 | { | ||
3156 | #if VERBOSE_TESTING | 3148 | #if VERBOSE_TESTING |
3157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3158 | _("Checking copy status of file %d\n"), pg_iter); | 3150 | _("Checking copy status of file %d\n"), pg_iter); |
3159 | #endif | ||
3160 | if (procarr[pg_iter] != NULL) /* Check for already completed! */ | ||
3161 | { | ||
3162 | if (GNUNET_OS_process_status (procarr[pg_iter], &type, | ||
3163 | &return_code) != GNUNET_OK) | ||
3164 | { | ||
3165 | ret = GNUNET_SYSERR; | ||
3166 | } | ||
3167 | else if ((type != GNUNET_OS_PROCESS_EXITED) || (return_code != 0)) | ||
3168 | { | ||
3169 | ret = GNUNET_SYSERR; | ||
3170 | } | ||
3171 | else | ||
3172 | { | ||
3173 | GNUNET_OS_process_close (procarr[pg_iter]); | ||
3174 | procarr[pg_iter] = NULL; | ||
3175 | #if VERBOSE_TESTING | ||
3176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3177 | _("File %d copied\n"), pg_iter); | ||
3178 | #endif | 3151 | #endif |
3179 | } | 3152 | if (procarr[pg_iter] != NULL) /* Check for already completed! */ |
3180 | } | 3153 | { |
3154 | if (GNUNET_OS_process_status (procarr[pg_iter], &type, | ||
3155 | &return_code) != GNUNET_OK) | ||
3156 | { | ||
3157 | ret = GNUNET_SYSERR; | ||
3181 | } | 3158 | } |
3182 | count++; | 3159 | else if ((type != GNUNET_OS_PROCESS_EXITED) || (return_code != 0)) |
3183 | if (ret == GNUNET_SYSERR) | ||
3184 | { | 3160 | { |
3185 | /* FIXME: why sleep here? -CG */ | 3161 | ret = GNUNET_SYSERR; |
3186 | sleep (1); | ||
3187 | } | 3162 | } |
3163 | else | ||
3164 | { | ||
3165 | GNUNET_OS_process_close (procarr[pg_iter]); | ||
3166 | procarr[pg_iter] = NULL; | ||
3167 | #if VERBOSE_TESTING | ||
3168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("File %d copied\n"), pg_iter); | ||
3169 | #endif | ||
3170 | } | ||
3171 | } | ||
3172 | } | ||
3173 | count++; | ||
3174 | if (ret == GNUNET_SYSERR) | ||
3175 | { | ||
3176 | /* FIXME: why sleep here? -CG */ | ||
3177 | sleep (1); | ||
3188 | } | 3178 | } |
3179 | } | ||
3189 | 3180 | ||
3190 | #if VERBOSE_TESTING | 3181 | #if VERBOSE_TESTING |
3191 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3182 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3192 | _("Finished copying all blacklist files!\n")); | 3183 | _("Finished copying all blacklist files!\n")); |
3193 | #endif | 3184 | #endif |
3194 | GNUNET_free (procarr); | 3185 | GNUNET_free (procarr); |
3195 | return ret; | 3186 | return ret; |
@@ -3197,7 +3188,7 @@ create_and_copy_blacklist_files(struct GNUNET_TESTING_PeerGroup *pg, | |||
3197 | 3188 | ||
3198 | /* Forward Declaration */ | 3189 | /* Forward Declaration */ |
3199 | static void | 3190 | static void |
3200 | schedule_connect(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 3191 | schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
3201 | 3192 | ||
3202 | /** | 3193 | /** |
3203 | * Choose a random peer's next connection to create, and | 3194 | * Choose a random peer's next connection to create, and |
@@ -3206,7 +3197,7 @@ schedule_connect(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | |||
3206 | * @param ct_ctx the overall connection context | 3197 | * @param ct_ctx the overall connection context |
3207 | */ | 3198 | */ |
3208 | static void | 3199 | static void |
3209 | preschedule_connect(struct GNUNET_TESTING_PeerGroup *pg) | 3200 | preschedule_connect (struct GNUNET_TESTING_PeerGroup *pg) |
3210 | { | 3201 | { |
3211 | struct ConnectTopologyContext *ct_ctx = &pg->ct_ctx; | 3202 | struct ConnectTopologyContext *ct_ctx = &pg->ct_ctx; |
3212 | struct PeerConnection *connection_iter; | 3203 | struct PeerConnection *connection_iter; |
@@ -3227,14 +3218,18 @@ preschedule_connect(struct GNUNET_TESTING_PeerGroup *pg) | |||
3227 | connect_context->second_index = connection_iter->index; | 3218 | connect_context->second_index = connection_iter->index; |
3228 | connect_context->ct_ctx = ct_ctx; | 3219 | connect_context->ct_ctx = ct_ctx; |
3229 | GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context); | 3220 | GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context); |
3230 | GNUNET_CONTAINER_DLL_remove(pg->peers[random_peer].connect_peers_head, pg->peers[random_peer].connect_peers_tail, connection_iter); | 3221 | GNUNET_CONTAINER_DLL_remove (pg->peers[random_peer].connect_peers_head, |
3231 | GNUNET_free(connection_iter); | 3222 | pg->peers[random_peer].connect_peers_tail, |
3223 | connection_iter); | ||
3224 | GNUNET_free (connection_iter); | ||
3232 | ct_ctx->remaining_connections--; | 3225 | ct_ctx->remaining_connections--; |
3233 | } | 3226 | } |
3234 | 3227 | ||
3235 | #if USE_SEND_HELLOS | 3228 | #if USE_SEND_HELLOS |
3236 | /* Forward declaration */ | 3229 | /* Forward declaration */ |
3237 | static void schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 3230 | static void schedule_send_hellos (void *cls, |
3231 | const struct GNUNET_SCHEDULER_TaskContext | ||
3232 | *tc); | ||
3238 | 3233 | ||
3239 | /** | 3234 | /** |
3240 | * Close connections and free the hello context. | 3235 | * Close connections and free the hello context. |
@@ -3244,26 +3239,27 @@ static void schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskC | |||
3244 | */ | 3239 | */ |
3245 | static void | 3240 | static void |
3246 | free_hello_context (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3241 | free_hello_context (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
3242 | { | ||
3243 | struct SendHelloContext *send_hello_context = cls; | ||
3244 | |||
3245 | if (send_hello_context->peer->daemon->server != NULL) | ||
3247 | { | 3246 | { |
3248 | struct SendHelloContext *send_hello_context = cls; | 3247 | GNUNET_CORE_disconnect (send_hello_context->peer->daemon->server); |
3249 | if (send_hello_context->peer->daemon->server != NULL) | 3248 | send_hello_context->peer->daemon->server = NULL; |
3250 | { | 3249 | } |
3251 | GNUNET_CORE_disconnect(send_hello_context->peer->daemon->server); | 3250 | if (send_hello_context->peer->daemon->th != NULL) |
3252 | send_hello_context->peer->daemon->server = NULL; | 3251 | { |
3253 | } | 3252 | GNUNET_TRANSPORT_disconnect (send_hello_context->peer->daemon->th); |
3254 | if (send_hello_context->peer->daemon->th != NULL) | 3253 | send_hello_context->peer->daemon->th = NULL; |
3255 | { | ||
3256 | GNUNET_TRANSPORT_disconnect(send_hello_context->peer->daemon->th); | ||
3257 | send_hello_context->peer->daemon->th = NULL; | ||
3258 | } | ||
3259 | if (send_hello_context->core_connect_task != GNUNET_SCHEDULER_NO_TASK) | ||
3260 | { | ||
3261 | GNUNET_SCHEDULER_cancel(send_hello_context->core_connect_task); | ||
3262 | send_hello_context->core_connect_task = GNUNET_SCHEDULER_NO_TASK; | ||
3263 | } | ||
3264 | send_hello_context->pg->outstanding_connects--; | ||
3265 | GNUNET_free(send_hello_context); | ||
3266 | } | 3254 | } |
3255 | if (send_hello_context->core_connect_task != GNUNET_SCHEDULER_NO_TASK) | ||
3256 | { | ||
3257 | GNUNET_SCHEDULER_cancel (send_hello_context->core_connect_task); | ||
3258 | send_hello_context->core_connect_task = GNUNET_SCHEDULER_NO_TASK; | ||
3259 | } | ||
3260 | send_hello_context->pg->outstanding_connects--; | ||
3261 | GNUNET_free (send_hello_context); | ||
3262 | } | ||
3267 | 3263 | ||
3268 | /** | 3264 | /** |
3269 | * For peers that haven't yet connected, notify | 3265 | * For peers that haven't yet connected, notify |
@@ -3273,40 +3269,41 @@ free_hello_context (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
3273 | * @param tc scheduler context | 3269 | * @param tc scheduler context |
3274 | */ | 3270 | */ |
3275 | static void | 3271 | static void |
3276 | notify_remaining_connections_failed (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3272 | notify_remaining_connections_failed (void *cls, |
3277 | { | 3273 | const struct GNUNET_SCHEDULER_TaskContext |
3278 | struct SendHelloContext *send_hello_context = cls; | 3274 | *tc) |
3279 | struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg; | 3275 | { |
3280 | struct PeerConnection *connection; | 3276 | struct SendHelloContext *send_hello_context = cls; |
3277 | struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg; | ||
3278 | struct PeerConnection *connection; | ||
3281 | 3279 | ||
3282 | GNUNET_CORE_disconnect(send_hello_context->peer->daemon->server); | 3280 | GNUNET_CORE_disconnect (send_hello_context->peer->daemon->server); |
3283 | send_hello_context->peer->daemon->server = NULL; | 3281 | send_hello_context->peer->daemon->server = NULL; |
3284 | 3282 | ||
3285 | connection = send_hello_context->peer->connect_peers_head; | 3283 | connection = send_hello_context->peer->connect_peers_head; |
3286 | 3284 | ||
3287 | while (connection != NULL) | 3285 | while (connection != NULL) |
3288 | { | 3286 | { |
3289 | if (pg->notify_connection != NULL) | 3287 | if (pg->notify_connection != NULL) |
3290 | { | 3288 | { |
3291 | pg->notify_connection(pg->notify_connection_cls, | 3289 | pg->notify_connection (pg->notify_connection_cls, &send_hello_context->peer->daemon->id, &pg->peers[connection->index].daemon->id, 0, /* FIXME */ |
3292 | &send_hello_context->peer->daemon->id, | 3290 | send_hello_context->peer->daemon->cfg, |
3293 | &pg->peers[connection->index].daemon->id, | 3291 | pg->peers[connection->index].daemon->cfg, |
3294 | 0, /* FIXME */ | 3292 | send_hello_context->peer->daemon, |
3295 | send_hello_context->peer->daemon->cfg, | 3293 | pg->peers[connection->index].daemon, |
3296 | pg->peers[connection->index].daemon->cfg, | 3294 | "Peers failed to connect (timeout)"); |
3297 | send_hello_context->peer->daemon, | 3295 | } |
3298 | pg->peers[connection->index].daemon, | 3296 | GNUNET_CONTAINER_DLL_remove (send_hello_context->peer->connect_peers_head, |
3299 | "Peers failed to connect (timeout)"); | 3297 | send_hello_context->peer->connect_peers_tail, |
3300 | } | 3298 | connection); |
3301 | GNUNET_CONTAINER_DLL_remove(send_hello_context->peer->connect_peers_head, send_hello_context->peer->connect_peers_tail, connection); | 3299 | GNUNET_free (connection); |
3302 | GNUNET_free(connection); | 3300 | connection = connection->next; |
3303 | connection = connection->next; | 3301 | } |
3304 | } | 3302 | GNUNET_SCHEDULER_add_now (&free_hello_context, send_hello_context); |
3305 | GNUNET_SCHEDULER_add_now(&free_hello_context, send_hello_context); | ||
3306 | #if BAD | 3303 | #if BAD |
3307 | other_peer = &pg->peers[connection->index]; | 3304 | other_peer = &pg->peers[connection->index]; |
3308 | #endif | 3305 | #endif |
3309 | } | 3306 | } |
3310 | 3307 | ||
3311 | /** | 3308 | /** |
3312 | * For peers that haven't yet connected, send | 3309 | * For peers that haven't yet connected, send |
@@ -3316,37 +3313,48 @@ notify_remaining_connections_failed (void *cls, const struct GNUNET_SCHEDULER_Ta | |||
3316 | * @param tc scheduler context | 3313 | * @param tc scheduler context |
3317 | */ | 3314 | */ |
3318 | static void | 3315 | static void |
3319 | send_core_connect_requests (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3316 | send_core_connect_requests (void *cls, |
3320 | { | 3317 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
3321 | struct SendHelloContext *send_hello_context = cls; | 3318 | { |
3322 | struct PeerConnection *conn; | 3319 | struct SendHelloContext *send_hello_context = cls; |
3323 | GNUNET_assert(send_hello_context->peer->daemon->server != NULL); | 3320 | struct PeerConnection *conn; |
3324 | 3321 | ||
3325 | send_hello_context->core_connect_task = GNUNET_SCHEDULER_NO_TASK; | 3322 | GNUNET_assert (send_hello_context->peer->daemon->server != NULL); |
3326 | 3323 | ||
3327 | send_hello_context->connect_attempts++; | 3324 | send_hello_context->core_connect_task = GNUNET_SCHEDULER_NO_TASK; |
3328 | if (send_hello_context->connect_attempts < send_hello_context->pg->ct_ctx.connect_attempts) | ||
3329 | { | ||
3330 | conn = send_hello_context->peer->connect_peers_head; | ||
3331 | while (conn != NULL) | ||
3332 | { | ||
3333 | GNUNET_CORE_peer_request_connect(send_hello_context->peer->daemon->server, | ||
3334 | &send_hello_context->pg->peers[conn->index].daemon->id, | ||
3335 | NULL, | ||
3336 | NULL); | ||
3337 | conn = conn->next; | ||
3338 | } | ||
3339 | send_hello_context->core_connect_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_divide(send_hello_context->pg->ct_ctx.connect_timeout, send_hello_context->pg->ct_ctx.connect_attempts) , | ||
3340 | &send_core_connect_requests, | ||
3341 | send_hello_context); | ||
3342 | } | ||
3343 | else | ||
3344 | { | ||
3345 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Timeout before all connections created, marking rest as failed!\n"); | ||
3346 | GNUNET_SCHEDULER_add_now(¬ify_remaining_connections_failed, send_hello_context); | ||
3347 | } | ||
3348 | 3325 | ||
3326 | send_hello_context->connect_attempts++; | ||
3327 | if (send_hello_context->connect_attempts < | ||
3328 | send_hello_context->pg->ct_ctx.connect_attempts) | ||
3329 | { | ||
3330 | conn = send_hello_context->peer->connect_peers_head; | ||
3331 | while (conn != NULL) | ||
3332 | { | ||
3333 | GNUNET_CORE_peer_request_connect (send_hello_context->peer-> | ||
3334 | daemon->server, | ||
3335 | &send_hello_context->pg-> | ||
3336 | peers[conn->index].daemon->id, NULL, | ||
3337 | NULL); | ||
3338 | conn = conn->next; | ||
3339 | } | ||
3340 | send_hello_context->core_connect_task = | ||
3341 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide | ||
3342 | (send_hello_context->pg-> | ||
3343 | ct_ctx.connect_timeout, | ||
3344 | send_hello_context->pg-> | ||
3345 | ct_ctx.connect_attempts), | ||
3346 | &send_core_connect_requests, | ||
3347 | send_hello_context); | ||
3349 | } | 3348 | } |
3349 | else | ||
3350 | { | ||
3351 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
3352 | "Timeout before all connections created, marking rest as failed!\n"); | ||
3353 | GNUNET_SCHEDULER_add_now (¬ify_remaining_connections_failed, | ||
3354 | send_hello_context); | ||
3355 | } | ||
3356 | |||
3357 | } | ||
3350 | 3358 | ||
3351 | /** | 3359 | /** |
3352 | * Success, connection is up. Signal client our success. | 3360 | * Success, connection is up. Signal client our success. |
@@ -3361,96 +3369,101 @@ send_core_connect_requests (void *cls, const struct GNUNET_SCHEDULER_TaskContext | |||
3361 | */ | 3369 | */ |
3362 | static void | 3370 | static void |
3363 | core_connect_notify (void *cls, | 3371 | core_connect_notify (void *cls, |
3364 | const struct GNUNET_PeerIdentity *peer, | 3372 | const struct GNUNET_PeerIdentity *peer, |
3365 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 3373 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
3366 | { | 3374 | { |
3367 | struct SendHelloContext *send_hello_context = cls; | 3375 | struct SendHelloContext *send_hello_context = cls; |
3368 | struct PeerConnection *connection; | 3376 | struct PeerConnection *connection; |
3369 | struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg; | 3377 | struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg; |
3378 | |||
3370 | #if BAD | 3379 | #if BAD |
3371 | struct PeerData *other_peer; | 3380 | struct PeerData *other_peer; |
3372 | #endif | 3381 | #endif |
3373 | #if DEBUG_TESTING | 3382 | #if DEBUG_TESTING |
3374 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3383 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3375 | "Connected peer %s to peer %s\n", | 3384 | "Connected peer %s to peer %s\n", |
3376 | ctx->d1->shortname, GNUNET_i2s(peer)); | 3385 | ctx->d1->shortname, GNUNET_i2s (peer)); |
3377 | #endif | 3386 | #endif |
3378 | 3387 | ||
3379 | if (0 == memcmp(&send_hello_context->peer->daemon->id, peer, sizeof(struct GNUNET_PeerIdentity))) | 3388 | if (0 == |
3389 | memcmp (&send_hello_context->peer->daemon->id, peer, | ||
3390 | sizeof (struct GNUNET_PeerIdentity))) | ||
3380 | return; | 3391 | return; |
3381 | 3392 | ||
3382 | connection = send_hello_context->peer->connect_peers_head; | 3393 | connection = send_hello_context->peer->connect_peers_head; |
3383 | #if BAD | 3394 | #if BAD |
3384 | other_peer = NULL; | 3395 | other_peer = NULL; |
3385 | #endif | 3396 | #endif |
3386 | 3397 | ||
3387 | while ((connection != NULL) && | 3398 | while ((connection != NULL) && |
3388 | (0 != memcmp(&pg->peers[connection->index].daemon->id, peer, sizeof(struct GNUNET_PeerIdentity)))) | 3399 | (0 != |
3389 | { | 3400 | memcmp (&pg->peers[connection->index].daemon->id, peer, |
3390 | connection = connection->next; | 3401 | sizeof (struct GNUNET_PeerIdentity)))) |
3391 | } | 3402 | { |
3403 | connection = connection->next; | ||
3404 | } | ||
3392 | 3405 | ||
3393 | if (connection == NULL) | 3406 | if (connection == NULL) |
3394 | { | 3407 | { |
3395 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Connected peer %s to %s, not in list (no problem(?))\n", GNUNET_i2s(peer), send_hello_context->peer->daemon->shortname); | 3408 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3396 | } | 3409 | "Connected peer %s to %s, not in list (no problem(?))\n", |
3397 | else | 3410 | GNUNET_i2s (peer), send_hello_context->peer->daemon->shortname); |
3398 | { | 3411 | } |
3412 | else | ||
3413 | { | ||
3399 | #if BAD | 3414 | #if BAD |
3400 | other_peer = &pg->peers[connection->index]; | 3415 | other_peer = &pg->peers[connection->index]; |
3401 | #endif | 3416 | #endif |
3402 | if (pg->notify_connection != NULL) | 3417 | if (pg->notify_connection != NULL) |
3403 | { | 3418 | { |
3404 | pg->notify_connection(pg->notify_connection_cls, | 3419 | pg->notify_connection (pg->notify_connection_cls, &send_hello_context->peer->daemon->id, peer, 0, /* FIXME */ |
3405 | &send_hello_context->peer->daemon->id, | 3420 | send_hello_context->peer->daemon->cfg, |
3406 | peer, | 3421 | pg->peers[connection->index].daemon->cfg, |
3407 | 0, /* FIXME */ | 3422 | send_hello_context->peer->daemon, |
3408 | send_hello_context->peer->daemon->cfg, | 3423 | pg->peers[connection->index].daemon, NULL); |
3409 | pg->peers[connection->index].daemon->cfg, | 3424 | } |
3410 | send_hello_context->peer->daemon, | 3425 | GNUNET_CONTAINER_DLL_remove (send_hello_context->peer->connect_peers_head, |
3411 | pg->peers[connection->index].daemon, | 3426 | send_hello_context->peer->connect_peers_tail, |
3412 | NULL); | 3427 | connection); |
3413 | } | 3428 | GNUNET_free (connection); |
3414 | GNUNET_CONTAINER_DLL_remove(send_hello_context->peer->connect_peers_head, send_hello_context->peer->connect_peers_tail, connection); | 3429 | } |
3415 | GNUNET_free(connection); | ||
3416 | } | ||
3417 | 3430 | ||
3418 | #if BAD | 3431 | #if BAD |
3419 | /* Notify of reverse connection and remove from other peers list of outstanding */ | 3432 | /* Notify of reverse connection and remove from other peers list of outstanding */ |
3420 | if (other_peer != NULL) | 3433 | if (other_peer != NULL) |
3434 | { | ||
3435 | connection = other_peer->connect_peers_head; | ||
3436 | while ((connection != NULL) && | ||
3437 | (0 != | ||
3438 | memcmp (&send_hello_context->peer->daemon->id, | ||
3439 | &pg->peers[connection->index].daemon->id, | ||
3440 | sizeof (struct GNUNET_PeerIdentity)))) | ||
3441 | { | ||
3442 | connection = connection->next; | ||
3443 | } | ||
3444 | if (connection != NULL) | ||
3445 | { | ||
3446 | if (pg->notify_connection != NULL) | ||
3421 | { | 3447 | { |
3422 | connection = other_peer->connect_peers_head; | 3448 | pg->notify_connection (pg->notify_connection_cls, peer, &send_hello_context->peer->daemon->id, 0, /* FIXME */ |
3423 | while ((connection != NULL) && | 3449 | pg->peers[connection->index].daemon->cfg, |
3424 | (0 != memcmp(&send_hello_context->peer->daemon->id, &pg->peers[connection->index].daemon->id, sizeof(struct GNUNET_PeerIdentity)))) | 3450 | send_hello_context->peer->daemon->cfg, |
3425 | { | 3451 | pg->peers[connection->index].daemon, |
3426 | connection = connection->next; | 3452 | send_hello_context->peer->daemon, NULL); |
3427 | } | ||
3428 | if (connection != NULL) | ||
3429 | { | ||
3430 | if (pg->notify_connection != NULL) | ||
3431 | { | ||
3432 | pg->notify_connection(pg->notify_connection_cls, | ||
3433 | peer, | ||
3434 | &send_hello_context->peer->daemon->id, | ||
3435 | 0, /* FIXME */ | ||
3436 | pg->peers[connection->index].daemon->cfg, | ||
3437 | send_hello_context->peer->daemon->cfg, | ||
3438 | pg->peers[connection->index].daemon, | ||
3439 | send_hello_context->peer->daemon, | ||
3440 | NULL); | ||
3441 | } | ||
3442 | |||
3443 | GNUNET_CONTAINER_DLL_remove(other_peer->connect_peers_head, other_peer->connect_peers_tail, connection); | ||
3444 | GNUNET_free(connection); | ||
3445 | } | ||
3446 | } | 3453 | } |
3454 | |||
3455 | GNUNET_CONTAINER_DLL_remove (other_peer->connect_peers_head, | ||
3456 | other_peer->connect_peers_tail, connection); | ||
3457 | GNUNET_free (connection); | ||
3458 | } | ||
3459 | } | ||
3447 | #endif | 3460 | #endif |
3448 | 3461 | ||
3449 | if (send_hello_context->peer->connect_peers_head == NULL) | 3462 | if (send_hello_context->peer->connect_peers_head == NULL) |
3450 | { | 3463 | { |
3451 | GNUNET_SCHEDULER_add_now(&free_hello_context, send_hello_context); | 3464 | GNUNET_SCHEDULER_add_now (&free_hello_context, send_hello_context); |
3452 | } | ||
3453 | } | 3465 | } |
3466 | } | ||
3454 | 3467 | ||
3455 | /** | 3468 | /** |
3456 | * Notify of a successful connection to the core service. | 3469 | * Notify of a successful connection to the core service. |
@@ -3462,16 +3475,14 @@ core_connect_notify (void *cls, | |||
3462 | */ | 3475 | */ |
3463 | void | 3476 | void |
3464 | core_init (void *cls, | 3477 | core_init (void *cls, |
3465 | struct GNUNET_CORE_Handle * server, | 3478 | struct GNUNET_CORE_Handle *server, |
3466 | const struct GNUNET_PeerIdentity * | 3479 | const struct GNUNET_PeerIdentity *my_identity, |
3467 | my_identity, | 3480 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) |
3468 | const struct | 3481 | { |
3469 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded * | 3482 | struct SendHelloContext *send_hello_context = cls; |
3470 | publicKey) | 3483 | |
3471 | { | 3484 | send_hello_context->core_ready = GNUNET_YES; |
3472 | struct SendHelloContext *send_hello_context = cls; | 3485 | } |
3473 | send_hello_context->core_ready = GNUNET_YES; | ||
3474 | } | ||
3475 | 3486 | ||
3476 | /** | 3487 | /** |
3477 | * Function called once a hello has been sent | 3488 | * Function called once a hello has been sent |
@@ -3483,55 +3494,58 @@ core_init (void *cls, | |||
3483 | */ | 3494 | */ |
3484 | static void | 3495 | static void |
3485 | hello_sent_callback (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3496 | hello_sent_callback (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
3497 | { | ||
3498 | struct SendHelloContext *send_hello_context = cls; | ||
3499 | |||
3500 | //unsigned int pg_iter; | ||
3501 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | ||
3486 | { | 3502 | { |
3487 | struct SendHelloContext *send_hello_context = cls; | 3503 | GNUNET_free (send_hello_context); |
3488 | //unsigned int pg_iter; | 3504 | return; |
3489 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 3505 | } |
3490 | { | ||
3491 | GNUNET_free(send_hello_context); | ||
3492 | return; | ||
3493 | } | ||
3494 | 3506 | ||
3495 | send_hello_context->pg->remaining_hellos--; | 3507 | send_hello_context->pg->remaining_hellos--; |
3496 | #if DEBUG_TESTING | 3508 | #if DEBUG_TESTING |
3497 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sent HELLO, have %d remaining!\n", send_hello_context->pg->remaining_hellos); | 3509 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Sent HELLO, have %d remaining!\n", |
3510 | send_hello_context->pg->remaining_hellos); | ||
3498 | #endif | 3511 | #endif |
3499 | if (send_hello_context->peer_pos == NULL) /* All HELLOs (for this peer!) have been transmitted! */ | 3512 | if (send_hello_context->peer_pos == NULL) /* All HELLOs (for this peer!) have been transmitted! */ |
3500 | { | 3513 | { |
3501 | #if DEBUG_TESTING | 3514 | #if DEBUG_TESTING |
3502 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "All hellos for this peer sent, disconnecting transport!\n"); | 3515 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3503 | #endif | 3516 | "All hellos for this peer sent, disconnecting transport!\n"); |
3504 | GNUNET_assert(send_hello_context->peer->daemon->th != NULL); | 3517 | #endif |
3505 | GNUNET_TRANSPORT_disconnect(send_hello_context->peer->daemon->th); | 3518 | GNUNET_assert (send_hello_context->peer->daemon->th != NULL); |
3506 | send_hello_context->peer->daemon->th = NULL; | 3519 | GNUNET_TRANSPORT_disconnect (send_hello_context->peer->daemon->th); |
3507 | 3520 | send_hello_context->peer->daemon->th = NULL; | |
3508 | /*if (send_hello_context->pg->remaining_hellos == 0) | 3521 | |
3509 | { | 3522 | /*if (send_hello_context->pg->remaining_hellos == 0) |
3510 | for (pg_iter = 0; pg_iter < send_hello_context->pg->max_outstanding_connections; pg_iter++) | 3523 | * { |
3511 | { | 3524 | * for (pg_iter = 0; pg_iter < send_hello_context->pg->max_outstanding_connections; pg_iter++) |
3512 | preschedule_connect(&send_hello_context->pg->ct_ctx); | 3525 | * { |
3513 | } | 3526 | * preschedule_connect(&send_hello_context->pg->ct_ctx); |
3514 | } | 3527 | * } |
3515 | */ | 3528 | * } |
3516 | GNUNET_assert (send_hello_context->peer->daemon->server == NULL); | 3529 | */ |
3517 | send_hello_context->peer->daemon->server = GNUNET_CORE_connect(send_hello_context->peer->cfg, | 3530 | GNUNET_assert (send_hello_context->peer->daemon->server == NULL); |
3518 | 1, | 3531 | send_hello_context->peer->daemon->server = |
3519 | send_hello_context, | 3532 | GNUNET_CORE_connect (send_hello_context->peer->cfg, 1, |
3520 | &core_init, | 3533 | send_hello_context, &core_init, |
3521 | &core_connect_notify, | 3534 | &core_connect_notify, NULL, NULL, NULL, GNUNET_NO, |
3522 | NULL, | 3535 | NULL, GNUNET_NO, no_handlers); |
3523 | NULL, | 3536 | |
3524 | NULL, GNUNET_NO, | 3537 | send_hello_context->core_connect_task = |
3525 | NULL, GNUNET_NO, | 3538 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide |
3526 | no_handlers); | 3539 | (send_hello_context->pg-> |
3527 | 3540 | ct_ctx.connect_timeout, | |
3528 | send_hello_context->core_connect_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_divide(send_hello_context->pg->ct_ctx.connect_timeout, send_hello_context->pg->ct_ctx.connect_attempts), | 3541 | send_hello_context->pg-> |
3529 | &send_core_connect_requests, | 3542 | ct_ctx.connect_attempts), |
3530 | send_hello_context); | 3543 | &send_core_connect_requests, |
3531 | } | 3544 | send_hello_context); |
3532 | else | ||
3533 | GNUNET_SCHEDULER_add_now(&schedule_send_hellos, send_hello_context); | ||
3534 | } | 3545 | } |
3546 | else | ||
3547 | GNUNET_SCHEDULER_add_now (&schedule_send_hellos, send_hello_context); | ||
3548 | } | ||
3535 | 3549 | ||
3536 | /** | 3550 | /** |
3537 | * Connect to a peer, give it all the HELLO's of those peers | 3551 | * Connect to a peer, give it all the HELLO's of those peers |
@@ -3539,59 +3553,63 @@ hello_sent_callback (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
3539 | * | 3553 | * |
3540 | * @param ct_ctx the overall connection context | 3554 | * @param ct_ctx the overall connection context |
3541 | */ | 3555 | */ |
3542 | static void schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3556 | static void |
3543 | { | 3557 | schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
3544 | struct SendHelloContext *send_hello_context = cls; | 3558 | { |
3545 | struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg; | 3559 | struct SendHelloContext *send_hello_context = cls; |
3560 | struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg; | ||
3546 | 3561 | ||
3547 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 3562 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
3548 | { | 3563 | { |
3549 | GNUNET_free(send_hello_context); | 3564 | GNUNET_free (send_hello_context); |
3550 | return; | 3565 | return; |
3551 | } | 3566 | } |
3552 | 3567 | ||
3553 | GNUNET_assert(send_hello_context->peer_pos != NULL); /* All of the HELLO sends to be scheduled have been scheduled! */ | 3568 | GNUNET_assert (send_hello_context->peer_pos != NULL); /* All of the HELLO sends to be scheduled have been scheduled! */ |
3554 | 3569 | ||
3555 | if (((send_hello_context->peer->daemon->th == NULL) && | 3570 | if (((send_hello_context->peer->daemon->th == NULL) && |
3556 | (pg->outstanding_connects > pg->max_outstanding_connections)) || | 3571 | (pg->outstanding_connects > pg->max_outstanding_connections)) || |
3557 | (pg->stop_connects == GNUNET_YES)) | 3572 | (pg->stop_connects == GNUNET_YES)) |
3558 | { | 3573 | { |
3559 | #if VERBOSE_TESTING > 2 | 3574 | #if VERBOSE_TESTING > 2 |
3560 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3575 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3561 | _ | 3576 | _ |
3562 | ("Delaying connect, we have too many outstanding connections!\n")); | 3577 | ("Delaying connect, we have too many outstanding connections!\n")); |
3563 | #endif | 3578 | #endif |
3564 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 3579 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
3565 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), | 3580 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
3566 | &schedule_send_hellos, send_hello_context); | 3581 | &schedule_send_hellos, send_hello_context); |
3567 | } | 3582 | } |
3568 | else | 3583 | else |
3569 | { | 3584 | { |
3570 | #if VERBOSE_TESTING > 2 | 3585 | #if VERBOSE_TESTING > 2 |
3571 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3586 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3572 | _("Creating connection, outstanding_connections is %d\n"), | 3587 | _("Creating connection, outstanding_connections is %d\n"), |
3573 | outstanding_connects); | 3588 | outstanding_connects); |
3574 | #endif | 3589 | #endif |
3575 | if (send_hello_context->peer->daemon->th == NULL) | 3590 | if (send_hello_context->peer->daemon->th == NULL) |
3576 | { | 3591 | { |
3577 | pg->outstanding_connects++; /* Actual TRANSPORT, CORE connections! */ | 3592 | pg->outstanding_connects++; /* Actual TRANSPORT, CORE connections! */ |
3578 | send_hello_context->peer->daemon->th | 3593 | send_hello_context->peer->daemon->th |
3579 | = GNUNET_TRANSPORT_connect (send_hello_context->peer->cfg, NULL, | 3594 | = GNUNET_TRANSPORT_connect (send_hello_context->peer->cfg, NULL, |
3580 | send_hello_context, NULL, NULL, NULL); | 3595 | send_hello_context, NULL, NULL, NULL); |
3581 | } | 3596 | } |
3582 | #if DEBUG_TESTING | 3597 | #if DEBUG_TESTING |
3583 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3598 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3584 | _("Offering Hello of peer %s to peer %s\n"), | 3599 | _("Offering Hello of peer %s to peer %s\n"), |
3585 | send_hello_context->peer->daemon->shortname, pg->peers[send_hello_context->peer_pos->index].daemon->shortname); | 3600 | send_hello_context->peer->daemon->shortname, |
3586 | #endif | 3601 | pg->peers[send_hello_context->peer_pos->index]. |
3587 | GNUNET_TRANSPORT_offer_hello(send_hello_context->peer->daemon->th, | 3602 | daemon->shortname); |
3588 | (const struct GNUNET_MessageHeader *)pg->peers[send_hello_context->peer_pos->index].daemon->hello, | 3603 | #endif |
3589 | &hello_sent_callback, | 3604 | GNUNET_TRANSPORT_offer_hello (send_hello_context->peer->daemon->th, |
3590 | send_hello_context); | 3605 | (const struct GNUNET_MessageHeader *) |
3591 | send_hello_context->peer_pos = send_hello_context->peer_pos->next; | 3606 | pg->peers[send_hello_context->peer_pos-> |
3592 | GNUNET_assert(send_hello_context->peer->daemon->th != NULL); | 3607 | index].daemon->hello, |
3593 | } | 3608 | &hello_sent_callback, send_hello_context); |
3609 | send_hello_context->peer_pos = send_hello_context->peer_pos->next; | ||
3610 | GNUNET_assert (send_hello_context->peer->daemon->th != NULL); | ||
3594 | } | 3611 | } |
3612 | } | ||
3595 | #endif | 3613 | #endif |
3596 | 3614 | ||
3597 | /** | 3615 | /** |
@@ -3599,14 +3617,14 @@ static void schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskC | |||
3599 | * happen instead of flooding all testing daemons with requests to connect. | 3617 | * happen instead of flooding all testing daemons with requests to connect. |
3600 | */ | 3618 | */ |
3601 | static void | 3619 | static void |
3602 | internal_connect_notify(void *cls, const struct GNUNET_PeerIdentity *first, | 3620 | internal_connect_notify (void *cls, const struct GNUNET_PeerIdentity *first, |
3603 | const struct GNUNET_PeerIdentity *second, | 3621 | const struct GNUNET_PeerIdentity *second, |
3604 | uint32_t distance, | 3622 | uint32_t distance, |
3605 | const struct GNUNET_CONFIGURATION_Handle *first_cfg, | 3623 | const struct GNUNET_CONFIGURATION_Handle *first_cfg, |
3606 | const struct GNUNET_CONFIGURATION_Handle *second_cfg, | 3624 | const struct GNUNET_CONFIGURATION_Handle *second_cfg, |
3607 | struct GNUNET_TESTING_Daemon *first_daemon, | 3625 | struct GNUNET_TESTING_Daemon *first_daemon, |
3608 | struct GNUNET_TESTING_Daemon *second_daemon, | 3626 | struct GNUNET_TESTING_Daemon *second_daemon, |
3609 | const char *emsg) | 3627 | const char *emsg) |
3610 | { | 3628 | { |
3611 | struct ConnectContext *connect_ctx = cls; | 3629 | struct ConnectContext *connect_ctx = cls; |
3612 | struct ConnectTopologyContext *ct_ctx = connect_ctx->ct_ctx; | 3630 | struct ConnectTopologyContext *ct_ctx = connect_ctx->ct_ctx; |
@@ -3627,33 +3645,41 @@ internal_connect_notify(void *cls, const struct GNUNET_PeerIdentity *first, | |||
3627 | #endif | 3645 | #endif |
3628 | 3646 | ||
3629 | while ((connection != NULL) && (0 | 3647 | while ((connection != NULL) && (0 |
3630 | != memcmp (first, &pg->peers[connection->index].daemon->id, | 3648 | != memcmp (first, |
3631 | sizeof(struct GNUNET_PeerIdentity)))) | 3649 | &pg->peers[connection-> |
3632 | { | 3650 | index].daemon->id, |
3633 | connection = connection->next; | 3651 | sizeof (struct |
3634 | } | 3652 | GNUNET_PeerIdentity)))) |
3653 | { | ||
3654 | connection = connection->next; | ||
3655 | } | ||
3635 | 3656 | ||
3636 | if (connection != NULL) /* Can safely remove! */ | 3657 | if (connection != NULL) /* Can safely remove! */ |
3637 | { | 3658 | { |
3638 | GNUNET_assert (0 < ct_ctx->remaining_connections); | 3659 | GNUNET_assert (0 < ct_ctx->remaining_connections); |
3639 | ct_ctx->remaining_connections--; | 3660 | ct_ctx->remaining_connections--; |
3640 | if (pg->notify_connection != NULL) /* Notify of reverse connection */ | 3661 | if (pg->notify_connection != NULL) /* Notify of reverse connection */ |
3641 | pg->notify_connection (pg->notify_connection_cls, second, first, | 3662 | pg->notify_connection (pg->notify_connection_cls, second, first, |
3642 | distance, second_cfg, first_cfg, second_daemon, | 3663 | distance, second_cfg, first_cfg, second_daemon, |
3643 | first_daemon, emsg); | 3664 | first_daemon, emsg); |
3644 | 3665 | ||
3645 | GNUNET_CONTAINER_DLL_remove(pg->peers[connect_ctx->second_index].connect_peers_head, pg->peers[connect_ctx->second_index].connect_peers_tail, connection); | 3666 | GNUNET_CONTAINER_DLL_remove (pg-> |
3646 | GNUNET_free(connection); | 3667 | peers[connect_ctx-> |
3647 | } | 3668 | second_index].connect_peers_head, |
3669 | pg->peers[connect_ctx-> | ||
3670 | second_index].connect_peers_tail, | ||
3671 | connection); | ||
3672 | GNUNET_free (connection); | ||
3673 | } | ||
3648 | 3674 | ||
3649 | if (ct_ctx->remaining_connections == 0) | 3675 | if (ct_ctx->remaining_connections == 0) |
3676 | { | ||
3677 | if (ct_ctx->notify_connections_done != NULL) | ||
3650 | { | 3678 | { |
3651 | if (ct_ctx->notify_connections_done != NULL) | 3679 | ct_ctx->notify_connections_done (ct_ctx->notify_cls, NULL); |
3652 | { | 3680 | ct_ctx->notify_connections_done = NULL; |
3653 | ct_ctx->notify_connections_done (ct_ctx->notify_cls, NULL); | ||
3654 | ct_ctx->notify_connections_done = NULL; | ||
3655 | } | ||
3656 | } | 3681 | } |
3682 | } | ||
3657 | else | 3683 | else |
3658 | preschedule_connect (pg); | 3684 | preschedule_connect (pg); |
3659 | 3685 | ||
@@ -3662,7 +3688,7 @@ internal_connect_notify(void *cls, const struct GNUNET_PeerIdentity *first, | |||
3662 | first_cfg, second_cfg, first_daemon, second_daemon, | 3688 | first_cfg, second_cfg, first_daemon, second_daemon, |
3663 | emsg); | 3689 | emsg); |
3664 | 3690 | ||
3665 | GNUNET_free(connect_ctx); | 3691 | GNUNET_free (connect_ctx); |
3666 | } | 3692 | } |
3667 | 3693 | ||
3668 | /** | 3694 | /** |
@@ -3673,49 +3699,49 @@ internal_connect_notify(void *cls, const struct GNUNET_PeerIdentity *first, | |||
3673 | * @param tc the task runtime context | 3699 | * @param tc the task runtime context |
3674 | */ | 3700 | */ |
3675 | static void | 3701 | static void |
3676 | schedule_connect(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3702 | schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
3677 | { | 3703 | { |
3678 | struct ConnectContext *connect_context = cls; | 3704 | struct ConnectContext *connect_context = cls; |
3679 | struct GNUNET_TESTING_PeerGroup *pg = connect_context->ct_ctx->pg; | 3705 | struct GNUNET_TESTING_PeerGroup *pg = connect_context->ct_ctx->pg; |
3680 | 3706 | ||
3681 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 3707 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
3682 | return; | 3708 | return; |
3683 | 3709 | ||
3684 | if ((pg->outstanding_connects > pg->max_outstanding_connections) | 3710 | if ((pg->outstanding_connects > pg->max_outstanding_connections) |
3685 | || (pg->stop_connects == GNUNET_YES)) | 3711 | || (pg->stop_connects == GNUNET_YES)) |
3686 | { | 3712 | { |
3687 | #if VERBOSE_TESTING | 3713 | #if VERBOSE_TESTING |
3688 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3714 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3689 | _ | 3715 | _ |
3690 | ("Delaying connect, we have too many outstanding connections!\n")); | 3716 | ("Delaying connect, we have too many outstanding connections!\n")); |
3691 | #endif | 3717 | #endif |
3692 | GNUNET_SCHEDULER_add_delayed ( | 3718 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
3693 | GNUNET_TIME_relative_multiply ( | 3719 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
3694 | GNUNET_TIME_UNIT_MILLISECONDS, | 3720 | &schedule_connect, connect_context); |
3695 | 100), | 3721 | } |
3696 | &schedule_connect, connect_context); | ||
3697 | } | ||
3698 | else | 3722 | else |
3699 | { | 3723 | { |
3700 | #if VERBOSE_TESTING | 3724 | #if VERBOSE_TESTING |
3701 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3725 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3702 | _("Creating connection, outstanding_connections is %d (max %d)\n"), | 3726 | _ |
3703 | pg->outstanding_connects, pg->max_outstanding_connections); | 3727 | ("Creating connection, outstanding_connections is %d (max %d)\n"), |
3704 | #endif | 3728 | pg->outstanding_connects, pg->max_outstanding_connections); |
3705 | pg->outstanding_connects++; | 3729 | #endif |
3706 | pg->total_connects_scheduled++; | 3730 | pg->outstanding_connects++; |
3707 | GNUNET_TESTING_daemons_connect ( | 3731 | pg->total_connects_scheduled++; |
3708 | pg->peers[connect_context->first_index].daemon, | 3732 | GNUNET_TESTING_daemons_connect (pg-> |
3709 | pg->peers[connect_context->second_index].daemon, | 3733 | peers[connect_context->first_index].daemon, |
3710 | connect_context->ct_ctx->connect_timeout, | 3734 | pg->peers[connect_context-> |
3711 | connect_context->ct_ctx->connect_attempts, | 3735 | second_index].daemon, |
3736 | connect_context->ct_ctx->connect_timeout, | ||
3737 | connect_context->ct_ctx->connect_attempts, | ||
3712 | #if USE_SEND_HELLOS | 3738 | #if USE_SEND_HELLOS |
3713 | GNUNET_NO, | 3739 | GNUNET_NO, |
3714 | #else | 3740 | #else |
3715 | GNUNET_YES, | 3741 | GNUNET_YES, |
3716 | #endif | 3742 | #endif |
3717 | &internal_connect_notify, connect_context); /* FIXME: free connect context! */ | 3743 | &internal_connect_notify, connect_context); /* FIXME: free connect context! */ |
3718 | } | 3744 | } |
3719 | } | 3745 | } |
3720 | 3746 | ||
3721 | #if !OLD | 3747 | #if !OLD |
@@ -3731,20 +3757,20 @@ schedule_connect(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
3731 | */ | 3757 | */ |
3732 | static int | 3758 | static int |
3733 | connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | 3759 | connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
3734 | { | 3760 | { |
3735 | struct ConnectTopologyContext *ct_ctx = cls; | 3761 | struct ConnectTopologyContext *ct_ctx = cls; |
3736 | struct PeerData *first = ct_ctx->first; | 3762 | struct PeerData *first = ct_ctx->first; |
3737 | struct GNUNET_TESTING_Daemon *second = value; | 3763 | struct GNUNET_TESTING_Daemon *second = value; |
3738 | struct ConnectContext *connect_context; | 3764 | struct ConnectContext *connect_context; |
3739 | 3765 | ||
3740 | connect_context = GNUNET_malloc (sizeof (struct ConnectContext)); | 3766 | connect_context = GNUNET_malloc (sizeof (struct ConnectContext)); |
3741 | connect_context->first = first->daemon; | 3767 | connect_context->first = first->daemon; |
3742 | connect_context->second = second; | 3768 | connect_context->second = second; |
3743 | connect_context->ct_ctx = ct_ctx; | 3769 | connect_context->ct_ctx = ct_ctx; |
3744 | GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context); | 3770 | GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context); |
3745 | 3771 | ||
3746 | return GNUNET_YES; | 3772 | return GNUNET_YES; |
3747 | } | 3773 | } |
3748 | #endif | 3774 | #endif |
3749 | 3775 | ||
3750 | #if !OLD | 3776 | #if !OLD |
@@ -3760,16 +3786,16 @@ connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
3760 | */ | 3786 | */ |
3761 | static int | 3787 | static int |
3762 | copy_topology_iterator (void *cls, const GNUNET_HashCode * key, void *value) | 3788 | copy_topology_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
3763 | { | 3789 | { |
3764 | struct PeerData *first = cls; | 3790 | struct PeerData *first = cls; |
3765 | 3791 | ||
3766 | GNUNET_assert (GNUNET_OK == | 3792 | GNUNET_assert (GNUNET_OK == |
3767 | GNUNET_CONTAINER_multihashmap_put (first->connect_peers, key, | 3793 | GNUNET_CONTAINER_multihashmap_put (first->connect_peers, key, |
3768 | value, | 3794 | value, |
3769 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 3795 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
3770 | 3796 | ||
3771 | return GNUNET_YES; | 3797 | return GNUNET_YES; |
3772 | } | 3798 | } |
3773 | #endif | 3799 | #endif |
3774 | 3800 | ||
3775 | /** | 3801 | /** |
@@ -3779,42 +3805,41 @@ copy_topology_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
3779 | * @param pg the peer group | 3805 | * @param pg the peer group |
3780 | */ | 3806 | */ |
3781 | static int | 3807 | static int |
3782 | copy_allowed_topology(struct GNUNET_TESTING_PeerGroup *pg) | 3808 | copy_allowed_topology (struct GNUNET_TESTING_PeerGroup *pg) |
3783 | { | 3809 | { |
3784 | unsigned int pg_iter; | 3810 | unsigned int pg_iter; |
3785 | int ret; | 3811 | int ret; |
3786 | int total; | 3812 | int total; |
3813 | |||
3787 | #if OLD | 3814 | #if OLD |
3788 | struct PeerConnection *iter; | 3815 | struct PeerConnection *iter; |
3789 | #endif | 3816 | #endif |
3790 | total = 0; | 3817 | total = 0; |
3791 | ret = 0; | 3818 | ret = 0; |
3792 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3819 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
3793 | { | 3820 | { |
3794 | #if OLD | 3821 | #if OLD |
3795 | iter = pg->peers[pg_iter].allowed_peers_head; | 3822 | iter = pg->peers[pg_iter].allowed_peers_head; |
3796 | while (iter != NULL) | 3823 | while (iter != NULL) |
3797 | { | 3824 | { |
3798 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3825 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3799 | "Creating connection between %d and %d\n", pg_iter, | 3826 | "Creating connection between %d and %d\n", pg_iter, |
3800 | iter->index); | 3827 | iter->index); |
3801 | total += add_connections (pg, pg_iter, iter->index, CONNECT, | 3828 | total += add_connections (pg, pg_iter, iter->index, CONNECT, GNUNET_YES); |
3802 | GNUNET_YES); | 3829 | //total += add_actual_connections(pg, pg_iter, iter->index); |
3803 | //total += add_actual_connections(pg, pg_iter, iter->index); | 3830 | iter = iter->next; |
3804 | iter = iter->next; | 3831 | } |
3805 | } | ||
3806 | #else | 3832 | #else |
3807 | ret = | 3833 | ret = |
3808 | GNUNET_CONTAINER_multihashmap_iterate (pg-> | 3834 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].allowed_peers, |
3809 | peers[pg_iter].allowed_peers, | 3835 | ©_topology_iterator, |
3810 | ©_topology_iterator, | 3836 | &pg->peers[pg_iter]); |
3811 | &pg->peers[pg_iter]); | ||
3812 | #endif | 3837 | #endif |
3813 | if (GNUNET_SYSERR == ret) | 3838 | if (GNUNET_SYSERR == ret) |
3814 | return GNUNET_SYSERR; | 3839 | return GNUNET_SYSERR; |
3815 | 3840 | ||
3816 | total = total + ret; | 3841 | total = total + ret; |
3817 | } | 3842 | } |
3818 | 3843 | ||
3819 | return total; | 3844 | return total; |
3820 | } | 3845 | } |
@@ -3832,11 +3857,11 @@ copy_allowed_topology(struct GNUNET_TESTING_PeerGroup *pg) | |||
3832 | * @return the number of connections that will be attempted | 3857 | * @return the number of connections that will be attempted |
3833 | */ | 3858 | */ |
3834 | static int | 3859 | static int |
3835 | connect_topology(struct GNUNET_TESTING_PeerGroup *pg, | 3860 | connect_topology (struct GNUNET_TESTING_PeerGroup *pg, |
3836 | struct GNUNET_TIME_Relative connect_timeout, | 3861 | struct GNUNET_TIME_Relative connect_timeout, |
3837 | unsigned int connect_attempts, | 3862 | unsigned int connect_attempts, |
3838 | GNUNET_TESTING_NotifyCompletion notify_callback, | 3863 | GNUNET_TESTING_NotifyCompletion notify_callback, |
3839 | void *notify_cls) | 3864 | void *notify_cls) |
3840 | { | 3865 | { |
3841 | unsigned int pg_iter; | 3866 | unsigned int pg_iter; |
3842 | unsigned int total; | 3867 | unsigned int total; |
@@ -3854,19 +3879,19 @@ connect_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
3854 | pg->ct_ctx.pg = pg; | 3879 | pg->ct_ctx.pg = pg; |
3855 | 3880 | ||
3856 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3881 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
3857 | { | 3882 | { |
3858 | #if OLD | 3883 | #if OLD |
3859 | connection_iter = pg->peers[pg_iter].connect_peers_head; | 3884 | connection_iter = pg->peers[pg_iter].connect_peers_head; |
3860 | while (connection_iter != NULL) | 3885 | while (connection_iter != NULL) |
3861 | { | 3886 | { |
3862 | connection_iter = connection_iter->next; | 3887 | connection_iter = connection_iter->next; |
3863 | total++; | 3888 | total++; |
3864 | } | 3889 | } |
3865 | #else | 3890 | #else |
3866 | total += | 3891 | total += |
3867 | GNUNET_CONTAINER_multihashmap_size (pg->peers[pg_iter].connect_peers); | 3892 | GNUNET_CONTAINER_multihashmap_size (pg->peers[pg_iter].connect_peers); |
3868 | #endif | 3893 | #endif |
3869 | } | 3894 | } |
3870 | 3895 | ||
3871 | if (total == 0) | 3896 | if (total == 0) |
3872 | return total; | 3897 | return total; |
@@ -3879,18 +3904,18 @@ connect_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
3879 | /* First give all peers the HELLO's of other peers (connect to first peer's transport service, give HELLO's of other peers, continue...) */ | 3904 | /* First give all peers the HELLO's of other peers (connect to first peer's transport service, give HELLO's of other peers, continue...) */ |
3880 | pg->remaining_hellos = total; | 3905 | pg->remaining_hellos = total; |
3881 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3906 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
3882 | { | 3907 | { |
3883 | send_hello_context = GNUNET_malloc(sizeof(struct SendHelloContext)); | 3908 | send_hello_context = GNUNET_malloc (sizeof (struct SendHelloContext)); |
3884 | send_hello_context->peer = &pg->peers[pg_iter]; | 3909 | send_hello_context->peer = &pg->peers[pg_iter]; |
3885 | send_hello_context->peer_pos = pg->peers[pg_iter].connect_peers_head; | 3910 | send_hello_context->peer_pos = pg->peers[pg_iter].connect_peers_head; |
3886 | send_hello_context->pg = pg; | 3911 | send_hello_context->pg = pg; |
3887 | GNUNET_SCHEDULER_add_now(&schedule_send_hellos, send_hello_context); | 3912 | GNUNET_SCHEDULER_add_now (&schedule_send_hellos, send_hello_context); |
3888 | } | 3913 | } |
3889 | #else | 3914 | #else |
3890 | for (pg_iter = 0; pg_iter < pg->max_outstanding_connections; pg_iter++) | 3915 | for (pg_iter = 0; pg_iter < pg->max_outstanding_connections; pg_iter++) |
3891 | { | 3916 | { |
3892 | preschedule_connect (pg); | 3917 | preschedule_connect (pg); |
3893 | } | 3918 | } |
3894 | #endif | 3919 | #endif |
3895 | return total; | 3920 | return total; |
3896 | 3921 | ||
@@ -3918,10 +3943,10 @@ connect_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
3918 | * connected to each other | 3943 | * connected to each other |
3919 | */ | 3944 | */ |
3920 | unsigned int | 3945 | unsigned int |
3921 | GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | 3946 | GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, |
3922 | enum GNUNET_TESTING_Topology topology, | 3947 | enum GNUNET_TESTING_Topology topology, |
3923 | enum GNUNET_TESTING_Topology restrict_topology, | 3948 | enum GNUNET_TESTING_Topology restrict_topology, |
3924 | const char *restrict_transports) | 3949 | const char *restrict_transports) |
3925 | { | 3950 | { |
3926 | int ret; | 3951 | int ret; |
3927 | 3952 | ||
@@ -3934,20 +3959,18 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
3934 | 3959 | ||
3935 | #if !OLD | 3960 | #if !OLD |
3936 | unsigned int i; | 3961 | unsigned int i; |
3962 | |||
3937 | for (i = 0; i < pg->total; i++) | 3963 | for (i = 0; i < pg->total; i++) |
3938 | { | 3964 | { |
3939 | pg->peers[i].allowed_peers = | 3965 | pg->peers[i].allowed_peers = GNUNET_CONTAINER_multihashmap_create (100); |
3940 | GNUNET_CONTAINER_multihashmap_create (100); | 3966 | pg->peers[i].connect_peers = GNUNET_CONTAINER_multihashmap_create (100); |
3941 | pg->peers[i].connect_peers = | 3967 | pg->peers[i].blacklisted_peers = GNUNET_CONTAINER_multihashmap_create (100); |
3942 | GNUNET_CONTAINER_multihashmap_create (100); | 3968 | pg->peers[i].pg = pg; |
3943 | pg->peers[i].blacklisted_peers = | 3969 | } |
3944 | GNUNET_CONTAINER_multihashmap_create (100); | ||
3945 | pg->peers[i].pg = pg; | ||
3946 | } | ||
3947 | #endif | 3970 | #endif |
3948 | 3971 | ||
3949 | switch (topology) | 3972 | switch (topology) |
3950 | { | 3973 | { |
3951 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: | 3974 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: |
3952 | #if VERBOSE_TESTING | 3975 | #if VERBOSE_TESTING |
3953 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating clique topology\n")); | 3976 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating clique topology\n")); |
@@ -3957,14 +3980,14 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
3957 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: | 3980 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: |
3958 | #if VERBOSE_TESTING | 3981 | #if VERBOSE_TESTING |
3959 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3982 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3960 | _("Creating small world (ring) topology\n")); | 3983 | _("Creating small world (ring) topology\n")); |
3961 | #endif | 3984 | #endif |
3962 | num_connections = create_small_world_ring (pg, &add_connections, ALLOWED); | 3985 | num_connections = create_small_world_ring (pg, &add_connections, ALLOWED); |
3963 | break; | 3986 | break; |
3964 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: | 3987 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: |
3965 | #if VERBOSE_TESTING | 3988 | #if VERBOSE_TESTING |
3966 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3989 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3967 | _("Creating small world (2d-torus) topology\n")); | 3990 | _("Creating small world (2d-torus) topology\n")); |
3968 | #endif | 3991 | #endif |
3969 | num_connections = create_small_world (pg, &add_connections, ALLOWED); | 3992 | num_connections = create_small_world (pg, &add_connections, ALLOWED); |
3970 | break; | 3993 | break; |
@@ -3982,8 +4005,7 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
3982 | break; | 4005 | break; |
3983 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: | 4006 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: |
3984 | #if VERBOSE_TESTING | 4007 | #if VERBOSE_TESTING |
3985 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4008 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating Erdos-Renyi topology\n")); |
3986 | _("Creating Erdos-Renyi topology\n")); | ||
3987 | #endif | 4009 | #endif |
3988 | num_connections = create_erdos_renyi (pg, &add_connections, ALLOWED); | 4010 | num_connections = create_erdos_renyi (pg, &add_connections, ALLOWED); |
3989 | break; | 4011 | break; |
@@ -3995,22 +4017,20 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
3995 | break; | 4017 | break; |
3996 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: | 4018 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: |
3997 | #if VERBOSE_TESTING | 4019 | #if VERBOSE_TESTING |
3998 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4020 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating Scale Free topology\n")); |
3999 | _("Creating Scale Free topology\n")); | ||
4000 | #endif | 4021 | #endif |
4001 | num_connections = create_scale_free (pg, &add_connections, ALLOWED); | 4022 | num_connections = create_scale_free (pg, &add_connections, ALLOWED); |
4002 | break; | 4023 | break; |
4003 | case GNUNET_TESTING_TOPOLOGY_LINE: | 4024 | case GNUNET_TESTING_TOPOLOGY_LINE: |
4004 | #if VERBOSE_TESTING | 4025 | #if VERBOSE_TESTING |
4005 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4026 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4006 | _("Creating straight line topology\n")); | 4027 | _("Creating straight line topology\n")); |
4007 | #endif | 4028 | #endif |
4008 | num_connections = create_line (pg, &add_connections, ALLOWED); | 4029 | num_connections = create_line (pg, &add_connections, ALLOWED); |
4009 | break; | 4030 | break; |
4010 | case GNUNET_TESTING_TOPOLOGY_FROM_FILE: | 4031 | case GNUNET_TESTING_TOPOLOGY_FROM_FILE: |
4011 | #if VERBOSE_TESTING | 4032 | #if VERBOSE_TESTING |
4012 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4033 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating topology from file!\n")); |
4013 | _("Creating topology from file!\n")); | ||
4014 | #endif | 4034 | #endif |
4015 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "testing", | 4035 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "testing", |
4016 | "topology_file", | 4036 | "topology_file", |
@@ -4018,50 +4038,50 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4018 | num_connections = create_from_file (pg, filename, &add_connections, | 4038 | num_connections = create_from_file (pg, filename, &add_connections, |
4019 | ALLOWED); | 4039 | ALLOWED); |
4020 | else | 4040 | else |
4021 | { | 4041 | { |
4022 | GNUNET_log ( | 4042 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
4023 | GNUNET_ERROR_TYPE_WARNING, | 4043 | "Missing configuration option TESTING:TOPOLOGY_FILE for creating topology from file!\n"); |
4024 | "Missing configuration option TESTING:TOPOLOGY_FILE for creating topology from file!\n"); | 4044 | num_connections = 0; |
4025 | num_connections = 0; | 4045 | } |
4026 | } | ||
4027 | break; | 4046 | break; |
4028 | case GNUNET_TESTING_TOPOLOGY_NONE: | 4047 | case GNUNET_TESTING_TOPOLOGY_NONE: |
4029 | #if VERBOSE_TESTING | 4048 | #if VERBOSE_TESTING |
4030 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4049 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4031 | _ | 4050 | _ |
4032 | ("Creating no allowed topology (all peers can connect at core level)\n")); | 4051 | ("Creating no allowed topology (all peers can connect at core level)\n")); |
4033 | #endif | 4052 | #endif |
4034 | num_connections = pg->total * pg->total; /* Clique is allowed! */ | 4053 | num_connections = pg->total * pg->total; /* Clique is allowed! */ |
4035 | break; | 4054 | break; |
4036 | default: | 4055 | default: |
4037 | num_connections = 0; | 4056 | num_connections = 0; |
4038 | break; | 4057 | break; |
4039 | } | 4058 | } |
4040 | 4059 | ||
4041 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "TESTING", | 4060 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "TESTING", |
4042 | "F2F")) | 4061 | "F2F")) |
4062 | { | ||
4063 | ret = create_and_copy_friend_files (pg); | ||
4064 | if (ret != GNUNET_OK) | ||
4043 | { | 4065 | { |
4044 | ret = create_and_copy_friend_files (pg); | ||
4045 | if (ret != GNUNET_OK) | ||
4046 | { | ||
4047 | #if VERBOSE_TESTING | 4066 | #if VERBOSE_TESTING |
4048 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4067 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4049 | _("Failed during friend file copying!\n")); | 4068 | _("Failed during friend file copying!\n")); |
4050 | #endif | 4069 | #endif |
4051 | return GNUNET_SYSERR; | 4070 | return GNUNET_SYSERR; |
4052 | } | 4071 | } |
4053 | else | 4072 | else |
4054 | { | 4073 | { |
4055 | #if VERBOSE_TESTING | 4074 | #if VERBOSE_TESTING |
4056 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4075 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4057 | _("Friend files created/copied successfully!\n")); | 4076 | _("Friend files created/copied successfully!\n")); |
4058 | #endif | 4077 | #endif |
4059 | } | ||
4060 | } | 4078 | } |
4079 | } | ||
4061 | 4080 | ||
4062 | /* Use the create clique method to initially set all connections as blacklisted. */ | 4081 | /* Use the create clique method to initially set all connections as blacklisted. */ |
4063 | if ((restrict_topology != GNUNET_TESTING_TOPOLOGY_NONE) && (restrict_topology | 4082 | if ((restrict_topology != GNUNET_TESTING_TOPOLOGY_NONE) && (restrict_topology |
4064 | != GNUNET_TESTING_TOPOLOGY_FROM_FILE)) | 4083 | != |
4084 | GNUNET_TESTING_TOPOLOGY_FROM_FILE)) | ||
4065 | create_clique (pg, &add_connections, BLACKLIST, GNUNET_NO); | 4085 | create_clique (pg, &add_connections, BLACKLIST, GNUNET_NO); |
4066 | else | 4086 | else |
4067 | return num_connections; | 4087 | return num_connections; |
@@ -4069,11 +4089,11 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4069 | unblacklisted_connections = 0; | 4089 | unblacklisted_connections = 0; |
4070 | /* Un-blacklist connections as per the topology specified */ | 4090 | /* Un-blacklist connections as per the topology specified */ |
4071 | switch (restrict_topology) | 4091 | switch (restrict_topology) |
4072 | { | 4092 | { |
4073 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: | 4093 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: |
4074 | #if VERBOSE_TESTING | 4094 | #if VERBOSE_TESTING |
4075 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4095 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4076 | _("Blacklisting all but clique topology\n")); | 4096 | _("Blacklisting all but clique topology\n")); |
4077 | #endif | 4097 | #endif |
4078 | unblacklisted_connections = create_clique (pg, &remove_connections, | 4098 | unblacklisted_connections = create_clique (pg, &remove_connections, |
4079 | BLACKLIST, GNUNET_NO); | 4099 | BLACKLIST, GNUNET_NO); |
@@ -4081,7 +4101,7 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4081 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: | 4101 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: |
4082 | #if VERBOSE_TESTING | 4102 | #if VERBOSE_TESTING |
4083 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4084 | _("Blacklisting all but small world (ring) topology\n")); | 4104 | _("Blacklisting all but small world (ring) topology\n")); |
4085 | #endif | 4105 | #endif |
4086 | unblacklisted_connections = create_small_world_ring (pg, | 4106 | unblacklisted_connections = create_small_world_ring (pg, |
4087 | &remove_connections, | 4107 | &remove_connections, |
@@ -4090,8 +4110,7 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4090 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: | 4110 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: |
4091 | #if VERBOSE_TESTING | 4111 | #if VERBOSE_TESTING |
4092 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4093 | _ | 4113 | _("Blacklisting all but small world (2d-torus) topology\n")); |
4094 | ("Blacklisting all but small world (2d-torus) topology\n")); | ||
4095 | #endif | 4114 | #endif |
4096 | unblacklisted_connections = create_small_world (pg, &remove_connections, | 4115 | unblacklisted_connections = create_small_world (pg, &remove_connections, |
4097 | BLACKLIST); | 4116 | BLACKLIST); |
@@ -4099,7 +4118,7 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4099 | case GNUNET_TESTING_TOPOLOGY_RING: | 4118 | case GNUNET_TESTING_TOPOLOGY_RING: |
4100 | #if VERBOSE_TESTING | 4119 | #if VERBOSE_TESTING |
4101 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4102 | _("Blacklisting all but ring topology\n")); | 4121 | _("Blacklisting all but ring topology\n")); |
4103 | #endif | 4122 | #endif |
4104 | unblacklisted_connections | 4123 | unblacklisted_connections |
4105 | = create_ring (pg, &remove_connections, BLACKLIST); | 4124 | = create_ring (pg, &remove_connections, BLACKLIST); |
@@ -4107,7 +4126,7 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4107 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: | 4126 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: |
4108 | #if VERBOSE_TESTING | 4127 | #if VERBOSE_TESTING |
4109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4110 | _("Blacklisting all but 2d torus topology\n")); | 4129 | _("Blacklisting all but 2d torus topology\n")); |
4111 | #endif | 4130 | #endif |
4112 | unblacklisted_connections = create_2d_torus (pg, &remove_connections, | 4131 | unblacklisted_connections = create_2d_torus (pg, &remove_connections, |
4113 | BLACKLIST); | 4132 | BLACKLIST); |
@@ -4115,7 +4134,7 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4115 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: | 4134 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: |
4116 | #if VERBOSE_TESTING | 4135 | #if VERBOSE_TESTING |
4117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4118 | _("Blacklisting all but Erdos-Renyi topology\n")); | 4137 | _("Blacklisting all but Erdos-Renyi topology\n")); |
4119 | #endif | 4138 | #endif |
4120 | unblacklisted_connections = create_erdos_renyi (pg, &remove_connections, | 4139 | unblacklisted_connections = create_erdos_renyi (pg, &remove_connections, |
4121 | BLACKLIST); | 4140 | BLACKLIST); |
@@ -4123,44 +4142,44 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4123 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: | 4142 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: |
4124 | #if VERBOSE_TESTING | 4143 | #if VERBOSE_TESTING |
4125 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4126 | _("Blacklisting all but InterNAT topology\n")); | 4145 | _("Blacklisting all but InterNAT topology\n")); |
4127 | #endif | 4146 | #endif |
4128 | 4147 | ||
4129 | #if TOPOLOGY_HACK | 4148 | #if TOPOLOGY_HACK |
4130 | for (off = 0; off < pg->total; off++) | 4149 | for (off = 0; off < pg->total; off++) |
4150 | { | ||
4151 | conn_iter = pg->peers[off].allowed_peers_head; | ||
4152 | while (conn_iter != NULL) | ||
4131 | { | 4153 | { |
4132 | conn_iter = pg->peers[off].allowed_peers_head; | 4154 | temp_conn = conn_iter->next; |
4133 | while (conn_iter != NULL) | 4155 | GNUNET_free (conn_iter); |
4134 | { | 4156 | conn_iter = temp_conn; |
4135 | temp_conn = conn_iter->next; | ||
4136 | GNUNET_free(conn_iter); | ||
4137 | conn_iter = temp_conn; | ||
4138 | } | ||
4139 | pg->peers[off].allowed_peers_head = NULL; | ||
4140 | pg->peers[off].allowed_peers_tail = NULL; | ||
4141 | |||
4142 | conn_iter = pg->peers[off].connect_peers_head; | ||
4143 | while (conn_iter != NULL) | ||
4144 | { | ||
4145 | temp_conn = conn_iter->next; | ||
4146 | GNUNET_free(conn_iter); | ||
4147 | conn_iter = temp_conn; | ||
4148 | } | ||
4149 | pg->peers[off].connect_peers_head = NULL; | ||
4150 | pg->peers[off].connect_peers_tail = NULL; | ||
4151 | } | 4157 | } |
4158 | pg->peers[off].allowed_peers_head = NULL; | ||
4159 | pg->peers[off].allowed_peers_tail = NULL; | ||
4160 | |||
4161 | conn_iter = pg->peers[off].connect_peers_head; | ||
4162 | while (conn_iter != NULL) | ||
4163 | { | ||
4164 | temp_conn = conn_iter->next; | ||
4165 | GNUNET_free (conn_iter); | ||
4166 | conn_iter = temp_conn; | ||
4167 | } | ||
4168 | pg->peers[off].connect_peers_head = NULL; | ||
4169 | pg->peers[off].connect_peers_tail = NULL; | ||
4170 | } | ||
4152 | unblacklisted_connections | 4171 | unblacklisted_connections |
4153 | = create_nated_internet_copy (pg, &remove_connections, BLACKLIST); | 4172 | = create_nated_internet_copy (pg, &remove_connections, BLACKLIST); |
4154 | #else | 4173 | #else |
4155 | unblacklisted_connections = | 4174 | unblacklisted_connections = |
4156 | create_nated_internet (pg, &remove_connections, BLACKLIST); | 4175 | create_nated_internet (pg, &remove_connections, BLACKLIST); |
4157 | #endif | 4176 | #endif |
4158 | 4177 | ||
4159 | break; | 4178 | break; |
4160 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: | 4179 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: |
4161 | #if VERBOSE_TESTING | 4180 | #if VERBOSE_TESTING |
4162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4163 | _("Blacklisting all but Scale Free topology\n")); | 4182 | _("Blacklisting all but Scale Free topology\n")); |
4164 | #endif | 4183 | #endif |
4165 | unblacklisted_connections = create_scale_free (pg, &remove_connections, | 4184 | unblacklisted_connections = create_scale_free (pg, &remove_connections, |
4166 | BLACKLIST); | 4185 | BLACKLIST); |
@@ -4168,35 +4187,35 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4168 | case GNUNET_TESTING_TOPOLOGY_LINE: | 4187 | case GNUNET_TESTING_TOPOLOGY_LINE: |
4169 | #if VERBOSE_TESTING | 4188 | #if VERBOSE_TESTING |
4170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4171 | _("Blacklisting all but straight line topology\n")); | 4190 | _("Blacklisting all but straight line topology\n")); |
4172 | #endif | 4191 | #endif |
4173 | unblacklisted_connections | 4192 | unblacklisted_connections |
4174 | = create_line (pg, &remove_connections, BLACKLIST); | 4193 | = create_line (pg, &remove_connections, BLACKLIST); |
4175 | default: | 4194 | default: |
4176 | break; | 4195 | break; |
4177 | } | 4196 | } |
4178 | 4197 | ||
4179 | if ((unblacklisted_connections > 0) && (restrict_transports != NULL)) | 4198 | if ((unblacklisted_connections > 0) && (restrict_transports != NULL)) |
4199 | { | ||
4200 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating blacklist with `%s'\n", | ||
4201 | restrict_transports); | ||
4202 | ret = create_and_copy_blacklist_files (pg, restrict_transports); | ||
4203 | if (ret != GNUNET_OK) | ||
4180 | { | 4204 | { |
4181 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating blacklist with `%s'\n", | ||
4182 | restrict_transports); | ||
4183 | ret = create_and_copy_blacklist_files (pg, restrict_transports); | ||
4184 | if (ret != GNUNET_OK) | ||
4185 | { | ||
4186 | #if VERBOSE_TESTING | 4205 | #if VERBOSE_TESTING |
4187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4188 | _("Failed during blacklist file copying!\n")); | 4207 | _("Failed during blacklist file copying!\n")); |
4189 | #endif | 4208 | #endif |
4190 | return 0; | 4209 | return 0; |
4191 | } | 4210 | } |
4192 | else | 4211 | else |
4193 | { | 4212 | { |
4194 | #if VERBOSE_TESTING | 4213 | #if VERBOSE_TESTING |
4195 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4196 | _("Blacklist files created/copied successfully!\n")); | 4215 | _("Blacklist files created/copied successfully!\n")); |
4197 | #endif | 4216 | #endif |
4198 | } | ||
4199 | } | 4217 | } |
4218 | } | ||
4200 | return num_connections; | 4219 | return num_connections; |
4201 | } | 4220 | } |
4202 | 4221 | ||
@@ -4212,38 +4231,38 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4212 | */ | 4231 | */ |
4213 | static int | 4232 | static int |
4214 | random_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | 4233 | random_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
4234 | { | ||
4235 | struct RandomContext *random_ctx = cls; | ||
4236 | double random_number; | ||
4237 | uint32_t second_pos; | ||
4238 | GNUNET_HashCode first_hash; | ||
4239 | |||
4240 | random_number = | ||
4241 | ((double) | ||
4242 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
4243 | UINT64_MAX)) / ((double) UINT64_MAX); | ||
4244 | if (random_number < random_ctx->percentage) | ||
4215 | { | 4245 | { |
4216 | struct RandomContext *random_ctx = cls; | 4246 | GNUNET_assert (GNUNET_OK == |
4217 | double random_number; | 4247 | GNUNET_CONTAINER_multihashmap_put (random_ctx-> |
4218 | uint32_t second_pos; | 4248 | first->connect_peers_working_set, |
4219 | GNUNET_HashCode first_hash; | 4249 | key, value, |
4220 | random_number = | 4250 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
4221 | ((double) | 4251 | } |
4222 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
4223 | UINT64_MAX)) / ((double) UINT64_MAX); | ||
4224 | if (random_number < random_ctx->percentage) | ||
4225 | { | ||
4226 | GNUNET_assert (GNUNET_OK == | ||
4227 | GNUNET_CONTAINER_multihashmap_put (random_ctx-> | ||
4228 | first->connect_peers_working_set, | ||
4229 | key, value, | ||
4230 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
4231 | } | ||
4232 | 4252 | ||
4233 | /* Now we have considered this particular connection, remove it from the second peer so it's not double counted */ | 4253 | /* Now we have considered this particular connection, remove it from the second peer so it's not double counted */ |
4234 | uid_from_hash (key, &second_pos); | 4254 | uid_from_hash (key, &second_pos); |
4235 | hash_from_uid (random_ctx->first_uid, &first_hash); | 4255 | hash_from_uid (random_ctx->first_uid, &first_hash); |
4236 | GNUNET_assert (random_ctx->pg->total > second_pos); | 4256 | GNUNET_assert (random_ctx->pg->total > second_pos); |
4237 | GNUNET_assert (GNUNET_YES == | 4257 | GNUNET_assert (GNUNET_YES == |
4238 | GNUNET_CONTAINER_multihashmap_remove (random_ctx-> | 4258 | GNUNET_CONTAINER_multihashmap_remove (random_ctx->pg->peers |
4239 | pg->peers | 4259 | [second_pos].connect_peers, |
4240 | [second_pos].connect_peers, | 4260 | &first_hash, |
4241 | &first_hash, | 4261 | random_ctx-> |
4242 | random_ctx-> | 4262 | first->daemon)); |
4243 | first->daemon)); | ||
4244 | 4263 | ||
4245 | return GNUNET_YES; | 4264 | return GNUNET_YES; |
4246 | } | 4265 | } |
4247 | 4266 | ||
4248 | /** | 4267 | /** |
4249 | * Iterator for adding at least X peers to a peers connection set. | 4268 | * Iterator for adding at least X peers to a peers connection set. |
@@ -4256,49 +4275,48 @@ random_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
4256 | */ | 4275 | */ |
4257 | static int | 4276 | static int |
4258 | minimum_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | 4277 | minimum_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
4259 | { | 4278 | { |
4260 | struct MinimumContext *min_ctx = cls; | 4279 | struct MinimumContext *min_ctx = cls; |
4261 | uint32_t second_pos; | 4280 | uint32_t second_pos; |
4262 | GNUNET_HashCode first_hash; | 4281 | GNUNET_HashCode first_hash; |
4263 | unsigned int i; | 4282 | unsigned int i; |
4264 | 4283 | ||
4265 | if (GNUNET_CONTAINER_multihashmap_size | 4284 | if (GNUNET_CONTAINER_multihashmap_size |
4266 | (min_ctx->first->connect_peers_working_set) < min_ctx->num_to_add) | 4285 | (min_ctx->first->connect_peers_working_set) < min_ctx->num_to_add) |
4286 | { | ||
4287 | for (i = 0; i < min_ctx->num_to_add; i++) | ||
4288 | { | ||
4289 | if (min_ctx->pg_array[i] == min_ctx->current) | ||
4267 | { | 4290 | { |
4268 | for (i = 0; i < min_ctx->num_to_add; i++) | 4291 | GNUNET_assert (GNUNET_OK == |
4269 | { | 4292 | GNUNET_CONTAINER_multihashmap_put |
4270 | if (min_ctx->pg_array[i] == min_ctx->current) | 4293 | (min_ctx->first->connect_peers_working_set, key, |
4271 | { | ||
4272 | GNUNET_assert (GNUNET_OK == | ||
4273 | GNUNET_CONTAINER_multihashmap_put | ||
4274 | (min_ctx->first->connect_peers_working_set, key, | ||
4275 | value, | 4294 | value, |
4276 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 4295 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
4277 | uid_from_hash (key, &second_pos); | 4296 | uid_from_hash (key, &second_pos); |
4278 | hash_from_uid (min_ctx->first_uid, &first_hash); | 4297 | hash_from_uid (min_ctx->first_uid, &first_hash); |
4279 | GNUNET_assert (min_ctx->pg->total > second_pos); | 4298 | GNUNET_assert (min_ctx->pg->total > second_pos); |
4280 | GNUNET_assert (GNUNET_OK == | 4299 | GNUNET_assert (GNUNET_OK == |
4281 | GNUNET_CONTAINER_multihashmap_put (min_ctx-> | 4300 | GNUNET_CONTAINER_multihashmap_put (min_ctx->pg->peers |
4282 | pg->peers | 4301 | [second_pos].connect_peers_working_set, |
4283 | [second_pos].connect_peers_working_set, | 4302 | &first_hash, |
4284 | &first_hash, | 4303 | min_ctx->first-> |
4285 | min_ctx->first-> | 4304 | daemon, |
4286 | daemon, | 4305 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
4287 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 4306 | /* Now we have added this particular connection, remove it from the second peer's map so it's not double counted */ |
4288 | /* Now we have added this particular connection, remove it from the second peer's map so it's not double counted */ | 4307 | GNUNET_assert (GNUNET_YES == |
4289 | GNUNET_assert (GNUNET_YES == | 4308 | GNUNET_CONTAINER_multihashmap_remove |
4290 | GNUNET_CONTAINER_multihashmap_remove | 4309 | (min_ctx->pg->peers[second_pos].connect_peers, |
4291 | (min_ctx->pg->peers[second_pos].connect_peers, | ||
4292 | &first_hash, min_ctx->first->daemon)); | 4310 | &first_hash, min_ctx->first->daemon)); |
4293 | } | ||
4294 | } | ||
4295 | min_ctx->current++; | ||
4296 | return GNUNET_YES; | ||
4297 | } | 4311 | } |
4298 | else | 4312 | } |
4299 | return GNUNET_NO; /* We can stop iterating, we have enough peers! */ | 4313 | min_ctx->current++; |
4300 | 4314 | return GNUNET_YES; | |
4301 | } | 4315 | } |
4316 | else | ||
4317 | return GNUNET_NO; /* We can stop iterating, we have enough peers! */ | ||
4318 | |||
4319 | } | ||
4302 | 4320 | ||
4303 | /** | 4321 | /** |
4304 | * Iterator for adding peers to a connection set based on a depth first search. | 4322 | * Iterator for adding peers to a connection set based on a depth first search. |
@@ -4311,41 +4329,40 @@ minimum_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
4311 | */ | 4329 | */ |
4312 | static int | 4330 | static int |
4313 | dfs_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | 4331 | dfs_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
4314 | { | 4332 | { |
4315 | struct DFSContext *dfs_ctx = cls; | 4333 | struct DFSContext *dfs_ctx = cls; |
4316 | GNUNET_HashCode first_hash; | 4334 | GNUNET_HashCode first_hash; |
4317 | |||
4318 | if (dfs_ctx->current == dfs_ctx->chosen) | ||
4319 | { | ||
4320 | GNUNET_assert (GNUNET_OK == | ||
4321 | GNUNET_CONTAINER_multihashmap_put (dfs_ctx-> | ||
4322 | first->connect_peers_working_set, | ||
4323 | key, value, | ||
4324 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
4325 | uid_from_hash (key, &dfs_ctx->second_uid); | ||
4326 | hash_from_uid (dfs_ctx->first_uid, &first_hash); | ||
4327 | GNUNET_assert (GNUNET_OK == | ||
4328 | GNUNET_CONTAINER_multihashmap_put (dfs_ctx-> | ||
4329 | pg->peers | ||
4330 | [dfs_ctx->second_uid].connect_peers_working_set, | ||
4331 | &first_hash, | ||
4332 | dfs_ctx-> | ||
4333 | first->daemon, | ||
4334 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
4335 | GNUNET_assert (GNUNET_YES == | ||
4336 | GNUNET_CONTAINER_multihashmap_remove (dfs_ctx-> | ||
4337 | pg->peers | ||
4338 | [dfs_ctx->second_uid].connect_peers, | ||
4339 | &first_hash, | ||
4340 | dfs_ctx-> | ||
4341 | first->daemon)); | ||
4342 | /* Can't remove second from first yet because we are currently iterating, hence the return value in the DFSContext! */ | ||
4343 | return GNUNET_NO; /* We have found our peer, don't iterate more */ | ||
4344 | } | ||
4345 | 4335 | ||
4346 | dfs_ctx->current++; | 4336 | if (dfs_ctx->current == dfs_ctx->chosen) |
4347 | return GNUNET_YES; | 4337 | { |
4338 | GNUNET_assert (GNUNET_OK == | ||
4339 | GNUNET_CONTAINER_multihashmap_put (dfs_ctx-> | ||
4340 | first->connect_peers_working_set, | ||
4341 | key, value, | ||
4342 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
4343 | uid_from_hash (key, &dfs_ctx->second_uid); | ||
4344 | hash_from_uid (dfs_ctx->first_uid, &first_hash); | ||
4345 | GNUNET_assert (GNUNET_OK == | ||
4346 | GNUNET_CONTAINER_multihashmap_put (dfs_ctx->pg->peers | ||
4347 | [dfs_ctx-> | ||
4348 | second_uid].connect_peers_working_set, | ||
4349 | &first_hash, | ||
4350 | dfs_ctx->first->daemon, | ||
4351 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
4352 | GNUNET_assert (GNUNET_YES == | ||
4353 | GNUNET_CONTAINER_multihashmap_remove (dfs_ctx-> | ||
4354 | pg->peers | ||
4355 | [dfs_ctx->second_uid].connect_peers, | ||
4356 | &first_hash, | ||
4357 | dfs_ctx-> | ||
4358 | first->daemon)); | ||
4359 | /* Can't remove second from first yet because we are currently iterating, hence the return value in the DFSContext! */ | ||
4360 | return GNUNET_NO; /* We have found our peer, don't iterate more */ | ||
4348 | } | 4361 | } |
4362 | |||
4363 | dfs_ctx->current++; | ||
4364 | return GNUNET_YES; | ||
4365 | } | ||
4349 | #endif | 4366 | #endif |
4350 | 4367 | ||
4351 | /** | 4368 | /** |
@@ -4356,10 +4373,11 @@ dfs_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
4356 | * @param percentage what percent of total connections to make | 4373 | * @param percentage what percent of total connections to make |
4357 | */ | 4374 | */ |
4358 | void | 4375 | void |
4359 | choose_random_connections(struct GNUNET_TESTING_PeerGroup *pg, | 4376 | choose_random_connections (struct GNUNET_TESTING_PeerGroup *pg, |
4360 | double percentage) | 4377 | double percentage) |
4361 | { | 4378 | { |
4362 | uint32_t pg_iter; | 4379 | uint32_t pg_iter; |
4380 | |||
4363 | #if OLD | 4381 | #if OLD |
4364 | struct PeerConnection *conn_iter; | 4382 | struct PeerConnection *conn_iter; |
4365 | double random_number; | 4383 | double random_number; |
@@ -4368,56 +4386,55 @@ choose_random_connections(struct GNUNET_TESTING_PeerGroup *pg, | |||
4368 | #endif | 4386 | #endif |
4369 | 4387 | ||
4370 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4388 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4371 | { | 4389 | { |
4372 | #if OLD | 4390 | #if OLD |
4373 | conn_iter = pg->peers[pg_iter].connect_peers_head; | 4391 | conn_iter = pg->peers[pg_iter].connect_peers_head; |
4374 | while (conn_iter != NULL) | 4392 | while (conn_iter != NULL) |
4375 | { | 4393 | { |
4376 | random_number | 4394 | random_number |
4377 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 4395 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
4378 | UINT64_MAX)) | 4396 | UINT64_MAX)) |
4379 | / ((double) UINT64_MAX); | 4397 | / ((double) UINT64_MAX); |
4380 | if (random_number < percentage) | 4398 | if (random_number < percentage) |
4381 | { | 4399 | { |
4382 | add_connections (pg, pg_iter, conn_iter->index, WORKING_SET, | 4400 | add_connections (pg, pg_iter, conn_iter->index, WORKING_SET, |
4383 | GNUNET_YES); | 4401 | GNUNET_YES); |
4384 | } | 4402 | } |
4385 | conn_iter = conn_iter->next; | 4403 | conn_iter = conn_iter->next; |
4386 | } | 4404 | } |
4387 | #else | 4405 | #else |
4388 | random_ctx.first_uid = pg_iter; | 4406 | random_ctx.first_uid = pg_iter; |
4389 | random_ctx.first = &pg->peers[pg_iter]; | 4407 | random_ctx.first = &pg->peers[pg_iter]; |
4390 | random_ctx.percentage = percentage; | 4408 | random_ctx.percentage = percentage; |
4391 | random_ctx.pg = pg; | 4409 | random_ctx.pg = pg; |
4392 | pg->peers[pg_iter].connect_peers_working_set | 4410 | pg->peers[pg_iter].connect_peers_working_set |
4393 | = GNUNET_CONTAINER_multihashmap_create (pg->total); | 4411 | = GNUNET_CONTAINER_multihashmap_create (pg->total); |
4394 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers, | 4412 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers, |
4395 | &random_connect_iterator, | 4413 | &random_connect_iterator, |
4396 | &random_ctx); | 4414 | &random_ctx); |
4397 | /* Now remove the old connections */ | 4415 | /* Now remove the old connections */ |
4398 | GNUNET_CONTAINER_multihashmap_destroy (pg-> | 4416 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[pg_iter].connect_peers); |
4399 | peers[pg_iter].connect_peers); | 4417 | /* And replace with the random set */ |
4400 | /* And replace with the random set */ | 4418 | pg->peers[pg_iter].connect_peers |
4401 | pg->peers[pg_iter].connect_peers | 4419 | = pg->peers[pg_iter].connect_peers_working_set; |
4402 | = pg->peers[pg_iter].connect_peers_working_set; | ||
4403 | #endif | 4420 | #endif |
4404 | } | 4421 | } |
4405 | 4422 | ||
4406 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4423 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4407 | { | 4424 | { |
4408 | conn_iter = pg->peers[pg_iter].connect_peers_head; | 4425 | conn_iter = pg->peers[pg_iter].connect_peers_head; |
4409 | while (pg->peers[pg_iter].connect_peers_head != NULL) | 4426 | while (pg->peers[pg_iter].connect_peers_head != NULL) |
4410 | remove_connections (pg, pg_iter, | 4427 | remove_connections (pg, pg_iter, |
4411 | pg->peers[pg_iter].connect_peers_head->index, | 4428 | pg->peers[pg_iter].connect_peers_head->index, |
4412 | CONNECT, GNUNET_YES); | 4429 | CONNECT, GNUNET_YES); |
4413 | 4430 | ||
4414 | pg->peers[pg_iter].connect_peers_head | 4431 | pg->peers[pg_iter].connect_peers_head |
4415 | = pg->peers[pg_iter].connect_peers_working_set_head; | 4432 | = pg->peers[pg_iter].connect_peers_working_set_head; |
4416 | pg->peers[pg_iter].connect_peers_tail | 4433 | pg->peers[pg_iter].connect_peers_tail |
4417 | = pg->peers[pg_iter].connect_peers_working_set_tail; | 4434 | = pg->peers[pg_iter].connect_peers_working_set_tail; |
4418 | pg->peers[pg_iter].connect_peers_working_set_head = NULL; | 4435 | pg->peers[pg_iter].connect_peers_working_set_head = NULL; |
4419 | pg->peers[pg_iter].connect_peers_working_set_tail = NULL; | 4436 | pg->peers[pg_iter].connect_peers_working_set_tail = NULL; |
4420 | } | 4437 | } |
4421 | } | 4438 | } |
4422 | 4439 | ||
4423 | /** | 4440 | /** |
@@ -4428,76 +4445,76 @@ choose_random_connections(struct GNUNET_TESTING_PeerGroup *pg, | |||
4428 | * @return the number of elements in the list | 4445 | * @return the number of elements in the list |
4429 | */ | 4446 | */ |
4430 | static unsigned int | 4447 | static unsigned int |
4431 | count_connections(struct PeerConnection *conn_list) | 4448 | count_connections (struct PeerConnection *conn_list) |
4432 | { | 4449 | { |
4433 | struct PeerConnection *iter; | 4450 | struct PeerConnection *iter; |
4434 | unsigned int count; | 4451 | unsigned int count; |
4452 | |||
4435 | count = 0; | 4453 | count = 0; |
4436 | iter = conn_list; | 4454 | iter = conn_list; |
4437 | while (iter != NULL) | 4455 | while (iter != NULL) |
4438 | { | 4456 | { |
4439 | iter = iter->next; | 4457 | iter = iter->next; |
4440 | count++; | 4458 | count++; |
4441 | } | 4459 | } |
4442 | return count; | 4460 | return count; |
4443 | } | 4461 | } |
4444 | 4462 | ||
4445 | static unsigned int | 4463 | static unsigned int |
4446 | count_workingset_connections(struct GNUNET_TESTING_PeerGroup *pg) | 4464 | count_workingset_connections (struct GNUNET_TESTING_PeerGroup *pg) |
4447 | { | 4465 | { |
4448 | unsigned int count; | 4466 | unsigned int count; |
4449 | unsigned int pg_iter; | 4467 | unsigned int pg_iter; |
4468 | |||
4450 | #if OLD | 4469 | #if OLD |
4451 | struct PeerConnection *conn_iter; | 4470 | struct PeerConnection *conn_iter; |
4452 | #endif | 4471 | #endif |
4453 | count = 0; | 4472 | count = 0; |
4454 | 4473 | ||
4455 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4474 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4456 | { | 4475 | { |
4457 | #if OLD | 4476 | #if OLD |
4458 | conn_iter = pg->peers[pg_iter].connect_peers_working_set_head; | 4477 | conn_iter = pg->peers[pg_iter].connect_peers_working_set_head; |
4459 | while (conn_iter != NULL) | 4478 | while (conn_iter != NULL) |
4460 | { | 4479 | { |
4461 | count++; | 4480 | count++; |
4462 | conn_iter = conn_iter->next; | 4481 | conn_iter = conn_iter->next; |
4463 | } | 4482 | } |
4464 | #else | 4483 | #else |
4465 | count += | 4484 | count += |
4466 | GNUNET_CONTAINER_multihashmap_size (pg-> | 4485 | GNUNET_CONTAINER_multihashmap_size (pg->peers |
4467 | peers | 4486 | [pg_iter].connect_peers_working_set); |
4468 | [pg_iter].connect_peers_working_set); | ||
4469 | #endif | 4487 | #endif |
4470 | } | 4488 | } |
4471 | 4489 | ||
4472 | return count; | 4490 | return count; |
4473 | } | 4491 | } |
4474 | 4492 | ||
4475 | static unsigned int | 4493 | static unsigned int |
4476 | count_allowed_connections(struct GNUNET_TESTING_PeerGroup *pg) | 4494 | count_allowed_connections (struct GNUNET_TESTING_PeerGroup *pg) |
4477 | { | 4495 | { |
4478 | unsigned int count; | 4496 | unsigned int count; |
4479 | unsigned int pg_iter; | 4497 | unsigned int pg_iter; |
4498 | |||
4480 | #if OLD | 4499 | #if OLD |
4481 | struct PeerConnection *conn_iter; | 4500 | struct PeerConnection *conn_iter; |
4482 | #endif | 4501 | #endif |
4483 | 4502 | ||
4484 | count = 0; | 4503 | count = 0; |
4485 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4504 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4486 | { | 4505 | { |
4487 | #if OLD | 4506 | #if OLD |
4488 | conn_iter = pg->peers[pg_iter].allowed_peers_head; | 4507 | conn_iter = pg->peers[pg_iter].allowed_peers_head; |
4489 | while (conn_iter != NULL) | 4508 | while (conn_iter != NULL) |
4490 | { | 4509 | { |
4491 | count++; | 4510 | count++; |
4492 | conn_iter = conn_iter->next; | 4511 | conn_iter = conn_iter->next; |
4493 | } | 4512 | } |
4494 | #else | 4513 | #else |
4495 | count += | 4514 | count += |
4496 | GNUNET_CONTAINER_multihashmap_size (pg-> | 4515 | GNUNET_CONTAINER_multihashmap_size (pg->peers[pg_iter].allowed_peers); |
4497 | peers | ||
4498 | [pg_iter].allowed_peers); | ||
4499 | #endif | 4516 | #endif |
4500 | } | 4517 | } |
4501 | 4518 | ||
4502 | return count; | 4519 | return count; |
4503 | } | 4520 | } |
@@ -4510,7 +4527,7 @@ count_allowed_connections(struct GNUNET_TESTING_PeerGroup *pg) | |||
4510 | * @param num how many connections at least should each peer have (if possible)? | 4527 | * @param num how many connections at least should each peer have (if possible)? |
4511 | */ | 4528 | */ |
4512 | static void | 4529 | static void |
4513 | choose_minimum(struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | 4530 | choose_minimum (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) |
4514 | { | 4531 | { |
4515 | #if !OLD | 4532 | #if !OLD |
4516 | struct MinimumContext minimum_ctx; | 4533 | struct MinimumContext minimum_ctx; |
@@ -4519,113 +4536,110 @@ choose_minimum(struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | |||
4519 | unsigned int temp_list_size; | 4536 | unsigned int temp_list_size; |
4520 | unsigned int i; | 4537 | unsigned int i; |
4521 | unsigned int count; | 4538 | unsigned int count; |
4522 | uint32_t random; /* Random list entry to connect peer to */ | 4539 | uint32_t random; /* Random list entry to connect peer to */ |
4523 | #endif | 4540 | #endif |
4524 | uint32_t pg_iter; | 4541 | uint32_t pg_iter; |
4525 | 4542 | ||
4526 | #if OLD | 4543 | #if OLD |
4527 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4544 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4545 | { | ||
4546 | temp_list_size = count_connections (pg->peers[pg_iter].connect_peers_head); | ||
4547 | if (temp_list_size == 0) | ||
4528 | { | 4548 | { |
4529 | temp_list_size | 4549 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
4530 | = count_connections (pg->peers[pg_iter].connect_peers_head); | 4550 | "Peer %d has 0 connections!?!?\n", pg_iter); |
4531 | if (temp_list_size == 0) | 4551 | break; |
4532 | { | ||
4533 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
4534 | "Peer %d has 0 connections!?!?\n", pg_iter); | ||
4535 | break; | ||
4536 | } | ||
4537 | for (i = 0; i < num; i++) | ||
4538 | { | ||
4539 | random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
4540 | temp_list_size); | ||
4541 | conn_iter = pg->peers[pg_iter].connect_peers_head; | ||
4542 | for (count = 0; count < random; count++) | ||
4543 | conn_iter = conn_iter->next; | ||
4544 | /* We now have a random connection, connect it! */ | ||
4545 | GNUNET_assert(conn_iter != NULL); | ||
4546 | add_connections (pg, pg_iter, conn_iter->index, WORKING_SET, | ||
4547 | GNUNET_YES); | ||
4548 | } | ||
4549 | } | 4552 | } |
4550 | #else | 4553 | for (i = 0; i < num; i++) |
4551 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
4552 | { | 4554 | { |
4553 | pg->peers[pg_iter].connect_peers_working_set = | 4555 | random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
4554 | GNUNET_CONTAINER_multihashmap_create (num); | 4556 | temp_list_size); |
4557 | conn_iter = pg->peers[pg_iter].connect_peers_head; | ||
4558 | for (count = 0; count < random; count++) | ||
4559 | conn_iter = conn_iter->next; | ||
4560 | /* We now have a random connection, connect it! */ | ||
4561 | GNUNET_assert (conn_iter != NULL); | ||
4562 | add_connections (pg, pg_iter, conn_iter->index, WORKING_SET, GNUNET_YES); | ||
4555 | } | 4563 | } |
4564 | } | ||
4565 | #else | ||
4566 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
4567 | { | ||
4568 | pg->peers[pg_iter].connect_peers_working_set = | ||
4569 | GNUNET_CONTAINER_multihashmap_create (num); | ||
4570 | } | ||
4556 | 4571 | ||
4557 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4572 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4558 | { | 4573 | { |
4559 | minimum_ctx.first_uid = pg_iter; | 4574 | minimum_ctx.first_uid = pg_iter; |
4560 | minimum_ctx.pg_array = | 4575 | minimum_ctx.pg_array = |
4561 | GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, | 4576 | GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, |
4562 | GNUNET_CONTAINER_multihashmap_size | 4577 | GNUNET_CONTAINER_multihashmap_size |
4563 | (pg->peers[pg_iter].connect_peers)); | 4578 | (pg->peers[pg_iter].connect_peers)); |
4564 | minimum_ctx.first = &pg->peers[pg_iter]; | 4579 | minimum_ctx.first = &pg->peers[pg_iter]; |
4565 | minimum_ctx.pg = pg; | 4580 | minimum_ctx.pg = pg; |
4566 | minimum_ctx.num_to_add = num; | 4581 | minimum_ctx.num_to_add = num; |
4567 | minimum_ctx.current = 0; | 4582 | minimum_ctx.current = 0; |
4568 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers, | 4583 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers, |
4569 | &minimum_connect_iterator, | 4584 | &minimum_connect_iterator, |
4570 | &minimum_ctx); | 4585 | &minimum_ctx); |
4571 | } | 4586 | } |
4572 | 4587 | ||
4573 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4588 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4574 | { | 4589 | { |
4575 | /* Remove the "old" connections */ | 4590 | /* Remove the "old" connections */ |
4576 | GNUNET_CONTAINER_multihashmap_destroy (pg-> | 4591 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[pg_iter].connect_peers); |
4577 | peers[pg_iter].connect_peers); | 4592 | /* And replace with the working set */ |
4578 | /* And replace with the working set */ | 4593 | pg->peers[pg_iter].connect_peers = |
4579 | pg->peers[pg_iter].connect_peers = | 4594 | pg->peers[pg_iter].connect_peers_working_set; |
4580 | pg->peers[pg_iter].connect_peers_working_set; | 4595 | } |
4581 | } | ||
4582 | #endif | 4596 | #endif |
4583 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4597 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4598 | { | ||
4599 | while (pg->peers[pg_iter].connect_peers_head != NULL) | ||
4584 | { | 4600 | { |
4585 | while (pg->peers[pg_iter].connect_peers_head != NULL) | 4601 | conn_iter = pg->peers[pg_iter].connect_peers_head; |
4586 | { | 4602 | GNUNET_CONTAINER_DLL_remove (pg->peers[pg_iter].connect_peers_head, |
4587 | conn_iter = pg->peers[pg_iter].connect_peers_head; | 4603 | pg->peers[pg_iter].connect_peers_tail, |
4588 | GNUNET_CONTAINER_DLL_remove(pg->peers[pg_iter].connect_peers_head, | 4604 | conn_iter); |
4589 | pg->peers[pg_iter].connect_peers_tail, | 4605 | GNUNET_free (conn_iter); |
4590 | conn_iter); | 4606 | /*remove_connections(pg, pg_iter, pg->peers[pg_iter].connect_peers_head->index, CONNECT, GNUNET_YES); */ |
4591 | GNUNET_free(conn_iter); | 4607 | } |
4592 | /*remove_connections(pg, pg_iter, pg->peers[pg_iter].connect_peers_head->index, CONNECT, GNUNET_YES);*/ | 4608 | |
4593 | } | 4609 | pg->peers[pg_iter].connect_peers_head |
4594 | 4610 | = pg->peers[pg_iter].connect_peers_working_set_head; | |
4595 | pg->peers[pg_iter].connect_peers_head | 4611 | pg->peers[pg_iter].connect_peers_tail |
4596 | = pg->peers[pg_iter].connect_peers_working_set_head; | 4612 | = pg->peers[pg_iter].connect_peers_working_set_tail; |
4597 | pg->peers[pg_iter].connect_peers_tail | 4613 | pg->peers[pg_iter].connect_peers_working_set_head = NULL; |
4598 | = pg->peers[pg_iter].connect_peers_working_set_tail; | 4614 | pg->peers[pg_iter].connect_peers_working_set_tail = NULL; |
4599 | pg->peers[pg_iter].connect_peers_working_set_head = NULL; | 4615 | } |
4600 | pg->peers[pg_iter].connect_peers_working_set_tail = NULL; | ||
4601 | } | ||
4602 | } | 4616 | } |
4603 | 4617 | ||
4604 | #if !OLD | 4618 | #if !OLD |
4605 | struct FindClosestContext | 4619 | struct FindClosestContext |
4606 | { | 4620 | { |
4607 | /** | 4621 | /** |
4608 | * The currently known closest peer. | 4622 | * The currently known closest peer. |
4609 | */ | 4623 | */ |
4610 | struct GNUNET_TESTING_Daemon *closest; | 4624 | struct GNUNET_TESTING_Daemon *closest; |
4611 | 4625 | ||
4612 | /** | 4626 | /** |
4613 | * The info for the peer we are adding connections for. | 4627 | * The info for the peer we are adding connections for. |
4614 | */ | 4628 | */ |
4615 | struct PeerData *curr_peer; | 4629 | struct PeerData *curr_peer; |
4616 | 4630 | ||
4617 | /** | 4631 | /** |
4618 | * The distance (bits) between the current | 4632 | * The distance (bits) between the current |
4619 | * peer and the currently known closest. | 4633 | * peer and the currently known closest. |
4620 | */ | 4634 | */ |
4621 | unsigned int closest_dist; | 4635 | unsigned int closest_dist; |
4622 | 4636 | ||
4623 | /** | 4637 | /** |
4624 | * The offset of the closest known peer in | 4638 | * The offset of the closest known peer in |
4625 | * the peer group. | 4639 | * the peer group. |
4626 | */ | 4640 | */ |
4627 | unsigned int closest_num; | 4641 | unsigned int closest_num; |
4628 | }; | 4642 | }; |
4629 | 4643 | ||
4630 | /** | 4644 | /** |
4631 | * Iterator over hash map entries of the allowed | 4645 | * Iterator over hash map entries of the allowed |
@@ -4641,29 +4655,29 @@ struct FindClosestContext | |||
4641 | */ | 4655 | */ |
4642 | static int | 4656 | static int |
4643 | find_closest_peers (void *cls, const GNUNET_HashCode * key, void *value) | 4657 | find_closest_peers (void *cls, const GNUNET_HashCode * key, void *value) |
4658 | { | ||
4659 | struct FindClosestContext *closest_ctx = cls; | ||
4660 | struct GNUNET_TESTING_Daemon *daemon = value; | ||
4661 | |||
4662 | if (((closest_ctx->closest == NULL) || | ||
4663 | (GNUNET_CRYPTO_hash_matching_bits | ||
4664 | (&daemon->id.hashPubKey, | ||
4665 | &closest_ctx->curr_peer->daemon->id.hashPubKey) > | ||
4666 | closest_ctx->closest_dist)) | ||
4667 | && (GNUNET_YES != | ||
4668 | GNUNET_CONTAINER_multihashmap_contains (closest_ctx-> | ||
4669 | curr_peer->connect_peers, | ||
4670 | key))) | ||
4644 | { | 4671 | { |
4645 | struct FindClosestContext *closest_ctx = cls; | 4672 | closest_ctx->closest_dist = |
4646 | struct GNUNET_TESTING_Daemon *daemon = value; | ||
4647 | |||
4648 | if (((closest_ctx->closest == NULL) || | ||
4649 | (GNUNET_CRYPTO_hash_matching_bits | ||
4650 | (&daemon->id.hashPubKey, | ||
4651 | &closest_ctx->curr_peer->daemon->id.hashPubKey) > | ||
4652 | closest_ctx->closest_dist)) | ||
4653 | && (GNUNET_YES != | ||
4654 | GNUNET_CONTAINER_multihashmap_contains (closest_ctx-> | ||
4655 | curr_peer->connect_peers, | ||
4656 | key))) | ||
4657 | { | ||
4658 | closest_ctx->closest_dist = | ||
4659 | GNUNET_CRYPTO_hash_matching_bits (&daemon->id.hashPubKey, | 4673 | GNUNET_CRYPTO_hash_matching_bits (&daemon->id.hashPubKey, |
4660 | &closest_ctx->curr_peer->daemon-> | 4674 | &closest_ctx->curr_peer->daemon-> |
4661 | id.hashPubKey); | 4675 | id.hashPubKey); |
4662 | closest_ctx->closest = daemon; | 4676 | closest_ctx->closest = daemon; |
4663 | uid_from_hash (key, &closest_ctx->closest_num); | 4677 | uid_from_hash (key, &closest_ctx->closest_num); |
4664 | } | ||
4665 | return GNUNET_YES; | ||
4666 | } | 4678 | } |
4679 | return GNUNET_YES; | ||
4680 | } | ||
4667 | 4681 | ||
4668 | /** | 4682 | /** |
4669 | * From the set of connections possible, choose at num connections per | 4683 | * From the set of connections possible, choose at num connections per |
@@ -4678,36 +4692,34 @@ find_closest_peers (void *cls, const GNUNET_HashCode * key, void *value) | |||
4678 | */ | 4692 | */ |
4679 | void | 4693 | void |
4680 | add_closest (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num, | 4694 | add_closest (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num, |
4681 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 4695 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
4682 | { | 4696 | { |
4683 | #if OLD | 4697 | #if OLD |
4684 | 4698 | ||
4685 | #else | 4699 | #else |
4686 | struct FindClosestContext closest_ctx; | 4700 | struct FindClosestContext closest_ctx; |
4687 | #endif | 4701 | #endif |
4688 | uint32_t pg_iter; | 4702 | uint32_t pg_iter; |
4689 | uint32_t i; | 4703 | uint32_t i; |
4690 | 4704 | ||
4691 | for (i = 0; i < num; i++) /* Each time find a closest peer (from those available) */ | 4705 | for (i = 0; i < num; i++) /* Each time find a closest peer (from those available) */ |
4706 | { | ||
4707 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
4708 | { | ||
4709 | closest_ctx.curr_peer = &pg->peers[pg_iter]; | ||
4710 | closest_ctx.closest = NULL; | ||
4711 | closest_ctx.closest_dist = 0; | ||
4712 | closest_ctx.closest_num = 0; | ||
4713 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].allowed_peers, | ||
4714 | &find_closest_peers, &closest_ctx); | ||
4715 | if (closest_ctx.closest != NULL) | ||
4692 | { | 4716 | { |
4693 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4717 | GNUNET_assert (closest_ctx.closest_num < pg->total); |
4694 | { | 4718 | proc (pg, pg_iter, closest_ctx.closest_num, list); |
4695 | closest_ctx.curr_peer = &pg->peers[pg_iter]; | ||
4696 | closest_ctx.closest = NULL; | ||
4697 | closest_ctx.closest_dist = 0; | ||
4698 | closest_ctx.closest_num = 0; | ||
4699 | GNUNET_CONTAINER_multihashmap_iterate (pg-> | ||
4700 | peers[pg_iter].allowed_peers, | ||
4701 | &find_closest_peers, | ||
4702 | &closest_ctx); | ||
4703 | if (closest_ctx.closest != NULL) | ||
4704 | { | ||
4705 | GNUNET_assert (closest_ctx.closest_num < pg->total); | ||
4706 | proc (pg, pg_iter, closest_ctx.closest_num, list); | ||
4707 | } | ||
4708 | } | ||
4709 | } | 4719 | } |
4720 | } | ||
4710 | } | 4721 | } |
4722 | } | ||
4711 | #endif | 4723 | #endif |
4712 | 4724 | ||
4713 | /** | 4725 | /** |
@@ -4719,13 +4731,14 @@ add_closest (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num, | |||
4719 | * @param num how many connections at least should each peer have (if possible)? | 4731 | * @param num how many connections at least should each peer have (if possible)? |
4720 | */ | 4732 | */ |
4721 | void | 4733 | void |
4722 | perform_dfs(struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | 4734 | perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) |
4723 | { | 4735 | { |
4724 | uint32_t pg_iter; | 4736 | uint32_t pg_iter; |
4725 | uint32_t dfs_count; | 4737 | uint32_t dfs_count; |
4726 | uint32_t starting_peer; | 4738 | uint32_t starting_peer; |
4727 | uint32_t least_connections; | 4739 | uint32_t least_connections; |
4728 | uint32_t random_connection; | 4740 | uint32_t random_connection; |
4741 | |||
4729 | #if OLD | 4742 | #if OLD |
4730 | unsigned int temp_count; | 4743 | unsigned int temp_count; |
4731 | struct PeerConnection *peer_iter; | 4744 | struct PeerConnection *peer_iter; |
@@ -4738,118 +4751,115 @@ perform_dfs(struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | |||
4738 | starting_peer = 0; | 4751 | starting_peer = 0; |
4739 | dfs_count = 0; | 4752 | dfs_count = 0; |
4740 | while ((count_workingset_connections (pg) < num * pg->total) | 4753 | while ((count_workingset_connections (pg) < num * pg->total) |
4741 | && (count_allowed_connections (pg) > 0)) | 4754 | && (count_allowed_connections (pg) > 0)) |
4755 | { | ||
4756 | if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly connected peer */ | ||
4742 | { | 4757 | { |
4743 | if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly connected peer */ | 4758 | least_connections = -1; /* Set to very high number */ |
4759 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
4760 | { | ||
4761 | temp_count | ||
4762 | = | ||
4763 | count_connections (pg-> | ||
4764 | peers[pg_iter].connect_peers_working_set_head); | ||
4765 | if (temp_count < least_connections) | ||
4744 | { | 4766 | { |
4745 | least_connections = -1; /* Set to very high number */ | 4767 | starting_peer = pg_iter; |
4746 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4768 | least_connections = temp_count; |
4747 | { | ||
4748 | temp_count | ||
4749 | = count_connections ( | ||
4750 | pg->peers[pg_iter].connect_peers_working_set_head); | ||
4751 | if (temp_count < least_connections) | ||
4752 | { | ||
4753 | starting_peer = pg_iter; | ||
4754 | least_connections = temp_count; | ||
4755 | } | ||
4756 | } | ||
4757 | } | 4769 | } |
4770 | } | ||
4771 | } | ||
4758 | 4772 | ||
4759 | temp_count | 4773 | temp_count |
4760 | = count_connections (pg->peers[starting_peer].connect_peers_head); | 4774 | = count_connections (pg->peers[starting_peer].connect_peers_head); |
4761 | if (temp_count == 0) | 4775 | if (temp_count == 0) |
4762 | continue; /* FIXME: infinite loop? */ | 4776 | continue; /* FIXME: infinite loop? */ |
4763 | 4777 | ||
4764 | random_connection = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 4778 | random_connection = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
4765 | temp_count); | 4779 | temp_count); |
4766 | temp_count = 0; | 4780 | temp_count = 0; |
4767 | peer_iter = pg->peers[starting_peer].connect_peers_head; | 4781 | peer_iter = pg->peers[starting_peer].connect_peers_head; |
4768 | while (temp_count < random_connection) | 4782 | while (temp_count < random_connection) |
4769 | { | 4783 | { |
4770 | peer_iter = peer_iter->next; | 4784 | peer_iter = peer_iter->next; |
4771 | temp_count++; | 4785 | temp_count++; |
4772 | } | ||
4773 | GNUNET_assert(peer_iter != NULL); | ||
4774 | add_connections (pg, starting_peer, peer_iter->index, WORKING_SET, | ||
4775 | GNUNET_NO); | ||
4776 | remove_connections (pg, starting_peer, peer_iter->index, CONNECT, | ||
4777 | GNUNET_YES); | ||
4778 | starting_peer = peer_iter->index; | ||
4779 | dfs_count++; | ||
4780 | } | 4786 | } |
4787 | GNUNET_assert (peer_iter != NULL); | ||
4788 | add_connections (pg, starting_peer, peer_iter->index, WORKING_SET, | ||
4789 | GNUNET_NO); | ||
4790 | remove_connections (pg, starting_peer, peer_iter->index, CONNECT, | ||
4791 | GNUNET_YES); | ||
4792 | starting_peer = peer_iter->index; | ||
4793 | dfs_count++; | ||
4794 | } | ||
4781 | 4795 | ||
4782 | #else | 4796 | #else |
4783 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4797 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4784 | { | 4798 | { |
4785 | pg->peers[pg_iter].connect_peers_working_set = | 4799 | pg->peers[pg_iter].connect_peers_working_set = |
4786 | GNUNET_CONTAINER_multihashmap_create (num); | 4800 | GNUNET_CONTAINER_multihashmap_create (num); |
4787 | } | 4801 | } |
4788 | 4802 | ||
4789 | starting_peer = 0; | 4803 | starting_peer = 0; |
4790 | dfs_count = 0; | 4804 | dfs_count = 0; |
4791 | while ((count_workingset_connections (pg) < num * pg->total) | 4805 | while ((count_workingset_connections (pg) < num * pg->total) |
4792 | && (count_allowed_connections (pg) > 0)) | 4806 | && (count_allowed_connections (pg) > 0)) |
4807 | { | ||
4808 | if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly connected peer */ | ||
4793 | { | 4809 | { |
4794 | if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly connected peer */ | 4810 | least_connections = -1; /* Set to very high number */ |
4795 | { | 4811 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4796 | least_connections = -1; /* Set to very high number */ | 4812 | { |
4797 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4813 | if (GNUNET_CONTAINER_multihashmap_size |
4798 | { | 4814 | (pg->peers[pg_iter].connect_peers_working_set) < least_connections) |
4799 | if (GNUNET_CONTAINER_multihashmap_size | ||
4800 | (pg->peers[pg_iter].connect_peers_working_set) < | ||
4801 | least_connections) | ||
4802 | { | ||
4803 | starting_peer = pg_iter; | ||
4804 | least_connections = | ||
4805 | GNUNET_CONTAINER_multihashmap_size (pg-> | ||
4806 | peers | ||
4807 | [pg_iter].connect_peers_working_set); | ||
4808 | } | ||
4809 | } | ||
4810 | } | ||
4811 | |||
4812 | if (GNUNET_CONTAINER_multihashmap_size (pg->peers[starting_peer].connect_peers) == 0) /* Ensure there is at least one peer left to connect! */ | ||
4813 | { | 4815 | { |
4814 | dfs_count = 0; | 4816 | starting_peer = pg_iter; |
4815 | continue; | 4817 | least_connections = |
4818 | GNUNET_CONTAINER_multihashmap_size (pg->peers | ||
4819 | [pg_iter].connect_peers_working_set); | ||
4816 | } | 4820 | } |
4817 | 4821 | } | |
4818 | /* Choose a random peer from the chosen peers set of connections to add */ | ||
4819 | dfs_ctx.chosen = | ||
4820 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
4821 | GNUNET_CONTAINER_multihashmap_size | ||
4822 | (pg->peers[starting_peer].connect_peers)); | ||
4823 | dfs_ctx.first_uid = starting_peer; | ||
4824 | dfs_ctx.first = &pg->peers[starting_peer]; | ||
4825 | dfs_ctx.pg = pg; | ||
4826 | dfs_ctx.current = 0; | ||
4827 | |||
4828 | GNUNET_CONTAINER_multihashmap_iterate (pg-> | ||
4829 | peers | ||
4830 | [starting_peer].connect_peers, | ||
4831 | &dfs_connect_iterator, &dfs_ctx); | ||
4832 | /* Remove the second from the first, since we will be continuing the search and may encounter the first peer again! */ | ||
4833 | hash_from_uid (dfs_ctx.second_uid, &second_hash); | ||
4834 | GNUNET_assert (GNUNET_YES == | ||
4835 | GNUNET_CONTAINER_multihashmap_remove (pg->peers | ||
4836 | [starting_peer].connect_peers, | ||
4837 | &second_hash, | ||
4838 | pg-> | ||
4839 | peers | ||
4840 | [dfs_ctx.second_uid].daemon)); | ||
4841 | starting_peer = dfs_ctx.second_uid; | ||
4842 | } | 4822 | } |
4843 | 4823 | ||
4844 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4824 | if (GNUNET_CONTAINER_multihashmap_size (pg->peers[starting_peer].connect_peers) == 0) /* Ensure there is at least one peer left to connect! */ |
4845 | { | 4825 | { |
4846 | /* Remove the "old" connections */ | 4826 | dfs_count = 0; |
4847 | GNUNET_CONTAINER_multihashmap_destroy (pg-> | 4827 | continue; |
4848 | peers[pg_iter].connect_peers); | ||
4849 | /* And replace with the working set */ | ||
4850 | pg->peers[pg_iter].connect_peers = | ||
4851 | pg->peers[pg_iter].connect_peers_working_set; | ||
4852 | } | 4828 | } |
4829 | |||
4830 | /* Choose a random peer from the chosen peers set of connections to add */ | ||
4831 | dfs_ctx.chosen = | ||
4832 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
4833 | GNUNET_CONTAINER_multihashmap_size | ||
4834 | (pg->peers[starting_peer].connect_peers)); | ||
4835 | dfs_ctx.first_uid = starting_peer; | ||
4836 | dfs_ctx.first = &pg->peers[starting_peer]; | ||
4837 | dfs_ctx.pg = pg; | ||
4838 | dfs_ctx.current = 0; | ||
4839 | |||
4840 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers | ||
4841 | [starting_peer].connect_peers, | ||
4842 | &dfs_connect_iterator, &dfs_ctx); | ||
4843 | /* Remove the second from the first, since we will be continuing the search and may encounter the first peer again! */ | ||
4844 | hash_from_uid (dfs_ctx.second_uid, &second_hash); | ||
4845 | GNUNET_assert (GNUNET_YES == | ||
4846 | GNUNET_CONTAINER_multihashmap_remove (pg->peers | ||
4847 | [starting_peer].connect_peers, | ||
4848 | &second_hash, | ||
4849 | pg-> | ||
4850 | peers | ||
4851 | [dfs_ctx.second_uid].daemon)); | ||
4852 | starting_peer = dfs_ctx.second_uid; | ||
4853 | } | ||
4854 | |||
4855 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
4856 | { | ||
4857 | /* Remove the "old" connections */ | ||
4858 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[pg_iter].connect_peers); | ||
4859 | /* And replace with the working set */ | ||
4860 | pg->peers[pg_iter].connect_peers = | ||
4861 | pg->peers[pg_iter].connect_peers_working_set; | ||
4862 | } | ||
4853 | #endif | 4863 | #endif |
4854 | } | 4864 | } |
4855 | 4865 | ||
@@ -4857,30 +4867,30 @@ perform_dfs(struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | |||
4857 | * Internal callback for topology information for a particular peer. | 4867 | * Internal callback for topology information for a particular peer. |
4858 | */ | 4868 | */ |
4859 | static void | 4869 | static void |
4860 | internal_topology_callback(void *cls, const struct GNUNET_PeerIdentity *peer, | 4870 | internal_topology_callback (void *cls, const struct GNUNET_PeerIdentity *peer, |
4861 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 4871 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
4862 | { | 4872 | { |
4863 | struct CoreContext *core_ctx = cls; | 4873 | struct CoreContext *core_ctx = cls; |
4864 | struct TopologyIterateContext *iter_ctx = core_ctx->iter_context; | 4874 | struct TopologyIterateContext *iter_ctx = core_ctx->iter_context; |
4865 | 4875 | ||
4866 | if (peer == NULL) /* Either finished, or something went wrong */ | 4876 | if (peer == NULL) /* Either finished, or something went wrong */ |
4867 | { | 4877 | { |
4868 | iter_ctx->completed++; | 4878 | iter_ctx->completed++; |
4869 | iter_ctx->connected--; | 4879 | iter_ctx->connected--; |
4870 | /* One core context allocated per iteration, must free! */ | 4880 | /* One core context allocated per iteration, must free! */ |
4871 | GNUNET_free (core_ctx); | 4881 | GNUNET_free (core_ctx); |
4872 | } | 4882 | } |
4873 | else | 4883 | else |
4874 | { | 4884 | { |
4875 | iter_ctx->topology_cb (iter_ctx->cls, &core_ctx->daemon->id, peer, NULL); | 4885 | iter_ctx->topology_cb (iter_ctx->cls, &core_ctx->daemon->id, peer, NULL); |
4876 | } | 4886 | } |
4877 | 4887 | ||
4878 | if (iter_ctx->completed == iter_ctx->total) | 4888 | if (iter_ctx->completed == iter_ctx->total) |
4879 | { | 4889 | { |
4880 | iter_ctx->topology_cb (iter_ctx->cls, NULL, NULL, NULL); | 4890 | iter_ctx->topology_cb (iter_ctx->cls, NULL, NULL, NULL); |
4881 | /* Once all are done, free the iteration context */ | 4891 | /* Once all are done, free the iteration context */ |
4882 | GNUNET_free (iter_ctx); | 4892 | GNUNET_free (iter_ctx); |
4883 | } | 4893 | } |
4884 | } | 4894 | } |
4885 | 4895 | ||
4886 | /** | 4896 | /** |
@@ -4888,45 +4898,43 @@ internal_topology_callback(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4888 | * schedule for some time in the future. | 4898 | * schedule for some time in the future. |
4889 | */ | 4899 | */ |
4890 | static void | 4900 | static void |
4891 | schedule_get_topology(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 4901 | schedule_get_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
4892 | { | 4902 | { |
4893 | struct CoreContext *core_context = cls; | 4903 | struct CoreContext *core_context = cls; |
4894 | struct TopologyIterateContext *topology_context = | 4904 | struct TopologyIterateContext *topology_context = |
4895 | (struct TopologyIterateContext *) core_context->iter_context; | 4905 | (struct TopologyIterateContext *) core_context->iter_context; |
4896 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 4906 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
4897 | return; | 4907 | return; |
4898 | 4908 | ||
4899 | if (topology_context->connected | 4909 | if (topology_context->connected |
4900 | > topology_context->pg->max_outstanding_connections) | 4910 | > topology_context->pg->max_outstanding_connections) |
4901 | { | 4911 | { |
4902 | #if VERBOSE_TESTING > 2 | 4912 | #if VERBOSE_TESTING > 2 |
4903 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4913 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4904 | _ | 4914 | _ |
4905 | ("Delaying connect, we have too many outstanding connections!\n")); | 4915 | ("Delaying connect, we have too many outstanding connections!\n")); |
4906 | #endif | 4916 | #endif |
4907 | GNUNET_SCHEDULER_add_delayed ( | 4917 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
4908 | GNUNET_TIME_relative_multiply ( | 4918 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
4909 | GNUNET_TIME_UNIT_MILLISECONDS, | 4919 | &schedule_get_topology, core_context); |
4910 | 100), | 4920 | } |
4911 | &schedule_get_topology, core_context); | ||
4912 | } | ||
4913 | else | 4921 | else |
4914 | { | 4922 | { |
4915 | #if VERBOSE_TESTING > 2 | 4923 | #if VERBOSE_TESTING > 2 |
4916 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4924 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4917 | _("Creating connection, outstanding_connections is %d\n"), | 4925 | _("Creating connection, outstanding_connections is %d\n"), |
4918 | outstanding_connects); | 4926 | outstanding_connects); |
4919 | #endif | 4927 | #endif |
4920 | topology_context->connected++; | 4928 | topology_context->connected++; |
4921 | 4929 | ||
4922 | if (GNUNET_OK != GNUNET_CORE_iterate_peers (core_context->daemon->cfg, | 4930 | if (GNUNET_OK != GNUNET_CORE_iterate_peers (core_context->daemon->cfg, |
4923 | &internal_topology_callback, | 4931 | &internal_topology_callback, |
4924 | core_context)) | 4932 | core_context)) |
4925 | { | 4933 | { |
4926 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Topology iteration failed.\n"); | 4934 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Topology iteration failed.\n"); |
4927 | internal_topology_callback (core_context, NULL, NULL); | 4935 | internal_topology_callback (core_context, NULL, NULL); |
4928 | } | ||
4929 | } | 4936 | } |
4937 | } | ||
4930 | } | 4938 | } |
4931 | 4939 | ||
4932 | /** | 4940 | /** |
@@ -4934,8 +4942,8 @@ schedule_get_topology(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
4934 | * all connections that each currently has. | 4942 | * all connections that each currently has. |
4935 | */ | 4943 | */ |
4936 | void | 4944 | void |
4937 | GNUNET_TESTING_get_topology(struct GNUNET_TESTING_PeerGroup *pg, | 4945 | GNUNET_TESTING_get_topology (struct GNUNET_TESTING_PeerGroup *pg, |
4938 | GNUNET_TESTING_NotifyTopology cb, void *cls) | 4946 | GNUNET_TESTING_NotifyTopology cb, void *cls) |
4939 | { | 4947 | { |
4940 | struct TopologyIterateContext *topology_context; | 4948 | struct TopologyIterateContext *topology_context; |
4941 | struct CoreContext *core_ctx; | 4949 | struct CoreContext *core_ctx; |
@@ -4949,23 +4957,23 @@ GNUNET_TESTING_get_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4949 | topology_context->pg = pg; | 4957 | topology_context->pg = pg; |
4950 | total_count = 0; | 4958 | total_count = 0; |
4951 | for (i = 0; i < pg->total; i++) | 4959 | for (i = 0; i < pg->total; i++) |
4960 | { | ||
4961 | if (pg->peers[i].daemon->running == GNUNET_YES) | ||
4952 | { | 4962 | { |
4953 | if (pg->peers[i].daemon->running == GNUNET_YES) | 4963 | /* Allocate one core context per core we need to connect to */ |
4954 | { | 4964 | core_ctx = GNUNET_malloc (sizeof (struct CoreContext)); |
4955 | /* Allocate one core context per core we need to connect to */ | 4965 | core_ctx->daemon = pg->peers[i].daemon; |
4956 | core_ctx = GNUNET_malloc (sizeof (struct CoreContext)); | 4966 | /* Set back pointer to topology iteration context */ |
4957 | core_ctx->daemon = pg->peers[i].daemon; | 4967 | core_ctx->iter_context = topology_context; |
4958 | /* Set back pointer to topology iteration context */ | 4968 | GNUNET_SCHEDULER_add_now (&schedule_get_topology, core_ctx); |
4959 | core_ctx->iter_context = topology_context; | 4969 | total_count++; |
4960 | GNUNET_SCHEDULER_add_now (&schedule_get_topology, core_ctx); | ||
4961 | total_count++; | ||
4962 | } | ||
4963 | } | 4970 | } |
4971 | } | ||
4964 | if (total_count == 0) | 4972 | if (total_count == 0) |
4965 | { | 4973 | { |
4966 | cb (cls, NULL, NULL, "Cannot iterate over topology, no running peers!"); | 4974 | cb (cls, NULL, NULL, "Cannot iterate over topology, no running peers!"); |
4967 | GNUNET_free (topology_context); | 4975 | GNUNET_free (topology_context); |
4968 | } | 4976 | } |
4969 | else | 4977 | else |
4970 | topology_context->total = total_count; | 4978 | topology_context->total = total_count; |
4971 | return; | 4979 | return; |
@@ -4985,8 +4993,8 @@ GNUNET_TESTING_get_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4985 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration | 4993 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration |
4986 | */ | 4994 | */ |
4987 | static int | 4995 | static int |
4988 | internal_stats_callback(void *cls, const char *subsystem, const char *name, | 4996 | internal_stats_callback (void *cls, const char *subsystem, const char *name, |
4989 | uint64_t value, int is_persistent) | 4997 | uint64_t value, int is_persistent) |
4990 | { | 4998 | { |
4991 | struct StatsCoreContext *core_context = cls; | 4999 | struct StatsCoreContext *core_context = cls; |
4992 | struct StatsIterateContext *stats_context = | 5000 | struct StatsIterateContext *stats_context = |
@@ -5004,7 +5012,7 @@ internal_stats_callback(void *cls, const char *subsystem, const char *name, | |||
5004 | * was canceled or not (we don't care) | 5012 | * was canceled or not (we don't care) |
5005 | */ | 5013 | */ |
5006 | static void | 5014 | static void |
5007 | internal_stats_cont(void *cls, int success) | 5015 | internal_stats_cont (void *cls, int success) |
5008 | { | 5016 | { |
5009 | struct StatsCoreContext *core_context = cls; | 5017 | struct StatsCoreContext *core_context = cls; |
5010 | struct StatsIterateContext *stats_context = | 5018 | struct StatsIterateContext *stats_context = |
@@ -5014,10 +5022,10 @@ internal_stats_cont(void *cls, int success) | |||
5014 | stats_context->completed++; | 5022 | stats_context->completed++; |
5015 | 5023 | ||
5016 | if (stats_context->completed == stats_context->total) | 5024 | if (stats_context->completed == stats_context->total) |
5017 | { | 5025 | { |
5018 | stats_context->cont (stats_context->cls, GNUNET_YES); | 5026 | stats_context->cont (stats_context->cls, GNUNET_YES); |
5019 | GNUNET_free (stats_context); | 5027 | GNUNET_free (stats_context); |
5020 | } | 5028 | } |
5021 | 5029 | ||
5022 | if (core_context->stats_handle != NULL) | 5030 | if (core_context->stats_handle != NULL) |
5023 | GNUNET_STATISTICS_destroy (core_context->stats_handle, GNUNET_NO); | 5031 | GNUNET_STATISTICS_destroy (core_context->stats_handle, GNUNET_NO); |
@@ -5030,55 +5038,53 @@ internal_stats_cont(void *cls, int success) | |||
5030 | * schedule for some time in the future. | 5038 | * schedule for some time in the future. |
5031 | */ | 5039 | */ |
5032 | static void | 5040 | static void |
5033 | schedule_get_statistics(void *cls, | 5041 | schedule_get_statistics (void *cls, |
5034 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 5042 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
5035 | { | 5043 | { |
5036 | struct StatsCoreContext *core_context = cls; | 5044 | struct StatsCoreContext *core_context = cls; |
5037 | struct StatsIterateContext *stats_context = | 5045 | struct StatsIterateContext *stats_context = |
5038 | (struct StatsIterateContext *) core_context->iter_context; | 5046 | (struct StatsIterateContext *) core_context->iter_context; |
5039 | 5047 | ||
5040 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 5048 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
5041 | return; | 5049 | return; |
5042 | 5050 | ||
5043 | if (stats_context->connected > stats_context->pg->max_outstanding_connections) | 5051 | if (stats_context->connected > stats_context->pg->max_outstanding_connections) |
5044 | { | 5052 | { |
5045 | #if VERBOSE_TESTING > 2 | 5053 | #if VERBOSE_TESTING > 2 |
5046 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5054 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5047 | _ | 5055 | _ |
5048 | ("Delaying connect, we have too many outstanding connections!\n")); | 5056 | ("Delaying connect, we have too many outstanding connections!\n")); |
5049 | #endif | 5057 | #endif |
5050 | GNUNET_SCHEDULER_add_delayed ( | 5058 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
5051 | GNUNET_TIME_relative_multiply ( | 5059 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
5052 | GNUNET_TIME_UNIT_MILLISECONDS, | 5060 | &schedule_get_statistics, core_context); |
5053 | 100), | 5061 | } |
5054 | &schedule_get_statistics, core_context); | ||
5055 | } | ||
5056 | else | 5062 | else |
5057 | { | 5063 | { |
5058 | #if VERBOSE_TESTING > 2 | 5064 | #if VERBOSE_TESTING > 2 |
5059 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5065 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5060 | _("Creating connection, outstanding_connections is %d\n"), | 5066 | _("Creating connection, outstanding_connections is %d\n"), |
5061 | outstanding_connects); | 5067 | outstanding_connects); |
5062 | #endif | 5068 | #endif |
5063 | 5069 | ||
5064 | stats_context->connected++; | 5070 | stats_context->connected++; |
5065 | core_context->stats_handle | 5071 | core_context->stats_handle |
5066 | = GNUNET_STATISTICS_create ("testing", core_context->daemon->cfg); | 5072 | = GNUNET_STATISTICS_create ("testing", core_context->daemon->cfg); |
5067 | if (core_context->stats_handle == NULL) | 5073 | if (core_context->stats_handle == NULL) |
5068 | { | 5074 | { |
5069 | internal_stats_cont (core_context, GNUNET_NO); | 5075 | internal_stats_cont (core_context, GNUNET_NO); |
5070 | return; | 5076 | return; |
5071 | } | 5077 | } |
5072 | 5078 | ||
5073 | core_context->stats_get_handle | 5079 | core_context->stats_get_handle |
5074 | = GNUNET_STATISTICS_get (core_context->stats_handle, NULL, NULL, | 5080 | = GNUNET_STATISTICS_get (core_context->stats_handle, NULL, NULL, |
5075 | GNUNET_TIME_relative_get_forever (), | 5081 | GNUNET_TIME_relative_get_forever (), |
5076 | &internal_stats_cont, | 5082 | &internal_stats_cont, |
5077 | &internal_stats_callback, core_context); | 5083 | &internal_stats_callback, core_context); |
5078 | if (core_context->stats_get_handle == NULL) | 5084 | if (core_context->stats_get_handle == NULL) |
5079 | internal_stats_cont (core_context, GNUNET_NO); | 5085 | internal_stats_cont (core_context, GNUNET_NO); |
5080 | 5086 | ||
5081 | } | 5087 | } |
5082 | } | 5088 | } |
5083 | 5089 | ||
5084 | struct DuplicateStats | 5090 | struct DuplicateStats |
@@ -5106,18 +5112,19 @@ struct DuplicateStats | |||
5106 | * GNUNET_NO if not (and we may have added it to the list) | 5112 | * GNUNET_NO if not (and we may have added it to the list) |
5107 | */ | 5113 | */ |
5108 | static int | 5114 | static int |
5109 | stats_check_existing(struct GNUNET_TESTING_PeerGroup *pg, | 5115 | stats_check_existing (struct GNUNET_TESTING_PeerGroup *pg, |
5110 | struct PeerData *specific_peer, | 5116 | struct PeerData *specific_peer, |
5111 | struct DuplicateStats **stats_list) | 5117 | struct DuplicateStats **stats_list) |
5112 | { | 5118 | { |
5113 | struct DuplicateStats *pos; | 5119 | struct DuplicateStats *pos; |
5114 | char *unix_domain_socket; | 5120 | char *unix_domain_socket; |
5115 | unsigned long long port; | 5121 | unsigned long long port; |
5116 | char *to_match; | 5122 | char *to_match; |
5123 | |||
5117 | if (GNUNET_YES | 5124 | if (GNUNET_YES |
5118 | != GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "testing", | 5125 | != GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "testing", |
5119 | "single_statistics_per_host")) | 5126 | "single_statistics_per_host")) |
5120 | return GNUNET_NO; /* Each peer has its own statistics instance, do nothing! */ | 5127 | return GNUNET_NO; /* Each peer has its own statistics instance, do nothing! */ |
5121 | 5128 | ||
5122 | pos = *stats_list; | 5129 | pos = *stats_list; |
5123 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (specific_peer->cfg, | 5130 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (specific_peer->cfg, |
@@ -5129,10 +5136,10 @@ stats_check_existing(struct GNUNET_TESTING_PeerGroup *pg, | |||
5129 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (specific_peer->cfg, | 5136 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (specific_peer->cfg, |
5130 | "statistics", "port", | 5137 | "statistics", "port", |
5131 | &port)) | 5138 | &port)) |
5132 | { | 5139 | { |
5133 | GNUNET_free(unix_domain_socket); | 5140 | GNUNET_free (unix_domain_socket); |
5134 | return GNUNET_NO; | 5141 | return GNUNET_NO; |
5135 | } | 5142 | } |
5136 | 5143 | ||
5137 | if (specific_peer->daemon->hostname != NULL) | 5144 | if (specific_peer->daemon->hostname != NULL) |
5138 | GNUNET_asprintf (&to_match, "%s%s%llu", specific_peer->daemon->hostname, | 5145 | GNUNET_asprintf (&to_match, "%s%s%llu", specific_peer->daemon->hostname, |
@@ -5141,15 +5148,15 @@ stats_check_existing(struct GNUNET_TESTING_PeerGroup *pg, | |||
5141 | GNUNET_asprintf (&to_match, "%s%llu", unix_domain_socket, port); | 5148 | GNUNET_asprintf (&to_match, "%s%llu", unix_domain_socket, port); |
5142 | 5149 | ||
5143 | while (pos != NULL) | 5150 | while (pos != NULL) |
5151 | { | ||
5152 | if (0 == strcmp (to_match, pos->unique_string)) | ||
5144 | { | 5153 | { |
5145 | if (0 == strcmp (to_match, pos->unique_string)) | 5154 | GNUNET_free (unix_domain_socket); |
5146 | { | 5155 | GNUNET_free (to_match); |
5147 | GNUNET_free (unix_domain_socket); | 5156 | return GNUNET_YES; |
5148 | GNUNET_free (to_match); | ||
5149 | return GNUNET_YES; | ||
5150 | } | ||
5151 | pos = pos->next; | ||
5152 | } | 5157 | } |
5158 | pos = pos->next; | ||
5159 | } | ||
5153 | pos = GNUNET_malloc (sizeof (struct DuplicateStats)); | 5160 | pos = GNUNET_malloc (sizeof (struct DuplicateStats)); |
5154 | pos->unique_string = to_match; | 5161 | pos->unique_string = to_match; |
5155 | pos->next = *stats_list; | 5162 | pos->next = *stats_list; |
@@ -5169,10 +5176,10 @@ stats_check_existing(struct GNUNET_TESTING_PeerGroup *pg, | |||
5169 | * | 5176 | * |
5170 | */ | 5177 | */ |
5171 | void | 5178 | void |
5172 | GNUNET_TESTING_get_statistics(struct GNUNET_TESTING_PeerGroup *pg, | 5179 | GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg, |
5173 | GNUNET_STATISTICS_Callback cont, | 5180 | GNUNET_STATISTICS_Callback cont, |
5174 | GNUNET_TESTING_STATISTICS_Iterator proc, | 5181 | GNUNET_TESTING_STATISTICS_Iterator proc, |
5175 | void *cls) | 5182 | void *cls) |
5176 | { | 5183 | { |
5177 | struct StatsIterateContext *stats_context; | 5184 | struct StatsIterateContext *stats_context; |
5178 | struct StatsCoreContext *core_ctx; | 5185 | struct StatsCoreContext *core_ctx; |
@@ -5180,6 +5187,7 @@ GNUNET_TESTING_get_statistics(struct GNUNET_TESTING_PeerGroup *pg, | |||
5180 | unsigned int total_count; | 5187 | unsigned int total_count; |
5181 | struct DuplicateStats *stats_list; | 5188 | struct DuplicateStats *stats_list; |
5182 | struct DuplicateStats *pos; | 5189 | struct DuplicateStats *pos; |
5190 | |||
5183 | stats_list = NULL; | 5191 | stats_list = NULL; |
5184 | 5192 | ||
5185 | /* Allocate a single stats iteration context */ | 5193 | /* Allocate a single stats iteration context */ |
@@ -5191,34 +5199,37 @@ GNUNET_TESTING_get_statistics(struct GNUNET_TESTING_PeerGroup *pg, | |||
5191 | total_count = 0; | 5199 | total_count = 0; |
5192 | 5200 | ||
5193 | for (i = 0; i < pg->total; i++) | 5201 | for (i = 0; i < pg->total; i++) |
5194 | { | 5202 | { |
5195 | if ((pg->peers[i].daemon->running == GNUNET_YES) && (GNUNET_NO | 5203 | if ((pg->peers[i].daemon->running == GNUNET_YES) && (GNUNET_NO |
5196 | == stats_check_existing (pg, &pg->peers[i], &stats_list))) | 5204 | == |
5197 | { | 5205 | stats_check_existing |
5198 | /* Allocate one core context per core we need to connect to */ | 5206 | (pg, &pg->peers[i], |
5199 | core_ctx = GNUNET_malloc (sizeof (struct StatsCoreContext)); | 5207 | &stats_list))) |
5200 | core_ctx->daemon = pg->peers[i].daemon; | 5208 | { |
5201 | /* Set back pointer to topology iteration context */ | 5209 | /* Allocate one core context per core we need to connect to */ |
5202 | core_ctx->iter_context = stats_context; | 5210 | core_ctx = GNUNET_malloc (sizeof (struct StatsCoreContext)); |
5203 | GNUNET_SCHEDULER_add_now (&schedule_get_statistics, core_ctx); | 5211 | core_ctx->daemon = pg->peers[i].daemon; |
5204 | total_count++; | 5212 | /* Set back pointer to topology iteration context */ |
5205 | } | 5213 | core_ctx->iter_context = stats_context; |
5214 | GNUNET_SCHEDULER_add_now (&schedule_get_statistics, core_ctx); | ||
5215 | total_count++; | ||
5206 | } | 5216 | } |
5217 | } | ||
5207 | 5218 | ||
5208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5219 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5209 | "Retrieving stats from %u total instances.\n", total_count); | 5220 | "Retrieving stats from %u total instances.\n", total_count); |
5210 | stats_context->total = total_count; | 5221 | stats_context->total = total_count; |
5211 | if (stats_list != NULL) | 5222 | if (stats_list != NULL) |
5223 | { | ||
5224 | pos = stats_list; | ||
5225 | while (pos != NULL) | ||
5212 | { | 5226 | { |
5213 | pos = stats_list; | 5227 | GNUNET_free (pos->unique_string); |
5214 | while (pos != NULL) | 5228 | stats_list = pos->next; |
5215 | { | 5229 | GNUNET_free (pos); |
5216 | GNUNET_free (pos->unique_string); | 5230 | pos = stats_list->next; |
5217 | stats_list = pos->next; | ||
5218 | GNUNET_free (pos); | ||
5219 | pos = stats_list->next; | ||
5220 | } | ||
5221 | } | 5231 | } |
5232 | } | ||
5222 | return; | 5233 | return; |
5223 | } | 5234 | } |
5224 | 5235 | ||
@@ -5228,7 +5239,7 @@ GNUNET_TESTING_get_statistics(struct GNUNET_TESTING_PeerGroup *pg, | |||
5228 | * @param pg the peer group to stop connecting | 5239 | * @param pg the peer group to stop connecting |
5229 | */ | 5240 | */ |
5230 | void | 5241 | void |
5231 | GNUNET_TESTING_stop_connections(struct GNUNET_TESTING_PeerGroup *pg) | 5242 | GNUNET_TESTING_stop_connections (struct GNUNET_TESTING_PeerGroup *pg) |
5232 | { | 5243 | { |
5233 | pg->stop_connects = GNUNET_YES; | 5244 | pg->stop_connects = GNUNET_YES; |
5234 | } | 5245 | } |
@@ -5239,7 +5250,7 @@ GNUNET_TESTING_stop_connections(struct GNUNET_TESTING_PeerGroup *pg) | |||
5239 | * @param pg the peer group to resume connecting | 5250 | * @param pg the peer group to resume connecting |
5240 | */ | 5251 | */ |
5241 | void | 5252 | void |
5242 | GNUNET_TESTING_resume_connections(struct GNUNET_TESTING_PeerGroup *pg) | 5253 | GNUNET_TESTING_resume_connections (struct GNUNET_TESTING_PeerGroup *pg) |
5243 | { | 5254 | { |
5244 | pg->stop_connects = GNUNET_NO; | 5255 | pg->stop_connects = GNUNET_NO; |
5245 | } | 5256 | } |
@@ -5267,18 +5278,17 @@ GNUNET_TESTING_resume_connections(struct GNUNET_TESTING_PeerGroup *pg) | |||
5267 | * @return the number of connections that will be attempted, GNUNET_SYSERR on error | 5278 | * @return the number of connections that will be attempted, GNUNET_SYSERR on error |
5268 | */ | 5279 | */ |
5269 | int | 5280 | int |
5270 | GNUNET_TESTING_connect_topology( | 5281 | GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg, |
5271 | struct GNUNET_TESTING_PeerGroup *pg, | 5282 | enum GNUNET_TESTING_Topology topology, |
5272 | enum GNUNET_TESTING_Topology topology, | 5283 | enum GNUNET_TESTING_TopologyOption options, |
5273 | enum GNUNET_TESTING_TopologyOption options, | 5284 | double option_modifier, |
5274 | double option_modifier, | 5285 | struct GNUNET_TIME_Relative connect_timeout, |
5275 | struct GNUNET_TIME_Relative connect_timeout, | 5286 | unsigned int connect_attempts, |
5276 | unsigned int connect_attempts, | 5287 | GNUNET_TESTING_NotifyCompletion |
5277 | GNUNET_TESTING_NotifyCompletion notify_callback, | 5288 | notify_callback, void *notify_cls) |
5278 | void *notify_cls) | ||
5279 | { | 5289 | { |
5280 | switch (topology) | 5290 | switch (topology) |
5281 | { | 5291 | { |
5282 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: | 5292 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: |
5283 | #if VERBOSE_TOPOLOGY | 5293 | #if VERBOSE_TOPOLOGY |
5284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5294 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -5349,17 +5359,17 @@ GNUNET_TESTING_connect_topology( | |||
5349 | break; | 5359 | break; |
5350 | default: | 5360 | default: |
5351 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ | 5361 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ |
5352 | ("Unknown topology specification, can't connect peers!\n")); | 5362 | ("Unknown topology specification, can't connect peers!\n")); |
5353 | return GNUNET_SYSERR; | 5363 | return GNUNET_SYSERR; |
5354 | } | 5364 | } |
5355 | 5365 | ||
5356 | switch (options) | 5366 | switch (options) |
5357 | { | 5367 | { |
5358 | case GNUNET_TESTING_TOPOLOGY_OPTION_RANDOM: | 5368 | case GNUNET_TESTING_TOPOLOGY_OPTION_RANDOM: |
5359 | #if VERBOSE_TOPOLOGY | 5369 | #if VERBOSE_TOPOLOGY |
5360 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ | 5370 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ |
5361 | ("Connecting random subset (%'.2f percent) of possible peers\n"), 100 | 5371 | ("Connecting random subset (%'.2f percent) of possible peers\n"), |
5362 | * option_modifier); | 5372 | 100 * option_modifier); |
5363 | #endif | 5373 | #endif |
5364 | choose_random_connections (pg, option_modifier); | 5374 | choose_random_connections (pg, option_modifier); |
5365 | break; | 5375 | break; |
@@ -5374,7 +5384,7 @@ GNUNET_TESTING_connect_topology( | |||
5374 | case GNUNET_TESTING_TOPOLOGY_OPTION_DFS: | 5384 | case GNUNET_TESTING_TOPOLOGY_OPTION_DFS: |
5375 | #if VERBOSE_TOPOLOGY | 5385 | #if VERBOSE_TOPOLOGY |
5376 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ | 5386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ |
5377 | ("Using DFS to connect a minimum of %u peers each (if possible)\n"), | 5387 | ("Using DFS to connect a minimum of %u peers each (if possible)\n"), |
5378 | (unsigned int) option_modifier); | 5388 | (unsigned int) option_modifier); |
5379 | #endif | 5389 | #endif |
5380 | #if FIXME | 5390 | #if FIXME |
@@ -5384,12 +5394,11 @@ GNUNET_TESTING_connect_topology( | |||
5384 | case GNUNET_TESTING_TOPOLOGY_OPTION_ADD_CLOSEST: | 5394 | case GNUNET_TESTING_TOPOLOGY_OPTION_ADD_CLOSEST: |
5385 | #if VERBOSE_TOPOLOGY | 5395 | #if VERBOSE_TOPOLOGY |
5386 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ | 5396 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ |
5387 | ("Finding additional %u closest peers each (if possible)\n"), | 5397 | ("Finding additional %u closest peers each (if possible)\n"), |
5388 | (unsigned int) option_modifier); | 5398 | (unsigned int) option_modifier); |
5389 | #endif | 5399 | #endif |
5390 | #if FIXME | 5400 | #if FIXME |
5391 | add_closest (pg, (unsigned int) option_modifier, | 5401 | add_closest (pg, (unsigned int) option_modifier, &add_connections, CONNECT); |
5392 | &add_connections, CONNECT); | ||
5393 | #endif | 5402 | #endif |
5394 | break; | 5403 | break; |
5395 | case GNUNET_TESTING_TOPOLOGY_OPTION_NONE: | 5404 | case GNUNET_TESTING_TOPOLOGY_OPTION_NONE: |
@@ -5398,7 +5407,7 @@ GNUNET_TESTING_connect_topology( | |||
5398 | break; | 5407 | break; |
5399 | default: | 5408 | default: |
5400 | break; | 5409 | break; |
5401 | } | 5410 | } |
5402 | 5411 | ||
5403 | return connect_topology (pg, connect_timeout, connect_attempts, | 5412 | return connect_topology (pg, connect_timeout, connect_attempts, |
5404 | notify_callback, notify_cls); | 5413 | notify_callback, notify_cls); |
@@ -5413,14 +5422,15 @@ GNUNET_TESTING_connect_topology( | |||
5413 | * @return the number of current ssh connections to the host | 5422 | * @return the number of current ssh connections to the host |
5414 | */ | 5423 | */ |
5415 | static unsigned int | 5424 | static unsigned int |
5416 | count_outstanding_at_host(const char *hostname, | 5425 | count_outstanding_at_host (const char *hostname, |
5417 | struct GNUNET_TESTING_PeerGroup *pg) | 5426 | struct GNUNET_TESTING_PeerGroup *pg) |
5418 | { | 5427 | { |
5419 | struct OutstandingSSH *pos; | 5428 | struct OutstandingSSH *pos; |
5429 | |||
5420 | pos = pg->ssh_head; | 5430 | pos = pg->ssh_head; |
5421 | while ((pos != NULL) && (strcmp (pos->hostname, hostname) != 0)) | 5431 | while ((pos != NULL) && (strcmp (pos->hostname, hostname) != 0)) |
5422 | pos = pos->next; | 5432 | pos = pos->next; |
5423 | GNUNET_assert(pos != NULL); | 5433 | GNUNET_assert (pos != NULL); |
5424 | return pos->outstanding; | 5434 | return pos->outstanding; |
5425 | } | 5435 | } |
5426 | 5436 | ||
@@ -5432,14 +5442,15 @@ count_outstanding_at_host(const char *hostname, | |||
5432 | * | 5442 | * |
5433 | */ | 5443 | */ |
5434 | static void | 5444 | static void |
5435 | increment_outstanding_at_host(const char *hostname, | 5445 | increment_outstanding_at_host (const char *hostname, |
5436 | struct GNUNET_TESTING_PeerGroup *pg) | 5446 | struct GNUNET_TESTING_PeerGroup *pg) |
5437 | { | 5447 | { |
5438 | struct OutstandingSSH *pos; | 5448 | struct OutstandingSSH *pos; |
5449 | |||
5439 | pos = pg->ssh_head; | 5450 | pos = pg->ssh_head; |
5440 | while ((pos != NULL) && (strcmp (pos->hostname, hostname) != 0)) | 5451 | while ((pos != NULL) && (strcmp (pos->hostname, hostname) != 0)) |
5441 | pos = pos->next; | 5452 | pos = pos->next; |
5442 | GNUNET_assert(pos != NULL); | 5453 | GNUNET_assert (pos != NULL); |
5443 | pos->outstanding++; | 5454 | pos->outstanding++; |
5444 | } | 5455 | } |
5445 | 5456 | ||
@@ -5451,14 +5462,15 @@ increment_outstanding_at_host(const char *hostname, | |||
5451 | * | 5462 | * |
5452 | */ | 5463 | */ |
5453 | static void | 5464 | static void |
5454 | decrement_outstanding_at_host(const char *hostname, | 5465 | decrement_outstanding_at_host (const char *hostname, |
5455 | struct GNUNET_TESTING_PeerGroup *pg) | 5466 | struct GNUNET_TESTING_PeerGroup *pg) |
5456 | { | 5467 | { |
5457 | struct OutstandingSSH *pos; | 5468 | struct OutstandingSSH *pos; |
5469 | |||
5458 | pos = pg->ssh_head; | 5470 | pos = pg->ssh_head; |
5459 | while ((pos != NULL) && (strcmp (pos->hostname, hostname) != 0)) | 5471 | while ((pos != NULL) && (strcmp (pos->hostname, hostname) != 0)) |
5460 | pos = pos->next; | 5472 | pos = pos->next; |
5461 | GNUNET_assert(pos != NULL); | 5473 | GNUNET_assert (pos != NULL); |
5462 | pos->outstanding--; | 5474 | pos->outstanding--; |
5463 | } | 5475 | } |
5464 | 5476 | ||
@@ -5473,10 +5485,11 @@ decrement_outstanding_at_host(const char *hostname, | |||
5473 | * @param emsg error message (NULL on success) | 5485 | * @param emsg error message (NULL on success) |
5474 | */ | 5486 | */ |
5475 | static void | 5487 | static void |
5476 | internal_hostkey_callback(void *cls, const struct GNUNET_PeerIdentity *id, | 5488 | internal_hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id, |
5477 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 5489 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
5478 | { | 5490 | { |
5479 | struct InternalStartContext *internal_context = cls; | 5491 | struct InternalStartContext *internal_context = cls; |
5492 | |||
5480 | internal_context->peer->pg->starting--; | 5493 | internal_context->peer->pg->starting--; |
5481 | internal_context->peer->pg->started++; | 5494 | internal_context->peer->pg->started++; |
5482 | if (internal_context->hostname != NULL) | 5495 | if (internal_context->hostname != NULL) |
@@ -5486,11 +5499,11 @@ internal_hostkey_callback(void *cls, const struct GNUNET_PeerIdentity *id, | |||
5486 | internal_context->hostkey_callback (internal_context->hostkey_cls, id, d, | 5499 | internal_context->hostkey_callback (internal_context->hostkey_cls, id, d, |
5487 | emsg); | 5500 | emsg); |
5488 | else if (internal_context->peer->pg->started | 5501 | else if (internal_context->peer->pg->started |
5489 | == internal_context->peer->pg->total) | 5502 | == internal_context->peer->pg->total) |
5490 | { | 5503 | { |
5491 | internal_context->peer->pg->started = 0; /* Internal startup may use this counter! */ | 5504 | internal_context->peer->pg->started = 0; /* Internal startup may use this counter! */ |
5492 | GNUNET_TESTING_daemons_continue_startup (internal_context->peer->pg); | 5505 | GNUNET_TESTING_daemons_continue_startup (internal_context->peer->pg); |
5493 | } | 5506 | } |
5494 | } | 5507 | } |
5495 | 5508 | ||
5496 | /** | 5509 | /** |
@@ -5505,11 +5518,12 @@ internal_hostkey_callback(void *cls, const struct GNUNET_PeerIdentity *id, | |||
5505 | * @param emsg error message (NULL on success) | 5518 | * @param emsg error message (NULL on success) |
5506 | */ | 5519 | */ |
5507 | static void | 5520 | static void |
5508 | internal_startup_callback(void *cls, const struct GNUNET_PeerIdentity *id, | 5521 | internal_startup_callback (void *cls, const struct GNUNET_PeerIdentity *id, |
5509 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 5522 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
5510 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 5523 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
5511 | { | 5524 | { |
5512 | struct InternalStartContext *internal_context = cls; | 5525 | struct InternalStartContext *internal_context = cls; |
5526 | |||
5513 | internal_context->peer->pg->starting--; | 5527 | internal_context->peer->pg->starting--; |
5514 | if (internal_context->hostname != NULL) | 5528 | if (internal_context->hostname != NULL) |
5515 | decrement_outstanding_at_host (internal_context->hostname, | 5529 | decrement_outstanding_at_host (internal_context->hostname, |
@@ -5520,38 +5534,35 @@ internal_startup_callback(void *cls, const struct GNUNET_PeerIdentity *id, | |||
5520 | } | 5534 | } |
5521 | 5535 | ||
5522 | static void | 5536 | static void |
5523 | internal_continue_startup(void *cls, | 5537 | internal_continue_startup (void *cls, |
5524 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 5538 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
5525 | { | 5539 | { |
5526 | struct InternalStartContext *internal_context = cls; | 5540 | struct InternalStartContext *internal_context = cls; |
5527 | 5541 | ||
5528 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 5542 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
5529 | { | 5543 | { |
5530 | return; | 5544 | return; |
5531 | } | 5545 | } |
5532 | 5546 | ||
5533 | if ((internal_context->peer->pg->starting | 5547 | if ((internal_context->peer->pg->starting |
5534 | < internal_context->peer->pg->max_concurrent_ssh) | 5548 | < internal_context->peer->pg->max_concurrent_ssh) |
5535 | || ((internal_context->hostname != NULL) | 5549 | || ((internal_context->hostname != NULL) |
5536 | && (count_outstanding_at_host (internal_context->hostname, | 5550 | && (count_outstanding_at_host (internal_context->hostname, |
5537 | internal_context->peer->pg) | 5551 | internal_context->peer->pg) |
5538 | < internal_context->peer->pg->max_concurrent_ssh))) | 5552 | < internal_context->peer->pg->max_concurrent_ssh))) |
5539 | { | 5553 | { |
5540 | if (internal_context->hostname != NULL) | 5554 | if (internal_context->hostname != NULL) |
5541 | increment_outstanding_at_host (internal_context->hostname, | 5555 | increment_outstanding_at_host (internal_context->hostname, |
5542 | internal_context->peer->pg); | 5556 | internal_context->peer->pg); |
5543 | internal_context->peer->pg->starting++; | 5557 | internal_context->peer->pg->starting++; |
5544 | GNUNET_TESTING_daemon_continue_startup (internal_context->peer->daemon); | 5558 | GNUNET_TESTING_daemon_continue_startup (internal_context->peer->daemon); |
5545 | } | 5559 | } |
5546 | else | 5560 | else |
5547 | { | 5561 | { |
5548 | GNUNET_SCHEDULER_add_delayed ( | 5562 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
5549 | GNUNET_TIME_relative_multiply ( | 5563 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
5550 | GNUNET_TIME_UNIT_MILLISECONDS, | 5564 | &internal_continue_startup, internal_context); |
5551 | 100), | 5565 | } |
5552 | &internal_continue_startup, | ||
5553 | internal_context); | ||
5554 | } | ||
5555 | } | 5566 | } |
5556 | 5567 | ||
5557 | /** | 5568 | /** |
@@ -5566,9 +5577,9 @@ internal_continue_startup(void *cls, | |||
5566 | * | 5577 | * |
5567 | */ | 5578 | */ |
5568 | void | 5579 | void |
5569 | churn_start_callback(void *cls, const struct GNUNET_PeerIdentity *id, | 5580 | churn_start_callback (void *cls, const struct GNUNET_PeerIdentity *id, |
5570 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 5581 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
5571 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 5582 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
5572 | { | 5583 | { |
5573 | struct ChurnRestartContext *startup_ctx = cls; | 5584 | struct ChurnRestartContext *startup_ctx = cls; |
5574 | struct ChurnContext *churn_ctx = startup_ctx->churn_ctx; | 5585 | struct ChurnContext *churn_ctx = startup_ctx->churn_ctx; |
@@ -5578,59 +5589,58 @@ churn_start_callback(void *cls, const struct GNUNET_PeerIdentity *id, | |||
5578 | 5589 | ||
5579 | error_message = NULL; | 5590 | error_message = NULL; |
5580 | if (emsg != NULL) | 5591 | if (emsg != NULL) |
5581 | { | 5592 | { |
5582 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 5593 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
5583 | "Churn stop callback failed with error `%s'\n", emsg); | 5594 | "Churn stop callback failed with error `%s'\n", emsg); |
5584 | churn_ctx->num_failed_start++; | 5595 | churn_ctx->num_failed_start++; |
5585 | } | 5596 | } |
5586 | else | 5597 | else |
5587 | { | 5598 | { |
5588 | churn_ctx->num_to_start--; | 5599 | churn_ctx->num_to_start--; |
5589 | } | 5600 | } |
5590 | 5601 | ||
5591 | total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) | 5602 | total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) |
5592 | + (churn_ctx->num_to_start - churn_ctx->num_failed_start); | 5603 | + (churn_ctx->num_to_start - churn_ctx->num_failed_start); |
5593 | 5604 | ||
5594 | if (total_left == 0) | 5605 | if (total_left == 0) |
5595 | { | 5606 | { |
5596 | if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0)) | 5607 | if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0)) |
5597 | GNUNET_asprintf ( | 5608 | GNUNET_asprintf (&error_message, |
5598 | &error_message, | 5609 | "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!", |
5599 | "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!", | 5610 | churn_ctx->num_failed_start, churn_ctx->num_failed_stop); |
5600 | churn_ctx->num_failed_start, | 5611 | churn_ctx->cb (churn_ctx->cb_cls, error_message); |
5601 | churn_ctx->num_failed_stop); | 5612 | GNUNET_free_non_null (error_message); |
5602 | churn_ctx->cb (churn_ctx->cb_cls, error_message); | 5613 | GNUNET_free (churn_ctx); |
5603 | GNUNET_free_non_null (error_message); | 5614 | GNUNET_free (startup_ctx); |
5604 | GNUNET_free (churn_ctx); | 5615 | } |
5605 | GNUNET_free (startup_ctx); | ||
5606 | } | ||
5607 | } | 5616 | } |
5608 | 5617 | ||
5609 | static void | 5618 | static void |
5610 | schedule_churn_restart(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 5619 | schedule_churn_restart (void *cls, |
5620 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
5611 | { | 5621 | { |
5612 | struct PeerRestartContext *peer_restart_ctx = cls; | 5622 | struct PeerRestartContext *peer_restart_ctx = cls; |
5613 | struct ChurnRestartContext *startup_ctx = peer_restart_ctx->churn_restart_ctx; | 5623 | struct ChurnRestartContext *startup_ctx = peer_restart_ctx->churn_restart_ctx; |
5614 | 5624 | ||
5615 | if (startup_ctx->outstanding > startup_ctx->pg->max_concurrent_ssh) | 5625 | if (startup_ctx->outstanding > startup_ctx->pg->max_concurrent_ssh) |
5616 | GNUNET_SCHEDULER_add_delayed ( | 5626 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
5617 | GNUNET_TIME_relative_multiply ( | 5627 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
5618 | GNUNET_TIME_UNIT_MILLISECONDS, | ||
5619 | 100), | ||
5620 | &schedule_churn_restart, peer_restart_ctx); | 5628 | &schedule_churn_restart, peer_restart_ctx); |
5621 | else | 5629 | else |
5622 | { | 5630 | { |
5623 | if (startup_ctx->churn_ctx->service != NULL) | 5631 | if (startup_ctx->churn_ctx->service != NULL) |
5624 | GNUNET_TESTING_daemon_start_stopped_service (peer_restart_ctx->daemon, | 5632 | GNUNET_TESTING_daemon_start_stopped_service (peer_restart_ctx->daemon, |
5625 | startup_ctx->churn_ctx->service, | 5633 | startup_ctx-> |
5626 | startup_ctx->timeout, | 5634 | churn_ctx->service, |
5627 | &churn_start_callback, startup_ctx); | 5635 | startup_ctx->timeout, |
5628 | else | 5636 | &churn_start_callback, |
5629 | GNUNET_TESTING_daemon_start_stopped (peer_restart_ctx->daemon, | 5637 | startup_ctx); |
5630 | startup_ctx->timeout, | 5638 | else |
5631 | &churn_start_callback, startup_ctx); | 5639 | GNUNET_TESTING_daemon_start_stopped (peer_restart_ctx->daemon, |
5632 | GNUNET_free (peer_restart_ctx); | 5640 | startup_ctx->timeout, |
5633 | } | 5641 | &churn_start_callback, startup_ctx); |
5642 | GNUNET_free (peer_restart_ctx); | ||
5643 | } | ||
5634 | } | 5644 | } |
5635 | 5645 | ||
5636 | /** | 5646 | /** |
@@ -5645,98 +5655,95 @@ schedule_churn_restart(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
5645 | * | 5655 | * |
5646 | */ | 5656 | */ |
5647 | void | 5657 | void |
5648 | service_start_callback(void *cls, | 5658 | service_start_callback (void *cls, |
5649 | const struct GNUNET_PeerIdentity *id, | 5659 | const struct GNUNET_PeerIdentity *id, |
5650 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 5660 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
5651 | struct GNUNET_TESTING_Daemon *d, | 5661 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
5652 | const char *emsg) | ||
5653 | { | 5662 | { |
5654 | struct ServiceStartContext *startup_ctx = (struct ServiceStartContext *)cls; | 5663 | struct ServiceStartContext *startup_ctx = (struct ServiceStartContext *) cls; |
5655 | 5664 | ||
5656 | if (emsg != NULL) | 5665 | if (emsg != NULL) |
5657 | { | 5666 | { |
5658 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 5667 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
5659 | "Service start failed with error `%s'\n", emsg); | 5668 | "Service start failed with error `%s'\n", emsg); |
5660 | } | 5669 | } |
5661 | 5670 | ||
5662 | startup_ctx->outstanding--; | 5671 | startup_ctx->outstanding--; |
5663 | startup_ctx->remaining--; | 5672 | startup_ctx->remaining--; |
5664 | 5673 | ||
5665 | if (startup_ctx->remaining == 0) | 5674 | if (startup_ctx->remaining == 0) |
5666 | { | 5675 | { |
5667 | startup_ctx->cb (startup_ctx->cb_cls, NULL); | 5676 | startup_ctx->cb (startup_ctx->cb_cls, NULL); |
5668 | GNUNET_free (startup_ctx->service); | 5677 | GNUNET_free (startup_ctx->service); |
5669 | GNUNET_free (startup_ctx); | 5678 | GNUNET_free (startup_ctx); |
5670 | } | 5679 | } |
5671 | } | 5680 | } |
5672 | 5681 | ||
5673 | static void | 5682 | static void |
5674 | schedule_service_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 5683 | schedule_service_start (void *cls, |
5684 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
5675 | { | 5685 | { |
5676 | struct PeerServiceStartContext *peer_ctx = cls; | 5686 | struct PeerServiceStartContext *peer_ctx = cls; |
5677 | struct ServiceStartContext *startup_ctx = peer_ctx->start_ctx; | 5687 | struct ServiceStartContext *startup_ctx = peer_ctx->start_ctx; |
5678 | 5688 | ||
5679 | if (startup_ctx->outstanding > startup_ctx->pg->max_concurrent_ssh) | 5689 | if (startup_ctx->outstanding > startup_ctx->pg->max_concurrent_ssh) |
5680 | GNUNET_SCHEDULER_add_delayed ( | 5690 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
5681 | GNUNET_TIME_relative_multiply ( | 5691 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
5682 | GNUNET_TIME_UNIT_MILLISECONDS, | ||
5683 | 100), | ||
5684 | &schedule_service_start, peer_ctx); | 5692 | &schedule_service_start, peer_ctx); |
5685 | else | 5693 | else |
5686 | { | 5694 | { |
5687 | 5695 | ||
5688 | GNUNET_TESTING_daemon_start_service (peer_ctx->daemon, | 5696 | GNUNET_TESTING_daemon_start_service (peer_ctx->daemon, |
5689 | startup_ctx->service, | 5697 | startup_ctx->service, |
5690 | startup_ctx->timeout, | 5698 | startup_ctx->timeout, |
5691 | &service_start_callback, startup_ctx); | 5699 | &service_start_callback, startup_ctx); |
5692 | GNUNET_free (peer_ctx); | 5700 | GNUNET_free (peer_ctx); |
5693 | } | 5701 | } |
5694 | } | 5702 | } |
5695 | 5703 | ||
5696 | 5704 | ||
5697 | static void | 5705 | static void |
5698 | internal_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 5706 | internal_start (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
5699 | { | 5707 | { |
5700 | struct InternalStartContext *internal_context = cls; | 5708 | struct InternalStartContext *internal_context = cls; |
5701 | 5709 | ||
5702 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 5710 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
5703 | { | 5711 | { |
5704 | return; | 5712 | return; |
5705 | } | 5713 | } |
5706 | 5714 | ||
5707 | if ((internal_context->peer->pg->starting | 5715 | if ((internal_context->peer->pg->starting |
5708 | < internal_context->peer->pg->max_concurrent_ssh) | 5716 | < internal_context->peer->pg->max_concurrent_ssh) |
5709 | || ((internal_context->hostname != NULL) | 5717 | || ((internal_context->hostname != NULL) |
5710 | && (count_outstanding_at_host (internal_context->hostname, | 5718 | && (count_outstanding_at_host (internal_context->hostname, |
5711 | internal_context->peer->pg) | 5719 | internal_context->peer->pg) |
5712 | < internal_context->peer->pg->max_concurrent_ssh))) | 5720 | < internal_context->peer->pg->max_concurrent_ssh))) |
5713 | { | 5721 | { |
5714 | if (internal_context->hostname != NULL) | 5722 | if (internal_context->hostname != NULL) |
5715 | increment_outstanding_at_host (internal_context->hostname, | 5723 | increment_outstanding_at_host (internal_context->hostname, |
5716 | internal_context->peer->pg); | 5724 | internal_context->peer->pg); |
5717 | internal_context->peer->pg->starting++; | 5725 | internal_context->peer->pg->starting++; |
5718 | internal_context->peer->daemon | 5726 | internal_context->peer->daemon |
5719 | = GNUNET_TESTING_daemon_start (internal_context->peer->cfg, | 5727 | = GNUNET_TESTING_daemon_start (internal_context->peer->cfg, |
5720 | internal_context->timeout, | 5728 | internal_context->timeout, |
5721 | GNUNET_NO, | 5729 | GNUNET_NO, |
5722 | internal_context->hostname, | 5730 | internal_context->hostname, |
5723 | internal_context->username, | 5731 | internal_context->username, |
5724 | internal_context->sshport, | 5732 | internal_context->sshport, |
5725 | internal_context->hostkey, | 5733 | internal_context->hostkey, |
5726 | &internal_hostkey_callback, | 5734 | &internal_hostkey_callback, |
5727 | internal_context, | 5735 | internal_context, |
5728 | &internal_startup_callback, | 5736 | &internal_startup_callback, |
5729 | internal_context); | 5737 | internal_context); |
5730 | } | 5738 | } |
5731 | else | 5739 | else |
5732 | { | 5740 | { |
5733 | GNUNET_SCHEDULER_add_delayed ( | 5741 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
5734 | GNUNET_TIME_relative_multiply ( | 5742 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
5735 | GNUNET_TIME_UNIT_MILLISECONDS, | 5743 | &internal_start, internal_context); |
5736 | 100), | 5744 | } |
5737 | &internal_start, internal_context); | ||
5738 | } | ||
5739 | } | 5745 | } |
5746 | |||
5740 | #if USE_START_HELPER | 5747 | #if USE_START_HELPER |
5741 | 5748 | ||
5742 | struct PeerStartHelperContext | 5749 | struct PeerStartHelperContext |
@@ -5757,40 +5764,41 @@ check_peers_started (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
5757 | unsigned int i; | 5764 | unsigned int i; |
5758 | GNUNET_TESTING_NotifyDaemonRunning cb; | 5765 | GNUNET_TESTING_NotifyDaemonRunning cb; |
5759 | 5766 | ||
5760 | if (GNUNET_NO == GNUNET_OS_process_status (helper->proc, &type, &code)) /* Still running, wait some more! */ | 5767 | if (GNUNET_NO == GNUNET_OS_process_status (helper->proc, &type, &code)) /* Still running, wait some more! */ |
5761 | { | 5768 | { |
5762 | GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_EXEC_WAIT, &check_peers_started, helper); | 5769 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, |
5770 | &check_peers_started, helper); | ||
5763 | return; | 5771 | return; |
5764 | } | 5772 | } |
5765 | 5773 | ||
5766 | helper->pg->starting--; | 5774 | helper->pg->starting--; |
5767 | if (helper->pg->starting == 0) /* All peers have finished starting! */ | 5775 | if (helper->pg->starting == 0) /* All peers have finished starting! */ |
5768 | { | 5776 | { |
5769 | /* Call the peer started callback for each peer, set proper FSM state (?) */ | 5777 | /* Call the peer started callback for each peer, set proper FSM state (?) */ |
5770 | for (i = 0; i < helper->pg->total; i++) | 5778 | for (i = 0; i < helper->pg->total; i++) |
5771 | { | 5779 | { |
5772 | cb = helper->pg->peers[i].daemon->cb; | 5780 | cb = helper->pg->peers[i].daemon->cb; |
5773 | helper->pg->peers[i].daemon->cb = NULL; | 5781 | helper->pg->peers[i].daemon->cb = NULL; |
5774 | helper->pg->peers[i].daemon->running = GNUNET_YES; | 5782 | helper->pg->peers[i].daemon->running = GNUNET_YES; |
5775 | helper->pg->peers[i].daemon->phase = SP_START_DONE; | 5783 | helper->pg->peers[i].daemon->phase = SP_START_DONE; |
5776 | if (NULL != cb) | 5784 | if (NULL != cb) |
5777 | { | 5785 | { |
5778 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | 5786 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) |
5779 | cb (helper->pg->peers[i].daemon->cb_cls, | 5787 | cb (helper->pg->peers[i].daemon->cb_cls, |
5780 | &helper->pg->peers[i].daemon->id, | 5788 | &helper->pg->peers[i].daemon->id, |
5781 | helper->pg->peers[i].daemon->cfg, helper->pg->peers[i].daemon, | 5789 | helper->pg->peers[i].daemon->cfg, helper->pg->peers[i].daemon, |
5782 | "Failed to execute peerStartHelper.pl, or return code bad!"); | 5790 | "Failed to execute peerStartHelper.pl, or return code bad!"); |
5783 | else | 5791 | else |
5784 | cb (helper->pg->peers[i].daemon->cb_cls, | 5792 | cb (helper->pg->peers[i].daemon->cb_cls, |
5785 | &helper->pg->peers[i].daemon->id, | 5793 | &helper->pg->peers[i].daemon->id, |
5786 | helper->pg->peers[i].daemon->cfg, helper->pg->peers[i].daemon, | 5794 | helper->pg->peers[i].daemon->cfg, helper->pg->peers[i].daemon, |
5787 | NULL); | 5795 | NULL); |
5788 | 5796 | ||
5789 | } | 5797 | } |
5790 | 5798 | ||
5791 | } | ||
5792 | } | 5799 | } |
5793 | GNUNET_OS_process_close(helper->proc); | 5800 | } |
5801 | GNUNET_OS_process_close (helper->proc); | ||
5794 | } | 5802 | } |
5795 | 5803 | ||
5796 | static void | 5804 | static void |
@@ -5800,20 +5808,26 @@ start_peer_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
5800 | char *baseservicehome; | 5808 | char *baseservicehome; |
5801 | char *tempdir; | 5809 | char *tempdir; |
5802 | char *arg; | 5810 | char *arg; |
5811 | |||
5803 | /* ssh user@host peerStartHelper /path/to/basedirectory */ | 5812 | /* ssh user@host peerStartHelper /path/to/basedirectory */ |
5804 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (helper->pg->cfg, "PATHS", "SERVICEHOME", | 5813 | GNUNET_assert (GNUNET_OK == |
5805 | &baseservicehome)); | 5814 | GNUNET_CONFIGURATION_get_value_string (helper->pg->cfg, |
5806 | GNUNET_asprintf(&tempdir, "%s/%s/", baseservicehome, helper->host->hostname); | 5815 | "PATHS", "SERVICEHOME", |
5816 | &baseservicehome)); | ||
5817 | GNUNET_asprintf (&tempdir, "%s/%s/", baseservicehome, helper->host->hostname); | ||
5807 | if (NULL != helper->host->username) | 5818 | if (NULL != helper->host->username) |
5808 | GNUNET_asprintf (&arg, "%s@%s", helper->host->username, helper->host->hostname); | 5819 | GNUNET_asprintf (&arg, "%s@%s", helper->host->username, |
5820 | helper->host->hostname); | ||
5809 | else | 5821 | else |
5810 | GNUNET_asprintf (&arg, "%s", helper->host->hostname); | 5822 | GNUNET_asprintf (&arg, "%s", helper->host->hostname); |
5811 | 5823 | ||
5812 | /* FIXME: Doesn't support ssh_port option! */ | 5824 | /* FIXME: Doesn't support ssh_port option! */ |
5813 | helper->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg, | 5825 | helper->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg, |
5814 | "peerStartHelper.pl", tempdir, NULL); | 5826 | "peerStartHelper.pl", tempdir, NULL); |
5815 | GNUNET_assert(helper->proc != NULL); | 5827 | GNUNET_assert (helper->proc != NULL); |
5816 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "starting peers with cmd ssh %s %s %s\n", arg, "peerStartHelper.pl", tempdir); | 5828 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
5829 | "starting peers with cmd ssh %s %s %s\n", arg, | ||
5830 | "peerStartHelper.pl", tempdir); | ||
5817 | GNUNET_SCHEDULER_add_now (&check_peers_started, helper); | 5831 | GNUNET_SCHEDULER_add_now (&check_peers_started, helper); |
5818 | GNUNET_free (tempdir); | 5832 | GNUNET_free (tempdir); |
5819 | GNUNET_free (baseservicehome); | 5833 | GNUNET_free (baseservicehome); |
@@ -5829,56 +5843,61 @@ start_peer_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
5829 | * | 5843 | * |
5830 | */ | 5844 | */ |
5831 | void | 5845 | void |
5832 | GNUNET_TESTING_daemons_continue_startup(struct GNUNET_TESTING_PeerGroup *pg) | 5846 | GNUNET_TESTING_daemons_continue_startup (struct GNUNET_TESTING_PeerGroup *pg) |
5833 | { | 5847 | { |
5834 | unsigned int i; | 5848 | unsigned int i; |
5835 | 5849 | ||
5836 | #if USE_START_HELPER | 5850 | #if USE_START_HELPER |
5837 | if ((pg->num_hosts > 0) && (pg->hostkey_data != NULL)) | 5851 | if ((pg->num_hosts > 0) && (pg->hostkey_data != NULL)) |
5852 | { | ||
5853 | struct PeerStartHelperContext *helper; | ||
5854 | |||
5855 | pg->starting = pg->num_hosts; | ||
5856 | for (i = 0; i < pg->num_hosts; i++) | ||
5838 | { | 5857 | { |
5839 | struct PeerStartHelperContext *helper; | 5858 | helper = GNUNET_malloc (sizeof (struct PeerStartHelperContext)); |
5840 | pg->starting = pg->num_hosts; | 5859 | helper->pg = pg; |
5841 | for (i = 0; i < pg->num_hosts; i++) | 5860 | helper->host = &pg->hosts[i]; |
5842 | { | 5861 | GNUNET_SCHEDULER_add_now (&start_peer_helper, helper); |
5843 | helper = GNUNET_malloc(sizeof(struct PeerStartHelperContext)); | ||
5844 | helper->pg = pg; | ||
5845 | helper->host = &pg->hosts[i]; | ||
5846 | GNUNET_SCHEDULER_add_now(&start_peer_helper, helper); | ||
5847 | } | ||
5848 | } | 5862 | } |
5863 | } | ||
5849 | else | 5864 | else |
5865 | { | ||
5866 | pg->starting = 0; | ||
5867 | for (i = 0; i < pg->total; i++) | ||
5850 | { | 5868 | { |
5851 | pg->starting = 0; | 5869 | GNUNET_SCHEDULER_add_now (&internal_continue_startup, |
5852 | for (i = 0; i < pg->total; i++) | 5870 | &pg->peers[i].internal_context); |
5853 | { | ||
5854 | GNUNET_SCHEDULER_add_now (&internal_continue_startup, | ||
5855 | &pg->peers[i].internal_context); | ||
5856 | } | ||
5857 | } | 5871 | } |
5872 | } | ||
5858 | #else | 5873 | #else |
5859 | pg->starting = 0; | 5874 | pg->starting = 0; |
5860 | for (i = 0; i < pg->total; i++) | 5875 | for (i = 0; i < pg->total; i++) |
5861 | { | 5876 | { |
5862 | GNUNET_SCHEDULER_add_now (&internal_continue_startup, | 5877 | GNUNET_SCHEDULER_add_now (&internal_continue_startup, |
5863 | &pg->peers[i].internal_context); | 5878 | &pg->peers[i].internal_context); |
5864 | } | 5879 | } |
5865 | #endif | 5880 | #endif |
5866 | } | 5881 | } |
5867 | 5882 | ||
5868 | #if USE_START_HELPER | 5883 | #if USE_START_HELPER |
5869 | static void | 5884 | static void |
5870 | call_hostkey_callbacks (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 5885 | call_hostkey_callbacks (void *cls, |
5886 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
5871 | { | 5887 | { |
5872 | struct GNUNET_TESTING_PeerGroup *pg = cls; | 5888 | struct GNUNET_TESTING_PeerGroup *pg = cls; |
5873 | unsigned int i; | 5889 | unsigned int i; |
5890 | |||
5874 | for (i = 0; i < pg->total; i++) | 5891 | for (i = 0; i < pg->total; i++) |
5875 | { | 5892 | { |
5876 | if (pg->peers[i].internal_context.hostkey_callback != NULL) | 5893 | if (pg->peers[i].internal_context.hostkey_callback != NULL) |
5877 | pg->peers[i].internal_context.hostkey_callback (pg->peers[i].internal_context.hostkey_cls, | 5894 | pg->peers[i].internal_context.hostkey_callback (pg->peers |
5878 | &pg->peers[i].daemon->id, | 5895 | [i]. |
5879 | pg->peers[i].daemon, | 5896 | internal_context.hostkey_cls, |
5880 | NULL); | 5897 | &pg->peers[i].daemon->id, |
5881 | } | 5898 | pg->peers[i].daemon, |
5899 | NULL); | ||
5900 | } | ||
5882 | 5901 | ||
5883 | if (pg->peers[0].internal_context.hostkey_callback == NULL) | 5902 | if (pg->peers[0].internal_context.hostkey_callback == NULL) |
5884 | GNUNET_TESTING_daemons_continue_startup (pg); | 5903 | GNUNET_TESTING_daemons_continue_startup (pg); |
@@ -5913,18 +5932,18 @@ call_hostkey_callbacks (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
5913 | * @return NULL on error, otherwise handle to control peer group | 5932 | * @return NULL on error, otherwise handle to control peer group |
5914 | */ | 5933 | */ |
5915 | struct GNUNET_TESTING_PeerGroup * | 5934 | struct GNUNET_TESTING_PeerGroup * |
5916 | GNUNET_TESTING_daemons_start(const struct GNUNET_CONFIGURATION_Handle *cfg, | 5935 | GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, |
5917 | unsigned int total, | 5936 | unsigned int total, |
5918 | unsigned int max_concurrent_connections, | 5937 | unsigned int max_concurrent_connections, |
5919 | unsigned int max_concurrent_ssh, | 5938 | unsigned int max_concurrent_ssh, |
5920 | struct GNUNET_TIME_Relative timeout, | 5939 | struct GNUNET_TIME_Relative timeout, |
5921 | GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback, | 5940 | GNUNET_TESTING_NotifyHostkeyCreated |
5922 | void *hostkey_cls, | 5941 | hostkey_callback, void *hostkey_cls, |
5923 | GNUNET_TESTING_NotifyDaemonRunning cb, | 5942 | GNUNET_TESTING_NotifyDaemonRunning cb, |
5924 | void *cb_cls, | 5943 | void *cb_cls, |
5925 | GNUNET_TESTING_NotifyConnection connect_callback, | 5944 | GNUNET_TESTING_NotifyConnection connect_callback, |
5926 | void *connect_callback_cls, | 5945 | void *connect_callback_cls, |
5927 | const struct GNUNET_TESTING_Host *hostnames) | 5946 | const struct GNUNET_TESTING_Host *hostnames) |
5928 | { | 5947 | { |
5929 | struct GNUNET_TESTING_PeerGroup *pg; | 5948 | struct GNUNET_TESTING_PeerGroup *pg; |
5930 | const struct GNUNET_TESTING_Host *hostpos; | 5949 | const struct GNUNET_TESTING_Host *hostpos; |
@@ -5952,10 +5971,10 @@ GNUNET_TESTING_daemons_start(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
5952 | 5971 | ||
5953 | username = NULL; | 5972 | username = NULL; |
5954 | if (0 == total) | 5973 | if (0 == total) |
5955 | { | 5974 | { |
5956 | GNUNET_break (0); | 5975 | GNUNET_break (0); |
5957 | return NULL; | 5976 | return NULL; |
5958 | } | 5977 | } |
5959 | 5978 | ||
5960 | upnum = 0; | 5979 | upnum = 0; |
5961 | fdnum = 0; | 5980 | fdnum = 0; |
@@ -5969,227 +5988,225 @@ GNUNET_TESTING_daemons_start(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
5969 | pg->max_outstanding_connections = max_concurrent_connections; | 5988 | pg->max_outstanding_connections = max_concurrent_connections; |
5970 | pg->max_concurrent_ssh = max_concurrent_ssh; | 5989 | pg->max_concurrent_ssh = max_concurrent_ssh; |
5971 | if (NULL != hostnames) | 5990 | if (NULL != hostnames) |
5991 | { | ||
5992 | off = 0; | ||
5993 | hostpos = hostnames; | ||
5994 | while (hostpos != NULL) | ||
5972 | { | 5995 | { |
5973 | off = 0; | 5996 | hostpos = hostpos->next; |
5974 | hostpos = hostnames; | 5997 | off++; |
5975 | while (hostpos != NULL) | 5998 | } |
5976 | { | 5999 | pg->hosts = GNUNET_malloc (off * sizeof (struct HostData)); |
5977 | hostpos = hostpos->next; | 6000 | off = 0; |
5978 | off++; | ||
5979 | } | ||
5980 | pg->hosts = GNUNET_malloc (off * sizeof (struct HostData)); | ||
5981 | off = 0; | ||
5982 | |||
5983 | hostpos = hostnames; | ||
5984 | while (hostpos != NULL) | ||
5985 | { | ||
5986 | pg->hosts[off].minport = LOW_PORT; | ||
5987 | pg->hosts[off].hostname = GNUNET_strdup (hostpos->hostname); | ||
5988 | if (hostpos->username != NULL) | ||
5989 | pg->hosts[off].username = GNUNET_strdup (hostpos->username); | ||
5990 | pg->hosts[off].sshport = hostpos->port; | ||
5991 | hostpos = hostpos->next; | ||
5992 | off++; | ||
5993 | } | ||
5994 | 6001 | ||
5995 | if (off == 0) | 6002 | hostpos = hostnames; |
5996 | { | 6003 | while (hostpos != NULL) |
5997 | pg->hosts = NULL; | 6004 | { |
5998 | } | 6005 | pg->hosts[off].minport = LOW_PORT; |
5999 | hostcnt = off; | 6006 | pg->hosts[off].hostname = GNUNET_strdup (hostpos->hostname); |
6000 | minport = 0; | 6007 | if (hostpos->username != NULL) |
6001 | pg->num_hosts = off; | 6008 | pg->hosts[off].username = GNUNET_strdup (hostpos->username); |
6009 | pg->hosts[off].sshport = hostpos->port; | ||
6010 | hostpos = hostpos->next; | ||
6011 | off++; | ||
6002 | } | 6012 | } |
6003 | else | 6013 | |
6014 | if (off == 0) | ||
6004 | { | 6015 | { |
6005 | hostcnt = 0; | 6016 | pg->hosts = NULL; |
6006 | minport = LOW_PORT; | ||
6007 | } | 6017 | } |
6018 | hostcnt = off; | ||
6019 | minport = 0; | ||
6020 | pg->num_hosts = off; | ||
6021 | } | ||
6022 | else | ||
6023 | { | ||
6024 | hostcnt = 0; | ||
6025 | minport = LOW_PORT; | ||
6026 | } | ||
6008 | 6027 | ||
6009 | /* Create the servicehome directory for each remote peer */ | 6028 | /* Create the servicehome directory for each remote peer */ |
6010 | GNUNET_assert(GNUNET_OK == | 6029 | GNUNET_assert (GNUNET_OK == |
6011 | GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME", | 6030 | GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", |
6012 | &baseservicehome)); | 6031 | "SERVICEHOME", |
6032 | &baseservicehome)); | ||
6013 | for (i = 0; i < pg->num_hosts; i++) | 6033 | for (i = 0; i < pg->num_hosts; i++) |
6034 | { | ||
6035 | ssh_entry = GNUNET_malloc (sizeof (struct OutstandingSSH)); | ||
6036 | ssh_entry->hostname = pg->hosts[i].hostname; /* Don't free! */ | ||
6037 | GNUNET_CONTAINER_DLL_insert (pg->ssh_head, pg->ssh_tail, ssh_entry); | ||
6038 | GNUNET_asprintf (&tmpdir, "%s/%s", baseservicehome, pg->hosts[i].hostname); | ||
6039 | if (NULL != pg->hosts[i].username) | ||
6040 | GNUNET_asprintf (&arg, "%s@%s", pg->hosts[i].username, | ||
6041 | pg->hosts[i].hostname); | ||
6042 | else | ||
6043 | GNUNET_asprintf (&arg, "%s", pg->hosts[i].hostname); | ||
6044 | if (pg->hosts[i].sshport != 0) | ||
6014 | { | 6045 | { |
6015 | ssh_entry = GNUNET_malloc(sizeof(struct OutstandingSSH)); | 6046 | GNUNET_asprintf (&ssh_port_str, "%d", pg->hosts[i].sshport); |
6016 | ssh_entry->hostname = pg->hosts[i].hostname; /* Don't free! */ | 6047 | proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", "-P", |
6017 | GNUNET_CONTAINER_DLL_insert(pg->ssh_head, pg->ssh_tail, ssh_entry); | 6048 | ssh_port_str, |
6018 | GNUNET_asprintf(&tmpdir, "%s/%s", baseservicehome, pg->hosts[i].hostname); | ||
6019 | if (NULL != pg->hosts[i].username) | ||
6020 | GNUNET_asprintf (&arg, "%s@%s", pg->hosts[i].username, | ||
6021 | pg->hosts[i].hostname); | ||
6022 | else | ||
6023 | GNUNET_asprintf (&arg, "%s", pg->hosts[i].hostname); | ||
6024 | if (pg->hosts[i].sshport != 0) | ||
6025 | { | ||
6026 | GNUNET_asprintf (&ssh_port_str, "%d", pg->hosts[i].sshport); | ||
6027 | proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", "-P", | ||
6028 | ssh_port_str, | ||
6029 | #if !DEBUG_TESTING | 6049 | #if !DEBUG_TESTING |
6030 | "-q", | 6050 | "-q", |
6031 | #endif | 6051 | #endif |
6032 | arg, "mkdir -p", tmpdir, | 6052 | arg, "mkdir -p", tmpdir, NULL); |
6033 | NULL); | ||
6034 | } | ||
6035 | else | ||
6036 | proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg, | ||
6037 | "mkdir -p", tmpdir, NULL); | ||
6038 | GNUNET_assert(proc != NULL); | ||
6039 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
6040 | "Creating remote dir with command ssh %s %s %s\n", arg, | ||
6041 | " mkdir -p ", tmpdir); | ||
6042 | GNUNET_free(tmpdir); | ||
6043 | GNUNET_free(arg); | ||
6044 | GNUNET_OS_process_wait (proc); | ||
6045 | GNUNET_OS_process_close(proc); | ||
6046 | } | 6053 | } |
6047 | GNUNET_free(baseservicehome); | 6054 | else |
6055 | proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg, | ||
6056 | "mkdir -p", tmpdir, NULL); | ||
6057 | GNUNET_assert (proc != NULL); | ||
6058 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
6059 | "Creating remote dir with command ssh %s %s %s\n", arg, | ||
6060 | " mkdir -p ", tmpdir); | ||
6061 | GNUNET_free (tmpdir); | ||
6062 | GNUNET_free (arg); | ||
6063 | GNUNET_OS_process_wait (proc); | ||
6064 | GNUNET_OS_process_close (proc); | ||
6065 | } | ||
6066 | GNUNET_free (baseservicehome); | ||
6048 | baseservicehome = NULL; | 6067 | baseservicehome = NULL; |
6049 | 6068 | ||
6050 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", | 6069 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", |
6051 | "HOSTKEYSFILE", | 6070 | "HOSTKEYSFILE", |
6052 | &hostkeys_file)) | 6071 | &hostkeys_file)) |
6072 | { | ||
6073 | if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file)) | ||
6074 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
6075 | _("Could not read hostkeys file!\n")); | ||
6076 | else | ||
6053 | { | 6077 | { |
6054 | if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file)) | 6078 | /* Check hostkey file size, read entire thing into memory */ |
6055 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 6079 | fd = GNUNET_DISK_file_open (hostkeys_file, |
6056 | _("Could not read hostkeys file!\n")); | 6080 | GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE); |
6057 | else | 6081 | if (NULL == fd) |
6082 | { | ||
6083 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
6084 | "open", hostkeys_file); | ||
6085 | GNUNET_free (hostkeys_file); | ||
6086 | for (i = 0; i < pg->num_hosts; i++) | ||
6058 | { | 6087 | { |
6059 | /* Check hostkey file size, read entire thing into memory */ | 6088 | GNUNET_free (pg->hosts[i].hostname); |
6060 | fd = GNUNET_DISK_file_open (hostkeys_file, | 6089 | GNUNET_free_non_null (pg->hosts[i].username); |
6061 | GNUNET_DISK_OPEN_READ, | ||
6062 | GNUNET_DISK_PERM_NONE); | ||
6063 | if (NULL == fd) | ||
6064 | { | ||
6065 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
6066 | "open", | ||
6067 | hostkeys_file); | ||
6068 | GNUNET_free (hostkeys_file); | ||
6069 | for (i=0;i<pg->num_hosts;i++) | ||
6070 | { | ||
6071 | GNUNET_free (pg->hosts[i].hostname); | ||
6072 | GNUNET_free_non_null (pg->hosts[i].username); | ||
6073 | } | ||
6074 | GNUNET_free (pg->peers); | ||
6075 | GNUNET_free (pg->hosts); | ||
6076 | GNUNET_free (pg); | ||
6077 | return NULL; | ||
6078 | } | ||
6079 | |||
6080 | if (GNUNET_YES != GNUNET_DISK_file_size (hostkeys_file, &fs, | ||
6081 | GNUNET_YES)) | ||
6082 | fs = 0; | ||
6083 | |||
6084 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
6085 | "Found file size %llu for hostkeys, expect hostkeys to be size %d\n", | ||
6086 | fs, HOSTKEYFILESIZE); | ||
6087 | |||
6088 | if (0 != (fs % HOSTKEYFILESIZE)) | ||
6089 | { | ||
6090 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
6091 | "File size %llu seems incorrect for hostkeys...\n", | ||
6092 | fs); | ||
6093 | } | ||
6094 | else | ||
6095 | { | ||
6096 | total_hostkeys = fs / HOSTKEYFILESIZE; | ||
6097 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
6098 | "Will read %llu hostkeys from file\n", | ||
6099 | total_hostkeys); | ||
6100 | pg->hostkey_data = GNUNET_malloc_large (fs); | ||
6101 | GNUNET_assert (fs == GNUNET_DISK_file_read (fd, pg->hostkey_data, fs)); | ||
6102 | } | ||
6103 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fd)); | ||
6104 | } | 6090 | } |
6105 | GNUNET_free(hostkeys_file); | 6091 | GNUNET_free (pg->peers); |
6092 | GNUNET_free (pg->hosts); | ||
6093 | GNUNET_free (pg); | ||
6094 | return NULL; | ||
6095 | } | ||
6096 | |||
6097 | if (GNUNET_YES != GNUNET_DISK_file_size (hostkeys_file, &fs, GNUNET_YES)) | ||
6098 | fs = 0; | ||
6099 | |||
6100 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
6101 | "Found file size %llu for hostkeys, expect hostkeys to be size %d\n", | ||
6102 | fs, HOSTKEYFILESIZE); | ||
6103 | |||
6104 | if (0 != (fs % HOSTKEYFILESIZE)) | ||
6105 | { | ||
6106 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
6107 | "File size %llu seems incorrect for hostkeys...\n", fs); | ||
6108 | } | ||
6109 | else | ||
6110 | { | ||
6111 | total_hostkeys = fs / HOSTKEYFILESIZE; | ||
6112 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
6113 | "Will read %llu hostkeys from file\n", total_hostkeys); | ||
6114 | pg->hostkey_data = GNUNET_malloc_large (fs); | ||
6115 | GNUNET_assert (fs == GNUNET_DISK_file_read (fd, pg->hostkey_data, fs)); | ||
6116 | } | ||
6117 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); | ||
6106 | } | 6118 | } |
6119 | GNUNET_free (hostkeys_file); | ||
6120 | } | ||
6107 | 6121 | ||
6108 | for (off = 0; off < total; off++) | 6122 | for (off = 0; off < total; off++) |
6123 | { | ||
6124 | if (hostcnt > 0) | ||
6109 | { | 6125 | { |
6110 | if (hostcnt > 0) | 6126 | hostname = pg->hosts[off % hostcnt].hostname; |
6111 | { | 6127 | username = pg->hosts[off % hostcnt].username; |
6112 | hostname = pg->hosts[off % hostcnt].hostname; | 6128 | sshport = pg->hosts[off % hostcnt].sshport; |
6113 | username = pg->hosts[off % hostcnt].username; | 6129 | pcfg = make_config (cfg, off, &pg->hosts[off % hostcnt].minport, |
6114 | sshport = pg->hosts[off % hostcnt].sshport; | 6130 | &upnum, hostname, &fdnum); |
6115 | pcfg = make_config (cfg, off, &pg->hosts[off % hostcnt].minport, | 6131 | } |
6116 | &upnum, hostname, &fdnum); | 6132 | else |
6117 | } | 6133 | { |
6118 | else | 6134 | hostname = NULL; |
6119 | { | 6135 | username = NULL; |
6120 | hostname = NULL; | 6136 | sshport = 0; |
6121 | username = NULL; | 6137 | pcfg = make_config (cfg, off, &minport, &upnum, hostname, &fdnum); |
6122 | sshport = 0; | 6138 | } |
6123 | pcfg = make_config (cfg, off, &minport, &upnum, hostname, &fdnum); | ||
6124 | } | ||
6125 | 6139 | ||
6126 | if (NULL == pcfg) | 6140 | if (NULL == pcfg) |
6127 | { | 6141 | { |
6128 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 6142 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
6129 | _("Could not create configuration for peer number %u on `%s'!\n"), | 6143 | _ |
6130 | off, | 6144 | ("Could not create configuration for peer number %u on `%s'!\n"), |
6131 | hostname == NULL ? "localhost" : hostname); | 6145 | off, hostname == NULL ? "localhost" : hostname); |
6132 | continue; | 6146 | continue; |
6133 | } | 6147 | } |
6134 | 6148 | ||
6135 | if (GNUNET_YES | 6149 | if (GNUNET_YES |
6136 | == GNUNET_CONFIGURATION_get_value_string (pcfg, "PATHS", | 6150 | == GNUNET_CONFIGURATION_get_value_string (pcfg, "PATHS", |
6137 | "SERVICEHOME", | 6151 | "SERVICEHOME", |
6138 | &baseservicehome)) | 6152 | &baseservicehome)) |
6139 | { | 6153 | { |
6140 | if (hostname != NULL) | 6154 | if (hostname != NULL) |
6141 | GNUNET_asprintf (&newservicehome, "%s/%s/%d/", baseservicehome, hostname, off); | 6155 | GNUNET_asprintf (&newservicehome, "%s/%s/%d/", baseservicehome, |
6142 | else | 6156 | hostname, off); |
6143 | GNUNET_asprintf (&newservicehome, "%s/%d/", baseservicehome, off); | ||
6144 | GNUNET_free (baseservicehome); | ||
6145 | baseservicehome = NULL; | ||
6146 | } | ||
6147 | else | 6157 | else |
6148 | { | 6158 | GNUNET_asprintf (&newservicehome, "%s/%d/", baseservicehome, off); |
6149 | tmpdir = getenv ("TMPDIR"); | 6159 | GNUNET_free (baseservicehome); |
6150 | tmpdir = tmpdir ? tmpdir : "/tmp"; | 6160 | baseservicehome = NULL; |
6151 | if (hostname != NULL) | 6161 | } |
6152 | GNUNET_asprintf (&newservicehome, "%s/%s/%s/%d/", tmpdir, hostname, | 6162 | else |
6153 | "gnunet-testing-test-test", off); | 6163 | { |
6154 | else | 6164 | tmpdir = getenv ("TMPDIR"); |
6155 | GNUNET_asprintf (&newservicehome, "%s/%s/%d/", tmpdir, | 6165 | tmpdir = tmpdir ? tmpdir : "/tmp"; |
6156 | "gnunet-testing-test-test", off); | 6166 | if (hostname != NULL) |
6157 | } | 6167 | GNUNET_asprintf (&newservicehome, "%s/%s/%s/%d/", tmpdir, hostname, |
6158 | GNUNET_CONFIGURATION_set_value_string (pcfg, "PATHS", "SERVICEHOME", | 6168 | "gnunet-testing-test-test", off); |
6159 | newservicehome); | 6169 | else |
6160 | GNUNET_free (newservicehome); | 6170 | GNUNET_asprintf (&newservicehome, "%s/%s/%d/", tmpdir, |
6161 | pg->peers[off].cfg = pcfg; | 6171 | "gnunet-testing-test-test", off); |
6162 | pg->peers[off].pg = pg; | 6172 | } |
6163 | pg->peers[off].internal_context.peer = &pg->peers[off]; | 6173 | GNUNET_CONFIGURATION_set_value_string (pcfg, "PATHS", "SERVICEHOME", |
6164 | pg->peers[off].internal_context.timeout = timeout; | 6174 | newservicehome); |
6165 | pg->peers[off].internal_context.hostname = hostname; | 6175 | GNUNET_free (newservicehome); |
6166 | pg->peers[off].internal_context.username = username; | 6176 | pg->peers[off].cfg = pcfg; |
6167 | pg->peers[off].internal_context.sshport = sshport; | 6177 | pg->peers[off].pg = pg; |
6168 | if (pg->hostkey_data != NULL) | 6178 | pg->peers[off].internal_context.peer = &pg->peers[off]; |
6169 | pg->peers[off].internal_context.hostkey = &pg->hostkey_data[off | 6179 | pg->peers[off].internal_context.timeout = timeout; |
6170 | * HOSTKEYFILESIZE]; | 6180 | pg->peers[off].internal_context.hostname = hostname; |
6171 | pg->peers[off].internal_context.hostkey_callback = hostkey_callback; | 6181 | pg->peers[off].internal_context.username = username; |
6172 | pg->peers[off].internal_context.hostkey_cls = hostkey_cls; | 6182 | pg->peers[off].internal_context.sshport = sshport; |
6173 | pg->peers[off].internal_context.start_cb = cb; | 6183 | if (pg->hostkey_data != NULL) |
6174 | pg->peers[off].internal_context.start_cb_cls = cb_cls; | 6184 | pg->peers[off].internal_context.hostkey = &pg->hostkey_data[off |
6185 | * | ||
6186 | HOSTKEYFILESIZE]; | ||
6187 | pg->peers[off].internal_context.hostkey_callback = hostkey_callback; | ||
6188 | pg->peers[off].internal_context.hostkey_cls = hostkey_cls; | ||
6189 | pg->peers[off].internal_context.start_cb = cb; | ||
6190 | pg->peers[off].internal_context.start_cb_cls = cb_cls; | ||
6175 | #if !USE_START_HELPER | 6191 | #if !USE_START_HELPER |
6176 | GNUNET_SCHEDULER_add_now (&internal_start, | 6192 | GNUNET_SCHEDULER_add_now (&internal_start, |
6177 | &pg->peers[off].internal_context); | 6193 | &pg->peers[off].internal_context); |
6178 | #else | 6194 | #else |
6179 | if ((pg->hostkey_data != NULL) && (hostcnt > 0)) | 6195 | if ((pg->hostkey_data != NULL) && (hostcnt > 0)) |
6180 | { | 6196 | { |
6181 | pg->peers[off].daemon | 6197 | pg->peers[off].daemon |
6182 | = GNUNET_TESTING_daemon_start (pcfg, | 6198 | = GNUNET_TESTING_daemon_start (pcfg, |
6183 | timeout, | 6199 | timeout, |
6184 | GNUNET_YES, | 6200 | GNUNET_YES, |
6185 | hostname, | 6201 | hostname, |
6186 | username, | 6202 | username, |
6187 | sshport, | 6203 | sshport, |
6188 | pg->peers[off].internal_context.hostkey, | 6204 | pg->peers[off]. |
6189 | &internal_hostkey_callback, | 6205 | internal_context.hostkey, |
6190 | &pg->peers[off].internal_context, | 6206 | &internal_hostkey_callback, |
6191 | &internal_startup_callback, | 6207 | &pg->peers[off].internal_context, |
6192 | &pg->peers[off].internal_context); | 6208 | &internal_startup_callback, |
6209 | &pg->peers[off].internal_context); | ||
6193 | /** | 6210 | /** |
6194 | * At this point, given that we had a hostkeyfile, | 6211 | * At this point, given that we had a hostkeyfile, |
6195 | * we can call the hostkey callback! | 6212 | * we can call the hostkey callback! |
@@ -6199,95 +6216,94 @@ GNUNET_TESTING_daemons_start(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
6199 | * then set pg->whatever_phase for each peer and let them | 6216 | * then set pg->whatever_phase for each peer and let them |
6200 | * enter the fsm to get the HELLO's for peers and start connecting. | 6217 | * enter the fsm to get the HELLO's for peers and start connecting. |
6201 | */ | 6218 | */ |
6202 | } | 6219 | } |
6203 | else | 6220 | else |
6204 | { | 6221 | { |
6205 | GNUNET_SCHEDULER_add_now (&internal_start, | 6222 | GNUNET_SCHEDULER_add_now (&internal_start, |
6206 | &pg->peers[off].internal_context); | 6223 | &pg->peers[off].internal_context); |
6207 | } | 6224 | } |
6208 | 6225 | ||
6209 | #endif | 6226 | #endif |
6210 | } | 6227 | } |
6211 | 6228 | ||
6212 | #if USE_START_HELPER /* Now the peergroup has been set up, hostkeys and configs written to files. */ | 6229 | #if USE_START_HELPER /* Now the peergroup has been set up, hostkeys and configs written to files. */ |
6213 | if ((pg->hostkey_data != NULL) && (hostcnt > 0)) | 6230 | if ((pg->hostkey_data != NULL) && (hostcnt > 0)) |
6231 | { | ||
6232 | for (off = 0; off < hostcnt; off++) | ||
6214 | { | 6233 | { |
6215 | for (off = 0; off < hostcnt; off++) | ||
6216 | { | ||
6217 | 6234 | ||
6218 | if (hostcnt > 0) | 6235 | if (hostcnt > 0) |
6219 | { | 6236 | { |
6220 | hostname = pg->hosts[off % hostcnt].hostname; | 6237 | hostname = pg->hosts[off % hostcnt].hostname; |
6221 | username = pg->hosts[off % hostcnt].username; | 6238 | username = pg->hosts[off % hostcnt].username; |
6222 | sshport = pg->hosts[off % hostcnt].sshport; | 6239 | sshport = pg->hosts[off % hostcnt].sshport; |
6223 | } | 6240 | } |
6224 | else | 6241 | else |
6225 | { | 6242 | { |
6226 | hostname = NULL; | 6243 | hostname = NULL; |
6227 | username = NULL; | 6244 | username = NULL; |
6228 | sshport = 0; | 6245 | sshport = 0; |
6229 | } | 6246 | } |
6230 | |||
6231 | if (GNUNET_YES | ||
6232 | == GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", | ||
6233 | "SERVICEHOME", | ||
6234 | &baseservicehome)) | ||
6235 | { | ||
6236 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "baseservice home is %s\n", baseservicehome); | ||
6237 | if (hostname != NULL) | ||
6238 | GNUNET_asprintf (&newservicehome, "%s/%s/", baseservicehome, hostname); | ||
6239 | else | ||
6240 | GNUNET_asprintf (&newservicehome, "%s/", baseservicehome); | ||
6241 | GNUNET_free (baseservicehome); | ||
6242 | baseservicehome = NULL; | ||
6243 | } | ||
6244 | else | ||
6245 | { | ||
6246 | tmpdir = getenv ("TMPDIR"); | ||
6247 | tmpdir = tmpdir ? tmpdir : "/tmp"; | ||
6248 | if (hostname != NULL) | ||
6249 | GNUNET_asprintf (&newservicehome, "%s/%s/%s/", tmpdir, hostname, | ||
6250 | "gnunet-testing-test-test"); | ||
6251 | else | ||
6252 | GNUNET_asprintf (&newservicehome, "%s/%s/", tmpdir, | ||
6253 | "gnunet-testing-test-test", off); | ||
6254 | } | ||
6255 | |||
6256 | if (NULL != username) | ||
6257 | GNUNET_asprintf (&arg, | ||
6258 | "%s@%s:%s", | ||
6259 | username, | ||
6260 | pg->hosts[off].hostname, | ||
6261 | newservicehome); | ||
6262 | else | ||
6263 | GNUNET_asprintf (&arg, | ||
6264 | "%s:%s", | ||
6265 | pg->hosts[off].hostname, | ||
6266 | newservicehome); | ||
6267 | |||
6268 | /* FIXME: Doesn't support ssh_port option! */ | ||
6269 | proc = GNUNET_OS_start_process (NULL, NULL, | ||
6270 | "rsync", | ||
6271 | "rsync", "-r", newservicehome, arg, NULL); | ||
6272 | 6247 | ||
6273 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 6248 | if (GNUNET_YES |
6274 | "copying directory with command rsync -r %s %s\n", | 6249 | == GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", |
6275 | newservicehome, arg); | 6250 | "SERVICEHOME", |
6276 | GNUNET_free(newservicehome); | 6251 | &baseservicehome)) |
6277 | GNUNET_free (arg); | 6252 | { |
6278 | if (NULL == proc) | 6253 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "baseservice home is %s\n", |
6279 | { | 6254 | baseservicehome); |
6280 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 6255 | if (hostname != NULL) |
6281 | _("Could not start `%s' process to copy configuration directory.\n"), | 6256 | GNUNET_asprintf (&newservicehome, "%s/%s/", baseservicehome, |
6282 | "scp"); | 6257 | hostname); |
6283 | GNUNET_assert(0); | 6258 | else |
6284 | } | 6259 | GNUNET_asprintf (&newservicehome, "%s/", baseservicehome); |
6285 | GNUNET_OS_process_wait (proc); | 6260 | GNUNET_free (baseservicehome); |
6286 | GNUNET_OS_process_close (proc); | 6261 | baseservicehome = NULL; |
6287 | } | 6262 | } |
6288 | /* Now all the configuration files and hostkeys are copied to the remote host. Call the hostkey callback for each peer! */ | 6263 | else |
6289 | GNUNET_SCHEDULER_add_now (&call_hostkey_callbacks, pg); | 6264 | { |
6265 | tmpdir = getenv ("TMPDIR"); | ||
6266 | tmpdir = tmpdir ? tmpdir : "/tmp"; | ||
6267 | if (hostname != NULL) | ||
6268 | GNUNET_asprintf (&newservicehome, "%s/%s/%s/", tmpdir, hostname, | ||
6269 | "gnunet-testing-test-test"); | ||
6270 | else | ||
6271 | GNUNET_asprintf (&newservicehome, "%s/%s/", tmpdir, | ||
6272 | "gnunet-testing-test-test", off); | ||
6273 | } | ||
6274 | |||
6275 | if (NULL != username) | ||
6276 | GNUNET_asprintf (&arg, | ||
6277 | "%s@%s:%s", | ||
6278 | username, pg->hosts[off].hostname, newservicehome); | ||
6279 | else | ||
6280 | GNUNET_asprintf (&arg, | ||
6281 | "%s:%s", pg->hosts[off].hostname, newservicehome); | ||
6282 | |||
6283 | /* FIXME: Doesn't support ssh_port option! */ | ||
6284 | proc = GNUNET_OS_start_process (NULL, NULL, | ||
6285 | "rsync", | ||
6286 | "rsync", "-r", newservicehome, arg, NULL); | ||
6287 | |||
6288 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
6289 | "copying directory with command rsync -r %s %s\n", | ||
6290 | newservicehome, arg); | ||
6291 | GNUNET_free (newservicehome); | ||
6292 | GNUNET_free (arg); | ||
6293 | if (NULL == proc) | ||
6294 | { | ||
6295 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
6296 | _ | ||
6297 | ("Could not start `%s' process to copy configuration directory.\n"), | ||
6298 | "scp"); | ||
6299 | GNUNET_assert (0); | ||
6300 | } | ||
6301 | GNUNET_OS_process_wait (proc); | ||
6302 | GNUNET_OS_process_close (proc); | ||
6290 | } | 6303 | } |
6304 | /* Now all the configuration files and hostkeys are copied to the remote host. Call the hostkey callback for each peer! */ | ||
6305 | GNUNET_SCHEDULER_add_now (&call_hostkey_callbacks, pg); | ||
6306 | } | ||
6291 | #endif | 6307 | #endif |
6292 | return pg; | 6308 | return pg; |
6293 | } | 6309 | } |
@@ -6297,8 +6313,8 @@ GNUNET_TESTING_daemons_start(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
6297 | * offsetting operation. | 6313 | * offsetting operation. |
6298 | */ | 6314 | */ |
6299 | struct GNUNET_TESTING_Daemon * | 6315 | struct GNUNET_TESTING_Daemon * |
6300 | GNUNET_TESTING_daemon_get(struct GNUNET_TESTING_PeerGroup *pg, | 6316 | GNUNET_TESTING_daemon_get (struct GNUNET_TESTING_PeerGroup *pg, |
6301 | unsigned int position) | 6317 | unsigned int position) |
6302 | { | 6318 | { |
6303 | if (position < pg->total) | 6319 | if (position < pg->total) |
6304 | return pg->peers[position].daemon; | 6320 | return pg->peers[position].daemon; |
@@ -6315,17 +6331,17 @@ GNUNET_TESTING_daemon_get(struct GNUNET_TESTING_PeerGroup *pg, | |||
6315 | * @return the daemon on success, or NULL if no such peer identity is found | 6331 | * @return the daemon on success, or NULL if no such peer identity is found |
6316 | */ | 6332 | */ |
6317 | struct GNUNET_TESTING_Daemon * | 6333 | struct GNUNET_TESTING_Daemon * |
6318 | GNUNET_TESTING_daemon_get_by_id(struct GNUNET_TESTING_PeerGroup *pg, | 6334 | GNUNET_TESTING_daemon_get_by_id (struct GNUNET_TESTING_PeerGroup *pg, |
6319 | struct GNUNET_PeerIdentity *peer_id) | 6335 | struct GNUNET_PeerIdentity *peer_id) |
6320 | { | 6336 | { |
6321 | unsigned int i; | 6337 | unsigned int i; |
6322 | 6338 | ||
6323 | for (i = 0; i < pg->total; i++) | 6339 | for (i = 0; i < pg->total; i++) |
6324 | { | 6340 | { |
6325 | if (0 == memcmp (&pg->peers[i].daemon->id, peer_id, | 6341 | if (0 == memcmp (&pg->peers[i].daemon->id, peer_id, |
6326 | sizeof(struct GNUNET_PeerIdentity))) | 6342 | sizeof (struct GNUNET_PeerIdentity))) |
6327 | return pg->peers[i].daemon; | 6343 | return pg->peers[i].daemon; |
6328 | } | 6344 | } |
6329 | return NULL; | 6345 | return NULL; |
6330 | } | 6346 | } |
6331 | 6347 | ||
@@ -6340,33 +6356,34 @@ GNUNET_TESTING_daemon_get_by_id(struct GNUNET_TESTING_PeerGroup *pg, | |||
6340 | * @param emsg NULL on success | 6356 | * @param emsg NULL on success |
6341 | */ | 6357 | */ |
6342 | static void | 6358 | static void |
6343 | restart_callback(void *cls, const struct GNUNET_PeerIdentity *id, | 6359 | restart_callback (void *cls, const struct GNUNET_PeerIdentity *id, |
6344 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 6360 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
6345 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 6361 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
6346 | { | 6362 | { |
6347 | struct RestartContext *restart_context = cls; | 6363 | struct RestartContext *restart_context = cls; |
6348 | 6364 | ||
6349 | if (emsg == NULL) | 6365 | if (emsg == NULL) |
6350 | { | 6366 | { |
6351 | restart_context->peers_restarted++; | 6367 | restart_context->peers_restarted++; |
6352 | } | 6368 | } |
6353 | else | 6369 | else |
6354 | { | 6370 | { |
6355 | restart_context->peers_restart_failed++; | 6371 | restart_context->peers_restart_failed++; |
6356 | } | 6372 | } |
6357 | 6373 | ||
6358 | if (restart_context->peers_restarted == restart_context->peer_group->total) | 6374 | if (restart_context->peers_restarted == restart_context->peer_group->total) |
6359 | { | 6375 | { |
6360 | restart_context->callback (restart_context->callback_cls, NULL); | 6376 | restart_context->callback (restart_context->callback_cls, NULL); |
6361 | GNUNET_free (restart_context); | 6377 | GNUNET_free (restart_context); |
6362 | } | 6378 | } |
6363 | else if (restart_context->peers_restart_failed | 6379 | else if (restart_context->peers_restart_failed |
6364 | + restart_context->peers_restarted == restart_context->peer_group->total) | 6380 | + restart_context->peers_restarted == |
6365 | { | 6381 | restart_context->peer_group->total) |
6366 | restart_context->callback (restart_context->callback_cls, | 6382 | { |
6367 | "Failed to restart peers!"); | 6383 | restart_context->callback (restart_context->callback_cls, |
6368 | GNUNET_free (restart_context); | 6384 | "Failed to restart peers!"); |
6369 | } | 6385 | GNUNET_free (restart_context); |
6386 | } | ||
6370 | 6387 | ||
6371 | } | 6388 | } |
6372 | 6389 | ||
@@ -6379,7 +6396,7 @@ restart_callback(void *cls, const struct GNUNET_PeerIdentity *id, | |||
6379 | * | 6396 | * |
6380 | */ | 6397 | */ |
6381 | static void | 6398 | static void |
6382 | churn_stop_callback(void *cls, const char *emsg) | 6399 | churn_stop_callback (void *cls, const char *emsg) |
6383 | { | 6400 | { |
6384 | struct ShutdownContext *shutdown_ctx = cls; | 6401 | struct ShutdownContext *shutdown_ctx = cls; |
6385 | struct ChurnContext *churn_ctx = shutdown_ctx->cb_cls; | 6402 | struct ChurnContext *churn_ctx = shutdown_ctx->cb_cls; |
@@ -6390,34 +6407,32 @@ churn_stop_callback(void *cls, const char *emsg) | |||
6390 | shutdown_ctx->outstanding--; | 6407 | shutdown_ctx->outstanding--; |
6391 | 6408 | ||
6392 | if (emsg != NULL) | 6409 | if (emsg != NULL) |
6393 | { | 6410 | { |
6394 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 6411 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
6395 | "Churn stop callback failed with error `%s'\n", emsg); | 6412 | "Churn stop callback failed with error `%s'\n", emsg); |
6396 | churn_ctx->num_failed_stop++; | 6413 | churn_ctx->num_failed_stop++; |
6397 | } | 6414 | } |
6398 | else | 6415 | else |
6399 | { | 6416 | { |
6400 | churn_ctx->num_to_stop--; | 6417 | churn_ctx->num_to_stop--; |
6401 | } | 6418 | } |
6402 | 6419 | ||
6403 | total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) | 6420 | total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) |
6404 | + (churn_ctx->num_to_start - churn_ctx->num_failed_start); | 6421 | + (churn_ctx->num_to_start - churn_ctx->num_failed_start); |
6405 | 6422 | ||
6406 | if (total_left == 0) | 6423 | if (total_left == 0) |
6424 | { | ||
6425 | if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0)) | ||
6407 | { | 6426 | { |
6408 | if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0)) | 6427 | GNUNET_asprintf (&error_message, |
6409 | { | 6428 | "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!", |
6410 | GNUNET_asprintf ( | 6429 | churn_ctx->num_failed_start, churn_ctx->num_failed_stop); |
6411 | &error_message, | ||
6412 | "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!", | ||
6413 | churn_ctx->num_failed_start, | ||
6414 | churn_ctx->num_failed_stop); | ||
6415 | } | ||
6416 | churn_ctx->cb (churn_ctx->cb_cls, error_message); | ||
6417 | GNUNET_free_non_null (error_message); | ||
6418 | GNUNET_free (churn_ctx); | ||
6419 | GNUNET_free (shutdown_ctx); | ||
6420 | } | 6430 | } |
6431 | churn_ctx->cb (churn_ctx->cb_cls, error_message); | ||
6432 | GNUNET_free_non_null (error_message); | ||
6433 | GNUNET_free (churn_ctx); | ||
6434 | GNUNET_free (shutdown_ctx); | ||
6435 | } | ||
6421 | } | 6436 | } |
6422 | 6437 | ||
6423 | /** | 6438 | /** |
@@ -6428,18 +6443,19 @@ churn_stop_callback(void *cls, const char *emsg) | |||
6428 | * @return the number of currently running peers in the peer group | 6443 | * @return the number of currently running peers in the peer group |
6429 | */ | 6444 | */ |
6430 | unsigned int | 6445 | unsigned int |
6431 | GNUNET_TESTING_daemons_running(struct GNUNET_TESTING_PeerGroup *pg) | 6446 | GNUNET_TESTING_daemons_running (struct GNUNET_TESTING_PeerGroup *pg) |
6432 | { | 6447 | { |
6433 | unsigned int i; | 6448 | unsigned int i; |
6434 | unsigned int running = 0; | 6449 | unsigned int running = 0; |
6450 | |||
6435 | for (i = 0; i < pg->total; i++) | 6451 | for (i = 0; i < pg->total; i++) |
6452 | { | ||
6453 | if (pg->peers[i].daemon->running == GNUNET_YES) | ||
6436 | { | 6454 | { |
6437 | if (pg->peers[i].daemon->running == GNUNET_YES) | 6455 | GNUNET_assert (running != -1); |
6438 | { | 6456 | running++; |
6439 | GNUNET_assert (running != -1); | ||
6440 | running++; | ||
6441 | } | ||
6442 | } | 6457 | } |
6458 | } | ||
6443 | return running; | 6459 | return running; |
6444 | } | 6460 | } |
6445 | 6461 | ||
@@ -6451,37 +6467,36 @@ GNUNET_TESTING_daemons_running(struct GNUNET_TESTING_PeerGroup *pg) | |||
6451 | * to calling gnunet-arm N times all at once). | 6467 | * to calling gnunet-arm N times all at once). |
6452 | */ | 6468 | */ |
6453 | static void | 6469 | static void |
6454 | schedule_churn_shutdown_task(void *cls, | 6470 | schedule_churn_shutdown_task (void *cls, |
6455 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 6471 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
6456 | { | 6472 | { |
6457 | struct PeerShutdownContext *peer_shutdown_ctx = cls; | 6473 | struct PeerShutdownContext *peer_shutdown_ctx = cls; |
6458 | struct ShutdownContext *shutdown_ctx; | 6474 | struct ShutdownContext *shutdown_ctx; |
6459 | struct ChurnContext *churn_ctx; | 6475 | struct ChurnContext *churn_ctx; |
6476 | |||
6460 | GNUNET_assert (peer_shutdown_ctx != NULL); | 6477 | GNUNET_assert (peer_shutdown_ctx != NULL); |
6461 | shutdown_ctx = peer_shutdown_ctx->shutdown_ctx; | 6478 | shutdown_ctx = peer_shutdown_ctx->shutdown_ctx; |
6462 | GNUNET_assert (shutdown_ctx != NULL); | 6479 | GNUNET_assert (shutdown_ctx != NULL); |
6463 | churn_ctx = (struct ChurnContext *) shutdown_ctx->cb_cls; | 6480 | churn_ctx = (struct ChurnContext *) shutdown_ctx->cb_cls; |
6464 | if (shutdown_ctx->outstanding > churn_ctx->pg->max_concurrent_ssh) | 6481 | if (shutdown_ctx->outstanding > churn_ctx->pg->max_concurrent_ssh) |
6465 | GNUNET_SCHEDULER_add_delayed ( | 6482 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
6466 | GNUNET_TIME_relative_multiply ( | 6483 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
6467 | GNUNET_TIME_UNIT_MILLISECONDS, | ||
6468 | 100), | ||
6469 | &schedule_churn_shutdown_task, | 6484 | &schedule_churn_shutdown_task, |
6470 | peer_shutdown_ctx); | 6485 | peer_shutdown_ctx); |
6471 | else | 6486 | else |
6472 | { | 6487 | { |
6473 | shutdown_ctx->outstanding++; | 6488 | shutdown_ctx->outstanding++; |
6474 | if (churn_ctx->service != NULL) | 6489 | if (churn_ctx->service != NULL) |
6475 | GNUNET_TESTING_daemon_stop_service (peer_shutdown_ctx->daemon, | 6490 | GNUNET_TESTING_daemon_stop_service (peer_shutdown_ctx->daemon, |
6476 | churn_ctx->service, | 6491 | churn_ctx->service, |
6477 | shutdown_ctx->timeout, shutdown_ctx->cb, | 6492 | shutdown_ctx->timeout, |
6478 | shutdown_ctx); | 6493 | shutdown_ctx->cb, shutdown_ctx); |
6479 | else | 6494 | else |
6480 | GNUNET_TESTING_daemon_stop (peer_shutdown_ctx->daemon, | 6495 | GNUNET_TESTING_daemon_stop (peer_shutdown_ctx->daemon, |
6481 | shutdown_ctx->timeout, shutdown_ctx->cb, | 6496 | shutdown_ctx->timeout, shutdown_ctx->cb, |
6482 | shutdown_ctx, GNUNET_NO, GNUNET_YES); | 6497 | shutdown_ctx, GNUNET_NO, GNUNET_YES); |
6483 | GNUNET_free (peer_shutdown_ctx); | 6498 | GNUNET_free (peer_shutdown_ctx); |
6484 | } | 6499 | } |
6485 | } | 6500 | } |
6486 | 6501 | ||
6487 | 6502 | ||
@@ -6507,11 +6522,11 @@ schedule_churn_shutdown_task(void *cls, | |||
6507 | * @param cb_cls closure for cb | 6522 | * @param cb_cls closure for cb |
6508 | */ | 6523 | */ |
6509 | void | 6524 | void |
6510 | GNUNET_TESTING_daemons_churn(struct GNUNET_TESTING_PeerGroup *pg, | 6525 | GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg, |
6511 | char *service, | 6526 | char *service, |
6512 | unsigned int voff, unsigned int von, | 6527 | unsigned int voff, unsigned int von, |
6513 | struct GNUNET_TIME_Relative timeout, | 6528 | struct GNUNET_TIME_Relative timeout, |
6514 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) | 6529 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) |
6515 | { | 6530 | { |
6516 | struct ChurnContext *churn_ctx; | 6531 | struct ChurnContext *churn_ctx; |
6517 | struct ShutdownContext *shutdown_ctx; | 6532 | struct ShutdownContext *shutdown_ctx; |
@@ -6538,73 +6553,75 @@ GNUNET_TESTING_daemons_churn(struct GNUNET_TESTING_PeerGroup *pg, | |||
6538 | running = 0; | 6553 | running = 0; |
6539 | stopped = 0; | 6554 | stopped = 0; |
6540 | 6555 | ||
6541 | if ((von == 0) && (voff == 0)) /* No peers at all? */ | 6556 | if ((von == 0) && (voff == 0)) /* No peers at all? */ |
6542 | { | 6557 | { |
6543 | cb (cb_cls, NULL); | 6558 | cb (cb_cls, NULL); |
6544 | return; | 6559 | return; |
6545 | } | 6560 | } |
6546 | 6561 | ||
6547 | for (i = 0; i < pg->total; i++) | 6562 | for (i = 0; i < pg->total; i++) |
6563 | { | ||
6564 | if (service == NULL) | ||
6548 | { | 6565 | { |
6549 | if (service == NULL) | 6566 | if (pg->peers[i].daemon->running == GNUNET_YES) |
6550 | { | 6567 | { |
6551 | if (pg->peers[i].daemon->running == GNUNET_YES) | 6568 | GNUNET_assert (running != -1); |
6552 | { | 6569 | running++; |
6553 | GNUNET_assert (running != -1); | 6570 | } |
6554 | running++; | ||
6555 | } | ||
6556 | else | ||
6557 | { | ||
6558 | GNUNET_assert (stopped != -1); | ||
6559 | stopped++; | ||
6560 | } | ||
6561 | } | ||
6562 | else | 6571 | else |
6563 | { | 6572 | { |
6564 | /* FIXME: make churned services a list! */ | 6573 | GNUNET_assert (stopped != -1); |
6565 | pos = pg->peers[i].daemon->churned_services; | 6574 | stopped++; |
6566 | /* FIXME: while (pos != NULL) */ | 6575 | } |
6567 | if (pos != NULL) | 6576 | } |
6568 | { | 6577 | else |
6578 | { | ||
6579 | /* FIXME: make churned services a list! */ | ||
6580 | pos = pg->peers[i].daemon->churned_services; | ||
6581 | /* FIXME: while (pos != NULL) */ | ||
6582 | if (pos != NULL) | ||
6583 | { | ||
6569 | #if FIXME | 6584 | #if FIXME |
6570 | if (0 == strcasecmp(pos, service)) | 6585 | if (0 == strcasecmp (pos, service)) |
6571 | { | 6586 | { |
6572 | 6587 | ||
6573 | break; | 6588 | break; |
6574 | } | ||
6575 | #endif | ||
6576 | GNUNET_assert (stopped != -1); | ||
6577 | stopped++; | ||
6578 | /* FIXME: pos = pos->next; */ | ||
6579 | } | ||
6580 | if (pos == NULL) | ||
6581 | { | ||
6582 | GNUNET_assert (running != -1); | ||
6583 | running++; | ||
6584 | } | ||
6585 | } | 6589 | } |
6590 | #endif | ||
6591 | GNUNET_assert (stopped != -1); | ||
6592 | stopped++; | ||
6593 | /* FIXME: pos = pos->next; */ | ||
6594 | } | ||
6595 | if (pos == NULL) | ||
6596 | { | ||
6597 | GNUNET_assert (running != -1); | ||
6598 | running++; | ||
6599 | } | ||
6586 | } | 6600 | } |
6601 | } | ||
6587 | 6602 | ||
6588 | if (voff > running) | 6603 | if (voff > running) |
6589 | { | 6604 | { |
6590 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 6605 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
6591 | "Trying to stop more peers (%d) than are currently running (%d)!\n", voff, running); | 6606 | "Trying to stop more peers (%d) than are currently running (%d)!\n", |
6592 | cb (cb_cls, "Trying to stop more peers than are currently running!"); | 6607 | voff, running); |
6593 | return; | 6608 | cb (cb_cls, "Trying to stop more peers than are currently running!"); |
6594 | } | 6609 | return; |
6610 | } | ||
6595 | 6611 | ||
6596 | if (von > stopped) | 6612 | if (von > stopped) |
6597 | { | 6613 | { |
6598 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 6614 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
6599 | "Trying to start more peers (%d) than are currently stopped (%d)!\n", von, stopped); | 6615 | "Trying to start more peers (%d) than are currently stopped (%d)!\n", |
6600 | cb (cb_cls, "Trying to start more peers than are currently stopped!"); | 6616 | von, stopped); |
6601 | return; | 6617 | cb (cb_cls, "Trying to start more peers than are currently stopped!"); |
6602 | } | 6618 | return; |
6619 | } | ||
6603 | 6620 | ||
6604 | churn_ctx = GNUNET_malloc (sizeof (struct ChurnContext)); | 6621 | churn_ctx = GNUNET_malloc (sizeof (struct ChurnContext)); |
6605 | 6622 | ||
6606 | if (service != NULL) | 6623 | if (service != NULL) |
6607 | churn_ctx->service = GNUNET_strdup(service); | 6624 | churn_ctx->service = GNUNET_strdup (service); |
6608 | running_arr = NULL; | 6625 | running_arr = NULL; |
6609 | if (running > 0) | 6626 | if (running > 0) |
6610 | running_arr = GNUNET_malloc (running * sizeof (unsigned int)); | 6627 | running_arr = GNUNET_malloc (running * sizeof (unsigned int)); |
@@ -6635,87 +6652,88 @@ GNUNET_TESTING_daemons_churn(struct GNUNET_TESTING_PeerGroup *pg, | |||
6635 | churn_ctx->pg = pg; | 6652 | churn_ctx->pg = pg; |
6636 | 6653 | ||
6637 | for (i = 0; i < pg->total; i++) | 6654 | for (i = 0; i < pg->total; i++) |
6655 | { | ||
6656 | if (service == NULL) | ||
6638 | { | 6657 | { |
6639 | if (service == NULL) | 6658 | if (pg->peers[i].daemon->running == GNUNET_YES) |
6640 | { | 6659 | { |
6641 | if (pg->peers[i].daemon->running == GNUNET_YES) | 6660 | GNUNET_assert ((running_arr != NULL) && (total_running > running)); |
6642 | { | 6661 | running_arr[running] = i; |
6643 | GNUNET_assert ((running_arr != NULL) && (total_running > running)); | 6662 | running++; |
6644 | running_arr[running] = i; | 6663 | } |
6645 | running++; | ||
6646 | } | ||
6647 | else | ||
6648 | { | ||
6649 | GNUNET_assert ((stopped_arr != NULL) && (total_stopped > stopped)); | ||
6650 | stopped_arr[stopped] = i; | ||
6651 | stopped++; | ||
6652 | } | ||
6653 | } | ||
6654 | else | 6664 | else |
6655 | { | 6665 | { |
6656 | /* FIXME: make churned services a list! */ | 6666 | GNUNET_assert ((stopped_arr != NULL) && (total_stopped > stopped)); |
6657 | pos = pg->peers[i].daemon->churned_services; | 6667 | stopped_arr[stopped] = i; |
6658 | /* FIXME: while (pos != NULL) */ | 6668 | stopped++; |
6659 | if (pos != NULL) | 6669 | } |
6660 | { | 6670 | } |
6661 | GNUNET_assert ((stopped_arr != NULL) && (total_stopped > stopped)); | 6671 | else |
6662 | stopped_arr[stopped] = i; | 6672 | { |
6663 | stopped++; | 6673 | /* FIXME: make churned services a list! */ |
6664 | /* FIXME: pos = pos->next; */ | 6674 | pos = pg->peers[i].daemon->churned_services; |
6665 | } | 6675 | /* FIXME: while (pos != NULL) */ |
6666 | if (pos == NULL) | 6676 | if (pos != NULL) |
6667 | { | 6677 | { |
6668 | GNUNET_assert ((running_arr != NULL) && (total_running > running)); | 6678 | GNUNET_assert ((stopped_arr != NULL) && (total_stopped > stopped)); |
6669 | running_arr[running] = i; | 6679 | stopped_arr[stopped] = i; |
6670 | running++; | 6680 | stopped++; |
6671 | } | 6681 | /* FIXME: pos = pos->next; */ |
6672 | } | 6682 | } |
6683 | if (pos == NULL) | ||
6684 | { | ||
6685 | GNUNET_assert ((running_arr != NULL) && (total_running > running)); | ||
6686 | running_arr[running] = i; | ||
6687 | running++; | ||
6688 | } | ||
6673 | } | 6689 | } |
6690 | } | ||
6674 | 6691 | ||
6675 | GNUNET_assert (running >= voff); | 6692 | GNUNET_assert (running >= voff); |
6676 | if (voff > 0) | 6693 | if (voff > 0) |
6677 | { | 6694 | { |
6678 | shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext)); | 6695 | shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext)); |
6679 | shutdown_ctx->cb = &churn_stop_callback; | 6696 | shutdown_ctx->cb = &churn_stop_callback; |
6680 | shutdown_ctx->cb_cls = churn_ctx; | 6697 | shutdown_ctx->cb_cls = churn_ctx; |
6681 | shutdown_ctx->total_peers = voff; | 6698 | shutdown_ctx->total_peers = voff; |
6682 | shutdown_ctx->timeout = timeout; | 6699 | shutdown_ctx->timeout = timeout; |
6683 | } | 6700 | } |
6684 | 6701 | ||
6685 | for (i = 0; i < voff; i++) | 6702 | for (i = 0; i < voff; i++) |
6686 | { | 6703 | { |
6687 | #if DEBUG_CHURN | 6704 | #if DEBUG_CHURN |
6688 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Stopping peer %d!\n", running_arr[running_permute[i]]); | 6705 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Stopping peer %d!\n", |
6689 | #endif | 6706 | running_arr[running_permute[i]]); |
6690 | GNUNET_assert (running_arr != NULL); | 6707 | #endif |
6691 | peer_shutdown_ctx = GNUNET_malloc (sizeof (struct PeerShutdownContext)); | 6708 | GNUNET_assert (running_arr != NULL); |
6692 | peer_shutdown_ctx->daemon | 6709 | peer_shutdown_ctx = GNUNET_malloc (sizeof (struct PeerShutdownContext)); |
6693 | = pg->peers[running_arr[running_permute[i]]].daemon; | 6710 | peer_shutdown_ctx->daemon |
6694 | peer_shutdown_ctx->shutdown_ctx = shutdown_ctx; | 6711 | = pg->peers[running_arr[running_permute[i]]].daemon; |
6695 | GNUNET_SCHEDULER_add_now (&schedule_churn_shutdown_task, | 6712 | peer_shutdown_ctx->shutdown_ctx = shutdown_ctx; |
6696 | peer_shutdown_ctx); | 6713 | GNUNET_SCHEDULER_add_now (&schedule_churn_shutdown_task, peer_shutdown_ctx); |
6697 | } | 6714 | } |
6698 | 6715 | ||
6699 | GNUNET_assert (stopped >= von); | 6716 | GNUNET_assert (stopped >= von); |
6700 | if (von > 0) | 6717 | if (von > 0) |
6701 | { | 6718 | { |
6702 | churn_startup_ctx = GNUNET_malloc (sizeof (struct ChurnRestartContext)); | 6719 | churn_startup_ctx = GNUNET_malloc (sizeof (struct ChurnRestartContext)); |
6703 | churn_startup_ctx->churn_ctx = churn_ctx; | 6720 | churn_startup_ctx->churn_ctx = churn_ctx; |
6704 | churn_startup_ctx->timeout = timeout; | 6721 | churn_startup_ctx->timeout = timeout; |
6705 | churn_startup_ctx->pg = pg; | 6722 | churn_startup_ctx->pg = pg; |
6706 | } | 6723 | } |
6707 | for (i = 0; i < von; i++) | 6724 | for (i = 0; i < von; i++) |
6708 | { | 6725 | { |
6709 | #if DEBUG_CHURN | 6726 | #if DEBUG_CHURN |
6710 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Starting up peer %d!\n", stopped_arr[stopped_permute[i]]); | 6727 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Starting up peer %d!\n", |
6711 | #endif | 6728 | stopped_arr[stopped_permute[i]]); |
6712 | GNUNET_assert (stopped_arr != NULL); | 6729 | #endif |
6713 | peer_restart_ctx = GNUNET_malloc (sizeof (struct PeerRestartContext)); | 6730 | GNUNET_assert (stopped_arr != NULL); |
6714 | peer_restart_ctx->churn_restart_ctx = churn_startup_ctx; | 6731 | peer_restart_ctx = GNUNET_malloc (sizeof (struct PeerRestartContext)); |
6715 | peer_restart_ctx->daemon | 6732 | peer_restart_ctx->churn_restart_ctx = churn_startup_ctx; |
6716 | = pg->peers[stopped_arr[stopped_permute[i]]].daemon; | 6733 | peer_restart_ctx->daemon |
6717 | GNUNET_SCHEDULER_add_now (&schedule_churn_restart, peer_restart_ctx); | 6734 | = pg->peers[stopped_arr[stopped_permute[i]]].daemon; |
6718 | } | 6735 | GNUNET_SCHEDULER_add_now (&schedule_churn_restart, peer_restart_ctx); |
6736 | } | ||
6719 | 6737 | ||
6720 | GNUNET_free_non_null (running_arr); | 6738 | GNUNET_free_non_null (running_arr); |
6721 | GNUNET_free_non_null (stopped_arr); | 6739 | GNUNET_free_non_null (stopped_arr); |
@@ -6745,26 +6763,28 @@ GNUNET_TESTING_daemons_start_service (struct GNUNET_TESTING_PeerGroup *pg, | |||
6745 | struct PeerServiceStartContext *peer_start_ctx; | 6763 | struct PeerServiceStartContext *peer_start_ctx; |
6746 | unsigned int i; | 6764 | unsigned int i; |
6747 | 6765 | ||
6748 | GNUNET_assert(service != NULL); | 6766 | GNUNET_assert (service != NULL); |
6749 | 6767 | ||
6750 | start_ctx = GNUNET_malloc(sizeof(struct ServiceStartContext)); | 6768 | start_ctx = GNUNET_malloc (sizeof (struct ServiceStartContext)); |
6751 | start_ctx->pg = pg; | 6769 | start_ctx->pg = pg; |
6752 | start_ctx->remaining = pg->total; | 6770 | start_ctx->remaining = pg->total; |
6753 | start_ctx->cb = cb; | 6771 | start_ctx->cb = cb; |
6754 | start_ctx->cb_cls = cb_cls; | 6772 | start_ctx->cb_cls = cb_cls; |
6755 | start_ctx->service = GNUNET_strdup(service); | 6773 | start_ctx->service = GNUNET_strdup (service); |
6756 | start_ctx->timeout = timeout; | 6774 | start_ctx->timeout = timeout; |
6757 | 6775 | ||
6758 | for (i = 0; i < pg->total; i++) | 6776 | for (i = 0; i < pg->total; i++) |
6759 | { | 6777 | { |
6760 | #if DEBUG_START | 6778 | #if DEBUG_START |
6761 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Starting up service %s on peer %d!\n", service, stopped_arr[stopped_permute[i]]); | 6779 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
6780 | "Starting up service %s on peer %d!\n", service, | ||
6781 | stopped_arr[stopped_permute[i]]); | ||
6762 | #endif | 6782 | #endif |
6763 | peer_start_ctx = GNUNET_malloc (sizeof (struct PeerServiceStartContext)); | 6783 | peer_start_ctx = GNUNET_malloc (sizeof (struct PeerServiceStartContext)); |
6764 | peer_start_ctx->start_ctx = start_ctx; | 6784 | peer_start_ctx->start_ctx = start_ctx; |
6765 | peer_start_ctx->daemon = pg->peers[i].daemon; | 6785 | peer_start_ctx->daemon = pg->peers[i].daemon; |
6766 | GNUNET_SCHEDULER_add_now (&schedule_service_start, peer_start_ctx); | 6786 | GNUNET_SCHEDULER_add_now (&schedule_service_start, peer_start_ctx); |
6767 | } | 6787 | } |
6768 | } | 6788 | } |
6769 | 6789 | ||
6770 | /** | 6790 | /** |
@@ -6775,27 +6795,27 @@ GNUNET_TESTING_daemons_start_service (struct GNUNET_TESTING_PeerGroup *pg, | |||
6775 | * @param callback_cls closure for the callback function | 6795 | * @param callback_cls closure for the callback function |
6776 | */ | 6796 | */ |
6777 | void | 6797 | void |
6778 | GNUNET_TESTING_daemons_restart(struct GNUNET_TESTING_PeerGroup *pg, | 6798 | GNUNET_TESTING_daemons_restart (struct GNUNET_TESTING_PeerGroup *pg, |
6779 | GNUNET_TESTING_NotifyCompletion callback, | 6799 | GNUNET_TESTING_NotifyCompletion callback, |
6780 | void *callback_cls) | 6800 | void *callback_cls) |
6781 | { | 6801 | { |
6782 | struct RestartContext *restart_context; | 6802 | struct RestartContext *restart_context; |
6783 | unsigned int off; | 6803 | unsigned int off; |
6784 | 6804 | ||
6785 | if (pg->total > 0) | 6805 | if (pg->total > 0) |
6786 | { | 6806 | { |
6787 | restart_context = GNUNET_malloc (sizeof (struct RestartContext)); | 6807 | restart_context = GNUNET_malloc (sizeof (struct RestartContext)); |
6788 | restart_context->peer_group = pg; | 6808 | restart_context->peer_group = pg; |
6789 | restart_context->peers_restarted = 0; | 6809 | restart_context->peers_restarted = 0; |
6790 | restart_context->callback = callback; | 6810 | restart_context->callback = callback; |
6791 | restart_context->callback_cls = callback_cls; | 6811 | restart_context->callback_cls = callback_cls; |
6792 | 6812 | ||
6793 | for (off = 0; off < pg->total; off++) | 6813 | for (off = 0; off < pg->total; off++) |
6794 | { | 6814 | { |
6795 | GNUNET_TESTING_daemon_restart (pg->peers[off].daemon, | 6815 | GNUNET_TESTING_daemon_restart (pg->peers[off].daemon, |
6796 | &restart_callback, restart_context); | 6816 | &restart_callback, restart_context); |
6797 | } | ||
6798 | } | 6817 | } |
6818 | } | ||
6799 | } | 6819 | } |
6800 | 6820 | ||
6801 | 6821 | ||
@@ -6810,47 +6830,47 @@ GNUNET_TESTING_daemons_restart(struct GNUNET_TESTING_PeerGroup *pg, | |||
6810 | * @param cb_cls closure for cb | 6830 | * @param cb_cls closure for cb |
6811 | */ | 6831 | */ |
6812 | void | 6832 | void |
6813 | GNUNET_TESTING_daemons_vary(struct GNUNET_TESTING_PeerGroup *pg, | 6833 | GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg, |
6814 | unsigned int offset, int desired_status, | 6834 | unsigned int offset, int desired_status, |
6815 | struct GNUNET_TIME_Relative timeout, | 6835 | struct GNUNET_TIME_Relative timeout, |
6816 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) | 6836 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) |
6817 | { | 6837 | { |
6818 | struct ShutdownContext *shutdown_ctx; | 6838 | struct ShutdownContext *shutdown_ctx; |
6819 | struct ChurnRestartContext *startup_ctx; | 6839 | struct ChurnRestartContext *startup_ctx; |
6820 | struct ChurnContext *churn_ctx; | 6840 | struct ChurnContext *churn_ctx; |
6821 | 6841 | ||
6822 | if (GNUNET_NO == desired_status) | 6842 | if (GNUNET_NO == desired_status) |
6843 | { | ||
6844 | if (NULL != pg->peers[offset].daemon) | ||
6823 | { | 6845 | { |
6824 | if (NULL != pg->peers[offset].daemon) | 6846 | shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext)); |
6825 | { | 6847 | churn_ctx = GNUNET_malloc (sizeof (struct ChurnContext)); |
6826 | shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext)); | 6848 | churn_ctx->num_to_start = 0; |
6827 | churn_ctx = GNUNET_malloc (sizeof (struct ChurnContext)); | 6849 | churn_ctx->num_to_stop = 1; |
6828 | churn_ctx->num_to_start = 0; | 6850 | churn_ctx->cb = cb; |
6829 | churn_ctx->num_to_stop = 1; | 6851 | churn_ctx->cb_cls = cb_cls; |
6830 | churn_ctx->cb = cb; | 6852 | shutdown_ctx->cb_cls = churn_ctx; |
6831 | churn_ctx->cb_cls = cb_cls; | 6853 | GNUNET_TESTING_daemon_stop (pg->peers[offset].daemon, timeout, |
6832 | shutdown_ctx->cb_cls = churn_ctx; | 6854 | &churn_stop_callback, shutdown_ctx, |
6833 | GNUNET_TESTING_daemon_stop (pg->peers[offset].daemon, timeout, | 6855 | GNUNET_NO, GNUNET_YES); |
6834 | &churn_stop_callback, shutdown_ctx, | ||
6835 | GNUNET_NO, GNUNET_YES); | ||
6836 | } | ||
6837 | } | 6856 | } |
6857 | } | ||
6838 | else if (GNUNET_YES == desired_status) | 6858 | else if (GNUNET_YES == desired_status) |
6839 | { | 6859 | { |
6840 | if (NULL == pg->peers[offset].daemon) | 6860 | if (NULL == pg->peers[offset].daemon) |
6841 | { | 6861 | { |
6842 | startup_ctx = GNUNET_malloc (sizeof (struct ChurnRestartContext)); | 6862 | startup_ctx = GNUNET_malloc (sizeof (struct ChurnRestartContext)); |
6843 | churn_ctx = GNUNET_malloc (sizeof (struct ChurnContext)); | 6863 | churn_ctx = GNUNET_malloc (sizeof (struct ChurnContext)); |
6844 | churn_ctx->num_to_start = 1; | 6864 | churn_ctx->num_to_start = 1; |
6845 | churn_ctx->num_to_stop = 0; | 6865 | churn_ctx->num_to_stop = 0; |
6846 | churn_ctx->cb = cb; | 6866 | churn_ctx->cb = cb; |
6847 | churn_ctx->cb_cls = cb_cls; | 6867 | churn_ctx->cb_cls = cb_cls; |
6848 | startup_ctx->churn_ctx = churn_ctx; | 6868 | startup_ctx->churn_ctx = churn_ctx; |
6849 | GNUNET_TESTING_daemon_start_stopped (pg->peers[offset].daemon, | 6869 | GNUNET_TESTING_daemon_start_stopped (pg->peers[offset].daemon, |
6850 | timeout, &churn_start_callback, | 6870 | timeout, &churn_start_callback, |
6851 | startup_ctx); | 6871 | startup_ctx); |
6852 | } | ||
6853 | } | 6872 | } |
6873 | } | ||
6854 | else | 6874 | else |
6855 | GNUNET_break (0); | 6875 | GNUNET_break (0); |
6856 | } | 6876 | } |
@@ -6863,7 +6883,7 @@ GNUNET_TESTING_daemons_vary(struct GNUNET_TESTING_PeerGroup *pg, | |||
6863 | * @param emsg NULL on success | 6883 | * @param emsg NULL on success |
6864 | */ | 6884 | */ |
6865 | static void | 6885 | static void |
6866 | internal_shutdown_callback(void *cls, const char *emsg) | 6886 | internal_shutdown_callback (void *cls, const char *emsg) |
6867 | { | 6887 | { |
6868 | struct PeerShutdownContext *peer_shutdown_ctx = cls; | 6888 | struct PeerShutdownContext *peer_shutdown_ctx = cls; |
6869 | struct ShutdownContext *shutdown_ctx = peer_shutdown_ctx->shutdown_ctx; | 6889 | struct ShutdownContext *shutdown_ctx = peer_shutdown_ctx->shutdown_ctx; |
@@ -6876,44 +6896,46 @@ internal_shutdown_callback(void *cls, const char *emsg) | |||
6876 | shutdown_ctx->pg); | 6896 | shutdown_ctx->pg); |
6877 | 6897 | ||
6878 | if (emsg == NULL) | 6898 | if (emsg == NULL) |
6879 | { | 6899 | { |
6880 | shutdown_ctx->peers_down++; | 6900 | shutdown_ctx->peers_down++; |
6881 | } | 6901 | } |
6882 | else | 6902 | else |
6883 | { | 6903 | { |
6884 | #if VERBOSE_TESTING | 6904 | #if VERBOSE_TESTING |
6885 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "internal_shutdown_callback", | 6905 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "internal_shutdown_callback", |
6886 | "Failed to stop a peer: %s\n", emsg); | 6906 | "Failed to stop a peer: %s\n", emsg); |
6887 | #endif | 6907 | #endif |
6888 | shutdown_ctx->peers_failed++; | 6908 | shutdown_ctx->peers_failed++; |
6889 | } | 6909 | } |
6890 | 6910 | ||
6891 | if ((shutdown_ctx->cb != NULL) && (shutdown_ctx->peers_down | 6911 | if ((shutdown_ctx->cb != NULL) && (shutdown_ctx->peers_down |
6892 | + shutdown_ctx->peers_failed == shutdown_ctx->total_peers)) | 6912 | + shutdown_ctx->peers_failed == |
6893 | { | 6913 | shutdown_ctx->total_peers)) |
6894 | if (shutdown_ctx->peers_failed > 0) | 6914 | { |
6895 | shutdown_ctx->cb (shutdown_ctx->cb_cls, | 6915 | if (shutdown_ctx->peers_failed > 0) |
6896 | "Not all peers successfully shut down!"); | 6916 | shutdown_ctx->cb (shutdown_ctx->cb_cls, |
6897 | else | 6917 | "Not all peers successfully shut down!"); |
6898 | shutdown_ctx->cb (shutdown_ctx->cb_cls, NULL); | 6918 | else |
6919 | shutdown_ctx->cb (shutdown_ctx->cb_cls, NULL); | ||
6899 | 6920 | ||
6900 | GNUNET_free (shutdown_ctx->pg->peers); | 6921 | GNUNET_free (shutdown_ctx->pg->peers); |
6901 | GNUNET_free_non_null(shutdown_ctx->pg->hostkey_data); | 6922 | GNUNET_free_non_null (shutdown_ctx->pg->hostkey_data); |
6902 | for (off = 0; off < shutdown_ctx->pg->num_hosts; off++) | 6923 | for (off = 0; off < shutdown_ctx->pg->num_hosts; off++) |
6903 | { | 6924 | { |
6904 | GNUNET_free (shutdown_ctx->pg->hosts[off].hostname); | 6925 | GNUNET_free (shutdown_ctx->pg->hosts[off].hostname); |
6905 | GNUNET_free_non_null (shutdown_ctx->pg->hosts[off].username); | 6926 | GNUNET_free_non_null (shutdown_ctx->pg->hosts[off].username); |
6906 | } | ||
6907 | GNUNET_free_non_null (shutdown_ctx->pg->hosts); | ||
6908 | while (NULL != (ssh_pos = shutdown_ctx->pg->ssh_head)) | ||
6909 | { | ||
6910 | GNUNET_CONTAINER_DLL_remove(shutdown_ctx->pg->ssh_head, shutdown_ctx->pg->ssh_tail, ssh_pos); | ||
6911 | GNUNET_free(ssh_pos); | ||
6912 | } | ||
6913 | GNUNET_free (shutdown_ctx->pg); | ||
6914 | GNUNET_free (shutdown_ctx); | ||
6915 | } | 6927 | } |
6916 | GNUNET_free(peer_shutdown_ctx); | 6928 | GNUNET_free_non_null (shutdown_ctx->pg->hosts); |
6929 | while (NULL != (ssh_pos = shutdown_ctx->pg->ssh_head)) | ||
6930 | { | ||
6931 | GNUNET_CONTAINER_DLL_remove (shutdown_ctx->pg->ssh_head, | ||
6932 | shutdown_ctx->pg->ssh_tail, ssh_pos); | ||
6933 | GNUNET_free (ssh_pos); | ||
6934 | } | ||
6935 | GNUNET_free (shutdown_ctx->pg); | ||
6936 | GNUNET_free (shutdown_ctx); | ||
6937 | } | ||
6938 | GNUNET_free (peer_shutdown_ctx); | ||
6917 | } | 6939 | } |
6918 | 6940 | ||
6919 | 6941 | ||
@@ -6925,7 +6947,8 @@ internal_shutdown_callback(void *cls, const char *emsg) | |||
6925 | * to calling gnunet-arm N times all at once). | 6947 | * to calling gnunet-arm N times all at once). |
6926 | */ | 6948 | */ |
6927 | static void | 6949 | static void |
6928 | schedule_shutdown_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 6950 | schedule_shutdown_task (void *cls, |
6951 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
6929 | { | 6952 | { |
6930 | struct PeerShutdownContext *peer_shutdown_ctx = cls; | 6953 | struct PeerShutdownContext *peer_shutdown_ctx = cls; |
6931 | struct ShutdownContext *shutdown_ctx; | 6954 | struct ShutdownContext *shutdown_ctx; |
@@ -6939,19 +6962,19 @@ schedule_shutdown_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
6939 | && (count_outstanding_at_host (peer_shutdown_ctx->daemon->hostname, | 6962 | && (count_outstanding_at_host (peer_shutdown_ctx->daemon->hostname, |
6940 | shutdown_ctx->pg) | 6963 | shutdown_ctx->pg) |
6941 | < shutdown_ctx->pg->max_concurrent_ssh))) | 6964 | < shutdown_ctx->pg->max_concurrent_ssh))) |
6942 | { | 6965 | { |
6943 | if (peer_shutdown_ctx->daemon->hostname != NULL) | 6966 | if (peer_shutdown_ctx->daemon->hostname != NULL) |
6944 | increment_outstanding_at_host (peer_shutdown_ctx->daemon->hostname, | 6967 | increment_outstanding_at_host (peer_shutdown_ctx->daemon->hostname, |
6945 | shutdown_ctx->pg); | 6968 | shutdown_ctx->pg); |
6946 | shutdown_ctx->outstanding++; | 6969 | shutdown_ctx->outstanding++; |
6947 | GNUNET_TESTING_daemon_stop (peer_shutdown_ctx->daemon, | 6970 | GNUNET_TESTING_daemon_stop (peer_shutdown_ctx->daemon, |
6948 | shutdown_ctx->timeout, | 6971 | shutdown_ctx->timeout, |
6949 | &internal_shutdown_callback, peer_shutdown_ctx, | 6972 | &internal_shutdown_callback, peer_shutdown_ctx, |
6950 | shutdown_ctx->delete_files, GNUNET_NO); | 6973 | shutdown_ctx->delete_files, GNUNET_NO); |
6951 | } | 6974 | } |
6952 | else | 6975 | else |
6953 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 6976 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
6954 | 100), | 6977 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
6955 | &schedule_shutdown_task, peer_shutdown_ctx); | 6978 | &schedule_shutdown_task, peer_shutdown_ctx); |
6956 | 6979 | ||
6957 | } | 6980 | } |
@@ -6987,71 +7010,67 @@ GNUNET_TESTING_hosts_load (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
6987 | temphost = NULL; | 7010 | temphost = NULL; |
6988 | data = NULL; | 7011 | data = NULL; |
6989 | if (hostfile != NULL) | 7012 | if (hostfile != NULL) |
7013 | { | ||
7014 | if (GNUNET_OK != GNUNET_DISK_file_test (hostfile)) | ||
7015 | GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ | ||
7016 | | GNUNET_DISK_PERM_USER_WRITE); | ||
7017 | if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0)) | ||
6990 | { | 7018 | { |
6991 | if (GNUNET_OK != GNUNET_DISK_file_test (hostfile)) | 7019 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
6992 | GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ | 7020 | "Could not open file specified for host list, ending test!"); |
6993 | | GNUNET_DISK_PERM_USER_WRITE); | 7021 | GNUNET_free (hostfile); |
6994 | if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0)) | 7022 | return NULL; |
6995 | { | 7023 | } |
6996 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
6997 | "Could not open file specified for host list, ending test!"); | ||
6998 | GNUNET_free(hostfile); | ||
6999 | return NULL; | ||
7000 | } | ||
7001 | 7024 | ||
7002 | data = GNUNET_malloc_large (frstat.st_size); | 7025 | data = GNUNET_malloc_large (frstat.st_size); |
7003 | GNUNET_assert(data != NULL); | 7026 | GNUNET_assert (data != NULL); |
7004 | if (frstat.st_size | 7027 | if (frstat.st_size != GNUNET_DISK_fn_read (hostfile, data, frstat.st_size)) |
7005 | != GNUNET_DISK_fn_read (hostfile, data, frstat.st_size)) | 7028 | { |
7006 | { | 7029 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
7007 | GNUNET_log ( | 7030 | "Could not read file %s specified for host list, ending test!", |
7008 | GNUNET_ERROR_TYPE_ERROR, | 7031 | hostfile); |
7009 | "Could not read file %s specified for host list, ending test!", | 7032 | GNUNET_free (hostfile); |
7010 | hostfile); | 7033 | GNUNET_free (data); |
7011 | GNUNET_free (hostfile); | 7034 | return NULL; |
7012 | GNUNET_free (data); | 7035 | } |
7013 | return NULL; | ||
7014 | } | ||
7015 | 7036 | ||
7016 | GNUNET_free_non_null(hostfile); | 7037 | GNUNET_free_non_null (hostfile); |
7017 | 7038 | ||
7018 | buf = data; | 7039 | buf = data; |
7019 | count = 0; | 7040 | count = 0; |
7020 | while (count < frstat.st_size - 1) | 7041 | while (count < frstat.st_size - 1) |
7042 | { | ||
7043 | count++; | ||
7044 | if (((data[count] == '\n')) && (buf != &data[count])) | ||
7045 | { | ||
7046 | data[count] = '\0'; | ||
7047 | temphost = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Host)); | ||
7048 | ret = sscanf (buf, "%a[a-zA-Z0-9_]@%a[a-zA-Z0-9.]:%hd", | ||
7049 | &temphost->username, &temphost->hostname, | ||
7050 | &temphost->port); | ||
7051 | if (3 == ret) | ||
7052 | { | ||
7053 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
7054 | "Successfully read host %s, port %d and user %s from file\n", | ||
7055 | temphost->hostname, temphost->port, temphost->username); | ||
7056 | } | ||
7057 | else | ||
7021 | { | 7058 | { |
7022 | count++; | 7059 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
7023 | if (((data[count] == '\n')) && (buf != &data[count])) | 7060 | "Error reading line `%s' in hostfile\n", buf); |
7024 | { | 7061 | GNUNET_free (temphost); |
7025 | data[count] = '\0'; | 7062 | buf = &data[count + 1]; |
7026 | temphost = GNUNET_malloc(sizeof(struct GNUNET_TESTING_Host)); | 7063 | continue; |
7027 | ret = sscanf (buf, "%a[a-zA-Z0-9_]@%a[a-zA-Z0-9.]:%hd", | ||
7028 | &temphost->username, &temphost->hostname, | ||
7029 | &temphost->port); | ||
7030 | if (3 == ret) | ||
7031 | { | ||
7032 | GNUNET_log ( | ||
7033 | GNUNET_ERROR_TYPE_DEBUG, | ||
7034 | "Successfully read host %s, port %d and user %s from file\n", | ||
7035 | temphost->hostname, temphost->port, | ||
7036 | temphost->username); | ||
7037 | } | ||
7038 | else | ||
7039 | { | ||
7040 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
7041 | "Error reading line `%s' in hostfile\n", buf); | ||
7042 | GNUNET_free(temphost); | ||
7043 | buf = &data[count + 1]; | ||
7044 | continue; | ||
7045 | } | ||
7046 | temphost->next = hosts; | ||
7047 | hosts = temphost; | ||
7048 | buf = &data[count + 1]; | ||
7049 | } | ||
7050 | else if ((data[count] == '\n') || (data[count] == '\0')) | ||
7051 | buf = &data[count + 1]; | ||
7052 | } | 7064 | } |
7065 | temphost->next = hosts; | ||
7066 | hosts = temphost; | ||
7067 | buf = &data[count + 1]; | ||
7068 | } | ||
7069 | else if ((data[count] == '\n') || (data[count] == '\0')) | ||
7070 | buf = &data[count + 1]; | ||
7053 | } | 7071 | } |
7054 | GNUNET_free_non_null(data); | 7072 | } |
7073 | GNUNET_free_non_null (data); | ||
7055 | 7074 | ||
7056 | return hosts; | 7075 | return hosts; |
7057 | } | 7076 | } |
@@ -7065,13 +7084,14 @@ GNUNET_TESTING_hosts_load (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
7065 | * @param cb_cls closure for cb | 7084 | * @param cb_cls closure for cb |
7066 | */ | 7085 | */ |
7067 | void | 7086 | void |
7068 | GNUNET_TESTING_daemons_stop(struct GNUNET_TESTING_PeerGroup *pg, | 7087 | GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, |
7069 | struct GNUNET_TIME_Relative timeout, | 7088 | struct GNUNET_TIME_Relative timeout, |
7070 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) | 7089 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) |
7071 | { | 7090 | { |
7072 | unsigned int off; | 7091 | unsigned int off; |
7073 | struct ShutdownContext *shutdown_ctx; | 7092 | struct ShutdownContext *shutdown_ctx; |
7074 | struct PeerShutdownContext *peer_shutdown_ctx; | 7093 | struct PeerShutdownContext *peer_shutdown_ctx; |
7094 | |||
7075 | #if OLD | 7095 | #if OLD |
7076 | struct PeerConnection *conn_iter; | 7096 | struct PeerConnection *conn_iter; |
7077 | struct PeerConnection *temp_conn; | 7097 | struct PeerConnection *temp_conn; |
@@ -7081,8 +7101,8 @@ GNUNET_TESTING_daemons_stop(struct GNUNET_TESTING_PeerGroup *pg, | |||
7081 | 7101 | ||
7082 | shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext)); | 7102 | shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext)); |
7083 | shutdown_ctx->delete_files = GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, | 7103 | shutdown_ctx->delete_files = GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, |
7084 | "TESTING", | 7104 | "TESTING", |
7085 | "DELETE_FILES"); | 7105 | "DELETE_FILES"); |
7086 | shutdown_ctx->cb = cb; | 7106 | shutdown_ctx->cb = cb; |
7087 | shutdown_ctx->cb_cls = cb_cls; | 7107 | shutdown_ctx->cb_cls = cb_cls; |
7088 | shutdown_ctx->total_peers = pg->total; | 7108 | shutdown_ctx->total_peers = pg->total; |
@@ -7091,60 +7111,59 @@ GNUNET_TESTING_daemons_stop(struct GNUNET_TESTING_PeerGroup *pg, | |||
7091 | /* shtudown_ctx->outstanding = 0; */ | 7111 | /* shtudown_ctx->outstanding = 0; */ |
7092 | 7112 | ||
7093 | for (off = 0; off < pg->total; off++) | 7113 | for (off = 0; off < pg->total; off++) |
7094 | { | 7114 | { |
7095 | GNUNET_assert (NULL != pg->peers[off].daemon); | 7115 | GNUNET_assert (NULL != pg->peers[off].daemon); |
7096 | peer_shutdown_ctx = GNUNET_malloc (sizeof (struct PeerShutdownContext)); | 7116 | peer_shutdown_ctx = GNUNET_malloc (sizeof (struct PeerShutdownContext)); |
7097 | peer_shutdown_ctx->daemon = pg->peers[off].daemon; | 7117 | peer_shutdown_ctx->daemon = pg->peers[off].daemon; |
7098 | peer_shutdown_ctx->shutdown_ctx = shutdown_ctx; | 7118 | peer_shutdown_ctx->shutdown_ctx = shutdown_ctx; |
7099 | GNUNET_SCHEDULER_add_now (&schedule_shutdown_task, peer_shutdown_ctx); | 7119 | GNUNET_SCHEDULER_add_now (&schedule_shutdown_task, peer_shutdown_ctx); |
7100 | 7120 | ||
7101 | if (NULL != pg->peers[off].cfg) | 7121 | if (NULL != pg->peers[off].cfg) |
7102 | { | 7122 | { |
7103 | GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg); | 7123 | GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg); |
7104 | pg->peers[off].cfg = NULL; | 7124 | pg->peers[off].cfg = NULL; |
7105 | } | 7125 | } |
7106 | #if OLD | 7126 | #if OLD |
7107 | conn_iter = pg->peers[off].allowed_peers_head; | 7127 | conn_iter = pg->peers[off].allowed_peers_head; |
7108 | while (conn_iter != NULL) | 7128 | while (conn_iter != NULL) |
7109 | { | 7129 | { |
7110 | temp_conn = conn_iter->next; | 7130 | temp_conn = conn_iter->next; |
7111 | GNUNET_free(conn_iter); | 7131 | GNUNET_free (conn_iter); |
7112 | conn_iter = temp_conn; | 7132 | conn_iter = temp_conn; |
7113 | } | 7133 | } |
7114 | 7134 | ||
7115 | conn_iter = pg->peers[off].connect_peers_head; | 7135 | conn_iter = pg->peers[off].connect_peers_head; |
7116 | while (conn_iter != NULL) | 7136 | while (conn_iter != NULL) |
7117 | { | 7137 | { |
7118 | temp_conn = conn_iter->next; | 7138 | temp_conn = conn_iter->next; |
7119 | GNUNET_free(conn_iter); | 7139 | GNUNET_free (conn_iter); |
7120 | conn_iter = temp_conn; | 7140 | conn_iter = temp_conn; |
7121 | } | 7141 | } |
7122 | 7142 | ||
7123 | conn_iter = pg->peers[off].blacklisted_peers_head; | 7143 | conn_iter = pg->peers[off].blacklisted_peers_head; |
7124 | while (conn_iter != NULL) | 7144 | while (conn_iter != NULL) |
7125 | { | 7145 | { |
7126 | temp_conn = conn_iter->next; | 7146 | temp_conn = conn_iter->next; |
7127 | GNUNET_free(conn_iter); | 7147 | GNUNET_free (conn_iter); |
7128 | conn_iter = temp_conn; | 7148 | conn_iter = temp_conn; |
7129 | } | 7149 | } |
7130 | 7150 | ||
7131 | conn_iter = pg->peers[off].connect_peers_working_set_head; | 7151 | conn_iter = pg->peers[off].connect_peers_working_set_head; |
7132 | while (conn_iter != NULL) | 7152 | while (conn_iter != NULL) |
7133 | { | 7153 | { |
7134 | temp_conn = conn_iter->next; | 7154 | temp_conn = conn_iter->next; |
7135 | GNUNET_free(conn_iter); | 7155 | GNUNET_free (conn_iter); |
7136 | conn_iter = temp_conn; | 7156 | conn_iter = temp_conn; |
7137 | } | 7157 | } |
7138 | #else | 7158 | #else |
7139 | if (pg->peers[off].allowed_peers != NULL) | 7159 | if (pg->peers[off].allowed_peers != NULL) |
7140 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].allowed_peers); | 7160 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].allowed_peers); |
7141 | if (pg->peers[off].connect_peers != NULL) | 7161 | if (pg->peers[off].connect_peers != NULL) |
7142 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].connect_peers); | 7162 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].connect_peers); |
7143 | if (pg->peers[off].blacklisted_peers != NULL) | 7163 | if (pg->peers[off].blacklisted_peers != NULL) |
7144 | GNUNET_CONTAINER_multihashmap_destroy (pg-> | 7164 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].blacklisted_peers); |
7145 | peers[off].blacklisted_peers); | ||
7146 | #endif | 7165 | #endif |
7147 | } | 7166 | } |
7148 | } | 7167 | } |
7149 | 7168 | ||
7150 | /* end of testing_group.c */ | 7169 | /* end of testing_group.c */ |
diff --git a/src/testing/testing_peergroup.c b/src/testing/testing_peergroup.c index fa2173f20..e81e9fad8 100644 --- a/src/testing/testing_peergroup.c +++ b/src/testing/testing_peergroup.c | |||
@@ -166,18 +166,19 @@ struct ProgressMeter | |||
166 | * @return the progress meter | 166 | * @return the progress meter |
167 | */ | 167 | */ |
168 | static struct ProgressMeter * | 168 | static struct ProgressMeter * |
169 | create_meter(unsigned int total, char * start_string, int print) | 169 | create_meter (unsigned int total, char *start_string, int print) |
170 | { | 170 | { |
171 | struct ProgressMeter *ret; | 171 | struct ProgressMeter *ret; |
172 | ret = GNUNET_malloc(sizeof(struct ProgressMeter)); | 172 | |
173 | ret = GNUNET_malloc (sizeof (struct ProgressMeter)); | ||
173 | ret->print = print; | 174 | ret->print = print; |
174 | ret->total = total; | 175 | ret->total = total; |
175 | ret->modnum = total / 4; | 176 | ret->modnum = total / 4; |
176 | ret->dotnum = (total / 50) + 1; | 177 | ret->dotnum = (total / 50) + 1; |
177 | if (start_string != NULL) | 178 | if (start_string != NULL) |
178 | ret->startup_string = GNUNET_strdup(start_string); | 179 | ret->startup_string = GNUNET_strdup (start_string); |
179 | else | 180 | else |
180 | ret->startup_string = GNUNET_strdup(""); | 181 | ret->startup_string = GNUNET_strdup (""); |
181 | 182 | ||
182 | return ret; | 183 | return ret; |
183 | } | 184 | } |
@@ -191,27 +192,27 @@ create_meter(unsigned int total, char * start_string, int print) | |||
191 | * GNUNET_NO if more items expected | 192 | * GNUNET_NO if more items expected |
192 | */ | 193 | */ |
193 | static int | 194 | static int |
194 | update_meter(struct ProgressMeter *meter) | 195 | update_meter (struct ProgressMeter *meter) |
195 | { | 196 | { |
196 | if (meter->print == GNUNET_YES) | 197 | if (meter->print == GNUNET_YES) |
198 | { | ||
199 | if (meter->completed % meter->modnum == 0) | ||
197 | { | 200 | { |
198 | if (meter->completed % meter->modnum == 0) | 201 | if (meter->completed == 0) |
199 | { | 202 | { |
200 | if (meter->completed == 0) | 203 | fprintf (stdout, "%sProgress: [0%%", meter->startup_string); |
201 | { | 204 | } |
202 | fprintf (stdout, "%sProgress: [0%%", meter->startup_string); | 205 | else |
203 | } | 206 | fprintf (stdout, "%d%%", (int) (((float) meter->completed |
204 | else | 207 | / meter->total) * 100)); |
205 | fprintf (stdout, "%d%%", (int) (((float) meter->completed | ||
206 | / meter->total) * 100)); | ||
207 | } | ||
208 | else if (meter->completed % meter->dotnum == 0) | ||
209 | fprintf (stdout, "."); | ||
210 | |||
211 | if (meter->completed + 1 == meter->total) | ||
212 | fprintf (stdout, "%d%%]\n", 100); | ||
213 | fflush (stdout); | ||
214 | } | 208 | } |
209 | else if (meter->completed % meter->dotnum == 0) | ||
210 | fprintf (stdout, "."); | ||
211 | |||
212 | if (meter->completed + 1 == meter->total) | ||
213 | fprintf (stdout, "%d%%]\n", 100); | ||
214 | fflush (stdout); | ||
215 | } | ||
215 | meter->completed++; | 216 | meter->completed++; |
216 | 217 | ||
217 | if (meter->completed == meter->total) | 218 | if (meter->completed == meter->total) |
@@ -228,7 +229,7 @@ update_meter(struct ProgressMeter *meter) | |||
228 | * GNUNET_SYSERR on error | 229 | * GNUNET_SYSERR on error |
229 | */ | 230 | */ |
230 | static int | 231 | static int |
231 | reset_meter(struct ProgressMeter *meter) | 232 | reset_meter (struct ProgressMeter *meter) |
232 | { | 233 | { |
233 | if (meter == NULL) | 234 | if (meter == NULL) |
234 | return GNUNET_SYSERR; | 235 | return GNUNET_SYSERR; |
@@ -243,7 +244,7 @@ reset_meter(struct ProgressMeter *meter) | |||
243 | * @param meter the meter to free | 244 | * @param meter the meter to free |
244 | */ | 245 | */ |
245 | static void | 246 | static void |
246 | free_meter(struct ProgressMeter *meter) | 247 | free_meter (struct ProgressMeter *meter) |
247 | { | 248 | { |
248 | GNUNET_free_non_null (meter->startup_string); | 249 | GNUNET_free_non_null (meter->startup_string); |
249 | GNUNET_free (meter); | 250 | GNUNET_free (meter); |
@@ -256,13 +257,14 @@ free_meter(struct ProgressMeter *meter) | |||
256 | * Check whether peers successfully shut down. | 257 | * Check whether peers successfully shut down. |
257 | */ | 258 | */ |
258 | static void | 259 | static void |
259 | internal_shutdown_callback(void *cls, const char *emsg) | 260 | internal_shutdown_callback (void *cls, const char *emsg) |
260 | { | 261 | { |
261 | struct PeerGroupStartupContext *pg_start_ctx = cls; | 262 | struct PeerGroupStartupContext *pg_start_ctx = cls; |
263 | |||
262 | if (emsg != NULL) | 264 | if (emsg != NULL) |
263 | pg_start_ctx->peergroup_cb(pg_start_ctx->cls, emsg); | 265 | pg_start_ctx->peergroup_cb (pg_start_ctx->cls, emsg); |
264 | else | 266 | else |
265 | pg_start_ctx->peergroup_cb(pg_start_ctx->cls, pg_start_ctx->fail_reason); | 267 | pg_start_ctx->peergroup_cb (pg_start_ctx->cls, pg_start_ctx->fail_reason); |
266 | } | 268 | } |
267 | 269 | ||
268 | /** | 270 | /** |
@@ -271,13 +273,18 @@ internal_shutdown_callback(void *cls, const char *emsg) | |||
271 | * test. | 273 | * test. |
272 | */ | 274 | */ |
273 | static void | 275 | static void |
274 | end_badly(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 276 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
275 | { | 277 | { |
276 | struct PeerGroupStartupContext *pg_start_ctx = cls; | 278 | struct PeerGroupStartupContext *pg_start_ctx = cls; |
277 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failing peer group startup with error: `%s'!\n", | 279 | |
280 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
281 | "Failing peer group startup with error: `%s'!\n", | ||
278 | pg_start_ctx->fail_reason); | 282 | pg_start_ctx->fail_reason); |
279 | 283 | ||
280 | GNUNET_TESTING_daemons_stop (pg_start_ctx->pg, GNUNET_TIME_absolute_get_remaining(pg_start_ctx->timeout), &internal_shutdown_callback, pg_start_ctx); | 284 | GNUNET_TESTING_daemons_stop (pg_start_ctx->pg, |
285 | GNUNET_TIME_absolute_get_remaining | ||
286 | (pg_start_ctx->timeout), | ||
287 | &internal_shutdown_callback, pg_start_ctx); | ||
281 | 288 | ||
282 | if (pg_start_ctx->hostkey_meter != NULL) | 289 | if (pg_start_ctx->hostkey_meter != NULL) |
283 | free_meter (pg_start_ctx->hostkey_meter); | 290 | free_meter (pg_start_ctx->hostkey_meter); |
@@ -297,21 +304,22 @@ end_badly(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
297 | * failure (peers failed to connect). | 304 | * failure (peers failed to connect). |
298 | */ | 305 | */ |
299 | static void | 306 | static void |
300 | internal_topology_callback( | 307 | internal_topology_callback (void *cls, |
301 | void *cls, | 308 | const struct GNUNET_PeerIdentity *first, |
302 | const struct GNUNET_PeerIdentity *first, | 309 | const struct GNUNET_PeerIdentity *second, |
303 | const struct GNUNET_PeerIdentity *second, | 310 | uint32_t distance, |
304 | uint32_t distance, | 311 | const struct GNUNET_CONFIGURATION_Handle *first_cfg, |
305 | const struct GNUNET_CONFIGURATION_Handle *first_cfg, | 312 | const struct GNUNET_CONFIGURATION_Handle |
306 | const struct GNUNET_CONFIGURATION_Handle *second_cfg, | 313 | *second_cfg, |
307 | struct GNUNET_TESTING_Daemon *first_daemon, | 314 | struct GNUNET_TESTING_Daemon *first_daemon, |
308 | struct GNUNET_TESTING_Daemon *second_daemon, | 315 | struct GNUNET_TESTING_Daemon *second_daemon, |
309 | const char *emsg) | 316 | const char *emsg) |
310 | { | 317 | { |
311 | struct PeerGroupStartupContext *pg_start_ctx = cls; | 318 | struct PeerGroupStartupContext *pg_start_ctx = cls; |
312 | char *temp_str; | 319 | char *temp_str; |
313 | char *second_str; | 320 | char *second_str; |
314 | int temp; | 321 | int temp; |
322 | |||
315 | #if TIMING | 323 | #if TIMING |
316 | unsigned long long duration; | 324 | unsigned long long duration; |
317 | unsigned long long total_duration; | 325 | unsigned long long total_duration; |
@@ -325,201 +333,201 @@ internal_topology_callback( | |||
325 | 333 | ||
326 | #if TIMING | 334 | #if TIMING |
327 | if (GNUNET_TIME_absolute_get_difference (connect_last_time, | 335 | if (GNUNET_TIME_absolute_get_difference (connect_last_time, |
328 | GNUNET_TIME_absolute_get ()).rel_value | 336 | GNUNET_TIME_absolute_get |
329 | > GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 337 | ()).rel_value > |
330 | CONN_UPDATE_DURATION).rel_value) | 338 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
331 | { | 339 | CONN_UPDATE_DURATION).rel_value) |
332 | /* Get number of new connections */ | 340 | { |
333 | new_connections = total_connections - previous_connections; | 341 | /* Get number of new connections */ |
334 | 342 | new_connections = total_connections - previous_connections; | |
335 | /* Get number of new FAILED connections */ | 343 | |
336 | new_failed_connections = failed_connections - previous_failed_connections; | 344 | /* Get number of new FAILED connections */ |
337 | 345 | new_failed_connections = failed_connections - previous_failed_connections; | |
338 | /* Get duration in seconds */ | 346 | |
339 | duration | 347 | /* Get duration in seconds */ |
340 | = GNUNET_TIME_absolute_get_difference (connect_last_time, | 348 | duration |
341 | GNUNET_TIME_absolute_get ()).rel_value | 349 | = GNUNET_TIME_absolute_get_difference (connect_last_time, |
342 | / 1000; | 350 | GNUNET_TIME_absolute_get |
343 | total_duration | 351 | ()).rel_value / 1000; |
344 | = GNUNET_TIME_absolute_get_difference (connect_start_time, | 352 | total_duration = |
345 | GNUNET_TIME_absolute_get ()).rel_value | 353 | GNUNET_TIME_absolute_get_difference (connect_start_time, |
346 | / 1000; | 354 | GNUNET_TIME_absolute_get |
347 | 355 | ()).rel_value / 1000; | |
348 | failed_conns_per_sec_recent = (double) new_failed_connections / duration; | 356 | |
349 | failed_conns_per_sec_total = (double) failed_connections / total_duration; | 357 | failed_conns_per_sec_recent = (double) new_failed_connections / duration; |
350 | conns_per_sec_recent = (double) new_connections / duration; | 358 | failed_conns_per_sec_total = (double) failed_connections / total_duration; |
351 | conns_per_sec_total = (double) total_connections / total_duration; | 359 | conns_per_sec_recent = (double) new_connections / duration; |
352 | GNUNET_log ( | 360 | conns_per_sec_total = (double) total_connections / total_duration; |
353 | GNUNET_ERROR_TYPE_WARNING, | 361 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
354 | "Recent: %.2f/s, Total: %.2f/s, Recent failed: %.2f/s, total failed %.2f/s\n", | 362 | "Recent: %.2f/s, Total: %.2f/s, Recent failed: %.2f/s, total failed %.2f/s\n", |
355 | conns_per_sec_recent, CONN_UPDATE_DURATION, | 363 | conns_per_sec_recent, CONN_UPDATE_DURATION, |
356 | conns_per_sec_total, failed_conns_per_sec_recent, | 364 | conns_per_sec_total, failed_conns_per_sec_recent, |
357 | failed_conns_per_sec_total); | 365 | failed_conns_per_sec_total); |
358 | connect_last_time = GNUNET_TIME_absolute_get (); | 366 | connect_last_time = GNUNET_TIME_absolute_get (); |
359 | previous_connections = total_connections; | 367 | previous_connections = total_connections; |
360 | previous_failed_connections = failed_connections; | 368 | previous_failed_connections = failed_connections; |
361 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 369 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
362 | "have %u total_connections, %u failed\n", total_connections, | 370 | "have %u total_connections, %u failed\n", total_connections, |
363 | failed_connections); | 371 | failed_connections); |
364 | } | 372 | } |
365 | #endif | 373 | #endif |
366 | 374 | ||
367 | 375 | ||
368 | if (emsg == NULL) | 376 | if (emsg == NULL) |
369 | { | 377 | { |
370 | pg_start_ctx->total_connections++; | 378 | pg_start_ctx->total_connections++; |
371 | #if VERBOSE > 1 | 379 | #if VERBOSE > 1 |
372 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n", | 380 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
373 | first_daemon->shortname, | 381 | "connected peer %s to peer %s, distance %u\n", |
374 | second_daemon->shortname, | 382 | first_daemon->shortname, second_daemon->shortname, distance); |
375 | distance); | ||
376 | #endif | 383 | #endif |
377 | if (pg_start_ctx->topology_output_file != NULL) | 384 | if (pg_start_ctx->topology_output_file != NULL) |
378 | { | 385 | { |
379 | second_str = GNUNET_strdup(GNUNET_i2s(second)); | 386 | second_str = GNUNET_strdup (GNUNET_i2s (second)); |
380 | temp = GNUNET_asprintf(&temp_str, "\t\"%s\" -- \"%s\"\n", GNUNET_i2s(first), second_str); | 387 | temp = |
381 | GNUNET_free(second_str); | 388 | GNUNET_asprintf (&temp_str, "\t\"%s\" -- \"%s\"\n", |
382 | if (temp > 0) | 389 | GNUNET_i2s (first), second_str); |
383 | GNUNET_DISK_file_write(pg_start_ctx->topology_output_file, temp_str, temp); | 390 | GNUNET_free (second_str); |
384 | GNUNET_free(temp_str); | 391 | if (temp > 0) |
385 | } | 392 | GNUNET_DISK_file_write (pg_start_ctx->topology_output_file, temp_str, |
393 | temp); | ||
394 | GNUNET_free (temp_str); | ||
386 | } | 395 | } |
396 | } | ||
387 | else | 397 | else |
388 | { | 398 | { |
389 | pg_start_ctx->failed_connections++; | 399 | pg_start_ctx->failed_connections++; |
390 | #if VERBOSE | 400 | #if VERBOSE |
391 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to connect peer %s to peer %s with error :\n%s\n", | 401 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
392 | first_daemon->shortname, | 402 | "Failed to connect peer %s to peer %s with error :\n%s\n", |
393 | second_daemon->shortname, emsg); | 403 | first_daemon->shortname, second_daemon->shortname, emsg); |
394 | 404 | ||
395 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n", | 405 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
396 | first_daemon->shortname, | 406 | "Failed to connect peer %s to peer %s with error :\n%s\n", |
397 | second_daemon->shortname, emsg); | 407 | first_daemon->shortname, second_daemon->shortname, emsg); |
398 | #endif | 408 | #endif |
399 | } | 409 | } |
400 | 410 | ||
401 | GNUNET_assert(pg_start_ctx->connect_meter != NULL); | 411 | GNUNET_assert (pg_start_ctx->connect_meter != NULL); |
402 | if (pg_start_ctx->connect_cb != NULL) | 412 | if (pg_start_ctx->connect_cb != NULL) |
403 | pg_start_ctx->connect_cb(pg_start_ctx->cls, first, | 413 | pg_start_ctx->connect_cb (pg_start_ctx->cls, first, |
404 | second, | 414 | second, |
405 | distance, | 415 | distance, |
406 | first_cfg, | 416 | first_cfg, |
407 | second_cfg, | 417 | second_cfg, first_daemon, second_daemon, emsg); |
408 | first_daemon, | ||
409 | second_daemon, | ||
410 | emsg); | ||
411 | if (GNUNET_YES == update_meter (pg_start_ctx->connect_meter)) | 418 | if (GNUNET_YES == update_meter (pg_start_ctx->connect_meter)) |
412 | { | 419 | { |
413 | #if VERBOSE | 420 | #if VERBOSE |
414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 421 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
415 | "Created %d total connections, which is our target number! Starting next phase of testing.\n", | 422 | "Created %d total connections, which is our target number! Starting next phase of testing.\n", |
416 | total_connections); | 423 | total_connections); |
417 | #endif | 424 | #endif |
418 | 425 | ||
419 | #if TIMING | 426 | #if TIMING |
420 | total_duration | 427 | total_duration |
421 | = GNUNET_TIME_absolute_get_difference (connect_start_time, | 428 | = GNUNET_TIME_absolute_get_difference (connect_start_time, |
422 | GNUNET_TIME_absolute_get ()).rel_value | 429 | GNUNET_TIME_absolute_get |
423 | / 1000; | 430 | ()).rel_value / 1000; |
424 | failed_conns_per_sec_total = (double) failed_connections / total_duration; | 431 | failed_conns_per_sec_total = (double) failed_connections / total_duration; |
425 | conns_per_sec_total = (double) total_connections / total_duration; | 432 | conns_per_sec_total = (double) total_connections / total_duration; |
426 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 433 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
427 | "Overall connection info --- Total: %u, Total Failed %u/s\n", | 434 | "Overall connection info --- Total: %u, Total Failed %u/s\n", |
428 | total_connections, failed_connections); | 435 | total_connections, failed_connections); |
429 | GNUNET_log ( | 436 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
430 | GNUNET_ERROR_TYPE_WARNING, | 437 | "Overall connection info --- Total: %.2f/s, Total Failed %.2f/s\n", |
431 | "Overall connection info --- Total: %.2f/s, Total Failed %.2f/s\n", | 438 | conns_per_sec_total, failed_conns_per_sec_total); |
432 | conns_per_sec_total, failed_conns_per_sec_total); | ||
433 | #endif | 439 | #endif |
434 | 440 | ||
435 | GNUNET_assert(pg_start_ctx->die_task != GNUNET_SCHEDULER_NO_TASK); | 441 | GNUNET_assert (pg_start_ctx->die_task != GNUNET_SCHEDULER_NO_TASK); |
436 | GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task); | 442 | GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task); |
437 | 443 | ||
438 | /* Call final callback, signifying that the peer group has been started and connected */ | 444 | /* Call final callback, signifying that the peer group has been started and connected */ |
439 | if (pg_start_ctx->peergroup_cb != NULL) | 445 | if (pg_start_ctx->peergroup_cb != NULL) |
440 | pg_start_ctx->peergroup_cb(pg_start_ctx->cls, NULL); | 446 | pg_start_ctx->peergroup_cb (pg_start_ctx->cls, NULL); |
441 | 447 | ||
442 | if (pg_start_ctx->topology_output_file != NULL) | 448 | if (pg_start_ctx->topology_output_file != NULL) |
443 | { | 449 | { |
444 | temp = GNUNET_asprintf(&temp_str, "}\n"); | 450 | temp = GNUNET_asprintf (&temp_str, "}\n"); |
445 | if (temp > 0) | 451 | if (temp > 0) |
446 | GNUNET_DISK_file_write(pg_start_ctx->topology_output_file, temp_str, temp); | 452 | GNUNET_DISK_file_write (pg_start_ctx->topology_output_file, temp_str, |
447 | GNUNET_free(temp_str); | 453 | temp); |
448 | GNUNET_DISK_file_close(pg_start_ctx->topology_output_file); | 454 | GNUNET_free (temp_str); |
449 | } | 455 | GNUNET_DISK_file_close (pg_start_ctx->topology_output_file); |
450 | } | 456 | } |
457 | } | ||
451 | } | 458 | } |
452 | 459 | ||
453 | static void | 460 | static void |
454 | internal_peers_started_callback(void *cls, const struct GNUNET_PeerIdentity *id, | 461 | internal_peers_started_callback (void *cls, |
455 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 462 | const struct GNUNET_PeerIdentity *id, |
456 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 463 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
464 | struct GNUNET_TESTING_Daemon *d, | ||
465 | const char *emsg) | ||
457 | { | 466 | { |
458 | struct PeerGroupStartupContext *pg_start_ctx = cls; | 467 | struct PeerGroupStartupContext *pg_start_ctx = cls; |
468 | |||
459 | if (emsg != NULL) | 469 | if (emsg != NULL) |
460 | { | 470 | { |
461 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 471 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
462 | "Failed to start daemon with error: `%s'\n", emsg); | 472 | "Failed to start daemon with error: `%s'\n", emsg); |
463 | return; | 473 | return; |
464 | } | 474 | } |
465 | GNUNET_assert (id != NULL); | 475 | GNUNET_assert (id != NULL); |
466 | 476 | ||
467 | #if VERBOSE > 1 | 477 | #if VERBOSE > 1 |
468 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n", | 478 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n", |
469 | (num_peers - peers_left) + 1, num_peers); | 479 | (num_peers - peers_left) + 1, num_peers); |
470 | #endif | 480 | #endif |
471 | 481 | ||
472 | pg_start_ctx->peers_left--; | 482 | pg_start_ctx->peers_left--; |
473 | 483 | ||
474 | if (GNUNET_YES == update_meter (pg_start_ctx->peer_start_meter)) | 484 | if (GNUNET_YES == update_meter (pg_start_ctx->peer_start_meter)) |
475 | { | 485 | { |
476 | #if VERBOSE | 486 | #if VERBOSE |
477 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 487 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
478 | "All %d daemons started, now connecting peers!\n", | 488 | "All %d daemons started, now connecting peers!\n", num_peers); |
479 | num_peers); | ||
480 | #endif | 489 | #endif |
481 | GNUNET_assert(pg_start_ctx->die_task != GNUNET_SCHEDULER_NO_TASK); | 490 | GNUNET_assert (pg_start_ctx->die_task != GNUNET_SCHEDULER_NO_TASK); |
482 | GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task); | 491 | GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task); |
492 | |||
493 | pg_start_ctx->expected_connections = UINT_MAX; | ||
494 | if ((pg_start_ctx->pg != NULL) && (pg_start_ctx->peers_left == 0)) | ||
495 | { | ||
496 | pg_start_ctx->connect_start_time = GNUNET_TIME_absolute_get (); | ||
497 | pg_start_ctx->expected_connections | ||
498 | = GNUNET_TESTING_connect_topology (pg_start_ctx->pg, | ||
499 | pg_start_ctx->connect_topology, | ||
500 | pg_start_ctx->connect_topology_option, | ||
501 | pg_start_ctx->connect_topology_option_modifier, | ||
502 | DEFAULT_CONNECT_TIMEOUT, | ||
503 | pg_start_ctx->connect_attempts, | ||
504 | NULL, NULL); | ||
505 | |||
506 | pg_start_ctx->connect_meter | ||
507 | = create_meter (pg_start_ctx->expected_connections, | ||
508 | "Peer connection ", pg_start_ctx->verbose); | ||
509 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
510 | "Have %d expected connections\n", | ||
511 | pg_start_ctx->expected_connections); | ||
512 | } | ||
483 | 513 | ||
484 | pg_start_ctx->expected_connections = UINT_MAX; | 514 | if (pg_start_ctx->expected_connections == 0) |
485 | if ((pg_start_ctx->pg != NULL) && (pg_start_ctx->peers_left == 0)) | 515 | { |
486 | { | 516 | GNUNET_free_non_null (pg_start_ctx->fail_reason); |
487 | pg_start_ctx->connect_start_time = GNUNET_TIME_absolute_get (); | 517 | pg_start_ctx->fail_reason = |
488 | pg_start_ctx->expected_connections | 518 | GNUNET_strdup ("from connect topology (bad return)"); |
489 | = GNUNET_TESTING_connect_topology ( | 519 | pg_start_ctx->die_task = |
490 | pg_start_ctx->pg, | 520 | GNUNET_SCHEDULER_add_now (&end_badly, pg_start_ctx); |
491 | pg_start_ctx->connect_topology, | ||
492 | pg_start_ctx->connect_topology_option, | ||
493 | pg_start_ctx->connect_topology_option_modifier, | ||
494 | DEFAULT_CONNECT_TIMEOUT, | ||
495 | pg_start_ctx->connect_attempts, | ||
496 | NULL, NULL); | ||
497 | |||
498 | pg_start_ctx->connect_meter | ||
499 | = create_meter (pg_start_ctx->expected_connections, | ||
500 | "Peer connection ", pg_start_ctx->verbose); | ||
501 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
502 | "Have %d expected connections\n", | ||
503 | pg_start_ctx->expected_connections); | ||
504 | } | ||
505 | |||
506 | if (pg_start_ctx->expected_connections == 0) | ||
507 | { | ||
508 | GNUNET_free_non_null(pg_start_ctx->fail_reason); | ||
509 | pg_start_ctx->fail_reason = GNUNET_strdup("from connect topology (bad return)"); | ||
510 | pg_start_ctx->die_task | ||
511 | = GNUNET_SCHEDULER_add_now (&end_badly, | ||
512 | pg_start_ctx); | ||
513 | } | ||
514 | |||
515 | GNUNET_free_non_null(pg_start_ctx->fail_reason); | ||
516 | pg_start_ctx->fail_reason = GNUNET_strdup("from connect topology (timeout)"); | ||
517 | pg_start_ctx->die_task | ||
518 | = GNUNET_SCHEDULER_add_delayed ( | ||
519 | GNUNET_TIME_absolute_get_remaining (pg_start_ctx->timeout), | ||
520 | &end_badly, | ||
521 | pg_start_ctx); | ||
522 | } | 521 | } |
522 | |||
523 | GNUNET_free_non_null (pg_start_ctx->fail_reason); | ||
524 | pg_start_ctx->fail_reason = | ||
525 | GNUNET_strdup ("from connect topology (timeout)"); | ||
526 | pg_start_ctx->die_task = | ||
527 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining | ||
528 | (pg_start_ctx->timeout), &end_badly, | ||
529 | pg_start_ctx); | ||
530 | } | ||
523 | } | 531 | } |
524 | 532 | ||
525 | /** | 533 | /** |
@@ -531,56 +539,61 @@ internal_peers_started_callback(void *cls, const struct GNUNET_PeerIdentity *id, | |||
531 | * @param emsg non-null on failure | 539 | * @param emsg non-null on failure |
532 | */ | 540 | */ |
533 | static void | 541 | static void |
534 | internal_hostkey_callback(void *cls, const struct GNUNET_PeerIdentity *id, | 542 | internal_hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id, |
535 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 543 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
536 | { | 544 | { |
537 | struct PeerGroupStartupContext *pg_start_ctx = cls; | 545 | struct PeerGroupStartupContext *pg_start_ctx = cls; |
538 | unsigned int create_expected_connections; | 546 | unsigned int create_expected_connections; |
539 | 547 | ||
540 | if (emsg != NULL) | 548 | if (emsg != NULL) |
541 | { | 549 | { |
542 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 550 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
543 | "Hostkey callback received error: %s\n", emsg); | 551 | "Hostkey callback received error: %s\n", emsg); |
544 | } | 552 | } |
545 | 553 | ||
546 | #if VERBOSE > 1 | 554 | #if VERBOSE > 1 |
547 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 555 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
548 | "Hostkey (%d/%d) created for peer `%s'\n", | 556 | "Hostkey (%d/%d) created for peer `%s'\n", |
549 | num_peers - peers_left, num_peers, GNUNET_i2s(id)); | 557 | num_peers - peers_left, num_peers, GNUNET_i2s (id)); |
550 | #endif | 558 | #endif |
551 | 559 | ||
552 | pg_start_ctx->peers_left--; | 560 | pg_start_ctx->peers_left--; |
553 | if (GNUNET_YES == update_meter (pg_start_ctx->hostkey_meter)) | 561 | if (GNUNET_YES == update_meter (pg_start_ctx->hostkey_meter)) |
562 | { | ||
563 | GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task); | ||
564 | /* Set up task in case topology creation doesn't finish | ||
565 | * within a reasonable amount of time */ | ||
566 | pg_start_ctx->die_task = | ||
567 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining | ||
568 | (pg_start_ctx->timeout), &end_badly, | ||
569 | "from create_topology"); | ||
570 | pg_start_ctx->peers_left = pg_start_ctx->total; /* Reset counter */ | ||
571 | create_expected_connections = | ||
572 | GNUNET_TESTING_create_topology (pg_start_ctx->pg, | ||
573 | pg_start_ctx->topology, | ||
574 | pg_start_ctx->restrict_topology, | ||
575 | pg_start_ctx->restrict_transports); | ||
576 | if (create_expected_connections > 0) | ||
577 | { | ||
578 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
579 | "Topology set up, have %u expected connections, now starting peers!\n", | ||
580 | create_expected_connections); | ||
581 | GNUNET_TESTING_daemons_continue_startup (pg_start_ctx->pg); | ||
582 | } | ||
583 | else | ||
554 | { | 584 | { |
555 | GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task); | 585 | GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task); |
556 | /* Set up task in case topology creation doesn't finish | 586 | pg_start_ctx->die_task = GNUNET_SCHEDULER_add_now (&end_badly, |
557 | * within a reasonable amount of time */ | 587 | "from create topology (bad return)"); |
558 | pg_start_ctx->die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining(pg_start_ctx->timeout), | ||
559 | &end_badly, | ||
560 | "from create_topology"); | ||
561 | pg_start_ctx->peers_left = pg_start_ctx->total; /* Reset counter */ | ||
562 | create_expected_connections = GNUNET_TESTING_create_topology (pg_start_ctx->pg, pg_start_ctx->topology, pg_start_ctx->restrict_topology, | ||
563 | pg_start_ctx->restrict_transports); | ||
564 | if (create_expected_connections > 0) | ||
565 | { | ||
566 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
567 | "Topology set up, have %u expected connections, now starting peers!\n", create_expected_connections); | ||
568 | GNUNET_TESTING_daemons_continue_startup (pg_start_ctx->pg); | ||
569 | } | ||
570 | else | ||
571 | { | ||
572 | GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task); | ||
573 | pg_start_ctx->die_task = GNUNET_SCHEDULER_add_now (&end_badly, | ||
574 | "from create topology (bad return)"); | ||
575 | } | ||
576 | |||
577 | GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task); | ||
578 | pg_start_ctx->die_task | ||
579 | = GNUNET_SCHEDULER_add_delayed ( | ||
580 | GNUNET_TIME_absolute_get_remaining(pg_start_ctx->timeout), | ||
581 | &end_badly, | ||
582 | "from continue startup (timeout)"); | ||
583 | } | 588 | } |
589 | |||
590 | GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task); | ||
591 | pg_start_ctx->die_task | ||
592 | = | ||
593 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining | ||
594 | (pg_start_ctx->timeout), &end_badly, | ||
595 | "from continue startup (timeout)"); | ||
596 | } | ||
584 | } | 597 | } |
585 | 598 | ||
586 | 599 | ||
@@ -597,41 +610,42 @@ internal_hostkey_callback(void *cls, const struct GNUNET_PeerIdentity *id, | |||
597 | void | 610 | void |
598 | write_topology_cb (void *cls, | 611 | write_topology_cb (void *cls, |
599 | const struct GNUNET_PeerIdentity *first, | 612 | const struct GNUNET_PeerIdentity *first, |
600 | const struct GNUNET_PeerIdentity *second, | 613 | const struct GNUNET_PeerIdentity *second, const char *emsg) |
601 | const char *emsg) | ||
602 | { | 614 | { |
603 | struct TopologyOutputContext *topo_ctx; | 615 | struct TopologyOutputContext *topo_ctx; |
604 | int temp; | 616 | int temp; |
605 | char *temp_str; | 617 | char *temp_str; |
606 | char *temp_pid2; | 618 | char *temp_pid2; |
607 | 619 | ||
608 | topo_ctx = (struct TopologyOutputContext *)cls; | 620 | topo_ctx = (struct TopologyOutputContext *) cls; |
609 | GNUNET_assert(topo_ctx->file != NULL); | 621 | GNUNET_assert (topo_ctx->file != NULL); |
610 | if ((emsg == NULL) && (first != NULL) && (second != NULL)) | 622 | if ((emsg == NULL) && (first != NULL) && (second != NULL)) |
611 | { | 623 | { |
612 | GNUNET_assert(first != NULL); | 624 | GNUNET_assert (first != NULL); |
613 | GNUNET_assert(second != NULL); | 625 | GNUNET_assert (second != NULL); |
614 | temp_pid2 = GNUNET_strdup(GNUNET_i2s(second)); | 626 | temp_pid2 = GNUNET_strdup (GNUNET_i2s (second)); |
615 | temp = GNUNET_asprintf(&temp_str, "\t\"%s\" -- \"%s\"\n", GNUNET_i2s(first), temp_pid2); | 627 | temp = |
616 | GNUNET_free(temp_pid2); | 628 | GNUNET_asprintf (&temp_str, "\t\"%s\" -- \"%s\"\n", GNUNET_i2s (first), |
617 | GNUNET_DISK_file_write(topo_ctx->file, temp_str, temp); | 629 | temp_pid2); |
618 | } | 630 | GNUNET_free (temp_pid2); |
631 | GNUNET_DISK_file_write (topo_ctx->file, temp_str, temp); | ||
632 | } | ||
619 | else if ((emsg == NULL) && (first == NULL) && (second == NULL)) | 633 | else if ((emsg == NULL) && (first == NULL) && (second == NULL)) |
620 | { | 634 | { |
621 | temp = GNUNET_asprintf(&temp_str, "}\n"); | 635 | temp = GNUNET_asprintf (&temp_str, "}\n"); |
622 | GNUNET_DISK_file_write(topo_ctx->file, temp_str, temp); | 636 | GNUNET_DISK_file_write (topo_ctx->file, temp_str, temp); |
623 | GNUNET_DISK_file_close(topo_ctx->file); | 637 | GNUNET_DISK_file_close (topo_ctx->file); |
624 | topo_ctx->notify_cb(topo_ctx->notify_cb_cls, NULL); | 638 | topo_ctx->notify_cb (topo_ctx->notify_cb_cls, NULL); |
625 | GNUNET_free(topo_ctx); | 639 | GNUNET_free (topo_ctx); |
626 | } | 640 | } |
627 | else | 641 | else |
628 | { | 642 | { |
629 | temp = GNUNET_asprintf(&temp_str, "}\n"); | 643 | temp = GNUNET_asprintf (&temp_str, "}\n"); |
630 | GNUNET_DISK_file_write(topo_ctx->file, temp_str, temp); | 644 | GNUNET_DISK_file_write (topo_ctx->file, temp_str, temp); |
631 | GNUNET_DISK_file_close(topo_ctx->file); | 645 | GNUNET_DISK_file_close (topo_ctx->file); |
632 | topo_ctx->notify_cb(topo_ctx->notify_cb_cls, emsg); | 646 | topo_ctx->notify_cb (topo_ctx->notify_cb_cls, emsg); |
633 | GNUNET_free(topo_ctx); | 647 | GNUNET_free (topo_ctx); |
634 | } | 648 | } |
635 | } | 649 | } |
636 | 650 | ||
637 | /** | 651 | /** |
@@ -644,34 +658,37 @@ write_topology_cb (void *cls, | |||
644 | * | 658 | * |
645 | */ | 659 | */ |
646 | void | 660 | void |
647 | GNUNET_TESTING_peergroup_topology_to_file(struct GNUNET_TESTING_PeerGroup *pg, | 661 | GNUNET_TESTING_peergroup_topology_to_file (struct GNUNET_TESTING_PeerGroup *pg, |
648 | const char *output_filename, | 662 | const char *output_filename, |
649 | GNUNET_TESTING_NotifyCompletion notify_cb, | 663 | GNUNET_TESTING_NotifyCompletion |
650 | void *notify_cb_cls) | 664 | notify_cb, void *notify_cb_cls) |
651 | { | 665 | { |
652 | struct TopologyOutputContext *topo_ctx; | 666 | struct TopologyOutputContext *topo_ctx; |
653 | int temp; | 667 | int temp; |
654 | char *temp_str; | 668 | char *temp_str; |
655 | topo_ctx = GNUNET_malloc(sizeof(struct TopologyOutputContext)); | 669 | |
670 | topo_ctx = GNUNET_malloc (sizeof (struct TopologyOutputContext)); | ||
656 | 671 | ||
657 | topo_ctx->notify_cb = notify_cb; | 672 | topo_ctx->notify_cb = notify_cb; |
658 | topo_ctx->notify_cb_cls = notify_cb_cls; | 673 | topo_ctx->notify_cb_cls = notify_cb_cls; |
659 | topo_ctx->file = GNUNET_DISK_file_open (output_filename, GNUNET_DISK_OPEN_READWRITE | 674 | topo_ctx->file = |
660 | | GNUNET_DISK_OPEN_CREATE, | 675 | GNUNET_DISK_file_open (output_filename, |
661 | GNUNET_DISK_PERM_USER_READ | | 676 | GNUNET_DISK_OPEN_READWRITE | |
662 | GNUNET_DISK_PERM_USER_WRITE); | 677 | GNUNET_DISK_OPEN_CREATE, |
678 | GNUNET_DISK_PERM_USER_READ | | ||
679 | GNUNET_DISK_PERM_USER_WRITE); | ||
663 | if (topo_ctx->file == NULL) | 680 | if (topo_ctx->file == NULL) |
664 | { | 681 | { |
665 | notify_cb (notify_cb_cls, "Failed to open output file!"); | 682 | notify_cb (notify_cb_cls, "Failed to open output file!"); |
666 | GNUNET_free (topo_ctx); | 683 | GNUNET_free (topo_ctx); |
667 | return; | 684 | return; |
668 | } | 685 | } |
669 | 686 | ||
670 | temp = GNUNET_asprintf(&temp_str, "strict graph G {\n"); | 687 | temp = GNUNET_asprintf (&temp_str, "strict graph G {\n"); |
671 | if (temp > 0) | 688 | if (temp > 0) |
672 | GNUNET_DISK_file_write(topo_ctx->file, temp_str, temp); | 689 | GNUNET_DISK_file_write (topo_ctx->file, temp_str, temp); |
673 | GNUNET_free_non_null(temp_str); | 690 | GNUNET_free_non_null (temp_str); |
674 | GNUNET_TESTING_get_topology(pg, &write_topology_cb, topo_ctx); | 691 | GNUNET_TESTING_get_topology (pg, &write_topology_cb, topo_ctx); |
675 | } | 692 | } |
676 | 693 | ||
677 | /** | 694 | /** |
@@ -692,75 +709,80 @@ GNUNET_TESTING_peergroup_topology_to_file(struct GNUNET_TESTING_PeerGroup *pg, | |||
692 | * @return NULL on error, otherwise handle to control peer group | 709 | * @return NULL on error, otherwise handle to control peer group |
693 | */ | 710 | */ |
694 | struct GNUNET_TESTING_PeerGroup * | 711 | struct GNUNET_TESTING_PeerGroup * |
695 | GNUNET_TESTING_peergroup_start(const struct GNUNET_CONFIGURATION_Handle *cfg, | 712 | GNUNET_TESTING_peergroup_start (const struct GNUNET_CONFIGURATION_Handle *cfg, |
696 | unsigned int total, | 713 | unsigned int total, |
697 | struct GNUNET_TIME_Relative timeout, | 714 | struct GNUNET_TIME_Relative timeout, |
698 | GNUNET_TESTING_NotifyConnection connect_cb, | 715 | GNUNET_TESTING_NotifyConnection connect_cb, |
699 | GNUNET_TESTING_NotifyCompletion peergroup_cb, | 716 | GNUNET_TESTING_NotifyCompletion peergroup_cb, |
700 | void *peergroup_cls, | 717 | void *peergroup_cls, |
701 | const struct GNUNET_TESTING_Host *hostnames) | 718 | const struct GNUNET_TESTING_Host *hostnames) |
702 | { | 719 | { |
703 | struct PeerGroupStartupContext *pg_start_ctx; | 720 | struct PeerGroupStartupContext *pg_start_ctx; |
704 | unsigned long long temp_config_number; | 721 | unsigned long long temp_config_number; |
705 | char *temp_str; | 722 | char *temp_str; |
706 | int temp; | 723 | int temp; |
707 | GNUNET_assert(total > 0); | ||
708 | GNUNET_assert(cfg != NULL); | ||
709 | 724 | ||
710 | pg_start_ctx = GNUNET_malloc(sizeof(struct PeerGroupStartupContext)); | 725 | GNUNET_assert (total > 0); |
726 | GNUNET_assert (cfg != NULL); | ||
727 | |||
728 | pg_start_ctx = GNUNET_malloc (sizeof (struct PeerGroupStartupContext)); | ||
711 | 729 | ||
712 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testing", | 730 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testing", |
713 | "connect_attempts", | 731 | "connect_attempts", |
714 | &pg_start_ctx->connect_attempts)) | 732 | &pg_start_ctx->connect_attempts)) |
715 | { | 733 | { |
716 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", | 734 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", |
717 | "testing", "connect_attempts"); | 735 | "testing", "connect_attempts"); |
718 | GNUNET_free(pg_start_ctx); | 736 | GNUNET_free (pg_start_ctx); |
719 | return NULL; | 737 | return NULL; |
720 | } | 738 | } |
721 | 739 | ||
722 | if (GNUNET_OK | 740 | if (GNUNET_OK |
723 | != GNUNET_CONFIGURATION_get_value_number (cfg, "testing", | 741 | != GNUNET_CONFIGURATION_get_value_number (cfg, "testing", |
724 | "max_outstanding_connections", | 742 | "max_outstanding_connections", |
725 | &pg_start_ctx->max_concurrent_connections)) | 743 | &pg_start_ctx->max_concurrent_connections)) |
726 | { | 744 | { |
727 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", | 745 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", |
728 | "testing", "max_outstanding_connections"); | 746 | "testing", "max_outstanding_connections"); |
729 | GNUNET_free(pg_start_ctx); | 747 | GNUNET_free (pg_start_ctx); |
730 | return NULL; | 748 | return NULL; |
731 | } | 749 | } |
732 | 750 | ||
733 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testing", | 751 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testing", |
734 | "max_concurrent_ssh", | 752 | "max_concurrent_ssh", |
735 | &pg_start_ctx->max_concurrent_ssh)) | 753 | &pg_start_ctx->max_concurrent_ssh)) |
736 | { | 754 | { |
737 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", | 755 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", |
738 | "testing", "max_concurrent_ssh"); | 756 | "testing", "max_concurrent_ssh"); |
739 | GNUNET_free(pg_start_ctx); | 757 | GNUNET_free (pg_start_ctx); |
740 | return NULL; | 758 | return NULL; |
741 | } | 759 | } |
742 | 760 | ||
743 | if (GNUNET_SYSERR == (pg_start_ctx->verbose = GNUNET_CONFIGURATION_get_value_yesno (cfg, "testing", | 761 | if (GNUNET_SYSERR == |
744 | "use_progressbars"))) | 762 | (pg_start_ctx->verbose = |
745 | { | 763 | GNUNET_CONFIGURATION_get_value_yesno (cfg, "testing", |
746 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", | 764 | "use_progressbars"))) |
747 | "testing", "use_progressbars"); | 765 | { |
748 | GNUNET_free(pg_start_ctx); | 766 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", |
749 | return NULL; | 767 | "testing", "use_progressbars"); |
750 | } | 768 | GNUNET_free (pg_start_ctx); |
769 | return NULL; | ||
770 | } | ||
751 | 771 | ||
752 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "testing", | 772 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "testing", |
753 | "peergroup_timeout", | 773 | "peergroup_timeout", |
754 | &temp_config_number)) | 774 | &temp_config_number)) |
755 | pg_start_ctx->timeout = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 775 | pg_start_ctx->timeout = |
756 | temp_config_number)); | 776 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply |
777 | (GNUNET_TIME_UNIT_SECONDS, | ||
778 | temp_config_number)); | ||
757 | else | 779 | else |
758 | { | 780 | { |
759 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", | 781 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", |
760 | "testing", "peergroup_timeout"); | 782 | "testing", "peergroup_timeout"); |
761 | GNUNET_free(pg_start_ctx); | 783 | GNUNET_free (pg_start_ctx); |
762 | return NULL; | 784 | return NULL; |
763 | } | 785 | } |
764 | 786 | ||
765 | 787 | ||
766 | /* Read topology related options from the configuration file */ | 788 | /* Read topology related options from the configuration file */ |
@@ -768,102 +790,106 @@ GNUNET_TESTING_peergroup_start(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
768 | if ((GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", | 790 | if ((GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
769 | "topology", | 791 | "topology", |
770 | &temp_str)) | 792 | &temp_str)) |
771 | && (GNUNET_NO == GNUNET_TESTING_topology_get (&pg_start_ctx->topology, temp_str))) | 793 | && (GNUNET_NO == |
772 | { | 794 | GNUNET_TESTING_topology_get (&pg_start_ctx->topology, temp_str))) |
773 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 795 | { |
774 | "Invalid topology `%s' given for section %s option %s\n", | 796 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
775 | temp_str, "TESTING", "TOPOLOGY"); | 797 | "Invalid topology `%s' given for section %s option %s\n", |
776 | pg_start_ctx->topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */ | 798 | temp_str, "TESTING", "TOPOLOGY"); |
777 | } | 799 | pg_start_ctx->topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */ |
778 | GNUNET_free_non_null(temp_str); | 800 | } |
779 | 801 | GNUNET_free_non_null (temp_str); | |
780 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology_output_file", &temp_str)) | 802 | |
803 | if (GNUNET_YES == | ||
804 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", | ||
805 | "topology_output_file", &temp_str)) | ||
806 | { | ||
807 | pg_start_ctx->topology_output_file = | ||
808 | GNUNET_DISK_file_open (temp_str, | ||
809 | GNUNET_DISK_OPEN_READWRITE | | ||
810 | GNUNET_DISK_OPEN_CREATE, | ||
811 | GNUNET_DISK_PERM_USER_READ | | ||
812 | GNUNET_DISK_PERM_USER_WRITE); | ||
813 | if (pg_start_ctx->topology_output_file != NULL) | ||
781 | { | 814 | { |
782 | pg_start_ctx->topology_output_file = GNUNET_DISK_file_open (temp_str, GNUNET_DISK_OPEN_READWRITE | 815 | GNUNET_free (temp_str); |
783 | | GNUNET_DISK_OPEN_CREATE, | 816 | temp = GNUNET_asprintf (&temp_str, "strict graph G {\n"); |
784 | GNUNET_DISK_PERM_USER_READ | | 817 | if (temp > 0) |
785 | GNUNET_DISK_PERM_USER_WRITE); | 818 | GNUNET_DISK_file_write (pg_start_ctx->topology_output_file, temp_str, |
786 | if (pg_start_ctx->topology_output_file != NULL) | 819 | temp); |
787 | { | ||
788 | GNUNET_free(temp_str); | ||
789 | temp = GNUNET_asprintf(&temp_str, "strict graph G {\n"); | ||
790 | if (temp > 0) | ||
791 | GNUNET_DISK_file_write(pg_start_ctx->topology_output_file, temp_str, temp); | ||
792 | } | ||
793 | GNUNET_free(temp_str); | ||
794 | } | 820 | } |
821 | GNUNET_free (temp_str); | ||
822 | } | ||
795 | 823 | ||
796 | if (GNUNET_OK | 824 | if (GNUNET_OK |
797 | != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "percentage", | 825 | != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "percentage", |
798 | &temp_str)) | 826 | &temp_str)) |
799 | pg_start_ctx->topology_percentage = 0.5; | 827 | pg_start_ctx->topology_percentage = 0.5; |
800 | else | 828 | else |
801 | { | 829 | { |
802 | pg_start_ctx->topology_percentage = atof (temp_str); | 830 | pg_start_ctx->topology_percentage = atof (temp_str); |
803 | GNUNET_free(temp_str); | 831 | GNUNET_free (temp_str); |
804 | } | 832 | } |
805 | 833 | ||
806 | if (GNUNET_OK | 834 | if (GNUNET_OK |
807 | != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "probability", | 835 | != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "probability", |
808 | &temp_str)) | 836 | &temp_str)) |
809 | pg_start_ctx->topology_probability = 0.5; | 837 | pg_start_ctx->topology_probability = 0.5; |
810 | else | 838 | else |
811 | { | 839 | { |
812 | pg_start_ctx->topology_probability = atof (temp_str); | 840 | pg_start_ctx->topology_probability = atof (temp_str); |
813 | GNUNET_free(temp_str); | 841 | GNUNET_free (temp_str); |
814 | } | 842 | } |
815 | 843 | ||
816 | if ((GNUNET_YES | 844 | if ((GNUNET_YES |
817 | == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", | 845 | == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
818 | "connect_topology", | 846 | "connect_topology", |
819 | &temp_str)) | 847 | &temp_str)) |
820 | && (GNUNET_NO == GNUNET_TESTING_topology_get (&pg_start_ctx->connect_topology, | 848 | && (GNUNET_NO == |
821 | temp_str))) | 849 | GNUNET_TESTING_topology_get (&pg_start_ctx->connect_topology, |
822 | { | 850 | temp_str))) |
823 | GNUNET_log ( | 851 | { |
824 | GNUNET_ERROR_TYPE_WARNING, | 852 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
825 | "Invalid connect topology `%s' given for section %s option %s\n", | 853 | "Invalid connect topology `%s' given for section %s option %s\n", |
826 | temp_str, "TESTING", "CONNECT_TOPOLOGY"); | 854 | temp_str, "TESTING", "CONNECT_TOPOLOGY"); |
827 | } | 855 | } |
828 | GNUNET_free_non_null(temp_str); | 856 | GNUNET_free_non_null (temp_str); |
829 | 857 | ||
830 | if ((GNUNET_YES | 858 | if ((GNUNET_YES |
831 | == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", | 859 | == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
832 | "connect_topology_option", | 860 | "connect_topology_option", |
833 | &temp_str)) | 861 | &temp_str)) |
834 | && (GNUNET_NO | 862 | && (GNUNET_NO |
835 | == GNUNET_TESTING_topology_option_get (&pg_start_ctx->connect_topology_option, | 863 | == |
836 | temp_str))) | 864 | GNUNET_TESTING_topology_option_get |
837 | { | 865 | (&pg_start_ctx->connect_topology_option, temp_str))) |
838 | GNUNET_log ( | 866 | { |
839 | GNUNET_ERROR_TYPE_WARNING, | 867 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
840 | "Invalid connect topology option `%s' given for section %s option %s\n", | 868 | "Invalid connect topology option `%s' given for section %s option %s\n", |
841 | temp_str, "TESTING", | 869 | temp_str, "TESTING", "CONNECT_TOPOLOGY_OPTION"); |
842 | "CONNECT_TOPOLOGY_OPTION"); | 870 | pg_start_ctx->connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */ |
843 | pg_start_ctx->connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */ | 871 | } |
844 | } | 872 | GNUNET_free_non_null (temp_str); |
845 | GNUNET_free_non_null(temp_str); | ||
846 | 873 | ||
847 | if (GNUNET_YES | 874 | if (GNUNET_YES |
848 | == GNUNET_CONFIGURATION_get_value_string (cfg, | 875 | == GNUNET_CONFIGURATION_get_value_string (cfg, |
849 | "testing", | 876 | "testing", |
850 | "connect_topology_option_modifier", | 877 | "connect_topology_option_modifier", |
851 | &temp_str)) | 878 | &temp_str)) |
879 | { | ||
880 | if (sscanf (temp_str, "%lf", | ||
881 | &pg_start_ctx->connect_topology_option_modifier) != 1) | ||
852 | { | 882 | { |
853 | if (sscanf (temp_str, "%lf", | 883 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
854 | &pg_start_ctx->connect_topology_option_modifier) != 1) | 884 | _ |
855 | { | 885 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
856 | GNUNET_log ( | 886 | temp_str, "connect_topology_option_modifier", "TESTING"); |
857 | GNUNET_ERROR_TYPE_WARNING, | ||
858 | _("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | ||
859 | temp_str, | ||
860 | "connect_topology_option_modifier", "TESTING"); | ||
861 | GNUNET_free (temp_str); | ||
862 | GNUNET_free(pg_start_ctx); | ||
863 | return NULL; | ||
864 | } | ||
865 | GNUNET_free (temp_str); | 887 | GNUNET_free (temp_str); |
888 | GNUNET_free (pg_start_ctx); | ||
889 | return NULL; | ||
866 | } | 890 | } |
891 | GNUNET_free (temp_str); | ||
892 | } | ||
867 | 893 | ||
868 | if (GNUNET_YES | 894 | if (GNUNET_YES |
869 | != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", | 895 | != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
@@ -873,18 +899,19 @@ GNUNET_TESTING_peergroup_start(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
873 | 899 | ||
874 | pg_start_ctx->restrict_topology = GNUNET_TESTING_TOPOLOGY_NONE; | 900 | pg_start_ctx->restrict_topology = GNUNET_TESTING_TOPOLOGY_NONE; |
875 | if ((GNUNET_YES | 901 | if ((GNUNET_YES |
876 | == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", | 902 | == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
877 | "blacklist_topology", | 903 | "blacklist_topology", |
878 | &temp_str)) | 904 | &temp_str)) |
879 | && (GNUNET_NO == GNUNET_TESTING_topology_get (&pg_start_ctx->restrict_topology, | 905 | && (GNUNET_NO == |
880 | temp_str))) | 906 | GNUNET_TESTING_topology_get (&pg_start_ctx->restrict_topology, |
881 | { | 907 | temp_str))) |
882 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 908 | { |
883 | "Invalid topology `%s' given for section %s option %s\n", | 909 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
884 | temp_str, "TESTING", "BLACKLIST_TOPOLOGY"); | 910 | "Invalid topology `%s' given for section %s option %s\n", |
885 | } | 911 | temp_str, "TESTING", "BLACKLIST_TOPOLOGY"); |
886 | 912 | } | |
887 | GNUNET_free_non_null(temp_str); | 913 | |
914 | GNUNET_free_non_null (temp_str); | ||
888 | 915 | ||
889 | pg_start_ctx->cfg = cfg; | 916 | pg_start_ctx->cfg = cfg; |
890 | pg_start_ctx->total = total; | 917 | pg_start_ctx->total = total; |
@@ -893,28 +920,30 @@ GNUNET_TESTING_peergroup_start(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
893 | pg_start_ctx->peergroup_cb = peergroup_cb; | 920 | pg_start_ctx->peergroup_cb = peergroup_cb; |
894 | pg_start_ctx->cls = peergroup_cls; | 921 | pg_start_ctx->cls = peergroup_cls; |
895 | pg_start_ctx->hostnames = hostnames; | 922 | pg_start_ctx->hostnames = hostnames; |
896 | pg_start_ctx->hostkey_meter = create_meter (pg_start_ctx->peers_left, "Hostkeys created ", pg_start_ctx->verbose); | 923 | pg_start_ctx->hostkey_meter = |
897 | pg_start_ctx->peer_start_meter = create_meter (pg_start_ctx->peers_left, "Peers started ", pg_start_ctx->verbose); | 924 | create_meter (pg_start_ctx->peers_left, "Hostkeys created ", |
925 | pg_start_ctx->verbose); | ||
926 | pg_start_ctx->peer_start_meter = | ||
927 | create_meter (pg_start_ctx->peers_left, "Peers started ", | ||
928 | pg_start_ctx->verbose); | ||
898 | /* Make compilers happy */ | 929 | /* Make compilers happy */ |
899 | reset_meter(pg_start_ctx->peer_start_meter); | 930 | reset_meter (pg_start_ctx->peer_start_meter); |
900 | pg_start_ctx->die_task | 931 | pg_start_ctx->die_task |
901 | = GNUNET_SCHEDULER_add_delayed ( | 932 | = |
902 | GNUNET_TIME_absolute_get_remaining ( | 933 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining |
903 | pg_start_ctx->timeout), | 934 | (pg_start_ctx->timeout), &end_badly, |
904 | &end_badly, | 935 | "didn't generate all hostkeys within allowed startup time!"); |
905 | "didn't generate all hostkeys within allowed startup time!"); | ||
906 | 936 | ||
907 | pg_start_ctx->pg | 937 | pg_start_ctx->pg |
908 | = GNUNET_TESTING_daemons_start ( | 938 | = GNUNET_TESTING_daemons_start (pg_start_ctx->cfg, |
909 | pg_start_ctx->cfg, | ||
910 | pg_start_ctx->peers_left, | 939 | pg_start_ctx->peers_left, |
911 | pg_start_ctx->max_concurrent_connections, | 940 | pg_start_ctx->max_concurrent_connections, |
912 | pg_start_ctx->max_concurrent_ssh, | 941 | pg_start_ctx->max_concurrent_ssh, |
913 | GNUNET_TIME_absolute_get_remaining(pg_start_ctx->timeout), | 942 | GNUNET_TIME_absolute_get_remaining |
943 | (pg_start_ctx->timeout), | ||
914 | &internal_hostkey_callback, pg_start_ctx, | 944 | &internal_hostkey_callback, pg_start_ctx, |
915 | &internal_peers_started_callback, | 945 | &internal_peers_started_callback, |
916 | pg_start_ctx, | 946 | pg_start_ctx, &internal_topology_callback, |
917 | &internal_topology_callback, | ||
918 | pg_start_ctx, pg_start_ctx->hostnames); | 947 | pg_start_ctx, pg_start_ctx->hostnames); |
919 | 948 | ||
920 | return pg_start_ctx->pg; | 949 | return pg_start_ctx->pg; |