aboutsummaryrefslogtreecommitdiff
path: root/src/dv/plugin_transport_dv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dv/plugin_transport_dv.c')
-rw-r--r--src/dv/plugin_transport_dv.c157
1 files changed, 81 insertions, 76 deletions
diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c
index 697ca0c4c..2803e347e 100644
--- a/src/dv/plugin_transport_dv.c
+++ b/src/dv/plugin_transport_dv.c
@@ -144,38 +144,40 @@ struct Plugin
144/** 144/**
145 * Handler for messages received from the DV service. 145 * Handler for messages received from the DV service.
146 */ 146 */
147void handle_dv_message_received (void *cls, 147void
148 struct GNUNET_PeerIdentity *sender, 148handle_dv_message_received (void *cls,
149 char *msg, 149 struct GNUNET_PeerIdentity *sender,
150 size_t msg_len, 150 char *msg,
151 uint32_t distance, 151 size_t msg_len,
152 char *sender_address, 152 uint32_t distance,
153 size_t sender_address_len) 153 char *sender_address, size_t sender_address_len)
154{ 154{
155 struct Plugin *plugin = cls; 155 struct Plugin *plugin = cls;
156
156#if DEBUG_DV_MESSAGES 157#if DEBUG_DV_MESSAGES
157 char *my_id; 158 char *my_id;
158 my_id = GNUNET_strdup(GNUNET_i2s(plugin->env->my_identity)); 159
160 my_id = GNUNET_strdup (GNUNET_i2s (plugin->env->my_identity));
159 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 161 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
160 "plugin_transport_dv", 162 "plugin_transport_dv",
161 _("%s Received message from %s of type %d, distance %u!\n"), 163 _("%s Received message from %s of type %d, distance %u!\n"),
162 my_id, GNUNET_i2s(sender), ntohs(((struct GNUNET_MessageHeader *)msg)->type), distance); 164 my_id, GNUNET_i2s (sender),
163 GNUNET_free_non_null(my_id); 165 ntohs (((struct GNUNET_MessageHeader *) msg)->type),
166 distance);
167 GNUNET_free_non_null (my_id);
164#endif 168#endif
165 struct GNUNET_TRANSPORT_ATS_Information ats[2]; 169 struct GNUNET_TRANSPORT_ATS_Information ats[2];
170
166 ats[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); 171 ats[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
167 ats[0].value = htonl (distance); 172 ats[0].value = htonl (distance);
168 ats[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 173 ats[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
169 ats[1].value = htonl (0); 174 ats[1].value = htonl (0);
170 175
171 plugin->env->receive(plugin->env->cls, 176 plugin->env->receive (plugin->env->cls,
172 sender, 177 sender,
173 (struct GNUNET_MessageHeader *)msg, 178 (struct GNUNET_MessageHeader *) msg,
174 (const struct GNUNET_TRANSPORT_ATS_Information *) &ats, 179 (const struct GNUNET_TRANSPORT_ATS_Information *) &ats,
175 2, 180 2, NULL, sender_address, sender_address_len);
176 NULL,
177 sender_address,
178 sender_address_len);
179 181
180} 182}
181 183
@@ -218,26 +220,20 @@ dv_plugin_send (void *cls,
218 size_t msgbuf_size, 220 size_t msgbuf_size,
219 unsigned int priority, 221 unsigned int priority,
220 struct GNUNET_TIME_Relative timeout, 222 struct GNUNET_TIME_Relative timeout,
221 struct Session *session, 223 struct Session *session,
222 const void *addr, 224 const void *addr,
223 size_t addrlen, 225 size_t addrlen,
224 int force_address, 226 int force_address,
225 GNUNET_TRANSPORT_TransmitContinuation 227 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
226 cont, void *cont_cls)
227{ 228{
228 int ret = 0; 229 int ret = 0;
229 struct Plugin *plugin = cls; 230 struct Plugin *plugin = cls;
230 231
231 ret = GNUNET_DV_send(plugin->dv_handle, 232 ret = GNUNET_DV_send (plugin->dv_handle,
232 target, 233 target,
233 msgbuf, 234 msgbuf,
234 msgbuf_size, 235 msgbuf_size,
235 priority, 236 priority, timeout, addr, addrlen, cont, cont_cls);
236 timeout,
237 addr,
238 addrlen,
239 cont,
240 cont_cls);
241 return ret; 237 return ret;
242} 238}
243 239
@@ -252,8 +248,7 @@ dv_plugin_send (void *cls,
252 * @param target peer from which to disconnect 248 * @param target peer from which to disconnect
253 */ 249 */
254static void 250static void
255dv_plugin_disconnect (void *cls, 251dv_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
256 const struct GNUNET_PeerIdentity *target)
257{ 252{
258 // struct Plugin *plugin = cls; 253 // struct Plugin *plugin = cls;
259 // TODO: Add message type to send to dv service to "disconnect" a peer 254 // TODO: Add message type to send to dv service to "disconnect" a peer
@@ -287,23 +282,28 @@ dv_plugin_address_pretty_printer (void *cls,
287 char *dest_peer; 282 char *dest_peer;
288 char *via_peer; 283 char *via_peer;
289 char *print_string; 284 char *print_string;
290 char *addr_buf = (char *)addr; 285 char *addr_buf = (char *) addr;
291 286
292 if (addrlen != sizeof(struct GNUNET_PeerIdentity) * 2) 287 if (addrlen != sizeof (struct GNUNET_PeerIdentity) * 2)
293 { 288 {
294 asc (asc_cls, NULL); 289 asc (asc_cls, NULL);
295 } 290 }
296 else 291 else
297 { 292 {
298 dest_peer = GNUNET_strdup(GNUNET_i2s((struct GNUNET_PeerIdentity *)addr)); 293 dest_peer =
299 via_peer = GNUNET_strdup(GNUNET_i2s((struct GNUNET_PeerIdentity *)&addr_buf[sizeof(struct GNUNET_PeerIdentity)])); 294 GNUNET_strdup (GNUNET_i2s ((struct GNUNET_PeerIdentity *) addr));
300 GNUNET_asprintf(&print_string, "DV Peer `%s' via peer`%s'", dest_peer, via_peer); 295 via_peer =
301 asc (asc_cls, print_string); 296 GNUNET_strdup (GNUNET_i2s
302 asc (asc_cls, NULL); 297 ((struct GNUNET_PeerIdentity *)
303 GNUNET_free(via_peer); 298 &addr_buf[sizeof (struct GNUNET_PeerIdentity)]));
304 GNUNET_free(dest_peer); 299 GNUNET_asprintf (&print_string, "DV Peer `%s' via peer`%s'", dest_peer,
305 GNUNET_free(print_string); 300 via_peer);
306 } 301 asc (asc_cls, print_string);
302 asc (asc_cls, NULL);
303 GNUNET_free (via_peer);
304 GNUNET_free (dest_peer);
305 GNUNET_free (print_string);
306 }
307} 307}
308 308
309/** 309/**
@@ -315,9 +315,8 @@ dv_plugin_address_pretty_printer (void *cls,
315 * 315 *
316 * @return string representing the DV address 316 * @return string representing the DV address
317 */ 317 */
318static const char *address_to_string (void *cls, 318static const char *
319 const void *addr, 319address_to_string (void *cls, const void *addr, size_t addrlen)
320 size_t addrlen)
321{ 320{
322 static char return_buffer[2 * 4 + 2]; // Two four character peer identity prefixes a ':' and '\0' 321 static char return_buffer[2 * 4 + 2]; // Two four character peer identity prefixes a ':' and '\0'
323 322
@@ -325,23 +324,22 @@ static const char *address_to_string (void *cls,
325 struct GNUNET_CRYPTO_HashAsciiEncoded via_hash; 324 struct GNUNET_CRYPTO_HashAsciiEncoded via_hash;
326 struct GNUNET_PeerIdentity *peer; 325 struct GNUNET_PeerIdentity *peer;
327 struct GNUNET_PeerIdentity *via; 326 struct GNUNET_PeerIdentity *via;
328 char *addr_buf = (char *)addr; 327 char *addr_buf = (char *) addr;
329 328
330 if (addrlen == (2 * sizeof(struct GNUNET_PeerIdentity))) 329 if (addrlen == (2 * sizeof (struct GNUNET_PeerIdentity)))
331 { 330 {
332 peer = (struct GNUNET_PeerIdentity *)addr_buf; 331 peer = (struct GNUNET_PeerIdentity *) addr_buf;
333 via = (struct GNUNET_PeerIdentity *)&addr_buf[sizeof(struct GNUNET_PeerIdentity)]; 332 via =
334 333 (struct GNUNET_PeerIdentity *)
335 GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &peer_hash); 334 &addr_buf[sizeof (struct GNUNET_PeerIdentity)];
336 peer_hash.encoding[4] = '\0'; 335
337 GNUNET_CRYPTO_hash_to_enc (&via->hashPubKey, &via_hash); 336 GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &peer_hash);
338 via_hash.encoding[4] = '\0'; 337 peer_hash.encoding[4] = '\0';
339 GNUNET_snprintf (return_buffer, 338 GNUNET_CRYPTO_hash_to_enc (&via->hashPubKey, &via_hash);
340 sizeof (return_buffer), 339 via_hash.encoding[4] = '\0';
341 "%s:%s", 340 GNUNET_snprintf (return_buffer,
342 &peer_hash, 341 sizeof (return_buffer), "%s:%s", &peer_hash, &via_hash);
343 &via_hash); 342 }
344 }
345 else 343 else
346 return NULL; 344 return NULL;
347 345
@@ -365,17 +363,23 @@ static const char *address_to_string (void *cls,
365 * 363 *
366 */ 364 */
367static int 365static int
368dv_plugin_check_address (void *cls, 366dv_plugin_check_address (void *cls, const void *addr, size_t addrlen)
369 const void *addr, size_t addrlen)
370{ 367{
371 struct Plugin *plugin = cls; 368 struct Plugin *plugin = cls;
369
372 /* Verify that the first peer of this address matches our peer id! */ 370 /* Verify that the first peer of this address matches our peer id! */
373 if ((addrlen != (2 * sizeof(struct GNUNET_PeerIdentity))) || (0 != memcmp(addr, plugin->env->my_identity, sizeof(struct GNUNET_PeerIdentity)))) 371 if ((addrlen != (2 * sizeof (struct GNUNET_PeerIdentity))) ||
372 (0 !=
373 memcmp (addr, plugin->env->my_identity,
374 sizeof (struct GNUNET_PeerIdentity))))
374 { 375 {
375 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Address not correct size or identity doesn't match ours!\n", GNUNET_i2s(plugin->env->my_identity)); 376 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
376 if (addrlen == (2 * sizeof(struct GNUNET_PeerIdentity))) 377 "%s: Address not correct size or identity doesn't match ours!\n",
378 GNUNET_i2s (plugin->env->my_identity));
379 if (addrlen == (2 * sizeof (struct GNUNET_PeerIdentity)))
377 { 380 {
378 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peer in address is %s\n", GNUNET_i2s(addr)); 381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer in address is %s\n",
382 GNUNET_i2s (addr));
379 } 383 }
380 return GNUNET_SYSERR; 384 return GNUNET_SYSERR;
381 } 385 }
@@ -396,11 +400,12 @@ libgnunet_plugin_transport_dv_init (void *cls)
396 plugin = GNUNET_malloc (sizeof (struct Plugin)); 400 plugin = GNUNET_malloc (sizeof (struct Plugin));
397 plugin->env = env; 401 plugin->env = env;
398 402
399 plugin->dv_handle = GNUNET_DV_connect(env->cfg, &handle_dv_message_received, plugin); 403 plugin->dv_handle =
404 GNUNET_DV_connect (env->cfg, &handle_dv_message_received, plugin);
400 405
401 if (plugin->dv_handle == NULL) 406 if (plugin->dv_handle == NULL)
402 { 407 {
403 GNUNET_free(plugin); 408 GNUNET_free (plugin);
404 return NULL; 409 return NULL;
405 } 410 }
406 411
@@ -425,7 +430,7 @@ libgnunet_plugin_transport_dv_done (void *cls)
425 struct Plugin *plugin = api->cls; 430 struct Plugin *plugin = api->cls;
426 431
427 if (plugin->dv_handle != NULL) 432 if (plugin->dv_handle != NULL)
428 GNUNET_DV_disconnect(plugin->dv_handle); 433 GNUNET_DV_disconnect (plugin->dv_handle);
429 434
430 GNUNET_free (plugin); 435 GNUNET_free (plugin);
431 GNUNET_free (api); 436 GNUNET_free (api);