From: Bart Polot Date: Wed, 31 Aug 2011 22:21:25 +0000 (+0000) Subject: WiP X-Git-Tag: initial-import-from-subversion-38251~17259 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=0f0f0759a16b5367757b78d9764902ac916fb689;p=oweals%2Fgnunet.git WiP --- diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index 5ea4789b8..615593621 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c @@ -200,6 +200,7 @@ send_hello_message (void *cls, size_t size, void *buf) struct peer_list_element *element = cls; struct GNUNET_MESH_Handle *handle = element->handle; + element->hello = NULL; struct GNUNET_MessageHeader *hdr = buf; @@ -216,22 +217,30 @@ send_hello_message (void *cls, size_t size, void *buf) return sent; } -void schedule_hello_message(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tctx) +void +schedule_hello_message (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tctx) { struct peer_list_element *element = cls; + element->sched = GNUNET_SCHEDULER_NO_TASK; if ((tctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) - return; + return; if (element->hello == NULL) - element->hello = GNUNET_CORE_notify_transmit_ready (element->handle->core, GNUNET_NO, 42, - GNUNET_TIME_UNIT_SECONDS, &element->peer, - sizeof (struct GNUNET_MessageHeader) + - element->handle->hello_message_size, - &send_hello_message, element); - - element->sched = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, schedule_hello_message, cls); + element->hello = + GNUNET_CORE_notify_transmit_ready (element->handle->core, GNUNET_NO, 42, + GNUNET_TIME_UNIT_SECONDS, + &element->peer, + sizeof (struct GNUNET_MessageHeader) + + + element->handle->hello_message_size, + &send_hello_message, element); + + element->sched = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, + schedule_hello_message, cls); } @@ -257,7 +266,7 @@ core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, element->handle = handle; /* Send a hello to this peer */ - element->sched = GNUNET_SCHEDULER_add_now(schedule_hello_message, element); + element->sched = GNUNET_SCHEDULER_add_now (schedule_hello_message, element); if (NULL != atsi) memcpy (&element->atsi, atsi, @@ -327,8 +336,8 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) tail); GNUNET_free (tail); } - GNUNET_CORE_notify_transmit_ready_cancel(element->hello); - GNUNET_SCHEDULER_cancel(element->sched); + GNUNET_CORE_notify_transmit_ready_cancel (element->hello); + GNUNET_SCHEDULER_cancel (element->sched); GNUNET_free (element); } @@ -885,8 +894,8 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) tail); GNUNET_free (tail); } - GNUNET_CORE_notify_transmit_ready_cancel(element->hello); - GNUNET_SCHEDULER_cancel(element->sched); + GNUNET_CORE_notify_transmit_ready_cancel (element->hello); + GNUNET_SCHEDULER_cancel (element->sched); GNUNET_free (element); element = next; } @@ -912,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 23ade2379..cd385b01d 100644 --- a/src/mesh/mesh_api_new.c +++ b/src/mesh/mesh_api_new.c @@ -651,8 +651,8 @@ send_raw (void *cls, size_t size, void *buf) /** * Auxiliary function to send an already constructed packet to the service. - * Takes care of creating a new queue element and calling the tmt_rdy function - * if necessary. + * Takes care of creating a new queue element, copying the message and + * calling the tmt_rdy function if necessary. * @param h mesh handle * @param msg message to transmit */ @@ -732,12 +732,14 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, h->message_handlers = handlers; h->applications = stypes; h->next_tid = GNUNET_MESH_LOCAL_TUNNEL_ID_MARK; + /* count handlers and apps, calculate size */ for (h->n_handlers = 0; handlers[h->n_handlers].type; h->n_handlers++) ; for (h->n_applications = 0; stypes[h->n_applications]; h->n_applications++) ; size = sizeof (struct GNUNET_MESH_ClientConnect); size += h->n_handlers * sizeof (uint16_t); size += h->n_applications * sizeof (GNUNET_MESH_ApplicationType); + { char buf[size]; @@ -826,16 +828,16 @@ void GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tun) { struct GNUNET_MESH_Handle *h; - struct GNUNET_MESH_TunnelMessage *msg; + struct GNUNET_MESH_TunnelMessage msg; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n"); h = tun->mesh; - msg = GNUNET_malloc (sizeof (struct GNUNET_MESH_TunnelMessage)); - msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); - msg->header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); - msg->tunnel_id = htonl (tun->tid); + + msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); + msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); + msg.tunnel_id = htonl (tun->tid); GNUNET_free (tun); - send_packet (h, &msg->header); + send_packet (h, &msg.header); } @@ -852,7 +854,7 @@ GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel, struct GNUNET_TIME_Relative timeout, const struct GNUNET_PeerIdentity *peer) { - struct GNUNET_MESH_PeerControl *msg; + struct GNUNET_MESH_PeerControl msg; GNUNET_PEER_Id peer_id; unsigned int i; @@ -870,14 +872,14 @@ GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel, tunnel->peers = GNUNET_realloc (tunnel->peers, tunnel->npeers * sizeof (GNUNET_PEER_Id)); tunnel->peers[tunnel->npeers - 1] = peer_id; - msg = GNUNET_malloc (sizeof (struct GNUNET_MESH_PeerControl)); - msg->header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); - msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD); - msg->tunnel_id = htonl (tunnel->tid); - msg->timeout = + + msg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); + msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD); + msg.tunnel_id = htonl (tunnel->tid); + msg.timeout = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (timeout)); - memcpy (&msg->peer, peer, sizeof (struct GNUNET_PeerIdentity)); - send_packet (tunnel->mesh, &msg->header); + msg.peer = *peer; + send_packet (tunnel->mesh, &msg.header); // tunnel->connect_handler (tunnel->cls, peer, NULL); FIXME call this later // TODO: remember timeout return;