diff options
Diffstat (limited to 'src/nse/nse_api.c')
-rw-r--r-- | src/nse/nse_api.c | 91 |
1 files changed, 46 insertions, 45 deletions
diff --git a/src/nse/nse_api.c b/src/nse/nse_api.c index 93716eb5f..af6a2065b 100644 --- a/src/nse/nse_api.c +++ b/src/nse/nse_api.c | |||
@@ -32,12 +32,13 @@ | |||
32 | #include "gnunet_nse_service.h" | 32 | #include "gnunet_nse_service.h" |
33 | #include "nse.h" | 33 | #include "nse.h" |
34 | 34 | ||
35 | #define LOG(kind, ...) GNUNET_log_from(kind, "nse-api", __VA_ARGS__) | 35 | #define LOG(kind, ...) GNUNET_log_from (kind, "nse-api", __VA_ARGS__) |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Handle for talking with the NSE service. | 38 | * Handle for talking with the NSE service. |
39 | */ | 39 | */ |
40 | struct GNUNET_NSE_Handle { | 40 | struct GNUNET_NSE_Handle |
41 | { | ||
41 | /** | 42 | /** |
42 | * Configuration to use. | 43 | * Configuration to use. |
43 | */ | 44 | */ |
@@ -76,7 +77,7 @@ struct GNUNET_NSE_Handle { | |||
76 | * @param cls closure with the `struct GNUNET_NSE_Handle *` | 77 | * @param cls closure with the `struct GNUNET_NSE_Handle *` |
77 | */ | 78 | */ |
78 | static void | 79 | static void |
79 | reconnect(void *cls); | 80 | reconnect (void *cls); |
80 | 81 | ||
81 | 82 | ||
82 | /** | 83 | /** |
@@ -89,16 +90,16 @@ reconnect(void *cls); | |||
89 | * @param error error code | 90 | * @param error error code |
90 | */ | 91 | */ |
91 | static void | 92 | static void |
92 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | 93 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
93 | { | 94 | { |
94 | struct GNUNET_NSE_Handle *h = cls; | 95 | struct GNUNET_NSE_Handle *h = cls; |
95 | 96 | ||
96 | (void)error; | 97 | (void) error; |
97 | GNUNET_MQ_destroy(h->mq); | 98 | GNUNET_MQ_destroy (h->mq); |
98 | h->mq = NULL; | 99 | h->mq = NULL; |
99 | h->reconnect_task = | 100 | h->reconnect_task = |
100 | GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect, h); | 101 | GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); |
101 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay); | 102 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); |
102 | } | 103 | } |
103 | 104 | ||
104 | 105 | ||
@@ -110,15 +111,15 @@ mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | |||
110 | * @param client_msg message received | 111 | * @param client_msg message received |
111 | */ | 112 | */ |
112 | static void | 113 | static void |
113 | handle_estimate(void *cls, const struct GNUNET_NSE_ClientMessage *client_msg) | 114 | handle_estimate (void *cls, const struct GNUNET_NSE_ClientMessage *client_msg) |
114 | { | 115 | { |
115 | struct GNUNET_NSE_Handle *h = cls; | 116 | struct GNUNET_NSE_Handle *h = cls; |
116 | 117 | ||
117 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 118 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
118 | h->recv_cb(h->recv_cb_cls, | 119 | h->recv_cb (h->recv_cb_cls, |
119 | GNUNET_TIME_absolute_ntoh(client_msg->timestamp), | 120 | GNUNET_TIME_absolute_ntoh (client_msg->timestamp), |
120 | GNUNET_ntoh_double(client_msg->size_estimate), | 121 | GNUNET_ntoh_double (client_msg->size_estimate), |
121 | GNUNET_ntoh_double(client_msg->std_deviation)); | 122 | GNUNET_ntoh_double (client_msg->std_deviation)); |
122 | } | 123 | } |
123 | 124 | ||
124 | 125 | ||
@@ -128,27 +129,27 @@ handle_estimate(void *cls, const struct GNUNET_NSE_ClientMessage *client_msg) | |||
128 | * @param cls the `struct GNUNET_NSE_Handle *` | 129 | * @param cls the `struct GNUNET_NSE_Handle *` |
129 | */ | 130 | */ |
130 | static void | 131 | static void |
131 | reconnect(void *cls) | 132 | reconnect (void *cls) |
132 | { | 133 | { |
133 | struct GNUNET_NSE_Handle *h = cls; | 134 | struct GNUNET_NSE_Handle *h = cls; |
134 | struct GNUNET_MQ_MessageHandler handlers[] = | 135 | struct GNUNET_MQ_MessageHandler handlers[] = |
135 | { GNUNET_MQ_hd_fixed_size(estimate, | 136 | { GNUNET_MQ_hd_fixed_size (estimate, |
136 | GNUNET_MESSAGE_TYPE_NSE_ESTIMATE, | 137 | GNUNET_MESSAGE_TYPE_NSE_ESTIMATE, |
137 | struct GNUNET_NSE_ClientMessage, | 138 | struct GNUNET_NSE_ClientMessage, |
138 | h), | 139 | h), |
139 | GNUNET_MQ_handler_end() }; | 140 | GNUNET_MQ_handler_end () }; |
140 | struct GNUNET_MessageHeader *msg; | 141 | struct GNUNET_MessageHeader *msg; |
141 | struct GNUNET_MQ_Envelope *env; | 142 | struct GNUNET_MQ_Envelope *env; |
142 | 143 | ||
143 | h->reconnect_task = NULL; | 144 | h->reconnect_task = NULL; |
144 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 145 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
145 | "Connecting to network size estimation service.\n"); | 146 | "Connecting to network size estimation service.\n"); |
146 | GNUNET_assert(NULL == h->mq); | 147 | GNUNET_assert (NULL == h->mq); |
147 | h->mq = GNUNET_CLIENT_connect(h->cfg, "nse", handlers, &mq_error_handler, h); | 148 | h->mq = GNUNET_CLIENT_connect (h->cfg, "nse", handlers, &mq_error_handler, h); |
148 | if (NULL == h->mq) | 149 | if (NULL == h->mq) |
149 | return; | 150 | return; |
150 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_NSE_START); | 151 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NSE_START); |
151 | GNUNET_MQ_send(h->mq, env); | 152 | GNUNET_MQ_send (h->mq, env); |
152 | } | 153 | } |
153 | 154 | ||
154 | 155 | ||
@@ -161,24 +162,24 @@ reconnect(void *cls) | |||
161 | * @return handle to use | 162 | * @return handle to use |
162 | */ | 163 | */ |
163 | struct GNUNET_NSE_Handle * | 164 | struct GNUNET_NSE_Handle * |
164 | GNUNET_NSE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, | 165 | GNUNET_NSE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
165 | GNUNET_NSE_Callback func, | 166 | GNUNET_NSE_Callback func, |
166 | void *func_cls) | 167 | void *func_cls) |
167 | { | 168 | { |
168 | struct GNUNET_NSE_Handle *h; | 169 | struct GNUNET_NSE_Handle *h; |
169 | 170 | ||
170 | GNUNET_assert(NULL != func); | 171 | GNUNET_assert (NULL != func); |
171 | h = GNUNET_new(struct GNUNET_NSE_Handle); | 172 | h = GNUNET_new (struct GNUNET_NSE_Handle); |
172 | h->cfg = cfg; | 173 | h->cfg = cfg; |
173 | h->recv_cb = func; | 174 | h->recv_cb = func; |
174 | h->recv_cb_cls = func_cls; | 175 | h->recv_cb_cls = func_cls; |
175 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 176 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
176 | reconnect(h); | 177 | reconnect (h); |
177 | if (NULL == h->mq) | 178 | if (NULL == h->mq) |
178 | { | 179 | { |
179 | GNUNET_free(h); | 180 | GNUNET_free (h); |
180 | return NULL; | 181 | return NULL; |
181 | } | 182 | } |
182 | return h; | 183 | return h; |
183 | } | 184 | } |
184 | 185 | ||
@@ -189,19 +190,19 @@ GNUNET_NSE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
189 | * @param h handle to destroy | 190 | * @param h handle to destroy |
190 | */ | 191 | */ |
191 | void | 192 | void |
192 | GNUNET_NSE_disconnect(struct GNUNET_NSE_Handle *h) | 193 | GNUNET_NSE_disconnect (struct GNUNET_NSE_Handle *h) |
193 | { | 194 | { |
194 | if (NULL != h->reconnect_task) | 195 | if (NULL != h->reconnect_task) |
195 | { | 196 | { |
196 | GNUNET_SCHEDULER_cancel(h->reconnect_task); | 197 | GNUNET_SCHEDULER_cancel (h->reconnect_task); |
197 | h->reconnect_task = NULL; | 198 | h->reconnect_task = NULL; |
198 | } | 199 | } |
199 | if (NULL != h->mq) | 200 | if (NULL != h->mq) |
200 | { | 201 | { |
201 | GNUNET_MQ_destroy(h->mq); | 202 | GNUNET_MQ_destroy (h->mq); |
202 | h->mq = NULL; | 203 | h->mq = NULL; |
203 | } | 204 | } |
204 | GNUNET_free(h); | 205 | GNUNET_free (h); |
205 | } | 206 | } |
206 | 207 | ||
207 | /* end of nse_api.c */ | 208 | /* end of nse_api.c */ |