diff options
Diffstat (limited to 'src/transport/transport_api_hello_get.c')
-rw-r--r-- | src/transport/transport_api_hello_get.c | 137 |
1 files changed, 69 insertions, 68 deletions
diff --git a/src/transport/transport_api_hello_get.c b/src/transport/transport_api_hello_get.c index 0f53148af..f8bcc5f07 100644 --- a/src/transport/transport_api_hello_get.c +++ b/src/transport/transport_api_hello_get.c | |||
@@ -36,7 +36,8 @@ | |||
36 | /** | 36 | /** |
37 | * Functions to call with this peer's HELLO. | 37 | * Functions to call with this peer's HELLO. |
38 | */ | 38 | */ |
39 | struct GNUNET_TRANSPORT_HelloGetHandle { | 39 | struct GNUNET_TRANSPORT_HelloGetHandle |
40 | { | ||
40 | /** | 41 | /** |
41 | * Our configuration. | 42 | * Our configuration. |
42 | */ | 43 | */ |
@@ -87,22 +88,22 @@ struct GNUNET_TRANSPORT_HelloGetHandle { | |||
87 | * @return #GNUNET_OK if message is well-formed | 88 | * @return #GNUNET_OK if message is well-formed |
88 | */ | 89 | */ |
89 | static int | 90 | static int |
90 | check_hello(void *cls, | 91 | check_hello (void *cls, |
91 | const struct GNUNET_MessageHeader *msg) | 92 | const struct GNUNET_MessageHeader *msg) |
92 | { | 93 | { |
93 | struct GNUNET_PeerIdentity me; | 94 | struct GNUNET_PeerIdentity me; |
94 | 95 | ||
95 | if (GNUNET_OK != | 96 | if (GNUNET_OK != |
96 | GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)msg, | 97 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg, |
97 | &me)) | 98 | &me)) |
98 | { | 99 | { |
99 | GNUNET_break(0); | 100 | GNUNET_break (0); |
100 | return GNUNET_SYSERR; | 101 | return GNUNET_SYSERR; |
101 | } | 102 | } |
102 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
103 | "Receiving (my own) HELLO message (%u bytes), I am `%s'.\n", | 104 | "Receiving (my own) HELLO message (%u bytes), I am `%s'.\n", |
104 | (unsigned int)ntohs(msg->size), | 105 | (unsigned int) ntohs (msg->size), |
105 | GNUNET_i2s(&me)); | 106 | GNUNET_i2s (&me)); |
106 | return GNUNET_OK; | 107 | return GNUNET_OK; |
107 | } | 108 | } |
108 | 109 | ||
@@ -114,13 +115,13 @@ check_hello(void *cls, | |||
114 | * @param msg message received | 115 | * @param msg message received |
115 | */ | 116 | */ |
116 | static void | 117 | static void |
117 | handle_hello(void *cls, | 118 | handle_hello (void *cls, |
118 | const struct GNUNET_MessageHeader *msg) | 119 | const struct GNUNET_MessageHeader *msg) |
119 | { | 120 | { |
120 | struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls; | 121 | struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls; |
121 | 122 | ||
122 | ghh->rec(ghh->rec_cls, | 123 | ghh->rec (ghh->rec_cls, |
123 | msg); | 124 | msg); |
124 | } | 125 | } |
125 | 126 | ||
126 | 127 | ||
@@ -131,7 +132,7 @@ handle_hello(void *cls, | |||
131 | * @param ghh transport service to reconnect | 132 | * @param ghh transport service to reconnect |
132 | */ | 133 | */ |
133 | static void | 134 | static void |
134 | schedule_reconnect(struct GNUNET_TRANSPORT_HelloGetHandle *ghh); | 135 | schedule_reconnect (struct GNUNET_TRANSPORT_HelloGetHandle *ghh); |
135 | 136 | ||
136 | 137 | ||
137 | /** | 138 | /** |
@@ -144,16 +145,16 @@ schedule_reconnect(struct GNUNET_TRANSPORT_HelloGetHandle *ghh); | |||
144 | * @param error error code | 145 | * @param error error code |
145 | */ | 146 | */ |
146 | static void | 147 | static void |
147 | mq_error_handler(void *cls, | 148 | mq_error_handler (void *cls, |
148 | enum GNUNET_MQ_Error error) | 149 | enum GNUNET_MQ_Error error) |
149 | { | 150 | { |
150 | struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls; | 151 | struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls; |
151 | 152 | ||
152 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 153 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
153 | "Error receiving from transport service, disconnecting temporarily.\n"); | 154 | "Error receiving from transport service, disconnecting temporarily.\n"); |
154 | GNUNET_MQ_destroy(ghh->mq); | 155 | GNUNET_MQ_destroy (ghh->mq); |
155 | ghh->mq = NULL; | 156 | ghh->mq = NULL; |
156 | schedule_reconnect(ghh); | 157 | schedule_reconnect (ghh); |
157 | } | 158 | } |
158 | 159 | ||
159 | 160 | ||
@@ -163,35 +164,35 @@ mq_error_handler(void *cls, | |||
163 | * @param cls the handle to the transport service | 164 | * @param cls the handle to the transport service |
164 | */ | 165 | */ |
165 | static void | 166 | static void |
166 | reconnect(void *cls) | 167 | reconnect (void *cls) |
167 | { | 168 | { |
168 | struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls; | 169 | struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls; |
169 | struct GNUNET_MQ_MessageHandler handlers[] = { | 170 | struct GNUNET_MQ_MessageHandler handlers[] = { |
170 | GNUNET_MQ_hd_var_size(hello, | 171 | GNUNET_MQ_hd_var_size (hello, |
171 | GNUNET_MESSAGE_TYPE_HELLO, | 172 | GNUNET_MESSAGE_TYPE_HELLO, |
172 | struct GNUNET_MessageHeader, | 173 | struct GNUNET_MessageHeader, |
173 | ghh), | 174 | ghh), |
174 | GNUNET_MQ_handler_end() | 175 | GNUNET_MQ_handler_end () |
175 | }; | 176 | }; |
176 | struct GNUNET_MQ_Envelope *env; | 177 | struct GNUNET_MQ_Envelope *env; |
177 | struct StartMessage *s; | 178 | struct StartMessage *s; |
178 | 179 | ||
179 | ghh->reconnect_task = NULL; | 180 | ghh->reconnect_task = NULL; |
180 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
181 | "Connecting to transport service.\n"); | 182 | "Connecting to transport service.\n"); |
182 | GNUNET_assert(NULL == ghh->mq); | 183 | GNUNET_assert (NULL == ghh->mq); |
183 | ghh->mq = GNUNET_CLIENT_connect(ghh->cfg, | 184 | ghh->mq = GNUNET_CLIENT_connect (ghh->cfg, |
184 | "transport", | 185 | "transport", |
185 | handlers, | 186 | handlers, |
186 | &mq_error_handler, | 187 | &mq_error_handler, |
187 | ghh); | 188 | ghh); |
188 | if (NULL == ghh->mq) | 189 | if (NULL == ghh->mq) |
189 | return; | 190 | return; |
190 | env = GNUNET_MQ_msg(s, | 191 | env = GNUNET_MQ_msg (s, |
191 | GNUNET_MESSAGE_TYPE_TRANSPORT_START); | 192 | GNUNET_MESSAGE_TYPE_TRANSPORT_START); |
192 | s->options = htonl(0); | 193 | s->options = htonl (0); |
193 | GNUNET_MQ_send(ghh->mq, | 194 | GNUNET_MQ_send (ghh->mq, |
194 | env); | 195 | env); |
195 | } | 196 | } |
196 | 197 | ||
197 | 198 | ||
@@ -202,13 +203,13 @@ reconnect(void *cls) | |||
202 | * @param ghh transport service to reconnect | 203 | * @param ghh transport service to reconnect |
203 | */ | 204 | */ |
204 | static void | 205 | static void |
205 | schedule_reconnect(struct GNUNET_TRANSPORT_HelloGetHandle *ghh) | 206 | schedule_reconnect (struct GNUNET_TRANSPORT_HelloGetHandle *ghh) |
206 | { | 207 | { |
207 | ghh->reconnect_task = | 208 | ghh->reconnect_task = |
208 | GNUNET_SCHEDULER_add_delayed(ghh->reconnect_delay, | 209 | GNUNET_SCHEDULER_add_delayed (ghh->reconnect_delay, |
209 | &reconnect, | 210 | &reconnect, |
210 | ghh); | 211 | ghh); |
211 | ghh->reconnect_delay = GNUNET_TIME_STD_BACKOFF(ghh->reconnect_delay); | 212 | ghh->reconnect_delay = GNUNET_TIME_STD_BACKOFF (ghh->reconnect_delay); |
212 | } | 213 | } |
213 | 214 | ||
214 | 215 | ||
@@ -226,24 +227,24 @@ schedule_reconnect(struct GNUNET_TRANSPORT_HelloGetHandle *ghh) | |||
226 | * @return handle to cancel the operation | 227 | * @return handle to cancel the operation |
227 | */ | 228 | */ |
228 | struct GNUNET_TRANSPORT_HelloGetHandle * | 229 | struct GNUNET_TRANSPORT_HelloGetHandle * |
229 | GNUNET_TRANSPORT_hello_get(const struct GNUNET_CONFIGURATION_Handle *cfg, | 230 | GNUNET_TRANSPORT_hello_get (const struct GNUNET_CONFIGURATION_Handle *cfg, |
230 | enum GNUNET_TRANSPORT_AddressClass ac, | 231 | enum GNUNET_TRANSPORT_AddressClass ac, |
231 | GNUNET_TRANSPORT_HelloUpdateCallback rec, | 232 | GNUNET_TRANSPORT_HelloUpdateCallback rec, |
232 | void *rec_cls) | 233 | void *rec_cls) |
233 | { | 234 | { |
234 | struct GNUNET_TRANSPORT_HelloGetHandle *ghh; | 235 | struct GNUNET_TRANSPORT_HelloGetHandle *ghh; |
235 | 236 | ||
236 | ghh = GNUNET_new(struct GNUNET_TRANSPORT_HelloGetHandle); | 237 | ghh = GNUNET_new (struct GNUNET_TRANSPORT_HelloGetHandle); |
237 | ghh->rec = rec; | 238 | ghh->rec = rec; |
238 | ghh->rec_cls = rec_cls; | 239 | ghh->rec_cls = rec_cls; |
239 | ghh->cfg = cfg; | 240 | ghh->cfg = cfg; |
240 | ghh->ac = ac; | 241 | ghh->ac = ac; |
241 | reconnect(ghh); | 242 | reconnect (ghh); |
242 | if (NULL == ghh->mq) | 243 | if (NULL == ghh->mq) |
243 | { | 244 | { |
244 | GNUNET_free(ghh); | 245 | GNUNET_free (ghh); |
245 | return NULL; | 246 | return NULL; |
246 | } | 247 | } |
247 | return ghh; | 248 | return ghh; |
248 | } | 249 | } |
249 | 250 | ||
@@ -254,19 +255,19 @@ GNUNET_TRANSPORT_hello_get(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
254 | * @param ghh handle to cancel | 255 | * @param ghh handle to cancel |
255 | */ | 256 | */ |
256 | void | 257 | void |
257 | GNUNET_TRANSPORT_hello_get_cancel(struct GNUNET_TRANSPORT_HelloGetHandle *ghh) | 258 | GNUNET_TRANSPORT_hello_get_cancel (struct GNUNET_TRANSPORT_HelloGetHandle *ghh) |
258 | { | 259 | { |
259 | if (NULL != ghh->reconnect_task) | 260 | if (NULL != ghh->reconnect_task) |
260 | { | 261 | { |
261 | GNUNET_SCHEDULER_cancel(ghh->reconnect_task); | 262 | GNUNET_SCHEDULER_cancel (ghh->reconnect_task); |
262 | ghh->reconnect_task = NULL; | 263 | ghh->reconnect_task = NULL; |
263 | } | 264 | } |
264 | if (NULL != ghh->mq) | 265 | if (NULL != ghh->mq) |
265 | { | 266 | { |
266 | GNUNET_MQ_destroy(ghh->mq); | 267 | GNUNET_MQ_destroy (ghh->mq); |
267 | ghh->mq = NULL; | 268 | ghh->mq = NULL; |
268 | } | 269 | } |
269 | GNUNET_free(ghh); | 270 | GNUNET_free (ghh); |
270 | } | 271 | } |
271 | 272 | ||
272 | 273 | ||