diff options
author | LRN <lrn1986@gmail.com> | 2013-03-13 17:49:26 +0000 |
---|---|---|
committer | LRN <lrn1986@gmail.com> | 2013-03-13 17:49:26 +0000 |
commit | 405f776bc08486af4edb80e18149c0829732b347 (patch) | |
tree | d5fc635a51641dec6b53cb2540276f34ae8f6210 /src/arm/test_arm_api.c | |
parent | 3ceae682287492ecc768aea5c4c463216a35774d (diff) | |
download | gnunet-405f776bc08486af4edb80e18149c0829732b347.tar.gz gnunet-405f776bc08486af4edb80e18149c0829732b347.zip |
All-encompassing ARM update
Diffstat (limited to 'src/arm/test_arm_api.c')
-rw-r--r-- | src/arm/test_arm_api.c | 151 |
1 files changed, 110 insertions, 41 deletions
diff --git a/src/arm/test_arm_api.c b/src/arm/test_arm_api.c index 366d4e500..999bd77e6 100644 --- a/src/arm/test_arm_api.c +++ b/src/arm/test_arm_api.c | |||
@@ -42,77 +42,144 @@ static struct GNUNET_ARM_Handle *arm; | |||
42 | 42 | ||
43 | static int ok = 1; | 43 | static int ok = 1; |
44 | 44 | ||
45 | static int phase = 0; | ||
46 | |||
45 | static void | 47 | static void |
46 | arm_stopped (void *cls, enum GNUNET_ARM_ProcessStatus success) | 48 | arm_stop_cb (void *cls, struct GNUNET_ARM_Handle *h, enum GNUNET_ARM_RequestStatus status, const char *servicename, enum GNUNET_ARM_Result result) |
47 | { | 49 | { |
48 | GNUNET_break (success == GNUNET_ARM_PROCESS_DOWN); | 50 | /* (6), a stop request should be sent to ARM successfully */ |
49 | if (success != GNUNET_ARM_PROCESS_DOWN) | 51 | /* ARM should report that it is stopping */ |
50 | ok = 3; | 52 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); |
51 | else if (ok == 1) | 53 | GNUNET_break (result == GNUNET_ARM_RESULT_STOPPING); |
52 | ok = 0; | 54 | GNUNET_break (phase == 6); |
55 | phase++; | ||
56 | FPRINTF (stderr, "Sent 'STOP' request for arm to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | ||
53 | } | 57 | } |
54 | 58 | ||
55 | |||
56 | static void | 59 | static void |
57 | arm_notify_stop (void *cls, enum GNUNET_ARM_ProcessStatus success) | 60 | resolver_stop_cb (void *cls, struct GNUNET_ARM_Handle *h, enum GNUNET_ARM_RequestStatus status, const char *servicename, enum GNUNET_ARM_Result result) |
58 | { | 61 | { |
59 | GNUNET_break (success == GNUNET_ARM_PROCESS_DOWN); | 62 | /* (5), a stop request should be sent to ARM successfully. |
63 | * ARM should report that resolver is stopped. | ||
64 | */ | ||
65 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); | ||
66 | GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED); | ||
67 | GNUNET_break (phase == 5); | ||
68 | FPRINTF (stderr, "Sent 'STOP' request for resolver to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | ||
69 | phase++; | ||
60 | #if START_ARM | 70 | #if START_ARM |
61 | GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); | 71 | GNUNET_ARM_request_service_stop (arm, "arm", TIMEOUT, arm_stop_cb, NULL); |
72 | #else | ||
73 | arm_stop_cb (NULL, GNUNET_ARM_STATUS_SENT_OK, "arm", GNUNET_ARM_SERVICE_STOPPING); | ||
74 | arm_conn (NULL, GNUNET_NO, GNUNET_NO); | ||
62 | #endif | 75 | #endif |
63 | } | 76 | } |
64 | 77 | ||
65 | |||
66 | static void | 78 | static void |
67 | dns_notify (void *cls, const struct sockaddr *addr, socklen_t addrlen) | 79 | dns_notify (void *cls, const struct sockaddr *addr, socklen_t addrlen) |
68 | { | 80 | { |
69 | if (addr == NULL) | 81 | if (addr == NULL) |
70 | { | 82 | { |
83 | /* (4), resolver should finish resolving localhost */ | ||
84 | GNUNET_break (phase == 4); | ||
85 | phase++; | ||
86 | FPRINTF (stderr, "%s", "Finished resolving localhost\n"); | ||
71 | if (ok != 0) | 87 | if (ok != 0) |
72 | { | 88 | ok = 2; |
73 | GNUNET_break (0); | 89 | GNUNET_ARM_request_service_stop (arm, "resolver", TIMEOUT, resolver_stop_cb, NULL); |
74 | ok = 2; | ||
75 | } | ||
76 | GNUNET_ARM_stop_service (arm, "resolver", TIMEOUT, &arm_notify_stop, | ||
77 | NULL); | ||
78 | return; | 90 | return; |
79 | } | 91 | } |
92 | /* (3), resolver should resolve localhost */ | ||
93 | GNUNET_break (phase == 3); | ||
94 | FPRINTF (stderr, "%s", "Resolved localhost\n"); | ||
95 | phase++; | ||
80 | GNUNET_break (addr != NULL); | 96 | GNUNET_break (addr != NULL); |
81 | ok = 0; | 97 | ok = 0; |
82 | } | 98 | } |
83 | 99 | ||
84 | |||
85 | static void | 100 | static void |
86 | resolver_notify (void *cls, enum GNUNET_ARM_ProcessStatus success) | 101 | resolver_start_cb (void *cls, struct GNUNET_ARM_Handle *h, enum GNUNET_ARM_RequestStatus status, const char *servicename, enum GNUNET_ARM_Result result) |
87 | { | 102 | { |
88 | if (success != GNUNET_ARM_PROCESS_STARTING) | 103 | /* (2), the start request for resolver should be sent successfully |
89 | { | 104 | * ARM should report that resolver service is starting. |
90 | GNUNET_break (0); | 105 | */ |
91 | ok = 2; | 106 | GNUNET_assert (status == GNUNET_ARM_REQUEST_SENT_OK); |
92 | #if START_ARM | 107 | GNUNET_break (phase == 2); |
93 | GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); | 108 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); |
94 | #endif | 109 | FPRINTF (stderr, "Sent 'START' request for resolver to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); |
95 | return; | 110 | phase++; |
96 | } | ||
97 | GNUNET_RESOLVER_ip_get ("localhost", AF_INET, TIMEOUT, &dns_notify, NULL); | 111 | GNUNET_RESOLVER_ip_get ("localhost", AF_INET, TIMEOUT, &dns_notify, NULL); |
98 | } | 112 | } |
99 | 113 | ||
100 | |||
101 | static void | 114 | static void |
102 | arm_notify (void *cls, enum GNUNET_ARM_ProcessStatus success) | 115 | trigger_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
103 | { | 116 | { |
104 | if (success != GNUNET_ARM_PROCESS_STARTING) | 117 | GNUNET_ARM_disconnect ((struct GNUNET_ARM_Handle *) cls); |
105 | { | 118 | } |
106 | GNUNET_break (0); | 119 | |
107 | ok = 2; | 120 | |
121 | void | ||
122 | arm_conn (void *cls, struct GNUNET_ARM_Handle *arm, unsigned char connected, unsigned char error) | ||
123 | { | ||
124 | if (GNUNET_YES == error) | ||
125 | { | ||
126 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
127 | _("Fatal error initializing ARM API.\n")); | ||
128 | GNUNET_SCHEDULER_shutdown (); | ||
129 | GNUNET_assert (0); | ||
130 | return; | ||
131 | } | ||
132 | if (connected) | ||
133 | { | ||
134 | /* (1), arm connection should be established */ | ||
135 | FPRINTF (stderr, "%s", "Connected to ARM\n"); | ||
136 | GNUNET_break (phase == 1); | ||
137 | phase++; | ||
138 | GNUNET_ARM_request_service_start (arm, "resolver", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, resolver_start_cb, NULL); | ||
139 | } | ||
140 | else | ||
141 | { | ||
142 | /* (7), ARM should stop (we disconnect from it) */ | ||
143 | FPRINTF (stderr, "%s", "Disconnected from ARM\n"); | ||
144 | GNUNET_break (phase == 7); | ||
145 | if (phase != 7) | ||
146 | ok = 3; | ||
147 | else if (ok == 1) | ||
148 | ok = 0; | ||
149 | GNUNET_SCHEDULER_add_now (trigger_disconnect, arm); | ||
150 | } | ||
151 | } | ||
152 | |||
153 | void | ||
154 | srv_status (void *cls, const char *service, enum GNUNET_ARM_ServiceStatus status) | ||
155 | { | ||
156 | FPRINTF (stderr, "Service %s is %u\n", service, status); | ||
157 | switch (phase) | ||
158 | { | ||
159 | default: | ||
160 | FPRINTF (stderr, "Unexpectedly got status %u for service %s\n", service); | ||
161 | GNUNET_break (0); | ||
162 | ok = 2; | ||
108 | #if START_ARM | 163 | #if START_ARM |
109 | GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); | 164 | GNUNET_ARM_request_service_stop (arm, "arm", TIMEOUT, NULL, NULL); |
110 | #endif | 165 | #endif |
111 | } | 166 | } |
112 | GNUNET_ARM_start_service (arm, "resolver", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, &resolver_notify, | ||
113 | NULL); | ||
114 | } | 167 | } |
115 | 168 | ||
169 | static void | ||
170 | arm_start_cb (void *cls, struct GNUNET_ARM_Handle *h, enum GNUNET_ARM_RequestStatus status, const char *servicename, enum GNUNET_ARM_Result result) | ||
171 | { | ||
172 | /* (0) The request should be "sent" successfully | ||
173 | * ("sent", because it isn't going anywhere, ARM API starts ARM service | ||
174 | * by itself). | ||
175 | * ARM API should report that ARM service is starting. | ||
176 | */ | ||
177 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); | ||
178 | GNUNET_break (phase == 0); | ||
179 | FPRINTF (stderr, "Sent 'START' request for arm to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | ||
180 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); | ||
181 | phase++; | ||
182 | } | ||
116 | 183 | ||
117 | static void | 184 | static void |
118 | task (void *cls, char *const *args, const char *cfgfile, | 185 | task (void *cls, char *const *args, const char *cfgfile, |
@@ -133,11 +200,13 @@ task (void *cls, char *const *args, const char *cfgfile, | |||
133 | else | 200 | else |
134 | GNUNET_free (armconfig); | 201 | GNUNET_free (armconfig); |
135 | } | 202 | } |
136 | arm = GNUNET_ARM_connect (cfg, NULL); | 203 | arm = GNUNET_ARM_alloc (cfg); |
204 | GNUNET_ARM_connect (arm, arm_conn, NULL); | ||
137 | #if START_ARM | 205 | #if START_ARM |
138 | GNUNET_ARM_start_service (arm, "arm", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, &arm_notify, NULL); | 206 | GNUNET_ARM_request_service_start (arm, "arm", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, arm_start_cb, NULL); |
139 | #else | 207 | #else |
140 | arm_notify (NULL, GNUNET_YES); | 208 | arm_start_cb (NULL, arm, GNUNET_ARM_REQUEST_SENT_OK, "arm", GNUNET_ARM_RESULT_STARTING); |
209 | arm_conn (NULL, GNUNET_YES, GNUNET_NO); | ||
141 | #endif | 210 | #endif |
142 | } | 211 | } |
143 | 212 | ||