diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-09-07 16:24:53 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-09-07 16:24:53 +0000 |
commit | b25cf0c5e608045beb3c4cdfead6a94f0067284f (patch) | |
tree | f97ee547a595fd023fd0cdcd75370a349c893abf /src | |
parent | 6a32c510c139f0bbfd2d5d4043252c6996da1f5f (diff) | |
download | gnunet-b25cf0c5e608045beb3c4cdfead6a94f0067284f.tar.gz gnunet-b25cf0c5e608045beb3c4cdfead6a94f0067284f.zip |
Changed documentation, type names and code formatting
Extended test_local
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_mesh_service_new.h | 52 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 38 | ||||
-rw-r--r-- | src/mesh/mesh_api.c | 2 | ||||
-rw-r--r-- | src/mesh/mesh_api_new.c | 91 | ||||
-rw-r--r-- | src/mesh/test_mesh_api.c | 3 | ||||
-rw-r--r-- | src/mesh/test_mesh_local.c | 50 |
6 files changed, 132 insertions, 104 deletions
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 | |||
113 | * @param tunnel new handle to the tunnel | 113 | * @param tunnel new handle to the tunnel |
114 | * @param initiator peer that started the tunnel | 114 | * @param initiator peer that started the tunnel |
115 | * @param atsi performance information for the tunnel | 115 | * @param atsi performance information for the tunnel |
116 | * @return initial tunnel context for the tunnel (can be NULL -- that's not an error) | 116 | * @return initial tunnel context for the tunnel |
117 | * (can be NULL -- that's not an error) | ||
117 | */ | 118 | */ |
118 | typedef void* (GNUNET_MESH_InboundTunnelNotificationHandler) (void *cls, | 119 | typedef void* (GNUNET_MESH_InboundTunnelNotificationHandler) ( |
119 | struct GNUNET_MESH_Tunnel * tunnel, | 120 | void *cls, |
120 | const struct | 121 | struct GNUNET_MESH_Tunnel * tunnel, |
121 | GNUNET_PeerIdentity * | 122 | const struct GNUNET_PeerIdentity * initiator, |
122 | initiator, | 123 | const struct GNUNET_TRANSPORT_ATS_Information * atsi); |
123 | const struct | ||
124 | GNUNET_TRANSPORT_ATS_Information * | ||
125 | atsi); | ||
126 | 124 | ||
127 | 125 | ||
128 | /** | 126 | /** |
@@ -166,7 +164,8 @@ typedef uint32_t GNUNET_MESH_ApplicationType; | |||
166 | */ | 164 | */ |
167 | struct GNUNET_MESH_Handle * | 165 | struct GNUNET_MESH_Handle * |
168 | GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 166 | GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
169 | unsigned int queue_size, void *cls, | 167 | unsigned int queue_size, |
168 | void *cls, | ||
170 | GNUNET_MESH_InboundTunnelNotificationHandler new_tunnel, | 169 | GNUNET_MESH_InboundTunnelNotificationHandler new_tunnel, |
171 | GNUNET_MESH_TunnelEndHandler cleaner, | 170 | GNUNET_MESH_TunnelEndHandler cleaner, |
172 | const struct GNUNET_MESH_MessageHandler *handlers, | 171 | const struct GNUNET_MESH_MessageHandler *handlers, |
@@ -188,10 +187,9 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle); | |||
188 | * @param cls closure | 187 | * @param cls closure |
189 | * @param peer peer identity the tunnel stopped working with | 188 | * @param peer peer identity the tunnel stopped working with |
190 | */ | 189 | */ |
191 | typedef void (*GNUNET_MESH_TunnelDisconnectHandler) (void *cls, | 190 | typedef void (*GNUNET_MESH_PeerDisconnectHandler) ( |
192 | const struct | 191 | void *cls, |
193 | GNUNET_PeerIdentity * | 192 | const struct GNUNET_PeerIdentity * peer); |
194 | peer); | ||
195 | 193 | ||
196 | 194 | ||
197 | /** | 195 | /** |
@@ -202,12 +200,10 @@ typedef void (*GNUNET_MESH_TunnelDisconnectHandler) (void *cls, | |||
202 | * @param peer peer identity the tunnel was created to, NULL on timeout | 200 | * @param peer peer identity the tunnel was created to, NULL on timeout |
203 | * @param atsi performance data for the connection | 201 | * @param atsi performance data for the connection |
204 | */ | 202 | */ |
205 | typedef void (*GNUNET_MESH_TunnelConnectHandler) (void *cls, | 203 | typedef void (*GNUNET_MESH_PeerConnectHandler) ( |
206 | const struct | 204 | void *cls, |
207 | GNUNET_PeerIdentity * peer, | 205 | const struct GNUNET_PeerIdentity * peer, |
208 | const struct | 206 | const struct GNUNET_TRANSPORT_ATS_Information * atsi); |
209 | GNUNET_TRANSPORT_ATS_Information | ||
210 | * atsi); | ||
211 | 207 | ||
212 | 208 | ||
213 | 209 | ||
@@ -222,18 +218,19 @@ typedef void (*GNUNET_MESH_TunnelConnectHandler) (void *cls, | |||
222 | * @param handler_cls closure for connect/disconnect handlers | 218 | * @param handler_cls closure for connect/disconnect handlers |
223 | */ | 219 | */ |
224 | struct GNUNET_MESH_Tunnel * | 220 | struct GNUNET_MESH_Tunnel * |
225 | GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, void *tunnel_ctx, | 221 | GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, |
226 | GNUNET_MESH_TunnelConnectHandler connect_handler, | 222 | void *tunnel_ctx, |
227 | GNUNET_MESH_TunnelDisconnectHandler | 223 | GNUNET_MESH_PeerConnectHandler connect_handler, |
228 | disconnect_handler, void *handler_cls); | 224 | GNUNET_MESH_PeerDisconnectHandler disconnect_handler, |
225 | void *handler_cls); | ||
229 | 226 | ||
230 | /** | 227 | /** |
231 | * Destroy an existing tunnel. | 228 | * Destroy an existing tunnel. |
232 | * | 229 | * |
233 | * @param tun tunnel handle | 230 | * @param tunnel tunnel handle |
234 | */ | 231 | */ |
235 | void | 232 | void |
236 | GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tun); | 233 | GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel); |
237 | 234 | ||
238 | 235 | ||
239 | /** | 236 | /** |
@@ -300,7 +297,8 @@ struct GNUNET_MESH_TransmitHandle; | |||
300 | * memory); if NULL is returned, "notify" will NOT be called. | 297 | * memory); if NULL is returned, "notify" will NOT be called. |
301 | */ | 298 | */ |
302 | struct GNUNET_MESH_TransmitHandle * | 299 | struct GNUNET_MESH_TransmitHandle * |
303 | GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, | 300 | GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, |
301 | int cork, | ||
304 | uint32_t priority, | 302 | uint32_t priority, |
305 | struct GNUNET_TIME_Relative maxdelay, | 303 | struct GNUNET_TIME_Relative maxdelay, |
306 | const struct GNUNET_PeerIdentity *target, | 304 | 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) | |||
790 | { | 790 | { |
791 | r = GNUNET_SYSERR; | 791 | r = GNUNET_SYSERR; |
792 | } | 792 | } |
793 | GNUNET_CONTAINER_multihashmap_destroy(t->peers); | 793 | GNUNET_CONTAINER_multihashmap_destroy (t->peers); |
794 | q = t->queue_head; | 794 | q = t->queue_head; |
795 | while (NULL != q) | 795 | while (NULL != q) |
796 | { | 796 | { |
797 | if (NULL != q->data) | 797 | if (NULL != q->data) |
798 | GNUNET_free(q->data); | 798 | GNUNET_free (q->data); |
799 | qn = q->next; | 799 | qn = q->next; |
800 | GNUNET_free(q); | 800 | GNUNET_free (q); |
801 | q = qn; | 801 | q = qn; |
802 | /* TODO cancel core transmit ready in case it was active */ | 802 | /* TODO cancel core transmit ready in case it was active */ |
803 | } | 803 | } |
@@ -2027,24 +2027,24 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
2027 | /* deregister clients applications */ | 2027 | /* deregister clients applications */ |
2028 | for (i = 0; i < c->app_counter; i++) | 2028 | for (i = 0; i < c->app_counter; i++) |
2029 | { | 2029 | { |
2030 | for (j = 0; j < n_apps; j++) | 2030 | for (j = 0; j < n_apps; j++) |
2031 | { | 2031 | { |
2032 | if (c->apps[i] == applications[j] && 0 == --applications_rc[j]) | 2032 | if (c->apps[i] == applications[j] && 0 == --applications_rc[j]) |
2033 | { | 2033 | { |
2034 | applications[j] = applications[n_apps - 1]; | 2034 | applications[j] = applications[n_apps - 1]; |
2035 | GNUNET_array_grow(applications, n_apps, n_apps - 1); | 2035 | GNUNET_array_grow (applications, n_apps, n_apps - 1); |
2036 | n_apps++; | 2036 | n_apps++; |
2037 | applications_rc[j] = applications_rc[n_apps - 1]; | 2037 | applications_rc[j] = applications_rc[n_apps - 1]; |
2038 | GNUNET_array_grow(applications_rc, n_apps, n_apps - 1); | 2038 | GNUNET_array_grow (applications_rc, n_apps, n_apps - 1); |
2039 | 2039 | ||
2040 | } | 2040 | } |
2041 | break; | 2041 | break; |
2042 | } | 2042 | } |
2043 | } | 2043 | } |
2044 | GNUNET_free (c->apps); | 2044 | GNUNET_free (c->apps); |
2045 | if (0 == n_apps) | 2045 | if (0 == n_apps) |
2046 | { | 2046 | { |
2047 | GNUNET_SCHEDULER_cancel (announce_applications_task); | 2047 | GNUNET_SCHEDULER_cancel (announce_applications_task); |
2048 | } | 2048 | } |
2049 | } | 2049 | } |
2050 | if (0 != c->type_counter) | 2050 | if (0 != c->type_counter) |
@@ -2125,9 +2125,9 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client, | |||
2125 | if (!known) | 2125 | if (!known) |
2126 | { | 2126 | { |
2127 | /* Register previously unknown application */ | 2127 | /* Register previously unknown application */ |
2128 | GNUNET_array_append(applications, n_apps, c->apps[i]); | 2128 | GNUNET_array_append (applications, n_apps, c->apps[i]); |
2129 | n_apps--; | 2129 | n_apps--; |
2130 | GNUNET_array_append(applications_rc, n_apps, 1); | 2130 | GNUNET_array_append (applications_rc, n_apps, 1); |
2131 | if (GNUNET_SCHEDULER_NO_TASK == announce_applications_task) | 2131 | if (GNUNET_SCHEDULER_NO_TASK == announce_applications_task) |
2132 | { | 2132 | { |
2133 | announce_applications_task = | 2133 | 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) | |||
921 | GNUNET_free (handle); | 921 | GNUNET_free (handle); |
922 | } | 922 | } |
923 | 923 | ||
924 | /* end of mesh_api.c */ | 924 | /* 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 | |||
242 | /** | 242 | /** |
243 | * Callback to execute when peers connect to the tunnel | 243 | * Callback to execute when peers connect to the tunnel |
244 | */ | 244 | */ |
245 | GNUNET_MESH_TunnelConnectHandler connect_handler; | 245 | GNUNET_MESH_PeerConnectHandler connect_handler; |
246 | 246 | ||
247 | /** | 247 | /** |
248 | * Callback to execute when peers disconnect from the tunnel | 248 | * Callback to execute when peers disconnect from the tunnel |
249 | */ | 249 | */ |
250 | GNUNET_MESH_TunnelDisconnectHandler disconnect_handler; | 250 | GNUNET_MESH_PeerDisconnectHandler disconnect_handler; |
251 | 251 | ||
252 | /** | 252 | /** |
253 | * Closure for the connect/disconnect handlers | 253 | * Closure for the connect/disconnect handlers |
@@ -380,7 +380,7 @@ destroy_tunnel (struct GNUNET_MESH_Tunnel *t) | |||
380 | 380 | ||
381 | if (NULL == t) | 381 | if (NULL == t) |
382 | { | 382 | { |
383 | GNUNET_break(0); | 383 | GNUNET_break (0); |
384 | return; | 384 | return; |
385 | } | 385 | } |
386 | h = t->mesh; | 386 | h = t->mesh; |
@@ -390,16 +390,16 @@ destroy_tunnel (struct GNUNET_MESH_Tunnel *t) | |||
390 | if (th->tunnel == t) | 390 | if (th->tunnel == t) |
391 | { | 391 | { |
392 | aux = th->next; | 392 | aux = th->next; |
393 | GNUNET_CONTAINER_DLL_remove(h->th_head, h->th_tail, th); | 393 | GNUNET_CONTAINER_DLL_remove (h->th_head, h->th_tail, th); |
394 | if (NULL == h->th_head && NULL != h->th) | 394 | if (NULL == h->th_head && NULL != h->th) |
395 | { | 395 | { |
396 | GNUNET_CLIENT_notify_transmit_ready_cancel(h->th); | 396 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); |
397 | h->th = NULL; | 397 | h->th = NULL; |
398 | } | 398 | } |
399 | if (NULL != th->notify) | 399 | if (NULL != th->notify) |
400 | th->notify(th->notify_cls, 0, NULL); | 400 | th->notify (th->notify_cls, 0, NULL); |
401 | if (GNUNET_SCHEDULER_NO_TASK != th->timeout_task) | 401 | if (GNUNET_SCHEDULER_NO_TASK != th->timeout_task) |
402 | GNUNET_SCHEDULER_cancel(th->timeout_task); | 402 | GNUNET_SCHEDULER_cancel (th->timeout_task); |
403 | GNUNET_free (th); | 403 | GNUNET_free (th); |
404 | th = aux; | 404 | th = aux; |
405 | } | 405 | } |
@@ -420,7 +420,7 @@ destroy_tunnel (struct GNUNET_MESH_Tunnel *t) | |||
420 | GNUNET_free (t->peers[i]); | 420 | GNUNET_free (t->peers[i]); |
421 | } | 421 | } |
422 | if (t->npeers > 0) | 422 | if (t->npeers > 0) |
423 | GNUNET_free (t->peers); | 423 | GNUNET_free (t->peers); |
424 | if (NULL != h->cleaner && 0 != t->owner) | 424 | if (NULL != h->cleaner && 0 != t->owner) |
425 | h->cleaner (h->cls, t, t->ctx); | 425 | h->cleaner (h->cls, t, t->ctx); |
426 | if (0 != t->owner) | 426 | if (0 != t->owner) |
@@ -608,9 +608,11 @@ reconnect (struct GNUNET_MESH_Handle *h) | |||
608 | h->client = GNUNET_CLIENT_connect ("mesh", h->cfg); | 608 | h->client = GNUNET_CLIENT_connect ("mesh", h->cfg); |
609 | if (h->client == NULL) | 609 | if (h->client == NULL) |
610 | { | 610 | { |
611 | GNUNET_SCHEDULER_add_delayed(h->reconnect_time, &reconnect_cbk, h); | 611 | GNUNET_SCHEDULER_add_delayed (h->reconnect_time, &reconnect_cbk, h); |
612 | h->reconnect_time = GNUNET_TIME_relative_min(GNUNET_TIME_UNIT_HOURS, | 612 | h->reconnect_time = |
613 | GNUNET_TIME_relative_multiply(h->reconnect_time, 2)); | 613 | GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_HOURS, |
614 | GNUNET_TIME_relative_multiply | ||
615 | (h->reconnect_time, 2)); | ||
614 | GNUNET_break (0); | 616 | GNUNET_break (0); |
615 | return GNUNET_NO; | 617 | return GNUNET_NO; |
616 | } | 618 | } |
@@ -668,9 +670,10 @@ static void | |||
668 | reconnect_cbk (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 670 | reconnect_cbk (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
669 | { | 671 | { |
670 | struct GNUNET_MESH_Handle *h = cls; | 672 | struct GNUNET_MESH_Handle *h = cls; |
673 | |||
671 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) | 674 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
672 | return; | 675 | return; |
673 | reconnect(h); | 676 | reconnect (h); |
674 | } | 677 | } |
675 | 678 | ||
676 | 679 | ||
@@ -686,7 +689,7 @@ reconnect_cbk (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
686 | */ | 689 | */ |
687 | static void | 690 | static void |
688 | process_tunnel_created (struct GNUNET_MESH_Handle *h, | 691 | process_tunnel_created (struct GNUNET_MESH_Handle *h, |
689 | const struct GNUNET_MESH_TunnelNotification *msg) | 692 | const struct GNUNET_MESH_TunnelNotification *msg) |
690 | { | 693 | { |
691 | struct GNUNET_MESH_Tunnel *t; | 694 | struct GNUNET_MESH_Tunnel *t; |
692 | struct GNUNET_TRANSPORT_ATS_Information atsi; | 695 | struct GNUNET_TRANSPORT_ATS_Information atsi; |
@@ -712,7 +715,7 @@ process_tunnel_created (struct GNUNET_MESH_Handle *h, | |||
712 | { | 715 | { |
713 | atsi.type = 0; | 716 | atsi.type = 0; |
714 | atsi.value = 0; | 717 | atsi.value = 0; |
715 | t->ctx = h->new_tunnel(h->cls, t, &msg->peer, &atsi); | 718 | t->ctx = h->new_tunnel (h->cls, t, &msg->peer, &atsi); |
716 | } | 719 | } |
717 | GNUNET_CONTAINER_DLL_insert (h->tunnels_head, h->tunnels_tail, t); | 720 | GNUNET_CONTAINER_DLL_insert (h->tunnels_head, h->tunnels_tail, t); |
718 | return; | 721 | return; |
@@ -737,15 +740,15 @@ process_tunnel_destroy (struct GNUNET_MESH_Handle *h, | |||
737 | 740 | ||
738 | if (NULL == t) | 741 | if (NULL == t) |
739 | { | 742 | { |
740 | GNUNET_break(0); | 743 | GNUNET_break (0); |
741 | return; | 744 | return; |
742 | } | 745 | } |
743 | if (0 == t->owner) | 746 | if (0 == t->owner) |
744 | { | 747 | { |
745 | GNUNET_break(0); | 748 | GNUNET_break (0); |
746 | } | 749 | } |
747 | 750 | ||
748 | destroy_tunnel(t); | 751 | destroy_tunnel (t); |
749 | return; | 752 | return; |
750 | } | 753 | } |
751 | 754 | ||
@@ -775,7 +778,7 @@ process_peer_event (struct GNUNET_MESH_Handle *h, | |||
775 | t = retrieve_tunnel (h, ntohl (msg->tunnel_id)); | 778 | t = retrieve_tunnel (h, ntohl (msg->tunnel_id)); |
776 | if (NULL == t) | 779 | if (NULL == t) |
777 | { | 780 | { |
778 | GNUNET_break(0); | 781 | GNUNET_break (0); |
779 | return; | 782 | return; |
780 | } | 783 | } |
781 | id = GNUNET_PEER_search (&msg->peer); | 784 | id = GNUNET_PEER_search (&msg->peer); |
@@ -854,7 +857,7 @@ process_incoming_data (struct GNUNET_MESH_Handle *h, | |||
854 | GNUNET_break (0); | 857 | GNUNET_break (0); |
855 | return; | 858 | return; |
856 | } | 859 | } |
857 | type = ntohs(payload->type); | 860 | type = ntohs (payload->type); |
858 | for (i = 0; i < h->n_handlers; i++) | 861 | for (i = 0; i < h->n_handlers; i++) |
859 | { | 862 | { |
860 | handler = &h->message_handlers[i]; | 863 | handler = &h->message_handlers[i]; |
@@ -969,9 +972,9 @@ send_callback (void *cls, size_t size, void *buf) | |||
969 | { | 972 | { |
970 | #if DEBUG | 973 | #if DEBUG |
971 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: type: %u\n", | 974 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: type: %u\n", |
972 | ntohs (((struct GNUNET_MessageHeader *)&th[1])->type)); | 975 | ntohs (((struct GNUNET_MessageHeader *) &th[1])->type)); |
973 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: size: %u\n", | 976 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: size: %u\n", |
974 | ntohs (((struct GNUNET_MessageHeader *)&th[1])->size)); | 977 | ntohs (((struct GNUNET_MessageHeader *) &th[1])->size)); |
975 | #endif | 978 | #endif |
976 | if (NULL != th->notify) | 979 | if (NULL != th->notify) |
977 | { | 980 | { |
@@ -988,7 +991,7 @@ send_callback (void *cls, size_t size, void *buf) | |||
988 | mc.header.size = htons (sizeof (mc) + th->size); | 991 | mc.header.size = htons (sizeof (mc) + th->size); |
989 | mc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST); | 992 | mc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST); |
990 | mc.tid = htonl (th->tunnel->tid); | 993 | mc.tid = htonl (th->tunnel->tid); |
991 | memset (&mc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); /* myself */ | 994 | memset (&mc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); |
992 | memcpy (cbuf, &mc, sizeof (mc)); | 995 | memcpy (cbuf, &mc, sizeof (mc)); |
993 | psize = th->size + sizeof (mc); | 996 | psize = th->size + sizeof (mc); |
994 | } | 997 | } |
@@ -1006,7 +1009,7 @@ send_callback (void *cls, size_t size, void *buf) | |||
1006 | uc.header.size = htons (sizeof (uc) + th->size); | 1009 | uc.header.size = htons (sizeof (uc) + th->size); |
1007 | uc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_UNICAST); | 1010 | uc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_UNICAST); |
1008 | uc.tid = htonl (th->tunnel->tid); | 1011 | uc.tid = htonl (th->tunnel->tid); |
1009 | memset (&uc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); /* myself */ | 1012 | memset (&uc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); |
1010 | GNUNET_PEER_resolve (th->target, &uc.destination); | 1013 | GNUNET_PEER_resolve (th->target, &uc.destination); |
1011 | memcpy (cbuf, &uc, sizeof (uc)); | 1014 | memcpy (cbuf, &uc, sizeof (uc)); |
1012 | psize = th->size + sizeof (uc); | 1015 | psize = th->size + sizeof (uc); |
@@ -1210,9 +1213,9 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) | |||
1210 | */ | 1213 | */ |
1211 | struct GNUNET_MESH_Tunnel * | 1214 | struct GNUNET_MESH_Tunnel * |
1212 | GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, void *tunnel_ctx, | 1215 | GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, void *tunnel_ctx, |
1213 | GNUNET_MESH_TunnelConnectHandler connect_handler, | 1216 | GNUNET_MESH_PeerConnectHandler connect_handler, |
1214 | GNUNET_MESH_TunnelDisconnectHandler | 1217 | GNUNET_MESH_PeerDisconnectHandler disconnect_handler, |
1215 | disconnect_handler, void *handler_cls) | 1218 | void *handler_cls) |
1216 | { | 1219 | { |
1217 | struct GNUNET_MESH_Tunnel *t; | 1220 | struct GNUNET_MESH_Tunnel *t; |
1218 | struct GNUNET_MESH_TunnelMessage msg; | 1221 | struct GNUNET_MESH_TunnelMessage msg; |
@@ -1237,21 +1240,21 @@ GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, void *tunnel_ctx, | |||
1237 | * @param tun tunnel handle | 1240 | * @param tun tunnel handle |
1238 | */ | 1241 | */ |
1239 | void | 1242 | void |
1240 | GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *t) | 1243 | GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel) |
1241 | { | 1244 | { |
1242 | struct GNUNET_MESH_Handle *h; | 1245 | struct GNUNET_MESH_Handle *h; |
1243 | struct GNUNET_MESH_TunnelMessage msg; | 1246 | struct GNUNET_MESH_TunnelMessage msg; |
1244 | 1247 | ||
1245 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n"); | 1248 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n"); |
1246 | h = t->mesh; | 1249 | h = tunnel->mesh; |
1247 | 1250 | ||
1248 | if (0 != t->owner) | 1251 | if (0 != tunnel->owner) |
1249 | GNUNET_PEER_change_rc (t->owner, -1); | 1252 | GNUNET_PEER_change_rc (tunnel->owner, -1); |
1250 | 1253 | ||
1251 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); | 1254 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); |
1252 | msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); | 1255 | msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); |
1253 | msg.tunnel_id = htonl (t->tid); | 1256 | msg.tunnel_id = htonl (tunnel->tid); |
1254 | destroy_tunnel (t); | 1257 | destroy_tunnel (tunnel); |
1255 | send_packet (h, &msg.header); | 1258 | send_packet (h, &msg.header); |
1256 | } | 1259 | } |
1257 | 1260 | ||
@@ -1401,7 +1404,7 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, | |||
1401 | uint32_t least_priority; | 1404 | uint32_t least_priority; |
1402 | size_t overhead; | 1405 | size_t overhead; |
1403 | 1406 | ||
1404 | GNUNET_assert(NULL != notify); | 1407 | GNUNET_assert (NULL != notify); |
1405 | if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size && | 1408 | if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size && |
1406 | tunnel->npackets > 0) | 1409 | tunnel->npackets > 0) |
1407 | { | 1410 | { |
@@ -1422,16 +1425,16 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, | |||
1422 | } | 1425 | } |
1423 | if (NULL == least_priority_th) | 1426 | if (NULL == least_priority_th) |
1424 | return NULL; | 1427 | return NULL; |
1425 | GNUNET_assert(NULL != least_priority_th->notify); /* Cant be a cntrl msg */ | 1428 | /* Can't be a control message */ |
1426 | least_priority_th->notify(notify_cls, 0, NULL); | 1429 | GNUNET_assert (NULL != least_priority_th->notify); |
1430 | least_priority_th->notify (notify_cls, 0, NULL); | ||
1427 | least_priority_th->tunnel->npackets--; | 1431 | least_priority_th->tunnel->npackets--; |
1428 | tunnel->mesh->npackets--; | 1432 | tunnel->mesh->npackets--; |
1429 | GNUNET_CONTAINER_DLL_remove(tunnel->mesh->th_head, | 1433 | GNUNET_CONTAINER_DLL_remove (tunnel->mesh->th_head, tunnel->mesh->th_tail, |
1430 | tunnel->mesh->th_tail, | 1434 | least_priority_th); |
1431 | least_priority_th); | ||
1432 | if (GNUNET_SCHEDULER_NO_TASK != least_priority_th->timeout_task) | 1435 | if (GNUNET_SCHEDULER_NO_TASK != least_priority_th->timeout_task) |
1433 | GNUNET_SCHEDULER_cancel(least_priority_th->timeout_task); | 1436 | GNUNET_SCHEDULER_cancel (least_priority_th->timeout_task); |
1434 | GNUNET_free(least_priority_th); | 1437 | GNUNET_free (least_priority_th); |
1435 | } | 1438 | } |
1436 | tunnel->npackets++; | 1439 | tunnel->npackets++; |
1437 | tunnel->mesh->npackets++; | 1440 | tunnel->mesh->npackets++; |
@@ -1440,10 +1443,10 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, | |||
1440 | th->priority = priority; | 1443 | th->priority = priority; |
1441 | th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay); | 1444 | th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay); |
1442 | th->target = GNUNET_PEER_intern (target); | 1445 | th->target = GNUNET_PEER_intern (target); |
1443 | overhead = | 1446 | if (NULL == target) |
1444 | (NULL == | 1447 | overhead = sizeof (struct GNUNET_MESH_Multicast); |
1445 | target) ? sizeof (struct GNUNET_MESH_Multicast) : sizeof (struct | 1448 | else |
1446 | GNUNET_MESH_Unicast); | 1449 | overhead = sizeof (struct GNUNET_MESH_Unicast); |
1447 | th->size = notify_size + overhead; | 1450 | th->size = notify_size + overhead; |
1448 | th->notify = notify; | 1451 | th->notify = notify; |
1449 | th->notify_cls = notify_cls; | 1452 | 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) | |||
121 | GNUNET_MESH_tunnel_destroy (t); | 121 | GNUNET_MESH_tunnel_destroy (t); |
122 | } | 122 | } |
123 | 123 | ||
124 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown, | 124 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown, NULL); |
125 | NULL); | ||
126 | } | 125 | } |
127 | 126 | ||
128 | 127 | ||
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; | |||
41 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; | 41 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; |
42 | static GNUNET_SCHEDULER_TaskIdentifier test_task; | 42 | static GNUNET_SCHEDULER_TaskIdentifier test_task; |
43 | 43 | ||
44 | static struct GNUNET_MESH_MessageHandler handlers1[] = { | ||
45 | {&callback, 1, 0}, | ||
46 | {NULL, 0, 0} | ||
47 | }; | ||
48 | |||
49 | static struct GNUNET_MESH_MessageHandler handlers2[] = { {NULL, 0, 0} }; | ||
50 | |||
51 | |||
52 | |||
44 | /** | 53 | /** |
45 | * Function is called whenever a message is received. | 54 | * Function is called whenever a message is received. |
46 | * | 55 | * |
@@ -59,15 +68,37 @@ callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx, | |||
59 | const struct GNUNET_MessageHeader *message, | 68 | const struct GNUNET_MessageHeader *message, |
60 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 69 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
61 | { | 70 | { |
71 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Data callback\n"); | ||
62 | return GNUNET_OK; | 72 | return GNUNET_OK; |
63 | } | 73 | } |
64 | 74 | ||
65 | static struct GNUNET_MESH_MessageHandler handlers1[] = { | ||
66 | {&callback, 1, 0}, | ||
67 | {NULL, 0, 0} | ||
68 | }; | ||
69 | 75 | ||
70 | static struct GNUNET_MESH_MessageHandler handlers2[] = {{NULL, 0, 0}}; | 76 | /** |
77 | * Method called whenever another peer has added us to a tunnel | ||
78 | * the other peer initiated. | ||
79 | * | ||
80 | * @param cls closure | ||
81 | * @param tunnel new handle to the tunnel | ||
82 | * @param initiator peer that started the tunnel | ||
83 | * @param atsi performance information for the tunnel | ||
84 | * @return initial tunnel context for the tunnel (can be NULL -- that's not an error) | ||
85 | */ | ||
86 | static void * | ||
87 | inbound_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel, | ||
88 | const struct GNUNET_PeerIdentity *initiator, | ||
89 | const structGNUNET_TRANSPORT_ATS_Information * atsi) | ||
90 | { | ||
91 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: \n"); | ||
92 | return NULL; | ||
93 | } | ||
94 | |||
95 | |||
96 | |||
97 | |||
98 | |||
99 | |||
100 | |||
101 | |||
71 | 102 | ||
72 | 103 | ||
73 | static void | 104 | static void |
@@ -116,8 +147,7 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
116 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 147 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
117 | static const GNUNET_MESH_ApplicationType app1[] = | 148 | static const GNUNET_MESH_ApplicationType app1[] = |
118 | { 1, 2, 3, 4, 5, 6, 7, 8, 0 }; | 149 | { 1, 2, 3, 4, 5, 6, 7, 8, 0 }; |
119 | static const GNUNET_MESH_ApplicationType app2[] = | 150 | static const GNUNET_MESH_ApplicationType app2[] = { 0 }; |
120 | { 0 }; | ||
121 | 151 | ||
122 | test_task = (GNUNET_SCHEDULER_TaskIdentifier) 0; | 152 | test_task = (GNUNET_SCHEDULER_TaskIdentifier) 0; |
123 | mesh_peer_1 = GNUNET_MESH_connect (cfg, 10, 1, NULL, NULL, handlers1, app1); | 153 | 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) | |||
135 | t_1 = GNUNET_MESH_tunnel_create (mesh_peer_1, NULL, NULL, NULL, 1); | 165 | t_1 = GNUNET_MESH_tunnel_create (mesh_peer_1, NULL, NULL, NULL, 1); |
136 | // t_2 = GNUNET_MESH_tunnel_create (mesh_peer_2, NULL, NULL, NULL, 2); | 166 | // t_2 = GNUNET_MESH_tunnel_create (mesh_peer_2, NULL, NULL, NULL, 2); |
137 | 167 | ||
138 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( | 168 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
139 | GNUNET_TIME_UNIT_SECONDS, | 169 | (GNUNET_TIME_UNIT_SECONDS, 2), &do_shutdown, |
140 | 2), | ||
141 | &do_shutdown, | ||
142 | NULL); | 170 | NULL); |
143 | } | 171 | } |
144 | 172 | ||