aboutsummaryrefslogtreecommitdiff
path: root/src/arm/test_gnunet_service_manager.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arm/test_gnunet_service_manager.c')
-rw-r--r--src/arm/test_gnunet_service_manager.c123
1 files changed, 58 insertions, 65 deletions
diff --git a/src/arm/test_gnunet_service_manager.c b/src/arm/test_gnunet_service_manager.c
index 087e01ccb..4c4de9242 100644
--- a/src/arm/test_gnunet_service_manager.c
+++ b/src/arm/test_gnunet_service_manager.c
@@ -53,41 +53,36 @@ static struct GNUNET_ARM_Handle *arm;
53static void 53static void
54arm_stopped (void *cls, int success) 54arm_stopped (void *cls, int success)
55{ 55{
56 if (success != GNUNET_NO) 56 if (success != GNUNET_NO)
57 { 57 {
58 GNUNET_break (0); 58 GNUNET_break (0);
59 ret = 4; 59 ret = 4;
60 } 60 }
61 else 61 else
62 { 62 {
63 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 63 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM stopped\n");
64 "ARM stopped\n"); 64 }
65 }
66#if START_ARM 65#if START_ARM
67 GNUNET_ARM_disconnect (arm); 66 GNUNET_ARM_disconnect (arm);
68 arm = NULL; 67 arm = NULL;
69#endif 68#endif
70} 69}
71 70
72static void 71static void
73hostNameResolveCB(void *cls, 72hostNameResolveCB (void *cls, const struct sockaddr *addr, socklen_t addrlen)
74 const struct sockaddr *addr,
75 socklen_t addrlen)
76{ 73{
77 if ( (ret == 0) || (ret == 4) ) 74 if ((ret == 0) || (ret == 4))
78 return; 75 return;
79 if (NULL == addr) 76 if (NULL == addr)
80 { 77 {
81 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 78 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Name not resolved!\n");
82 "Name not resolved!\n");
83#if START_ARM 79#if START_ARM
84 GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); 80 GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
85#endif 81#endif
86 ret = 3; 82 ret = 3;
87 return; 83 return;
88 } 84 }
89 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 85 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Resolved hostname, now stopping ARM\n");
90 "Resolved hostname, now stopping ARM\n");
91 ret = 0; 86 ret = 0;
92#if START_ARM 87#if START_ARM
93 GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); 88 GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
@@ -99,34 +94,31 @@ static void
99arm_notify (void *cls, int success) 94arm_notify (void *cls, int success)
100{ 95{
101 if (success != GNUNET_YES) 96 if (success != GNUNET_YES)
102 { 97 {
103 GNUNET_break (0); 98 GNUNET_break (0);
104 ret = 1; 99 ret = 1;
105 return; 100 return;
106 } 101 }
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to resolve our own hostname!\n");
108 "Trying to resolve our own hostname!\n");
109 /* connect to the resolver service */ 103 /* connect to the resolver service */
110 if (NULL == GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC, 104 if (NULL == GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC,
111 TIMEOUT, 105 TIMEOUT,
112 &hostNameResolveCB, 106 &hostNameResolveCB, NULL))
113 NULL)) 107 {
114 { 108 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 109 "Unable initiate connection to resolver service\n");
116 "Unable initiate connection to resolver service\n"); 110 ret = 2;
117 ret = 2;
118#if START_ARM 111#if START_ARM
119 GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); 112 GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
120#endif 113#endif
121 } 114 }
122} 115}
123 116
124 117
125static void 118static void
126run(void *cls, 119run (void *cls,
127 char * const *args, 120 char *const *args,
128 const char *cfgfile, 121 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
129 const struct GNUNET_CONFIGURATION_Handle *c)
130{ 122{
131 cfg = c; 123 cfg = c;
132#if START_ARM 124#if START_ARM
@@ -139,7 +131,7 @@ run(void *cls,
139 131
140 132
141static void 133static void
142check() 134check ()
143{ 135{
144 char *const argv[] = { 136 char *const argv[] = {
145 "test-gnunet-service-manager", 137 "test-gnunet-service-manager",
@@ -153,39 +145,40 @@ check()
153 GNUNET_GETOPT_OPTION_END 145 GNUNET_GETOPT_OPTION_END
154 }; 146 };
155 GNUNET_assert (GNUNET_OK == 147 GNUNET_assert (GNUNET_OK ==
156 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 148 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
157 argv, 149 argv,
158 "test-gnunet-service-manager", 150 "test-gnunet-service-manager",
159 "nohelp", options, &run, NULL)); 151 "nohelp", options, &run, NULL));
160} 152}
161 153
162 154
163int 155int
164main (int argc, char *argv[]) 156main (int argc, char *argv[])
165{ 157{
166 char hostname[GNUNET_OS_get_hostname_max_length() + 1]; 158 char hostname[GNUNET_OS_get_hostname_max_length () + 1];
167 159
168 if (0 != gethostname (hostname, sizeof (hostname) - 1)) 160 if (0 != gethostname (hostname, sizeof (hostname) - 1))
169 { 161 {
170 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | 162 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR |
171 GNUNET_ERROR_TYPE_BULK, "gethostname"); 163 GNUNET_ERROR_TYPE_BULK, "gethostname");
172 fprintf (stderr, "Failed to determine my own hostname, testcase not run.\n"); 164 fprintf (stderr,
173 return 0; 165 "Failed to determine my own hostname, testcase not run.\n");
174 } 166 return 0;
167 }
175 if (NULL == gethostbyname (hostname)) 168 if (NULL == gethostbyname (hostname))
176 { 169 {
177 fprintf (stderr, "Failed to resolve my hostname `%s', testcase not run.\n", 170 fprintf (stderr, "Failed to resolve my hostname `%s', testcase not run.\n",
178 hostname); 171 hostname);
179 return 0; 172 return 0;
180 } 173 }
181 174
182 GNUNET_log_setup("test-gnunet-service-manager", 175 GNUNET_log_setup ("test-gnunet-service-manager",
183#if VERBOSE 176#if VERBOSE
184 "DEBUG", 177 "DEBUG",
185#else 178#else
186 "WARNING", 179 "WARNING",
187#endif 180#endif
188 NULL); 181 NULL);
189 check(); 182 check ();
190 return ret; 183 return ret;
191} 184}