X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fmesh%2Fmesh_api.c;h=8b1655dde501554967adae4b43e0c0424d4472da;hb=2e155cd114a5b983beabc8d7be31437e9aebd0dc;hp=68b2e587dd146ba4d7ba153d36f88abf72066a6e;hpb=43939383f2324840b5f2ebecfed5e23cbf1e4aa1;p=oweals%2Fgnunet.git diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index 68b2e587d..8b1655dde 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c @@ -141,6 +141,17 @@ send_self_connect(void* cls, GNUNET_SCHEDULER_add_now(send_end_connect, tunnel); } +static void +call_connect_handler (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct GNUNET_MESH_Tunnel *tunnel = cls; + + tunnel->connect_handler (tunnel->handler_cls, &tunnel->peer, + NULL); + GNUNET_SCHEDULER_add_now (send_end_connect, tunnel); +} + static void core_startup (void *cls, struct GNUNET_CORE_Handle *core, @@ -171,8 +182,7 @@ send_hello_message (void *cls, size_t size, void *buf) /** * Core calls this if we are connected to a new peer. * - * If core tells us that we are connected to ourself, we ignore it. Otherwise, the - * peer is added to the connected_peers-list. + * The peer is added to the connected_peers-list. * */ static void @@ -181,18 +191,25 @@ core_connect (void *cls, const struct GNUNET_TRANSPORT_ATS_Information *atsi) { struct GNUNET_MESH_Handle *handle = cls; - /* Check for connect-to-self-message, which we ignore */ - if (0 == - memcmp (peer, &handle->myself, sizeof (struct GNUNET_PeerIdentity))) - return; + /* Send a hello to this peer */ + GNUNET_CORE_notify_transmit_ready(handle->core, + GNUNET_NO, + 42, + GNUNET_TIME_UNIT_SECONDS, + peer, + sizeof(struct GNUNET_MessageHeader) + handle->hello_message_size, + &send_hello_message, + cls); /* put the new peer into the list of connected peers */ struct peer_list_element *element = GNUNET_malloc (sizeof (struct peer_list_element)); memcpy (&element->peer, peer, sizeof (struct GNUNET_PeerIdentity)); - memcpy (&element->atsi, atsi, - sizeof (struct GNUNET_TRANSPORT_ATS_Information)); + + if (NULL != atsi) + memcpy (&element->atsi, atsi, + sizeof (struct GNUNET_TRANSPORT_ATS_Information)); GNUNET_CONTAINER_DLL_insert_after (handle->connected_peers.head, handle->connected_peers.tail, @@ -220,15 +237,6 @@ core_connect (void *cls, else tunnel = tunnel->next; } - GNUNET_CORE_notify_transmit_ready(handle->core, - GNUNET_NO, - 42, - GNUNET_TIME_UNIT_SECONDS, - peer, - sizeof(struct GNUNET_MessageHeader) + handle->hello_message_size, - &send_hello_message, - cls); - } /** @@ -313,7 +321,6 @@ receive_hello (void *cls, element = element->next; } - /* TODO: handle self */ /* TODO: add, not replace! */ /* TODO: if this changes anything: send new hello */ element->num_types = *num; @@ -515,7 +522,7 @@ GNUNET_MESH_peer_request_connect_all (struct GNUNET_MESH_Handle *handle, handle->established_tunnels.tail, handle->established_tunnels.tail, tunnel); - connect_handler (handler_cls, &element->peer, &element->atsi); + GNUNET_SCHEDULER_add_now(call_connect_handler, tunnel); } else if (0 == memcmp (peers, &handle->myself, @@ -538,7 +545,7 @@ GNUNET_MESH_peer_request_connect_all (struct GNUNET_MESH_Handle *handle, (void) GNUNET_CORE_peer_request_connect (handle->core, timeout, peers, - NULL, NULL); + NULL, NULL); } return &tunnel->tunnel; @@ -628,6 +635,23 @@ GNUNET_MESH_notify_transmit_ready (struct return (struct GNUNET_MESH_TransmitHandle*) 1; } +void build_hello_message(struct GNUNET_MESH_Handle* handle, int num) +{ + handle->hello_message_size = sizeof(uint16_t) + /* For the number of types */ + num * sizeof(uint16_t); /* For the types */ + + uint16_t *nums = GNUNET_malloc(handle->hello_message_size); + uint16_t *types = nums + 1; + + *nums = num; + + unsigned int i; + for(i = 0; i < num; i++) + types[i] = handle->handlers[i].type; + + handle->hello_message = nums; +} + struct GNUNET_MESH_Handle * GNUNET_MESH_connect (const struct @@ -660,7 +684,7 @@ GNUNET_MESH_connect (const struct memcpy (ret->handlers, handlers, len * sizeof (struct GNUNET_MESH_MessageHandler)); - /* TODO: build hello */ + build_hello_message(ret, len); const static struct GNUNET_CORE_MessageHandler core_handlers[] = { {&core_receive, GNUNET_MESSAGE_TYPE_MESH, 0}, @@ -684,12 +708,14 @@ void GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) { GNUNET_free (handle->handlers); + GNUNET_free (handle->hello_message); GNUNET_CORE_disconnect (handle->core); struct peer_list_element *element = handle->connected_peers.head; while (element != NULL) { struct peer_list_element *next = element->next; + GNUNET_free_non_null(element->types); GNUNET_free (element); element = next; }