aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorPhilipp Tölke <toelke@in.tum.de>2011-06-15 07:15:39 +0000
committerPhilipp Tölke <toelke@in.tum.de>2011-06-15 07:15:39 +0000
commit36ae035929059eccda334bdecdcc774d7e0f3496 (patch)
tree557073855bbe0500a11274f1a599d3cb36cbc628 /src/mesh
parent8582645938e73f67e28e4e084d720ed5cbb622bd (diff)
downloadgnunet-36ae035929059eccda334bdecdcc774d7e0f3496.tar.gz
gnunet-36ae035929059eccda334bdecdcc774d7e0f3496.zip
use app-types, not msg-types for by-type
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/mesh_api.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c
index 971f491d2..edbc549b8 100644
--- a/src/mesh/mesh_api.c
+++ b/src/mesh/mesh_api.c
@@ -29,6 +29,7 @@
29#include <gnunet_mesh_service.h> 29#include <gnunet_mesh_service.h>
30#include <gnunet_core_service.h> 30#include <gnunet_core_service.h>
31#include <gnunet_container_lib.h> 31#include <gnunet_container_lib.h>
32#include <gnunet_applications.h>
32 33
33struct tunnel_id 34struct tunnel_id
34{ 35{
@@ -67,10 +68,10 @@ struct GNUNET_MESH_Tunnel
67 68
68 struct GNUNET_MESH_Handle* handle; 69 struct GNUNET_MESH_Handle* handle;
69 70
70 /* The message-type requested for this tunnel. Is only needed for pending 71 /* The application-type requested for this tunnel. Is only needed for pending
71 * by_tupe-tunnels 72 * by_tupe-tunnels
72 */ 73 */
73 uint16_t message_type; 74 uint16_t application_type;
74 75
75 /* The context of the receive-function. */ 76 /* The context of the receive-function. */
76 void *ctx; 77 void *ctx;
@@ -300,7 +301,7 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
300 301
301/** 302/**
302 * Receive a message from core. 303 * Receive a message from core.
303 * This is a hello-message, containing the message-types the other peer can receive 304 * This is a hello-message, containing the application-types the other peer can receive
304 */ 305 */
305static int 306static int
306receive_hello (void *cls, 307receive_hello (void *cls,
@@ -323,7 +324,6 @@ receive_hello (void *cls,
323 } 324 }
324 325
325 /* TODO: add, not replace! */ 326 /* TODO: add, not replace! */
326 /* TODO: if this changes anything: send new hello */
327 element->num_types = *num; 327 element->num_types = *num;
328 element->types = GNUNET_malloc (*num * sizeof (GNUNET_MESH_ApplicationType)); 328 element->types = GNUNET_malloc (*num * sizeof (GNUNET_MESH_ApplicationType));
329 329
@@ -336,7 +336,7 @@ receive_hello (void *cls,
336 struct tunnel_list_element *next = tunnel->next; 336 struct tunnel_list_element *next = tunnel->next;
337 for (i = 0; i < *num; i++) 337 for (i = 0; i < *num; i++)
338 { 338 {
339 if (ntohs (ports[i]) == tunnel->tunnel.message_type) 339 if (ntohs (ports[i]) == tunnel->tunnel.application_type)
340 { 340 {
341 GNUNET_CONTAINER_DLL_remove (handle->pending_tunnels.head, 341 GNUNET_CONTAINER_DLL_remove (handle->pending_tunnels.head,
342 handle->pending_tunnels.tail, 342 handle->pending_tunnels.tail,
@@ -353,7 +353,7 @@ receive_hello (void *cls,
353 break; 353 break;
354 } 354 }
355 } 355 }
356 if (ntohs (ports[i]) == tunnel->tunnel.message_type) 356 if (ntohs (ports[i]) == tunnel->tunnel.application_type)
357 tunnel = next; 357 tunnel = next;
358 else 358 else
359 tunnel = tunnel->next; 359 tunnel = tunnel->next;
@@ -434,7 +434,7 @@ core_receive (void *cls,
434struct GNUNET_MESH_Tunnel * 434struct GNUNET_MESH_Tunnel *
435GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Handle *handle, 435GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Handle *handle,
436 struct GNUNET_TIME_Relative timeout, 436 struct GNUNET_TIME_Relative timeout,
437 GNUNET_MESH_ApplicationType message_type, 437 GNUNET_MESH_ApplicationType application_type,
438 GNUNET_MESH_TunnelConnectHandler 438 GNUNET_MESH_TunnelConnectHandler
439 connect_handler, 439 connect_handler,
440 GNUNET_MESH_TunnelDisconnectHandler 440 GNUNET_MESH_TunnelDisconnectHandler
@@ -447,7 +447,7 @@ GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Handle *handle,
447 { 447 {
448 unsigned int i; 448 unsigned int i;
449 for (i = 0; i < element->num_types; i++) 449 for (i = 0; i < element->num_types; i++)
450 if (message_type == element->types[i]) 450 if (application_type == element->types[i])
451 return GNUNET_MESH_peer_request_connect_all (handle, timeout, 1, 451 return GNUNET_MESH_peer_request_connect_all (handle, timeout, 1,
452 &handle->myself, 452 &handle->myself,
453 connect_handler, 453 connect_handler,
@@ -468,7 +468,7 @@ GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Handle *handle,
468 memcpy (&tunnel->tunnel.id.initiator, &handle->myself, 468 memcpy (&tunnel->tunnel.id.initiator, &handle->myself,
469 sizeof (struct GNUNET_PeerIdentity)); 469 sizeof (struct GNUNET_PeerIdentity));
470 tunnel->tunnel.id.id = current_id++; 470 tunnel->tunnel.id.id = current_id++;
471 tunnel->tunnel.message_type = message_type; 471 tunnel->tunnel.application_type = application_type;
472 472
473 GNUNET_CONTAINER_DLL_insert_after (handle->pending_by_type_tunnels.head, 473 GNUNET_CONTAINER_DLL_insert_after (handle->pending_by_type_tunnels.head,
474 handle->pending_by_type_tunnels.tail, 474 handle->pending_by_type_tunnels.tail,
@@ -635,19 +635,22 @@ GNUNET_MESH_notify_transmit_ready (struct
635 return (struct GNUNET_MESH_TransmitHandle*) 1; 635 return (struct GNUNET_MESH_TransmitHandle*) 1;
636} 636}
637 637
638void build_hello_message(struct GNUNET_MESH_Handle* handle, int num) 638void build_hello_message(struct GNUNET_MESH_Handle* handle,
639 const GNUNET_MESH_ApplicationType *stypes)
639{ 640{
641 int num = 0;
642 const GNUNET_MESH_ApplicationType *t;
643
644 for (t = stypes; *t != GNUNET_APPLICATION_TYPE_END; t++, num++);
645
640 handle->hello_message_size = sizeof(uint16_t) + /* For the number of types */ 646 handle->hello_message_size = sizeof(uint16_t) + /* For the number of types */
641 num * sizeof(uint16_t); /* For the types */ 647 num * sizeof(GNUNET_MESH_ApplicationType); /* For the types */
642 648
643 uint16_t *nums = GNUNET_malloc(handle->hello_message_size); 649 uint16_t *nums = GNUNET_malloc(handle->hello_message_size);
644 uint16_t *types = nums + 1; 650 GNUNET_MESH_ApplicationType *types = (GNUNET_MESH_ApplicationType*)(nums + 1);
645 651
646 *nums = num; 652 *nums = num;
647 653 memcpy(types, stypes, num*sizeof(GNUNET_MESH_ApplicationType));
648 unsigned int i;
649 for(i = 0; i < num; i++)
650 types[i] = handle->handlers[i].type;
651 654
652 handle->hello_message = nums; 655 handle->hello_message = nums;
653} 656}
@@ -684,7 +687,7 @@ GNUNET_MESH_connect (const struct
684 memcpy (ret->handlers, handlers, 687 memcpy (ret->handlers, handlers,
685 len * sizeof (struct GNUNET_MESH_MessageHandler)); 688 len * sizeof (struct GNUNET_MESH_MessageHandler));
686 689
687 build_hello_message(ret, len); 690 build_hello_message(ret, stypes);
688 691
689 const static struct GNUNET_CORE_MessageHandler core_handlers[] = { 692 const static struct GNUNET_CORE_MessageHandler core_handlers[] = {
690 {&core_receive, GNUNET_MESSAGE_TYPE_MESH, 0}, 693 {&core_receive, GNUNET_MESSAGE_TYPE_MESH, 0},