aboutsummaryrefslogtreecommitdiff
path: root/src/arm/test_gnunet_service_arm.c
diff options
context:
space:
mode:
authorLRN <lrn1986@gmail.com>2013-03-13 17:49:26 +0000
committerLRN <lrn1986@gmail.com>2013-03-13 17:49:26 +0000
commit405f776bc08486af4edb80e18149c0829732b347 (patch)
treed5fc635a51641dec6b53cb2540276f34ae8f6210 /src/arm/test_gnunet_service_arm.c
parent3ceae682287492ecc768aea5c4c463216a35774d (diff)
downloadgnunet-405f776bc08486af4edb80e18149c0829732b347.tar.gz
gnunet-405f776bc08486af4edb80e18149c0829732b347.zip
All-encompassing ARM update
Diffstat (limited to 'src/arm/test_gnunet_service_arm.c')
-rw-r--r--src/arm/test_gnunet_service_arm.c81
1 files changed, 37 insertions, 44 deletions
diff --git a/src/arm/test_gnunet_service_arm.c b/src/arm/test_gnunet_service_arm.c
index 9e9286ac1..bd7fe5fa9 100644
--- a/src/arm/test_gnunet_service_arm.c
+++ b/src/arm/test_gnunet_service_arm.c
@@ -42,23 +42,22 @@ static int ret = 1;
42 42
43static struct GNUNET_ARM_Handle *arm; 43static struct GNUNET_ARM_Handle *arm;
44 44
45
46static void 45static void
47arm_stopped (void *cls, enum GNUNET_ARM_ProcessStatus success) 46trigger_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
48{ 47{
49 if (success != GNUNET_ARM_PROCESS_DOWN)
50 {
51 GNUNET_break (0);
52 ret = 4;
53 }
54 else
55 {
56 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM stopped\n");
57 }
58 GNUNET_ARM_disconnect (arm); 48 GNUNET_ARM_disconnect (arm);
59 arm = NULL; 49 arm = NULL;
60} 50}
61 51
52static void
53arm_stop_cb (void *cls, struct GNUNET_ARM_Handle *h, enum GNUNET_ARM_RequestStatus status, const char *servicename, enum GNUNET_ARM_Result result)
54{
55 GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
56 GNUNET_break (result == GNUNET_ARM_RESULT_STOPPING);
57 if (result != GNUNET_ARM_RESULT_STOPPING)
58 ret = 4;
59 GNUNET_SCHEDULER_add_now (trigger_disconnect, NULL);
60}
62 61
63static void 62static void
64hostNameResolveCB (void *cls, const struct sockaddr *addr, socklen_t addrlen) 63hostNameResolveCB (void *cls, const struct sockaddr *addr, socklen_t addrlen)
@@ -66,43 +65,37 @@ hostNameResolveCB (void *cls, const struct sockaddr *addr, socklen_t addrlen)
66 if ((ret == 0) || (ret == 4)) 65 if ((ret == 0) || (ret == 4))
67 return; 66 return;
68 if (NULL == addr) 67 if (NULL == addr)
69 { 68 {
70 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Name not resolved!\n"); 69 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Name not resolved!\n");
71 GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); 70 ret = 3;
72 ret = 3; 71 }
73 return; 72 else
74 } 73 {
75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 74 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
76 "Resolved hostname, now stopping ARM\n"); 75 "Resolved hostname, now stopping ARM\n");
77 ret = 0; 76 ret = 0;
78 GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); 77 }
78 GNUNET_ARM_request_service_stop (arm, "arm", TIMEOUT, arm_stop_cb, NULL);
79} 79}
80 80
81
82static void 81static void
83arm_notify (void *cls, enum GNUNET_ARM_ProcessStatus success) 82arm_start_cb (void *cls, struct GNUNET_ARM_Handle *h, enum GNUNET_ARM_RequestStatus status, const char *servicename, enum GNUNET_ARM_Result result)
84{ 83{
85 if (success != GNUNET_ARM_PROCESS_STARTING) 84 GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
86 { 85 GNUNET_break (result == GNUNET_ARM_RESULT_STARTING);
87 GNUNET_break (0);
88 ret = 1;
89 return;
90 }
91 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 86 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
92 "Trying to resolve our own hostname!\n"); 87 "Trying to resolve our own hostname!\n");
93 /* connect to the resolver service */ 88 /* connect to the resolver service */
94 if (NULL == 89 if (NULL == GNUNET_RESOLVER_hostname_resolve (
95 GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC, TIMEOUT, 90 AF_UNSPEC, TIMEOUT, &hostNameResolveCB, NULL))
96 &hostNameResolveCB, NULL)) 91 {
97 { 92 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
98 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 93 "Unable initiate connection to resolver service\n");
99 "Unable initiate connection to resolver service\n"); 94 ret = 2;
100 ret = 2; 95 GNUNET_ARM_request_service_stop (arm, "arm", TIMEOUT, arm_stop_cb, NULL);
101 GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); 96 }
102 }
103} 97}
104 98
105
106static void 99static void
107run (void *cls, char *const *args, const char *cfgfile, 100run (void *cls, char *const *args, const char *cfgfile,
108 const struct GNUNET_CONFIGURATION_Handle *c) 101 const struct GNUNET_CONFIGURATION_Handle *c)
@@ -122,10 +115,10 @@ run (void *cls, char *const *args, const char *cfgfile,
122 else 115 else
123 GNUNET_free (armconfig); 116 GNUNET_free (armconfig);
124 } 117 }
125 arm = GNUNET_ARM_connect (c, NULL); 118 arm = GNUNET_ARM_alloc (c);
126 GNUNET_ARM_start_service (arm, "arm", 119 GNUNET_ARM_connect (arm, NULL, NULL);
127 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, 120 GNUNET_ARM_request_service_start (arm, "arm",
128 &arm_notify, NULL); 121 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, arm_start_cb, NULL);
129} 122}
130 123
131 124