diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-04-12 15:20:56 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-04-12 15:20:56 +0000 |
commit | 2394bfd8caab98c8aebf59aaf19b4b699bcff541 (patch) | |
tree | 395232d86318f7e8c103843786cb3978b8faaa03 | |
parent | de58a619e8330b14a9a712d59acb1fbe4124eea4 (diff) | |
download | gnunet-2394bfd8caab98c8aebf59aaf19b4b699bcff541.tar.gz gnunet-2394bfd8caab98c8aebf59aaf19b4b699bcff541.zip |
-rw-r--r-- | src/hostlist/hostlist-server.c | 82 |
1 files changed, 57 insertions, 25 deletions
diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c index 2d0210cab..014a20b6b 100644 --- a/src/hostlist/hostlist-server.c +++ b/src/hostlist/hostlist-server.c | |||
@@ -356,13 +356,41 @@ access_handler_callback (void *cls, | |||
356 | return MHD_queue_response (connection, MHD_HTTP_OK, response); | 356 | return MHD_queue_response (connection, MHD_HTTP_OK, response); |
357 | } | 357 | } |
358 | 358 | ||
359 | #if 0 | 359 | struct GNUNET_HOSTLIST_ADV_Message adv_message; |
360 | char hostlist_uri[1024]; | ||
361 | |||
360 | static size_t | 362 | static size_t |
361 | adv_transmit_ready ( void *cls, size_t size, void *buf) | 363 | adv_transmit_ready ( void *cls, size_t size, void *buf) |
362 | { | 364 | { |
365 | int transmission_size; | ||
366 | |||
367 | transmission_size = sizeof (struct GNUNET_HOSTLIST_ADV_Message) + strlen(hostlist_uri) +1; | ||
368 | adv_message.header.size = htons (transmission_size); | ||
369 | |||
370 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
371 | "Assembled message size %u\n", transmission_size); | ||
372 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
373 | "Size Messageheader %u\n", sizeof (struct GNUNET_HOSTLIST_ADV_Message)); | ||
374 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
375 | "Size URI %u\n", strlen(hostlist_uri)); | ||
376 | if (buf == NULL) | ||
377 | { | ||
378 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Transmission failed, buffer invalid!\n"); | ||
379 | return 0; | ||
380 | } | ||
363 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 381 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
364 | _("Ready to transmit %u bytes of adv\n"), size); | 382 | _("Buffer valid of size %u\n"), size); |
383 | |||
384 | if (size >= transmission_size) | ||
385 | { | ||
386 | memcpy(buf, &adv_message, transmission_size); | ||
387 | |||
388 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sent advertisement message: Copied %d bytes into buffer!\n\n\n", transmission_size); | ||
389 | |||
390 | return transmission_size; | ||
391 | } | ||
365 | return size; | 392 | return size; |
393 | |||
366 | } | 394 | } |
367 | 395 | ||
368 | static int | 396 | static int |
@@ -379,22 +407,26 @@ adv_transmit_message ( const struct GNUNET_PeerIdentity * peer, int size ) | |||
379 | struct GNUNET_TIME_Relative timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, GNUNET_ADV_TIMEOUT); | 407 | struct GNUNET_TIME_Relative timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, GNUNET_ADV_TIMEOUT); |
380 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 408 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
381 | _("Asked to transmit %u bytes of adv\n"), size); | 409 | _("Asked to transmit %u bytes of adv\n"), size); |
382 | GNUNET_CORE_notify_transmit_ready (core, | 410 | struct GNUNET_CORE_TransmitHandle * th; |
411 | th = GNUNET_CORE_notify_transmit_ready (core, | ||
383 | 0, | 412 | 0, |
384 | timeout, | 413 | timeout, |
385 | peer, | 414 | peer, |
386 | size, | 415 | size, |
387 | &adv_transmit_ready, NULL); | 416 | &adv_transmit_ready, NULL); |
417 | if ( NULL == th ) | ||
418 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
419 | _("Advertisement message could not be queued by core\n")); | ||
420 | return GNUNET_NO; | ||
421 | |||
388 | return GNUNET_YES; | 422 | return GNUNET_YES; |
389 | } | 423 | } |
390 | #endif | ||
391 | 424 | ||
392 | /** | 425 | /** |
393 | * Function that assembles our hostlist adv message. | 426 | * Function that assembles our hostlist adv message. |
394 | */ | 427 | */ |
395 | static int | 428 | static int |
396 | adv_create_message ( const struct GNUNET_PeerIdentity * peer, | 429 | adv_create_message ( const struct GNUNET_PeerIdentity * peer ) |
397 | struct GNUNET_HOSTLIST_ADV_Message * adv_msg ) | ||
398 | 430 | ||
399 | { | 431 | { |
400 | int length = 0; | 432 | int length = 0; |
@@ -427,25 +459,22 @@ adv_create_message ( const struct GNUNET_PeerIdentity * peer, | |||
427 | uri = strcat(uri, ":"); | 459 | uri = strcat(uri, ":"); |
428 | uri = strcat(uri, port_s); | 460 | uri = strcat(uri, port_s); |
429 | uri = strcat(uri, "/"); | 461 | uri = strcat(uri, "/"); |
462 | strcpy(hostlist_uri,uri); | ||
430 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Address to obtain hostlist: %s\n", uri); | 463 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Address to obtain hostlist: %s\n", uri); |
431 | 464 | ||
432 | 465 | ||
433 | adv_msg = GNUNET_malloc ( sizeof(struct GNUNET_HOSTLIST_ADV_Message) + size); | 466 | /* adv_msg = GNUNET_malloc ( sizeof(struct GNUNET_HOSTLIST_ADV_Message) + size); |
434 | if (adv_msg==NULL) | 467 | if (adv_msg==NULL) |
435 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 468 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
436 | "Creating message:address null\n",sizeof(struct GNUNET_HOSTLIST_ADV_Message)); | 469 | "Creating message:address null\n",sizeof(struct GNUNET_HOSTLIST_ADV_Message)); |
437 | 470 | ||
438 | if ( NULL == adv_msg) | 471 | if ( NULL == adv_msg) |
439 | { | 472 | { |
440 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 473 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, |
441 | "Could not allocate memory for the message"); | 474 | "Could not allocate memory for the message"); |
442 | return GNUNET_NO; | 475 | return GNUNET_NO; |
443 | } | 476 | } |
444 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 477 | */ |
445 | "size ADV_Message: %u\n",sizeof(struct GNUNET_HOSTLIST_ADV_Message)); | ||
446 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
447 | "size uri: %u\n", (length + 1) * sizeof (char)); | ||
448 | |||
449 | 478 | ||
450 | if ( ( size + sizeof( struct GNUNET_HOSTLIST_ADV_Message )) > GNUNET_SERVER_MAX_MESSAGE_SIZE) | 479 | if ( ( size + sizeof( struct GNUNET_HOSTLIST_ADV_Message )) > GNUNET_SERVER_MAX_MESSAGE_SIZE) |
451 | { | 480 | { |
@@ -454,16 +483,19 @@ adv_create_message ( const struct GNUNET_PeerIdentity * peer, | |||
454 | return GNUNET_NO; | 483 | return GNUNET_NO; |
455 | } | 484 | } |
456 | 485 | ||
457 | adv_msg->header.type = htons (GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT); | 486 | //adv_msg->header.type = htons (GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT); |
458 | adv_msg->header.size = htons (sizeof (struct GNUNET_HOSTLIST_ADV_Message) + size); | 487 | //adv_msg->header.size = htons (sizeof (struct GNUNET_HOSTLIST_ADV_Message) + size); |
459 | memcpy(&adv_msg[1],uri,size); | 488 | // memcpy(&adv_msg[1],uri,size); |
489 | |||
490 | adv_message.header.type = htons (GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT); | ||
460 | 491 | ||
461 | /* Request core to transmit message to peer | 492 | /* Request core to transmit message to peer */ |
462 | adv_transmit_message(peer, size); */ | 493 | size = size + sizeof(struct GNUNET_HOSTLIST_ADV_Message); |
494 | adv_transmit_message(peer, size); | ||
463 | 495 | ||
464 | GNUNET_free ( port_s ); | 496 | GNUNET_free ( port_s ); |
465 | GNUNET_free ( uri ); | 497 | GNUNET_free ( uri ); |
466 | GNUNET_free ( adv_msg ); | 498 | //GNUNET_free ( adv_msg ); |
467 | 499 | ||
468 | return GNUNET_OK; | 500 | return GNUNET_OK; |
469 | } | 501 | } |
@@ -483,12 +515,10 @@ connect_handler (void *cls, | |||
483 | struct GNUNET_TIME_Relative latency, | 515 | struct GNUNET_TIME_Relative latency, |
484 | uint32_t distance) | 516 | uint32_t distance) |
485 | { | 517 | { |
486 | |||
487 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 518 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
488 | "A new peer connected to the server, preparing to send hostlist advertisement\n"); | 519 | "A new peer connected to the server, preparing to send hostlist advertisement\n"); |
489 | /* create a new advertisement message */ | 520 | /* create a new advertisement message */ |
490 | struct GNUNET_HOSTLIST_ADV_Message *adv_msg = NULL; | 521 | if ( (GNUNET_OK != adv_create_message(peer))) |
491 | if ( (GNUNET_OK != adv_create_message(peer, adv_msg))) | ||
492 | { | 522 | { |
493 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 523 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
494 | _(" GNUNET_OK Could not create a hostlist advertisement message, impossible to advertise hostlist\n")); | 524 | _(" GNUNET_OK Could not create a hostlist advertisement message, impossible to advertise hostlist\n")); |
@@ -665,7 +695,9 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
665 | (unsigned short) port); | 695 | (unsigned short) port); |
666 | return GNUNET_SYSERR; | 696 | return GNUNET_SYSERR; |
667 | } | 697 | } |
698 | |||
668 | core=co; | 699 | core=co; |
700 | |||
669 | *server_ch = &connect_handler; | 701 | *server_ch = &connect_handler; |
670 | *server_dh = &disconnect_handler; | 702 | *server_dh = &disconnect_handler; |
671 | 703 | ||