diff options
Diffstat (limited to 'src/cadet/cadet_api_get_channel.c')
-rw-r--r-- | src/cadet/cadet_api_get_channel.c | 121 |
1 files changed, 61 insertions, 60 deletions
diff --git a/src/cadet/cadet_api_get_channel.c b/src/cadet/cadet_api_get_channel.c index 5479f4238..6d86e8e81 100644 --- a/src/cadet/cadet_api_get_channel.c +++ b/src/cadet/cadet_api_get_channel.c | |||
@@ -34,7 +34,8 @@ | |||
34 | /** | 34 | /** |
35 | * Operation handle. | 35 | * Operation handle. |
36 | */ | 36 | */ |
37 | struct GNUNET_CADET_ChannelMonitor { | 37 | struct GNUNET_CADET_ChannelMonitor |
38 | { | ||
38 | /** | 39 | /** |
39 | * Channel callback. | 40 | * Channel callback. |
40 | */ | 41 | */ |
@@ -81,10 +82,10 @@ struct GNUNET_CADET_ChannelMonitor { | |||
81 | * #GNUNET_SYSERR otherwise | 82 | * #GNUNET_SYSERR otherwise |
82 | */ | 83 | */ |
83 | static int | 84 | static int |
84 | check_channel_info(void *cls, | 85 | check_channel_info (void *cls, |
85 | const struct GNUNET_CADET_ChannelInfoMessage *message) | 86 | const struct GNUNET_CADET_ChannelInfoMessage *message) |
86 | { | 87 | { |
87 | (void)cls; | 88 | (void) cls; |
88 | 89 | ||
89 | return GNUNET_OK; | 90 | return GNUNET_OK; |
90 | } | 91 | } |
@@ -97,17 +98,17 @@ check_channel_info(void *cls, | |||
97 | * @param message Message itself. | 98 | * @param message Message itself. |
98 | */ | 99 | */ |
99 | static void | 100 | static void |
100 | handle_channel_info(void *cls, | 101 | handle_channel_info (void *cls, |
101 | const struct GNUNET_CADET_ChannelInfoMessage *message) | 102 | const struct GNUNET_CADET_ChannelInfoMessage *message) |
102 | { | 103 | { |
103 | struct GNUNET_CADET_ChannelMonitor *cm = cls; | 104 | struct GNUNET_CADET_ChannelMonitor *cm = cls; |
104 | struct GNUNET_CADET_ChannelInternals ci; | 105 | struct GNUNET_CADET_ChannelInternals ci; |
105 | 106 | ||
106 | ci.root = message->root; | 107 | ci.root = message->root; |
107 | ci.dest = message->dest; | 108 | ci.dest = message->dest; |
108 | cm->channel_cb(cm->channel_cb_cls, | 109 | cm->channel_cb (cm->channel_cb_cls, |
109 | &ci); | 110 | &ci); |
110 | GNUNET_CADET_get_channel_cancel(cm); | 111 | GNUNET_CADET_get_channel_cancel (cm); |
111 | } | 112 | } |
112 | 113 | ||
113 | 114 | ||
@@ -118,14 +119,14 @@ handle_channel_info(void *cls, | |||
118 | * @param message Message itself. | 119 | * @param message Message itself. |
119 | */ | 120 | */ |
120 | static void | 121 | static void |
121 | handle_channel_info_end(void *cls, | 122 | handle_channel_info_end (void *cls, |
122 | const struct GNUNET_MessageHeader *message) | 123 | const struct GNUNET_MessageHeader *message) |
123 | { | 124 | { |
124 | struct GNUNET_CADET_ChannelMonitor *cm = cls; | 125 | struct GNUNET_CADET_ChannelMonitor *cm = cls; |
125 | 126 | ||
126 | cm->channel_cb(cm->channel_cb_cls, | 127 | cm->channel_cb (cm->channel_cb_cls, |
127 | NULL); | 128 | NULL); |
128 | GNUNET_CADET_get_channel_cancel(cm); | 129 | GNUNET_CADET_get_channel_cancel (cm); |
129 | } | 130 | } |
130 | 131 | ||
131 | 132 | ||
@@ -135,7 +136,7 @@ handle_channel_info_end(void *cls, | |||
135 | * @param cls a `struct GNUNET_CADET_ChannelMonitor` operation | 136 | * @param cls a `struct GNUNET_CADET_ChannelMonitor` operation |
136 | */ | 137 | */ |
137 | static void | 138 | static void |
138 | reconnect(void *cls); | 139 | reconnect (void *cls); |
139 | 140 | ||
140 | 141 | ||
141 | /** | 142 | /** |
@@ -145,18 +146,18 @@ reconnect(void *cls); | |||
145 | * @param error error code from MQ | 146 | * @param error error code from MQ |
146 | */ | 147 | */ |
147 | static void | 148 | static void |
148 | error_handler(void *cls, | 149 | error_handler (void *cls, |
149 | enum GNUNET_MQ_Error error) | 150 | enum GNUNET_MQ_Error error) |
150 | { | 151 | { |
151 | struct GNUNET_CADET_ChannelMonitor *cm = cls; | 152 | struct GNUNET_CADET_ChannelMonitor *cm = cls; |
152 | 153 | ||
153 | GNUNET_MQ_destroy(cm->mq); | 154 | GNUNET_MQ_destroy (cm->mq); |
154 | cm->mq = NULL; | 155 | cm->mq = NULL; |
155 | cm->backoff = GNUNET_TIME_randomized_backoff(cm->backoff, | 156 | cm->backoff = GNUNET_TIME_randomized_backoff (cm->backoff, |
156 | GNUNET_TIME_UNIT_MINUTES); | 157 | GNUNET_TIME_UNIT_MINUTES); |
157 | cm->reconnect_task = GNUNET_SCHEDULER_add_delayed(cm->backoff, | 158 | cm->reconnect_task = GNUNET_SCHEDULER_add_delayed (cm->backoff, |
158 | &reconnect, | 159 | &reconnect, |
159 | cm); | 160 | cm); |
160 | } | 161 | } |
161 | 162 | ||
162 | 163 | ||
@@ -166,36 +167,36 @@ error_handler(void *cls, | |||
166 | * @param cls a `struct GNUNET_CADET_ChannelMonitor` operation | 167 | * @param cls a `struct GNUNET_CADET_ChannelMonitor` operation |
167 | */ | 168 | */ |
168 | static void | 169 | static void |
169 | reconnect(void *cls) | 170 | reconnect (void *cls) |
170 | { | 171 | { |
171 | struct GNUNET_CADET_ChannelMonitor *cm = cls; | 172 | struct GNUNET_CADET_ChannelMonitor *cm = cls; |
172 | struct GNUNET_MQ_MessageHandler handlers[] = { | 173 | struct GNUNET_MQ_MessageHandler handlers[] = { |
173 | GNUNET_MQ_hd_fixed_size(channel_info_end, | 174 | GNUNET_MQ_hd_fixed_size (channel_info_end, |
174 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL_END, | 175 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL_END, |
175 | struct GNUNET_MessageHeader, | 176 | struct GNUNET_MessageHeader, |
176 | cm), | 177 | cm), |
177 | GNUNET_MQ_hd_var_size(channel_info, | 178 | GNUNET_MQ_hd_var_size (channel_info, |
178 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL, | 179 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL, |
179 | struct GNUNET_CADET_ChannelInfoMessage, | 180 | struct GNUNET_CADET_ChannelInfoMessage, |
180 | cm), | 181 | cm), |
181 | GNUNET_MQ_handler_end() | 182 | GNUNET_MQ_handler_end () |
182 | }; | 183 | }; |
183 | struct GNUNET_CADET_RequestChannelInfoMessage *msg; | 184 | struct GNUNET_CADET_RequestChannelInfoMessage *msg; |
184 | struct GNUNET_MQ_Envelope *env; | 185 | struct GNUNET_MQ_Envelope *env; |
185 | 186 | ||
186 | cm->reconnect_task = NULL; | 187 | cm->reconnect_task = NULL; |
187 | cm->mq = GNUNET_CLIENT_connect(cm->cfg, | 188 | cm->mq = GNUNET_CLIENT_connect (cm->cfg, |
188 | "cadet", | 189 | "cadet", |
189 | handlers, | 190 | handlers, |
190 | &error_handler, | 191 | &error_handler, |
191 | cm); | 192 | cm); |
192 | if (NULL == cm->mq) | 193 | if (NULL == cm->mq) |
193 | return; | 194 | return; |
194 | env = GNUNET_MQ_msg(msg, | 195 | env = GNUNET_MQ_msg (msg, |
195 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_CHANNEL); | 196 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_CHANNEL); |
196 | msg->target = cm->peer; | 197 | msg->target = cm->peer; |
197 | GNUNET_MQ_send(cm->mq, | 198 | GNUNET_MQ_send (cm->mq, |
198 | env); | 199 | env); |
199 | } | 200 | } |
200 | 201 | ||
201 | 202 | ||
@@ -209,29 +210,29 @@ reconnect(void *cls) | |||
209 | * @return NULL on error | 210 | * @return NULL on error |
210 | */ | 211 | */ |
211 | struct GNUNET_CADET_ChannelMonitor * | 212 | struct GNUNET_CADET_ChannelMonitor * |
212 | GNUNET_CADET_get_channel(const struct GNUNET_CONFIGURATION_Handle *cfg, | 213 | GNUNET_CADET_get_channel (const struct GNUNET_CONFIGURATION_Handle *cfg, |
213 | struct GNUNET_PeerIdentity *peer, | 214 | struct GNUNET_PeerIdentity *peer, |
214 | GNUNET_CADET_ChannelCB callback, | 215 | GNUNET_CADET_ChannelCB callback, |
215 | void *callback_cls) | 216 | void *callback_cls) |
216 | { | 217 | { |
217 | struct GNUNET_CADET_ChannelMonitor *cm; | 218 | struct GNUNET_CADET_ChannelMonitor *cm; |
218 | 219 | ||
219 | if (NULL == callback) | 220 | if (NULL == callback) |
220 | { | 221 | { |
221 | GNUNET_break(0); | 222 | GNUNET_break (0); |
222 | return NULL; | 223 | return NULL; |
223 | } | 224 | } |
224 | cm = GNUNET_new(struct GNUNET_CADET_ChannelMonitor); | 225 | cm = GNUNET_new (struct GNUNET_CADET_ChannelMonitor); |
225 | cm->channel_cb = callback; | 226 | cm->channel_cb = callback; |
226 | cm->channel_cb_cls = callback_cls; | 227 | cm->channel_cb_cls = callback_cls; |
227 | cm->cfg = cfg; | 228 | cm->cfg = cfg; |
228 | cm->peer = *peer; | 229 | cm->peer = *peer; |
229 | reconnect(cm); | 230 | reconnect (cm); |
230 | if (NULL == cm->mq) | 231 | if (NULL == cm->mq) |
231 | { | 232 | { |
232 | GNUNET_free(cm); | 233 | GNUNET_free (cm); |
233 | return NULL; | 234 | return NULL; |
234 | } | 235 | } |
235 | return cm; | 236 | return cm; |
236 | } | 237 | } |
237 | 238 | ||
@@ -243,15 +244,15 @@ GNUNET_CADET_get_channel(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
243 | * @return Closure that was given to #GNUNET_CADET_get_channel(). | 244 | * @return Closure that was given to #GNUNET_CADET_get_channel(). |
244 | */ | 245 | */ |
245 | void * | 246 | void * |
246 | GNUNET_CADET_get_channel_cancel(struct GNUNET_CADET_ChannelMonitor *cm) | 247 | GNUNET_CADET_get_channel_cancel (struct GNUNET_CADET_ChannelMonitor *cm) |
247 | { | 248 | { |
248 | void *ret = cm->channel_cb_cls; | 249 | void *ret = cm->channel_cb_cls; |
249 | 250 | ||
250 | if (NULL != cm->mq) | 251 | if (NULL != cm->mq) |
251 | GNUNET_MQ_destroy(cm->mq); | 252 | GNUNET_MQ_destroy (cm->mq); |
252 | if (NULL != cm->reconnect_task) | 253 | if (NULL != cm->reconnect_task) |
253 | GNUNET_SCHEDULER_cancel(cm->reconnect_task); | 254 | GNUNET_SCHEDULER_cancel (cm->reconnect_task); |
254 | GNUNET_free(cm); | 255 | GNUNET_free (cm); |
255 | return ret; | 256 | return ret; |
256 | } | 257 | } |
257 | 258 | ||