diff options
Diffstat (limited to 'src/nse/nse_api.c')
-rw-r--r-- | src/nse/nse_api.c | 95 |
1 files changed, 47 insertions, 48 deletions
diff --git a/src/nse/nse_api.c b/src/nse/nse_api.c index 259be75ed..93716eb5f 100644 --- a/src/nse/nse_api.c +++ b/src/nse/nse_api.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file nse/nse_api.c | 22 | * @file nse/nse_api.c |
@@ -32,13 +32,12 @@ | |||
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 | { | ||
42 | /** | 41 | /** |
43 | * Configuration to use. | 42 | * Configuration to use. |
44 | */ | 43 | */ |
@@ -77,7 +76,7 @@ struct GNUNET_NSE_Handle | |||
77 | * @param cls closure with the `struct GNUNET_NSE_Handle *` | 76 | * @param cls closure with the `struct GNUNET_NSE_Handle *` |
78 | */ | 77 | */ |
79 | static void | 78 | static void |
80 | reconnect (void *cls); | 79 | reconnect(void *cls); |
81 | 80 | ||
82 | 81 | ||
83 | /** | 82 | /** |
@@ -90,16 +89,16 @@ reconnect (void *cls); | |||
90 | * @param error error code | 89 | * @param error error code |
91 | */ | 90 | */ |
92 | static void | 91 | static void |
93 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | 92 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) |
94 | { | 93 | { |
95 | struct GNUNET_NSE_Handle *h = cls; | 94 | struct GNUNET_NSE_Handle *h = cls; |
96 | 95 | ||
97 | (void) error; | 96 | (void)error; |
98 | GNUNET_MQ_destroy (h->mq); | 97 | GNUNET_MQ_destroy(h->mq); |
99 | h->mq = NULL; | 98 | h->mq = NULL; |
100 | h->reconnect_task = | 99 | h->reconnect_task = |
101 | GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); | 100 | GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect, h); |
102 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); | 101 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay); |
103 | } | 102 | } |
104 | 103 | ||
105 | 104 | ||
@@ -111,15 +110,15 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | |||
111 | * @param client_msg message received | 110 | * @param client_msg message received |
112 | */ | 111 | */ |
113 | static void | 112 | static void |
114 | handle_estimate (void *cls, const struct GNUNET_NSE_ClientMessage *client_msg) | 113 | handle_estimate(void *cls, const struct GNUNET_NSE_ClientMessage *client_msg) |
115 | { | 114 | { |
116 | struct GNUNET_NSE_Handle *h = cls; | 115 | struct GNUNET_NSE_Handle *h = cls; |
117 | 116 | ||
118 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 117 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
119 | h->recv_cb (h->recv_cb_cls, | 118 | h->recv_cb(h->recv_cb_cls, |
120 | GNUNET_TIME_absolute_ntoh (client_msg->timestamp), | 119 | GNUNET_TIME_absolute_ntoh(client_msg->timestamp), |
121 | GNUNET_ntoh_double (client_msg->size_estimate), | 120 | GNUNET_ntoh_double(client_msg->size_estimate), |
122 | GNUNET_ntoh_double (client_msg->std_deviation)); | 121 | GNUNET_ntoh_double(client_msg->std_deviation)); |
123 | } | 122 | } |
124 | 123 | ||
125 | 124 | ||
@@ -129,27 +128,27 @@ handle_estimate (void *cls, const struct GNUNET_NSE_ClientMessage *client_msg) | |||
129 | * @param cls the `struct GNUNET_NSE_Handle *` | 128 | * @param cls the `struct GNUNET_NSE_Handle *` |
130 | */ | 129 | */ |
131 | static void | 130 | static void |
132 | reconnect (void *cls) | 131 | reconnect(void *cls) |
133 | { | 132 | { |
134 | struct GNUNET_NSE_Handle *h = cls; | 133 | struct GNUNET_NSE_Handle *h = cls; |
135 | struct GNUNET_MQ_MessageHandler handlers[] = | 134 | struct GNUNET_MQ_MessageHandler handlers[] = |
136 | {GNUNET_MQ_hd_fixed_size (estimate, | 135 | { GNUNET_MQ_hd_fixed_size(estimate, |
137 | GNUNET_MESSAGE_TYPE_NSE_ESTIMATE, | 136 | GNUNET_MESSAGE_TYPE_NSE_ESTIMATE, |
138 | struct GNUNET_NSE_ClientMessage, | 137 | struct GNUNET_NSE_ClientMessage, |
139 | h), | 138 | h), |
140 | GNUNET_MQ_handler_end ()}; | 139 | GNUNET_MQ_handler_end() }; |
141 | struct GNUNET_MessageHeader *msg; | 140 | struct GNUNET_MessageHeader *msg; |
142 | struct GNUNET_MQ_Envelope *env; | 141 | struct GNUNET_MQ_Envelope *env; |
143 | 142 | ||
144 | h->reconnect_task = NULL; | 143 | h->reconnect_task = NULL; |
145 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 144 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
146 | "Connecting to network size estimation service.\n"); | 145 | "Connecting to network size estimation service.\n"); |
147 | GNUNET_assert (NULL == h->mq); | 146 | GNUNET_assert(NULL == h->mq); |
148 | h->mq = GNUNET_CLIENT_connect (h->cfg, "nse", handlers, &mq_error_handler, h); | 147 | h->mq = GNUNET_CLIENT_connect(h->cfg, "nse", handlers, &mq_error_handler, h); |
149 | if (NULL == h->mq) | 148 | if (NULL == h->mq) |
150 | return; | 149 | return; |
151 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NSE_START); | 150 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_NSE_START); |
152 | GNUNET_MQ_send (h->mq, env); | 151 | GNUNET_MQ_send(h->mq, env); |
153 | } | 152 | } |
154 | 153 | ||
155 | 154 | ||
@@ -162,24 +161,24 @@ reconnect (void *cls) | |||
162 | * @return handle to use | 161 | * @return handle to use |
163 | */ | 162 | */ |
164 | struct GNUNET_NSE_Handle * | 163 | struct GNUNET_NSE_Handle * |
165 | GNUNET_NSE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 164 | GNUNET_NSE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, |
166 | GNUNET_NSE_Callback func, | 165 | GNUNET_NSE_Callback func, |
167 | void *func_cls) | 166 | void *func_cls) |
168 | { | 167 | { |
169 | struct GNUNET_NSE_Handle *h; | 168 | struct GNUNET_NSE_Handle *h; |
170 | 169 | ||
171 | GNUNET_assert (NULL != func); | 170 | GNUNET_assert(NULL != func); |
172 | h = GNUNET_new (struct GNUNET_NSE_Handle); | 171 | h = GNUNET_new(struct GNUNET_NSE_Handle); |
173 | h->cfg = cfg; | 172 | h->cfg = cfg; |
174 | h->recv_cb = func; | 173 | h->recv_cb = func; |
175 | h->recv_cb_cls = func_cls; | 174 | h->recv_cb_cls = func_cls; |
176 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 175 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
177 | reconnect (h); | 176 | reconnect(h); |
178 | if (NULL == h->mq) | 177 | if (NULL == h->mq) |
179 | { | 178 | { |
180 | GNUNET_free (h); | 179 | GNUNET_free(h); |
181 | return NULL; | 180 | return NULL; |
182 | } | 181 | } |
183 | return h; | 182 | return h; |
184 | } | 183 | } |
185 | 184 | ||
@@ -190,19 +189,19 @@ GNUNET_NSE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
190 | * @param h handle to destroy | 189 | * @param h handle to destroy |
191 | */ | 190 | */ |
192 | void | 191 | void |
193 | GNUNET_NSE_disconnect (struct GNUNET_NSE_Handle *h) | 192 | GNUNET_NSE_disconnect(struct GNUNET_NSE_Handle *h) |
194 | { | 193 | { |
195 | if (NULL != h->reconnect_task) | 194 | if (NULL != h->reconnect_task) |
196 | { | 195 | { |
197 | GNUNET_SCHEDULER_cancel (h->reconnect_task); | 196 | GNUNET_SCHEDULER_cancel(h->reconnect_task); |
198 | h->reconnect_task = NULL; | 197 | h->reconnect_task = NULL; |
199 | } | 198 | } |
200 | if (NULL != h->mq) | 199 | if (NULL != h->mq) |
201 | { | 200 | { |
202 | GNUNET_MQ_destroy (h->mq); | 201 | GNUNET_MQ_destroy(h->mq); |
203 | h->mq = NULL; | 202 | h->mq = NULL; |
204 | } | 203 | } |
205 | GNUNET_free (h); | 204 | GNUNET_free(h); |
206 | } | 205 | } |
207 | 206 | ||
208 | /* end of nse_api.c */ | 207 | /* end of nse_api.c */ |