From b25cf0c5e608045beb3c4cdfead6a94f0067284f Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Wed, 7 Sep 2011 16:24:53 +0000 Subject: Changed documentation, type names and code formatting Extended test_local --- src/include/gnunet_mesh_service_new.h | 52 ++++++++++---------- src/mesh/gnunet-service-mesh.c | 38 +++++++-------- src/mesh/mesh_api.c | 2 +- src/mesh/mesh_api_new.c | 91 ++++++++++++++++++----------------- src/mesh/test_mesh_api.c | 3 +- src/mesh/test_mesh_local.c | 50 ++++++++++++++----- 6 files changed, 132 insertions(+), 104 deletions(-) (limited to 'src') diff --git a/src/include/gnunet_mesh_service_new.h b/src/include/gnunet_mesh_service_new.h index 1b4faa382..f32bf28c5 100644 --- a/src/include/gnunet_mesh_service_new.h +++ b/src/include/gnunet_mesh_service_new.h @@ -113,16 +113,14 @@ struct GNUNET_MESH_MessageHandler * @param tunnel new handle to the tunnel * @param initiator peer that started the tunnel * @param atsi performance information for the tunnel - * @return initial tunnel context for the tunnel (can be NULL -- that's not an error) + * @return initial tunnel context for the tunnel + * (can be NULL -- that's not an error) */ -typedef void* (GNUNET_MESH_InboundTunnelNotificationHandler) (void *cls, - struct GNUNET_MESH_Tunnel * tunnel, - const struct - GNUNET_PeerIdentity * - initiator, - const struct - GNUNET_TRANSPORT_ATS_Information * - atsi); +typedef void* (GNUNET_MESH_InboundTunnelNotificationHandler) ( + void *cls, + struct GNUNET_MESH_Tunnel * tunnel, + const struct GNUNET_PeerIdentity * initiator, + const struct GNUNET_TRANSPORT_ATS_Information * atsi); /** @@ -166,7 +164,8 @@ typedef uint32_t GNUNET_MESH_ApplicationType; */ struct GNUNET_MESH_Handle * GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, - unsigned int queue_size, void *cls, + unsigned int queue_size, + void *cls, GNUNET_MESH_InboundTunnelNotificationHandler new_tunnel, GNUNET_MESH_TunnelEndHandler cleaner, const struct GNUNET_MESH_MessageHandler *handlers, @@ -188,10 +187,9 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle); * @param cls closure * @param peer peer identity the tunnel stopped working with */ -typedef void (*GNUNET_MESH_TunnelDisconnectHandler) (void *cls, - const struct - GNUNET_PeerIdentity * - peer); +typedef void (*GNUNET_MESH_PeerDisconnectHandler) ( + void *cls, + const struct GNUNET_PeerIdentity * peer); /** @@ -202,12 +200,10 @@ typedef void (*GNUNET_MESH_TunnelDisconnectHandler) (void *cls, * @param peer peer identity the tunnel was created to, NULL on timeout * @param atsi performance data for the connection */ -typedef void (*GNUNET_MESH_TunnelConnectHandler) (void *cls, - const struct - GNUNET_PeerIdentity * peer, - const struct - GNUNET_TRANSPORT_ATS_Information - * atsi); +typedef void (*GNUNET_MESH_PeerConnectHandler) ( + void *cls, + const struct GNUNET_PeerIdentity * peer, + const struct GNUNET_TRANSPORT_ATS_Information * atsi); @@ -222,18 +218,19 @@ typedef void (*GNUNET_MESH_TunnelConnectHandler) (void *cls, * @param handler_cls closure for connect/disconnect handlers */ struct GNUNET_MESH_Tunnel * -GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, void *tunnel_ctx, - GNUNET_MESH_TunnelConnectHandler connect_handler, - GNUNET_MESH_TunnelDisconnectHandler - disconnect_handler, void *handler_cls); +GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, + void *tunnel_ctx, + GNUNET_MESH_PeerConnectHandler connect_handler, + GNUNET_MESH_PeerDisconnectHandler disconnect_handler, + void *handler_cls); /** * Destroy an existing tunnel. * - * @param tun tunnel handle + * @param tunnel tunnel handle */ void -GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tun); +GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel); /** @@ -300,7 +297,8 @@ struct GNUNET_MESH_TransmitHandle; * memory); if NULL is returned, "notify" will NOT be called. */ struct GNUNET_MESH_TransmitHandle * -GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, +GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, + int cork, uint32_t priority, struct GNUNET_TIME_Relative maxdelay, const struct GNUNET_PeerIdentity *target, diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 625481c6b..9b3cef35f 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c @@ -790,14 +790,14 @@ destroy_tunnel (struct MeshTunnel *t) { r = GNUNET_SYSERR; } - GNUNET_CONTAINER_multihashmap_destroy(t->peers); + GNUNET_CONTAINER_multihashmap_destroy (t->peers); q = t->queue_head; while (NULL != q) { if (NULL != q->data) - GNUNET_free(q->data); + GNUNET_free (q->data); qn = q->next; - GNUNET_free(q); + GNUNET_free (q); q = qn; /* TODO cancel core transmit ready in case it was active */ } @@ -2027,24 +2027,24 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) /* deregister clients applications */ for (i = 0; i < c->app_counter; i++) { - for (j = 0; j < n_apps; j++) - { - if (c->apps[i] == applications[j] && 0 == --applications_rc[j]) - { - applications[j] = applications[n_apps - 1]; - GNUNET_array_grow(applications, n_apps, n_apps - 1); - n_apps++; - applications_rc[j] = applications_rc[n_apps - 1]; - GNUNET_array_grow(applications_rc, n_apps, n_apps - 1); - - } - break; - } + for (j = 0; j < n_apps; j++) + { + if (c->apps[i] == applications[j] && 0 == --applications_rc[j]) + { + applications[j] = applications[n_apps - 1]; + GNUNET_array_grow (applications, n_apps, n_apps - 1); + n_apps++; + applications_rc[j] = applications_rc[n_apps - 1]; + GNUNET_array_grow (applications_rc, n_apps, n_apps - 1); + + } + break; + } } GNUNET_free (c->apps); if (0 == n_apps) { - GNUNET_SCHEDULER_cancel (announce_applications_task); + GNUNET_SCHEDULER_cancel (announce_applications_task); } } if (0 != c->type_counter) @@ -2125,9 +2125,9 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client, if (!known) { /* Register previously unknown application */ - GNUNET_array_append(applications, n_apps, c->apps[i]); + GNUNET_array_append (applications, n_apps, c->apps[i]); n_apps--; - GNUNET_array_append(applications_rc, n_apps, 1); + GNUNET_array_append (applications_rc, n_apps, 1); if (GNUNET_SCHEDULER_NO_TASK == announce_applications_task) { announce_applications_task = diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index 8476be396..615593621 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c @@ -921,4 +921,4 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) GNUNET_free (handle); } -/* end of mesh_api.c */ +/* end of mesh_api.c */ \ No newline at end of file diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c index 0c818c908..ad8026d4a 100644 --- a/src/mesh/mesh_api_new.c +++ b/src/mesh/mesh_api_new.c @@ -242,12 +242,12 @@ struct GNUNET_MESH_Tunnel /** * Callback to execute when peers connect to the tunnel */ - GNUNET_MESH_TunnelConnectHandler connect_handler; + GNUNET_MESH_PeerConnectHandler connect_handler; /** * Callback to execute when peers disconnect from the tunnel */ - GNUNET_MESH_TunnelDisconnectHandler disconnect_handler; + GNUNET_MESH_PeerDisconnectHandler disconnect_handler; /** * Closure for the connect/disconnect handlers @@ -380,7 +380,7 @@ destroy_tunnel (struct GNUNET_MESH_Tunnel *t) if (NULL == t) { - GNUNET_break(0); + GNUNET_break (0); return; } h = t->mesh; @@ -390,16 +390,16 @@ destroy_tunnel (struct GNUNET_MESH_Tunnel *t) if (th->tunnel == t) { aux = th->next; - GNUNET_CONTAINER_DLL_remove(h->th_head, h->th_tail, th); + GNUNET_CONTAINER_DLL_remove (h->th_head, h->th_tail, th); if (NULL == h->th_head && NULL != h->th) { - GNUNET_CLIENT_notify_transmit_ready_cancel(h->th); + GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); h->th = NULL; } if (NULL != th->notify) - th->notify(th->notify_cls, 0, NULL); + th->notify (th->notify_cls, 0, NULL); if (GNUNET_SCHEDULER_NO_TASK != th->timeout_task) - GNUNET_SCHEDULER_cancel(th->timeout_task); + GNUNET_SCHEDULER_cancel (th->timeout_task); GNUNET_free (th); th = aux; } @@ -420,7 +420,7 @@ destroy_tunnel (struct GNUNET_MESH_Tunnel *t) GNUNET_free (t->peers[i]); } if (t->npeers > 0) - GNUNET_free (t->peers); + GNUNET_free (t->peers); if (NULL != h->cleaner && 0 != t->owner) h->cleaner (h->cls, t, t->ctx); if (0 != t->owner) @@ -608,9 +608,11 @@ reconnect (struct GNUNET_MESH_Handle *h) h->client = GNUNET_CLIENT_connect ("mesh", h->cfg); if (h->client == NULL) { - GNUNET_SCHEDULER_add_delayed(h->reconnect_time, &reconnect_cbk, h); - h->reconnect_time = GNUNET_TIME_relative_min(GNUNET_TIME_UNIT_HOURS, - GNUNET_TIME_relative_multiply(h->reconnect_time, 2)); + GNUNET_SCHEDULER_add_delayed (h->reconnect_time, &reconnect_cbk, h); + h->reconnect_time = + GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_HOURS, + GNUNET_TIME_relative_multiply + (h->reconnect_time, 2)); GNUNET_break (0); return GNUNET_NO; } @@ -668,9 +670,10 @@ static void reconnect_cbk (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_MESH_Handle *h = cls; + if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) return; - reconnect(h); + reconnect (h); } @@ -686,7 +689,7 @@ reconnect_cbk (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ static void process_tunnel_created (struct GNUNET_MESH_Handle *h, - const struct GNUNET_MESH_TunnelNotification *msg) + const struct GNUNET_MESH_TunnelNotification *msg) { struct GNUNET_MESH_Tunnel *t; struct GNUNET_TRANSPORT_ATS_Information atsi; @@ -712,7 +715,7 @@ process_tunnel_created (struct GNUNET_MESH_Handle *h, { atsi.type = 0; atsi.value = 0; - t->ctx = h->new_tunnel(h->cls, t, &msg->peer, &atsi); + t->ctx = h->new_tunnel (h->cls, t, &msg->peer, &atsi); } GNUNET_CONTAINER_DLL_insert (h->tunnels_head, h->tunnels_tail, t); return; @@ -737,15 +740,15 @@ process_tunnel_destroy (struct GNUNET_MESH_Handle *h, if (NULL == t) { - GNUNET_break(0); + GNUNET_break (0); return; } if (0 == t->owner) { - GNUNET_break(0); + GNUNET_break (0); } - destroy_tunnel(t); + destroy_tunnel (t); return; } @@ -775,7 +778,7 @@ process_peer_event (struct GNUNET_MESH_Handle *h, t = retrieve_tunnel (h, ntohl (msg->tunnel_id)); if (NULL == t) { - GNUNET_break(0); + GNUNET_break (0); return; } id = GNUNET_PEER_search (&msg->peer); @@ -854,7 +857,7 @@ process_incoming_data (struct GNUNET_MESH_Handle *h, GNUNET_break (0); return; } - type = ntohs(payload->type); + type = ntohs (payload->type); for (i = 0; i < h->n_handlers; i++) { handler = &h->message_handlers[i]; @@ -969,9 +972,9 @@ send_callback (void *cls, size_t size, void *buf) { #if DEBUG GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: type: %u\n", - ntohs (((struct GNUNET_MessageHeader *)&th[1])->type)); + ntohs (((struct GNUNET_MessageHeader *) &th[1])->type)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: size: %u\n", - ntohs (((struct GNUNET_MessageHeader *)&th[1])->size)); + ntohs (((struct GNUNET_MessageHeader *) &th[1])->size)); #endif if (NULL != th->notify) { @@ -988,7 +991,7 @@ send_callback (void *cls, size_t size, void *buf) mc.header.size = htons (sizeof (mc) + th->size); mc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST); mc.tid = htonl (th->tunnel->tid); - memset (&mc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); /* myself */ + memset (&mc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); memcpy (cbuf, &mc, sizeof (mc)); psize = th->size + sizeof (mc); } @@ -1006,7 +1009,7 @@ send_callback (void *cls, size_t size, void *buf) uc.header.size = htons (sizeof (uc) + th->size); uc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_UNICAST); uc.tid = htonl (th->tunnel->tid); - memset (&uc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); /* myself */ + memset (&uc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); GNUNET_PEER_resolve (th->target, &uc.destination); memcpy (cbuf, &uc, sizeof (uc)); psize = th->size + sizeof (uc); @@ -1210,9 +1213,9 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) */ struct GNUNET_MESH_Tunnel * GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, void *tunnel_ctx, - GNUNET_MESH_TunnelConnectHandler connect_handler, - GNUNET_MESH_TunnelDisconnectHandler - disconnect_handler, void *handler_cls) + GNUNET_MESH_PeerConnectHandler connect_handler, + GNUNET_MESH_PeerDisconnectHandler disconnect_handler, + void *handler_cls) { struct GNUNET_MESH_Tunnel *t; struct GNUNET_MESH_TunnelMessage msg; @@ -1237,21 +1240,21 @@ GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, void *tunnel_ctx, * @param tun tunnel handle */ void -GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *t) +GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel) { struct GNUNET_MESH_Handle *h; struct GNUNET_MESH_TunnelMessage msg; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n"); - h = t->mesh; + h = tunnel->mesh; - if (0 != t->owner) - GNUNET_PEER_change_rc (t->owner, -1); + if (0 != tunnel->owner) + GNUNET_PEER_change_rc (tunnel->owner, -1); msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); - msg.tunnel_id = htonl (t->tid); - destroy_tunnel (t); + msg.tunnel_id = htonl (tunnel->tid); + destroy_tunnel (tunnel); send_packet (h, &msg.header); } @@ -1401,7 +1404,7 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, uint32_t least_priority; size_t overhead; - GNUNET_assert(NULL != notify); + GNUNET_assert (NULL != notify); if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size && tunnel->npackets > 0) { @@ -1422,16 +1425,16 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, } if (NULL == least_priority_th) return NULL; - GNUNET_assert(NULL != least_priority_th->notify); /* Cant be a cntrl msg */ - least_priority_th->notify(notify_cls, 0, NULL); + /* Can't be a control message */ + GNUNET_assert (NULL != least_priority_th->notify); + least_priority_th->notify (notify_cls, 0, NULL); least_priority_th->tunnel->npackets--; tunnel->mesh->npackets--; - GNUNET_CONTAINER_DLL_remove(tunnel->mesh->th_head, - tunnel->mesh->th_tail, - least_priority_th); + GNUNET_CONTAINER_DLL_remove (tunnel->mesh->th_head, tunnel->mesh->th_tail, + least_priority_th); if (GNUNET_SCHEDULER_NO_TASK != least_priority_th->timeout_task) - GNUNET_SCHEDULER_cancel(least_priority_th->timeout_task); - GNUNET_free(least_priority_th); + GNUNET_SCHEDULER_cancel (least_priority_th->timeout_task); + GNUNET_free (least_priority_th); } tunnel->npackets++; tunnel->mesh->npackets++; @@ -1440,10 +1443,10 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, th->priority = priority; th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay); th->target = GNUNET_PEER_intern (target); - overhead = - (NULL == - target) ? sizeof (struct GNUNET_MESH_Multicast) : sizeof (struct - GNUNET_MESH_Unicast); + if (NULL == target) + overhead = sizeof (struct GNUNET_MESH_Multicast); + else + overhead = sizeof (struct GNUNET_MESH_Unicast); th->size = notify_size + overhead; th->notify = notify; th->notify_cls = notify_cls; diff --git a/src/mesh/test_mesh_api.c b/src/mesh/test_mesh_api.c index ada8e10e7..08c28bf64 100644 --- a/src/mesh/test_mesh_api.c +++ b/src/mesh/test_mesh_api.c @@ -121,8 +121,7 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_MESH_tunnel_destroy (t); } - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown, - NULL); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown, NULL); } diff --git a/src/mesh/test_mesh_local.c b/src/mesh/test_mesh_local.c index 789a2f63e..bf81ccc8e 100644 --- a/src/mesh/test_mesh_local.c +++ b/src/mesh/test_mesh_local.c @@ -41,6 +41,15 @@ static int result; static GNUNET_SCHEDULER_TaskIdentifier abort_task; static GNUNET_SCHEDULER_TaskIdentifier test_task; +static struct GNUNET_MESH_MessageHandler handlers1[] = { + {&callback, 1, 0}, + {NULL, 0, 0} +}; + +static struct GNUNET_MESH_MessageHandler handlers2[] = { {NULL, 0, 0} }; + + + /** * Function is called whenever a message is received. * @@ -59,15 +68,37 @@ callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx, const struct GNUNET_MessageHeader *message, const struct GNUNET_TRANSPORT_ATS_Information *atsi) { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Data callback\n"); return GNUNET_OK; } -static struct GNUNET_MESH_MessageHandler handlers1[] = { - {&callback, 1, 0}, - {NULL, 0, 0} -}; -static struct GNUNET_MESH_MessageHandler handlers2[] = {{NULL, 0, 0}}; +/** + * Method called whenever another peer has added us to a tunnel + * the other peer initiated. + * + * @param cls closure + * @param tunnel new handle to the tunnel + * @param initiator peer that started the tunnel + * @param atsi performance information for the tunnel + * @return initial tunnel context for the tunnel (can be NULL -- that's not an error) + */ +static void * +inbound_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel, + const struct GNUNET_PeerIdentity *initiator, + const structGNUNET_TRANSPORT_ATS_Information * atsi) +{ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: \n"); + return NULL; +} + + + + + + + + static void @@ -116,8 +147,7 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct GNUNET_CONFIGURATION_Handle *cfg = cls; static const GNUNET_MESH_ApplicationType app1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 0 }; - static const GNUNET_MESH_ApplicationType app2[] = - { 0 }; + static const GNUNET_MESH_ApplicationType app2[] = { 0 }; test_task = (GNUNET_SCHEDULER_TaskIdentifier) 0; mesh_peer_1 = GNUNET_MESH_connect (cfg, 10, 1, NULL, NULL, handlers1, app1); @@ -135,10 +165,8 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) t_1 = GNUNET_MESH_tunnel_create (mesh_peer_1, NULL, NULL, NULL, 1); // t_2 = GNUNET_MESH_tunnel_create (mesh_peer_2, NULL, NULL, NULL, 2); - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( - GNUNET_TIME_UNIT_SECONDS, - 2), - &do_shutdown, + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 2), &do_shutdown, NULL); } -- cgit v1.2.3