diff options
Diffstat (limited to 'src/arm/test_gnunet_service_manager.c')
-rw-r--r-- | src/arm/test_gnunet_service_manager.c | 153 |
1 files changed, 103 insertions, 50 deletions
diff --git a/src/arm/test_gnunet_service_manager.c b/src/arm/test_gnunet_service_manager.c index 2d39e392a..d0c29ded5 100644 --- a/src/arm/test_gnunet_service_manager.c +++ b/src/arm/test_gnunet_service_manager.c | |||
@@ -27,80 +27,133 @@ | |||
27 | #include "gnunet_resolver_service.h" | 27 | #include "gnunet_resolver_service.h" |
28 | #include "gnunet_program_lib.h" | 28 | #include "gnunet_program_lib.h" |
29 | 29 | ||
30 | /** | ||
31 | * Timeout for starting services, very short because of the strange way start works | ||
32 | * (by checking if running before starting, so really this time is always waited on | ||
33 | * startup (annoying)). | ||
34 | */ | ||
35 | #define START_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 50) | ||
36 | |||
30 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 37 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
31 | 38 | ||
32 | /* Global Variables */ | 39 | #define START_ARM GNUNET_YES |
33 | static int isOK = GNUNET_OK; | 40 | |
41 | static int ret = 1; | ||
42 | |||
43 | static struct GNUNET_SCHEDULER_Handle *sched; | ||
44 | |||
45 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
46 | |||
47 | static struct GNUNET_ARM_Handle *arm; | ||
48 | |||
49 | static void | ||
50 | arm_stopped (void *cls, int success) | ||
51 | { | ||
52 | if (success != GNUNET_OK) | ||
53 | ret = 4; | ||
54 | } | ||
34 | 55 | ||
35 | static void | 56 | static void |
36 | hostNameResolveCB(void *cls, | 57 | hostNameResolveCB(void *cls, |
37 | const struct sockaddr *addr, | 58 | const struct sockaddr *addr, |
38 | socklen_t addrlen) | 59 | socklen_t addrlen) |
39 | { | 60 | { |
40 | if (NULL == addr) | 61 | if ( (ret == 0) || (ret == 4) ) |
41 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Name not resolved!\n"); | 62 | return; |
63 | if (NULL == addr) | ||
64 | { | ||
65 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
66 | "Name not resolved!\n"); | ||
67 | #if START_ARM | ||
68 | GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); | ||
69 | #endif | ||
70 | ret = 3; | ||
71 | return; | ||
72 | } | ||
73 | ret = 0; | ||
74 | #if START_ARM | ||
75 | GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); | ||
76 | #endif | ||
77 | } | ||
78 | |||
79 | |||
80 | |||
81 | static void | ||
82 | arm_notify (void *cls, int success) | ||
83 | { | ||
84 | if (success != GNUNET_YES) | ||
85 | { | ||
86 | GNUNET_break (0); | ||
87 | ret = 1; | ||
88 | return; | ||
89 | } | ||
90 | /* connect to the resolver service */ | ||
91 | if (NULL == GNUNET_RESOLVER_hostname_resolve (sched, | ||
92 | cfg, AF_UNSPEC, | ||
93 | TIMEOUT, | ||
94 | &hostNameResolveCB, | ||
95 | NULL)) | ||
96 | { | ||
97 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
98 | "Unable to resolve our own hostname!\n"); | ||
99 | ret = 2; | ||
100 | #if START_ARM | ||
101 | GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); | ||
102 | #endif | ||
103 | } | ||
42 | } | 104 | } |
43 | 105 | ||
44 | 106 | ||
45 | static void | 107 | static void |
46 | run(void *cls, | 108 | run(void *cls, |
47 | struct GNUNET_SCHEDULER_Handle *sched, | 109 | struct GNUNET_SCHEDULER_Handle *s, |
48 | char * const *args, | 110 | char * const *args, |
49 | const char *cfgfile, | 111 | const char *cfgfile, |
50 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 112 | const struct GNUNET_CONFIGURATION_Handle *c) |
51 | { | 113 | { |
52 | struct GNUNET_RESOLVER_RequestHandle *resolveRet; | 114 | cfg = c; |
53 | 115 | sched = s; | |
54 | /* connect to the resolver service */ | 116 | arm = GNUNET_ARM_connect (cfg, sched, NULL); |
55 | resolveRet = | 117 | #if START_ARM |
56 | GNUNET_RESOLVER_hostname_resolve (sched, | 118 | GNUNET_ARM_start_service (arm, "arm", START_TIMEOUT, &arm_notify, NULL); |
57 | cfg, AF_UNSPEC, | 119 | #else |
58 | TIMEOUT, | 120 | arm_notify (NULL, GNUNET_YES); |
59 | &hostNameResolveCB, | 121 | #endif |
60 | NULL); | ||
61 | if (NULL == resolveRet) { | ||
62 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Unable to resolve our own hostname!\n"); | ||
63 | isOK = GNUNET_NO; | ||
64 | } | ||
65 | } | 122 | } |
66 | 123 | ||
67 | 124 | ||
68 | static int | 125 | static void |
69 | check() | 126 | check() |
70 | { | 127 | { |
71 | char *const argv[] = { | 128 | char *const argv[] = { |
72 | "test-gnunet-service-manager", | 129 | "test-gnunet-service-manager", |
73 | "-c", "test_arm_api_data.conf", | 130 | "-c", "test_arm_api_data.conf", |
74 | #if VERBOSE | 131 | #if VERBOSE |
75 | "-L", "DEBUG", | 132 | "-L", "DEBUG", |
76 | #endif | 133 | #endif |
77 | NULL | 134 | NULL |
78 | }; | 135 | }; |
79 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 136 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
80 | GNUNET_GETOPT_OPTION_END | 137 | GNUNET_GETOPT_OPTION_END |
81 | }; | 138 | }; |
82 | 139 | GNUNET_assert (GNUNET_OK == | |
83 | /* Running ARM and running the do_nothing task */ | 140 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
84 | GNUNET_assert (GNUNET_OK == | 141 | argv, |
85 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 142 | "test-gnunet-service-manager", |
86 | argv, | 143 | "nohelp", options, &run, NULL)); |
87 | "test-gnunet-service-manager", | ||
88 | "nohelp", options, &run, NULL)); | ||
89 | return isOK; | ||
90 | } | 144 | } |
91 | 145 | ||
92 | 146 | ||
93 | int | 147 | int |
94 | main (int argc, char *argv[]) | 148 | main (int argc, char *argv[]) |
95 | { | 149 | { |
96 | int ret; | ||
97 | GNUNET_log_setup("test-gnunet-service-manager", | 150 | GNUNET_log_setup("test-gnunet-service-manager", |
98 | #if VERBOSE | 151 | #if VERBOSE |
99 | "DEBUG", | 152 | "DEBUG", |
100 | #else | 153 | #else |
101 | "WARNING", | 154 | "WARNING", |
102 | #endif | 155 | #endif |
103 | NULL); | 156 | NULL); |
104 | ret = check(); | 157 | check(); |
105 | return ret; | 158 | return ret; |
106 | } | 159 | } |